List of usage examples for java.net URI getQuery
public String getQuery()
From source file:org.soyatec.windowsazure.internal.MessageCanonicalizer.java
private static String getCanonicalizedResource(URI address, ResourceUriComponents uriComponents) { // Algorithem is as follows // 1. Start with the empty string ("") // 2. Append the account name owning the resource preceded by a /. This // is not// www .j a va 2s . co m // the name of the account making the request but the account that owns // the // resource being accessed. // 3. Append the path part of the un-decoded HTTP Request-URI, up-to but // not // including the query string. // 4. If the request addresses a particular component of a resource, // like?comp= // metadata then append the sub-resource including question mark (like // ?comp= // metadata) StringBuilder canonicalizedResource = new StringBuilder(ConstChars.Slash); canonicalizedResource.append(uriComponents.getAccountName()); // Note that AbsolutePath starts with a '/' String path = address.getRawPath(); // path = path.replaceAll(" ", "%20"); // path = java.net.URLEncoder.encode(path); canonicalizedResource.append(path); NameValueCollection queryVariables = HttpUtilities.parseQueryString(address.getQuery()); String compQueryParameterValue = queryVariables.getSingleValue(QueryParams.QueryParamComp); if (compQueryParameterValue != null) { canonicalizedResource.append(ConstChars.QuestionMark); canonicalizedResource.append(QueryParams.QueryParamComp); canonicalizedResource.append(QueryParams.SeparatorForParameterAndValue); canonicalizedResource.append(compQueryParameterValue); } return canonicalizedResource.toString(); }
From source file:com.predic8.membrane.core.interceptor.administration.AdministrationInterceptor.java
private Map<String, String> getParams(Exchange exc) throws Exception { URI jUri = new URI(exc.getOriginalRequestUri()); String q = jUri.getQuery(); if (q == null) { if (hasNoFormParams(exc)) return new HashMap<String, String>(); q = new String(exc.getRequest().getBody().getRaw());// TODO // getBody().toString() // doesn't work. }//w w w. j a v a 2 s .co m return parseQueryString(q); }
From source file:com.zhm.config.MyAuthorizationCodeAccessTokenProvider.java
public String obtainAuthorizationCode(OAuth2ProtectedResourceDetails details, AccessTokenRequest request) throws UserRedirectRequiredException, UserApprovalRequiredException, AccessDeniedException, OAuth2AccessDeniedException { AuthorizationCodeResourceDetails resource = (AuthorizationCodeResourceDetails) details; HttpHeaders headers = getHeadersForAuthorizationRequest(request); MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>(); if (request.containsKey(OAuth2Utils.USER_OAUTH_APPROVAL)) { form.set(OAuth2Utils.USER_OAUTH_APPROVAL, request.getFirst(OAuth2Utils.USER_OAUTH_APPROVAL)); for (String scope : details.getScope()) { form.set(scopePrefix + scope, request.getFirst(OAuth2Utils.USER_OAUTH_APPROVAL)); }/*from www . j a v a2 s. c o m*/ } else { form.putAll(getParametersForAuthorizeRequest(resource, request)); } authorizationRequestEnhancer.enhance(request, resource, form, headers); final AccessTokenRequest copy = request; final ResponseExtractor<ResponseEntity<Void>> delegate = getAuthorizationResponseExtractor(); ResponseExtractor<ResponseEntity<Void>> extractor = new ResponseExtractor<ResponseEntity<Void>>() { @Override public ResponseEntity<Void> extractData(ClientHttpResponse response) throws IOException { if (response.getHeaders().containsKey("Set-Cookie")) { copy.setCookie(response.getHeaders().getFirst("Set-Cookie")); } return delegate.extractData(response); } }; // Instead of using restTemplate.exchange we use an explicit response extractor here so it can be overridden by // subclasses ResponseEntity<Void> response = getRestTemplate().execute(resource.getUserAuthorizationUri(), HttpMethod.POST, getRequestCallback(resource, form, headers), extractor, form.toSingleValueMap()); if (response.getStatusCode() == HttpStatus.OK) { // Need to re-submit with approval... throw getUserApprovalSignal(resource, request); } URI location = response.getHeaders().getLocation(); String query = location.getQuery(); Map<String, String> map = OAuth2Utils.extractMap(query); if (map.containsKey("state")) { request.setStateKey(map.get("state")); if (request.getPreservedState() == null) { String redirectUri = resource.getRedirectUri(request); if (redirectUri != null) { request.setPreservedState(redirectUri); } else { request.setPreservedState(new Object()); } } } String code = map.get("code"); if (code == null) { throw new UserRedirectRequiredException(location.toString(), form.toSingleValueMap()); } request.set("code", code); return code; }
From source file:org.apache.servicemix.http.HttpComponent.java
protected Endpoint getResolvedEPR(ServiceEndpoint ep) throws Exception { // We receive an exchange for an EPR that has not been used yet. // Register a provider endpoint and restart processing. HttpEndpoint httpEp = new HttpEndpoint(true); httpEp.setServiceUnit(new DefaultServiceUnit(component)); httpEp.setService(ep.getServiceName()); httpEp.setEndpoint(ep.getEndpointName()); httpEp.setRole(MessageExchange.Role.PROVIDER); URI uri = new URI(ep.getEndpointName()); Map map = URISupport.parseQuery(uri.getQuery()); if (IntrospectionSupport.setProperties(httpEp, map, "http.")) { uri = URISupport.createRemainingURI(uri, map); }/*from w w w .ja v a2 s .co m*/ if (httpEp.getLocationURI() == null) { httpEp.setLocationURI(uri.toString()); } return httpEp; }
From source file:de.zib.sfs.StatisticsFileSystem.java
static Path setAuthority(Path path, String authority) { if (authority != null) { URI pathUri = path.toUri(); String query = pathUri.getQuery(); String fragment = pathUri.getFragment(); return new Path(URI.create(pathUri.getScheme() + "://" + authority + "/" + pathUri.getPath() + (query != null ? ("?" + query) : "")) + (fragment != null ? ("#" + fragment) : "")); }// w w w .j a va2 s . c om return path; }
From source file:io.orchestrate.client.RelationResource.java
/** * Fetch objects related to a key in the Orchestrate service. * * <p>Usage:</p>//from www . j a va 2s . co m * <pre> * {@code * RelationList<String> relatedObjects = * client.relation("someCollection", "someKey") * .get(String.class, "someKind") * .get(); * } * </pre> * * @param clazz Type information for deserializing to type {@code T} at * runtime. * @param kinds The name of the relationships to traverse to the related * objects. * @param <T> The type to deserialize the response from the request to. * @return A prepared get request. */ public <T> OrchestrateRequest<RelationList<T>> get(final Class<T> clazz, final String... kinds) { checkNotNull(clazz, "clazz"); checkArgument(destCollection == null && destKey == null, "'destCollection' and 'destKey' not valid in GET query."); checkNoneEmpty(kinds, "kinds", "kind"); final String uri = client.uri(sourceCollection, sourceKey, "relations").concat("/" + client.encode(kinds)); final String query = "limit=".concat(limit + "").concat("&offset=").concat(offset + ""); final HttpContent packet = HttpRequestPacket.builder().method(Method.GET).uri(uri).query(query).build() .httpContentBuilder().build(); return new OrchestrateRequest<RelationList<T>>(client, packet, new ResponseConverter<RelationList<T>>() { @Override public RelationList<T> from(final HttpContent response) throws IOException { final int status = ((HttpResponsePacket) response.getHttpHeader()).getStatus(); assert (status == 200 || status == 404); if (status == 404) { return null; } final JsonNode jsonNode = toJsonNode(response); final OrchestrateRequest<RelationList<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<RelationList<T>>(client, packet, this, false); } else { next = null; } final int count = jsonNode.path("count").asInt(); final List<KvObject<T>> relatedObjects = new ArrayList<KvObject<T>>(count); for (JsonNode node : jsonNode.path("results")) { relatedObjects.add(toKvObject(node, clazz)); } return new RelationList<T>(relatedObjects, next); } }); }
From source file:org.kie.commons.java.nio.fs.jgit.JGitFileSystemProvider.java
private static Map<String, String> getQueryParams(final URI uri) { final String[] params = uri.getQuery().split("&"); return new HashMap<String, String>(params.length) { {//w w w. j av a2s.c o m for (String param : params) { final String[] kv = param.split("="); final String name = kv[0]; final String value; if (kv.length == 2) { value = kv[1]; } else { value = ""; } put(name, value); } } }; }
From source file:edu.wisc.ws.client.support.DestinationOverridingWebServiceTemplate.java
@Override public String getDefaultUri() { final DestinationProvider destinationProvider = this.getDestinationProvider(); if (destinationProvider != null) { final URI uri = destinationProvider.getDestination(); if (uri == null) { return null; }/*www. java2 s.c o m*/ if (portOverride == null) { return uri.toString(); } final URI overridenUri; try { overridenUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), portOverride, uri.getPath(), uri.getQuery(), uri.getFragment()); } catch (URISyntaxException e) { this.logger.error("Could not override port on URI " + uri + " to " + portOverride, e); return uri.toString(); } return overridenUri.toString(); } return null; }
From source file:com.qwazr.utils.json.client.JsonClientAbstract.java
protected JsonClientAbstract(String url, Integer msTimeOut, Credentials credentials) throws URISyntaxException { this.url = url; URI u = new URI(url); String path = u.getPath();//from ww w .j a v a 2 s .c o m if (path != null && path.endsWith("/")) u = new URI(u.getScheme(), null, u.getHost(), u.getPort(), path.substring(0, path.length() - 1), u.getQuery(), u.getFragment()); this.scheme = u.getScheme() == null ? "http" : u.getScheme(); this.host = u.getHost(); this.fragment = u.getFragment(); this.path = u.getPath(); this.port = u.getPort() == -1 ? 80 : u.getPort(); this.timeout = msTimeOut == null ? DEFAULT_TIMEOUT : msTimeOut; this.executor = credentials == null ? Executor.newInstance() : Executor.newInstance().auth(credentials); }
From source file:com.tasktop.c2c.server.ssh.server.commands.AbstractInteractiveProxyCommand.java
private void emitHttpRequestLine(OutputStream proxyOut, URI targetUri) throws IOException { if (targetUri.getQuery() != null) { // not supported throw new IllegalStateException(); }/* w w w .j a va2 s . c o m*/ String requestLine = "POST " + targetUri.getPath() + " HTTP/1.1\r\n"; proxyOut.write(requestLine.getBytes(HTTP_ENTITY_CHARSET)); }