List of usage examples for java.net URI getQuery
public String getQuery()
From source file:org.eclipse.orion.internal.server.servlets.workspace.ProjectParentDecorator.java
private void addParents(URI resource, JSONObject representation, ProjectInfo project, IPath resourcePath) throws JSONException { //start at parent of current resource resourcePath = resourcePath.removeLastSegments(1).addTrailingSeparator(); JSONArray parents = new JSONArray(); //for all but the project we can just manipulate the path to get the name and location while (resourcePath.segmentCount() > 2) { try {//from www. j a v a2 s. com URI uri = resource.resolve(new URI(null, null, resourcePath.toString(), null)); addParent(parents, resourcePath.lastSegment(), new URI(resource.getScheme(), resource.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment())); } catch (URISyntaxException e) { //ignore this parent LogHelper.log(e); } resourcePath = resourcePath.removeLastSegments(1); } //add the project if (resourcePath.segmentCount() == 2) { try { URI uri = resource.resolve(new URI(null, null, resourcePath.toString(), null)); addParent(parents, project.getFullName(), new URI(resource.getScheme(), resource.getAuthority(), uri.getPath(), uri.getQuery(), uri.getFragment())); } catch (URISyntaxException e) { //ignore this project LogHelper.log(e); } } representation.put(ProtocolConstants.KEY_PARENTS, parents); }
From source file:org.opencms.pdftools.CmsPdfUserAgent.java
/** * Reads an image from the VFS, scaling it if necessary.<p> * * @param uriWithParams the image uri, possible with scaling parameter * * @return the image data/*w w w . j a v a 2 s . co m*/ */ private byte[] readImage(String uriWithParams) { try { String pathAndQuery = OpenCms.getLinkManager().getRootPath(m_cms, uriWithParams); URI uri = new URI(pathAndQuery); String path = uri.getPath(); String query = uri.getQuery(); String scaleParams = null; if (query != null) { Matcher matcher = SCALE_PARAMS_PATTERN.matcher(query); if (matcher.find()) { scaleParams = matcher.group(1); } } CmsFile imageFile = m_rootCms.readFile(path); byte[] result = imageFile.getContents(); if (scaleParams != null) { CmsImageScaler scaler = new CmsImageScaler(scaleParams); result = scaler.scaleImage(imageFile); } return result; } catch (Exception e) { LOG.error("Problem with reading image " + uriWithParams + ": " + e.getLocalizedMessage(), e); return null; } }
From source file:com.esri.geoportal.commons.http.BotsHttpClient.java
private String getRelativePath(URI u) throws MalformedURLException { return String.format("%s%s%s", u.getPath() != null ? u.getPath() : "/", u.getQuery() != null ? "?" + u.getQuery() : "", u.getFragment() != null ? "#" + u.getFragment() : ""); }
From source file:org.deri.any23.http.DefaultHTTPClient.java
/** * * Opens an {@link java.io.InputStream} from a given URI. * It follows redirects./*from w w w. java 2 s . com*/ * * @param uri to be opened * @return {@link java.io.InputStream} * @throws IOException */ public InputStream openInputStream(String uri) throws IOException { GetMethod method = null; try { ensureClientInitialized(); String uriStr = null; try { URI uriObj = new URI(uri); // [scheme:][//authority][path][?query][#fragment] final String path = uriObj.getPath(); final String query = uriObj.getQuery(); final String fragment = uriObj.getFragment(); uriStr = String .format("%s://%s%s%s%s%s%s", uriObj.getScheme(), uriObj.getAuthority(), path != null ? URLEncoder.encode(path, "UTF-8").replaceAll("%2F", "/") : "", query == null ? "" : "?", query != null ? URLEncoder.encode(query, "UTF-8").replaceAll("%3D", "=") .replaceAll("%26", "&") : "", fragment == null ? "" : "#", fragment != null ? URLEncoder.encode(fragment, "UTF-8") : ""); } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid URI string.", e); } method = new GetMethod(uriStr); method.setFollowRedirects(true); client.executeMethod(method); _contentLength = method.getResponseContentLength(); final Header contentTypeHeader = method.getResponseHeader("Content-Type"); contentType = contentTypeHeader == null ? null : contentTypeHeader.getValue(); if (method.getStatusCode() != 200) { throw new IOException( "Failed to fetch " + uri + ": " + method.getStatusCode() + " " + method.getStatusText()); } actualDocumentURI = method.getURI().toString(); byte[] response = method.getResponseBody(); return new ByteArrayInputStream(response); } finally { if (method != null) { method.releaseConnection(); } } }
From source file:nl.esciencecenter.octopus.webservice.job.OctopusManager.java
/** * Submit a job request.// ww w .j a v a 2 s . com * * @param request The job request * @param httpClient http client used to reporting status to job callback. * @return SandboxedJob job * * @throws OctopusIOException * @throws OctopusException * @throws URISyntaxException */ public SandboxedJob submitJob(JobSubmitRequest request, HttpClient httpClient) throws OctopusIOException, OctopusException, URISyntaxException { Credential credential = configuration.getCredential(); // filesystems cant have path in them so strip eg. file:///tmp to file:/// URI s = configuration.getSandboxRoot(); URI sandboxURI = new URI(s.getScheme(), s.getUserInfo(), s.getHost(), s.getPort(), "/", s.getQuery(), s.getFragment()); //create sandbox FileSystem sandboxFS = octopus.files().newFileSystem(sandboxURI, credential, null); String sandboxRoot = configuration.getSandboxRoot().getPath(); AbsolutePath sandboxRootPath = octopus.files().newPath(sandboxFS, new RelativePath(sandboxRoot)); Sandbox sandbox = request.toSandbox(octopus, sandboxRootPath, null); // create job description JobDescription description = request.toJobDescription(); description.setQueueName(configuration.getQueue()); description.setWorkingDirectory(sandbox.getPath().getPath()); long cancelTimeout = configuration.getPollConfiguration().getCancelTimeout(); // CancelTimeout is in milliseconds and MaxTime must be in minutes, so convert it int maxTime = (int) TimeUnit.MINUTES.convert(cancelTimeout, TimeUnit.MILLISECONDS); description.setMaxTime(maxTime); // stage input files sandbox.upload(); // submit job Job job = octopus.jobs().submitJob(scheduler, description); // store job in jobs map SandboxedJob sjob = new SandboxedJob(sandbox, job, request, httpClient); jobs.put(sjob.getIdentifier(), sjob); // JobsPoller will poll job status and download sandbox when job is done. return sjob; }
From source file:org.xwiki.url.ExtendedURL.java
private Map<String, List<String>> extractParameters(URI uri) { Map<String, List<String>> uriParameters; if (uri.getQuery() != null) { uriParameters = new LinkedHashMap<>(); for (String nameValue : Arrays.asList(uri.getQuery().split("&"))) { String[] pair = nameValue.split("=", 2); // Check if the parameter has a value or not. if (pair.length == 2) { addParameter(pair[0], pair[1], uriParameters); } else { addParameter(pair[0], null, uriParameters); }/* w ww. j ava2 s.c o m*/ } } else { uriParameters = Collections.emptyMap(); } return uriParameters; }
From source file:org.apache.any23.http.DefaultHTTPClient.java
/** * * Opens an {@link java.io.InputStream} from a given URI. * It follows redirects./*from w w w.jav a2 s . c om*/ * * @param uri to be opened * @return {@link java.io.InputStream} * @throws IOException */ public InputStream openInputStream(String uri) throws IOException { GetMethod method = null; try { ensureClientInitialized(); String uriStr; try { URI uriObj = new URI(uri); // [scheme:][//authority][path][?query][#fragment] final String path = uriObj.getPath(); final String query = uriObj.getQuery(); final String fragment = uriObj.getFragment(); uriStr = String .format("%s://%s%s%s%s%s%s", uriObj.getScheme(), uriObj.getAuthority(), path != null ? URLEncoder.encode(path, "UTF-8").replaceAll("%2F", "/") : "", query == null ? "" : "?", query != null ? URLEncoder.encode(query, "UTF-8").replaceAll("%3D", "=") .replaceAll("%26", "&") : "", fragment == null ? "" : "#", fragment != null ? URLEncoder.encode(fragment, "UTF-8") : ""); } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid URI string.", e); } method = new GetMethod(uriStr); method.setFollowRedirects(true); client.executeMethod(method); _contentLength = method.getResponseContentLength(); final Header contentTypeHeader = method.getResponseHeader("Content-Type"); contentType = contentTypeHeader == null ? null : contentTypeHeader.getValue(); if (method.getStatusCode() != 200) { throw new IOException( "Failed to fetch " + uri + ": " + method.getStatusCode() + " " + method.getStatusText()); } actualDocumentURI = method.getURI().toString(); byte[] response = method.getResponseBody(); return new ByteArrayInputStream(response); } finally { if (method != null) { method.releaseConnection(); } } }
From source file:io.orchestrate.client.KvListResource.java
/** * Fetch a paginated, lexicographically ordered list of items contained in a * collection.// w w w . ja va 2 s. c om * * <p>Usage:</p> * <pre> * {@code * KvList<String> objects = * client.listCollection("someCollection") * .limit(10) * .get(String.class) * .get(); * } * </pre> * * @param clazz Type information for marshalling objects at runtime. * @param <T> The type to deserialize the result of the request to. * @return The prepared get request. */ public <T> OrchestrateRequest<KvList<T>> get(final @NonNull Class<T> clazz) { checkArgument(!inclusive || startKey != null, "'inclusive' requires 'startKey' for request."); final String uri = client.uri(collection); String query = "limit=".concat(Integer.toString(limit)); query = query.concat("&values=").concat(Boolean.toString(withValues)); if (startKey != null) { final String keyName = (inclusive) ? "startKey" : "afterKey"; query = query.concat('&' + keyName + '=').concat(client.encode(startKey)); } final HttpContent packet = HttpRequestPacket.builder().method(Method.GET).uri(uri).query(query).build() .httpContentBuilder().build(); return new OrchestrateRequest<KvList<T>>(client, packet, new ResponseConverter<KvList<T>>() { @Override public KvList<T> from(final HttpContent response) throws IOException { final int status = ((HttpResponsePacket) response.getHttpHeader()).getStatus(); assert (status == 200); final JsonNode jsonNode = toJsonNode(response); final OrchestrateRequest<KvList<T>> next; if (jsonNode.has("next")) { final String page = jsonNode.get("next").asText(); final URI url = URI.create(page); final HttpContent packet = HttpRequestPacket.builder().method(Method.GET).uri(uri) .query(url.getQuery()).build().httpContentBuilder().build(); next = new OrchestrateRequest<KvList<T>>(client, packet, this, false); } else { next = null; } final int count = jsonNode.get("count").asInt(); final List<KvObject<T>> results = new ArrayList<KvObject<T>>(count); final Iterator<JsonNode> iter = jsonNode.get("results").elements(); while (iter.hasNext()) { results.add(toKvObject(iter.next(), clazz)); } return new KvList<T>(results, count, next); } }); }
From source file:com.microsoft.windowsazure.messaging.Connection.java
/** * Adds the API Version querystring parameter to a URL * @param url The URL to modify/*from ww w . j ava 2 s. co m*/ * @return The modified URL */ private String AddApiVersionToUrl(String url) { URI uri = URI.create(url); if (uri.getQuery() == null) { url = url + "?"; } else { url = url + "&"; } url = url + API_VERSION_KEY + "=" + API_VERSION; return url; }
From source file:org.mobicents.servlet.sip.restcomm.interpreter.http.HttpRequestDescriptor.java
public HttpRequestDescriptor(final URI uri, final String method, final List<NameValuePair> parameters) throws UnsupportedEncodingException, URISyntaxException { super();/*from w ww.j a v a 2 s . c om*/ this.uri = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), null, null); this.method = method; final String query = uri.getQuery(); if (query != null) { parameters.addAll(URLEncodedUtils.parse(uri, "UTF-8")); } this.parameters = parameters; }