List of usage examples for java.net URI getQuery
public String getQuery()
From source file:org.sonatype.nexus.repository.httpclient.HttpClientFactoryImpl.java
private void applyRequestExecutor(final Builder builder, final String userAgent, final String urlParameters) { if (userAgent != null || urlParameters != null) { builder.getHttpClientBuilder().setRequestExecutor(new HttpRequestExecutor() { @Override// w w w . j a v a2 s. c o m public void preProcess(final HttpRequest request, final HttpProcessor processor, final HttpContext ctx) throws HttpException, IOException { if (userAgent != null) { // NEXUS-7575: In case of HTTP Proxy tunnel, add generic UA while performing CONNECT if (!request.containsHeader(HTTP.USER_AGENT)) { request.addHeader(new BasicHeader(HTTP.USER_AGENT, userAgent)); } } super.preProcess(request, processor, ctx); } @Override public HttpResponse execute(final HttpRequest request, final HttpClientConnection conn, final HttpContext context) throws IOException, HttpException { HttpResponse response = null; if (urlParameters != null) { HttpRequestWrapper wrappedRequest = HttpRequestWrapper.wrap(request); URI uri = wrappedRequest.getURI(); if (uri != null) { String uriString = uri.toASCIIString(); try { wrappedRequest.setURI( new URI(uriString + (uri.getQuery() == null ? "?" : "&") + urlParameters)); } catch (URISyntaxException e) { throw new HttpException( "Unable to add url parameters " + urlParameters + " to " + uriString, e); } response = super.execute(wrappedRequest, conn, context); } } if (response == null) { response = super.execute(request, conn, context); } return response; } }); } }
From source file:com.emergya.spring.security.oauth.google.GoogleAuthorizationCodeAccessTokenProvider.java
/** * Obtains the authorization code from the access token request. * * @param details the authenticatoin details * @param request the access token request * @return the authorization code/*from w w w .ja v a2 s . c o m*/ * @throws UserRedirectRequiredException when redirection is required * @throws UserApprovalRequiredException when the user requires approval * @throws AccessDeniedException when the user is denied access * @throws OAuth2AccessDeniedException when the user is denied access but we dont want the default Spring Security handling */ public final String obtainAuthorizationCode(final OAuth2ProtectedResourceDetails details, final AccessTokenRequest request) throws UserRedirectRequiredException, UserApprovalRequiredException, AccessDeniedException, OAuth2AccessDeniedException { GoogleAuthCodeResourceDetails resource; try { resource = (GoogleAuthCodeResourceDetails) details; } catch (ClassCastException ex) { throw new IllegalArgumentException("details is not an instance of class GoogleAuthCodeResourceDetails"); } HttpHeaders headers = getHeadersForAuthorizationRequest(request); MultiValueMap<String, String> form = new LinkedMultiValueMap<>(); 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)); } } 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 CookieResponseExtractor(copy, delegate); // 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.devnexus.aerogear.RestRunner.java
private URL appendQuery(String query, URL baseURL) { try {//from ww w . j av a 2 s . co m URI baseURI = baseURL.toURI(); String baseQuery = baseURI.getQuery(); if (baseQuery == null || baseQuery.isEmpty()) { baseQuery = query; } else { if (query != null && !query.isEmpty()) { baseQuery = baseQuery + "&" + query; } } if (baseQuery.isEmpty()) { baseQuery = null; } return new URI(baseURI.getScheme(), baseURI.getUserInfo(), baseURI.getHost(), baseURI.getPort(), baseURI.getPath(), baseQuery, baseURI.getFragment()).toURL(); } catch (MalformedURLException ex) { Log.e(TAG, "The URL could not be created from " + baseURL.toString(), ex); throw new RuntimeException(ex); } catch (URISyntaxException ex) { Log.e(TAG, "Error turning " + query + " into URI query.", ex); throw new RuntimeException(ex); } }
From source file:com.subgraph.vega.impl.scanner.state.PathState.java
private void addWebResponseToPath(IHttpResponse response) { final IContentAnalyzer contentAnalyzer = pathStateManager.getContentAnalyzer(); final IContentAnalyzerResult result = contentAnalyzer.processResponse(response, false, false); final URI uri = createRequest().getURI(); path.addGetResponse(uri.getQuery(), contentAnalyzerResultToMimeString(result)); }
From source file:org.soyatec.windowsazure.authenticate.SharedKeyCredentialsWrapper.java
/** * Replace the uri container name.//from w w w . java 2 s . c o m * * @param uri * @param accountName * @return The uri after be replaced the account name with the input * accountName. */ private URI replaceAccountName(URI uri, String accountName) { try { String host = uri.getHost(); String[] temp = host.split("\\."); temp[0] = accountName; return URIUtils.createURI(uri.getScheme(), join(".", temp), uri.getPort(), HttpUtilities.getNormalizePath(uri), (uri.getQuery() == null ? Utilities.emptyString() : uri.getQuery()), uri.getFragment()); } catch (URISyntaxException e) { Logger.error("", e); } return uri; }
From source file:com.mirth.connect.connectors.ws.WebServiceConnectorService.java
private WsdlInterface getWsdlInterface(URI wsdlUrl, String username, String password) throws Exception { /* add the username:password to the URL if using authentication */ if (StringUtils.isNotEmpty(username) && StringUtils.isNotEmpty(password)) { String hostWithCredentials = username + ":" + password + "@" + wsdlUrl.getHost(); wsdlUrl = new URI(wsdlUrl.getScheme(), hostWithCredentials, wsdlUrl.getPath(), wsdlUrl.getQuery(), wsdlUrl.getFragment());/* w w w. j a va 2s. c o m*/ } // SoapUI.setSoapUICore(new EmbeddedSoapUICore()); WsdlProject wsdlProject = new WsdlProjectFactory().createNew(); WsdlLoader wsdlLoader = new UrlWsdlLoader(wsdlUrl.toURL().toString()); try { Future<WsdlInterface> future = importWsdlInterface(wsdlProject, wsdlUrl, wsdlLoader); return future.get(30, TimeUnit.SECONDS); } catch (Exception e) { wsdlLoader.abort(); throw e; } }
From source file:com.mellanox.jxio.ServerPortal.java
private URI replacePortInURI(URI uri, int newPort) { URI newUri = null;//from w w w .j a v a 2 s. c o m try { newUri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), newPort, uri.getPath(), uri.getQuery(), uri.getFragment()); if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "uri with port " + newPort + " is " + newUri.toString()); } } catch (URISyntaxException e) { e.printStackTrace(); LOG.error(this.toLogString() + "URISyntaxException occured while trying to create a new URI"); } return newUri; }
From source file:com.adaptris.security.TestKeystoreLocation.java
@Test public void testRemoteKeystore() throws Exception { if (Boolean.parseBoolean(cfg.getProperty(Config.REMOTE_TESTS_ENABLED, "false"))) { String ks = cfg.getProperty(Config.KEYSTORE_TEST_URL); ks = ks.replaceAll("\\\\", "/"); URI uri = new URI(ks); File keystore = new File(uri.getPath()); String filename = keystore.getName(); File newFile = new File(cfg.getProperty(Config.KEYSTORE_REMOTE_REALPATH) + "/" + filename); FileUtils.copyFile(keystore, newFile); Thread.sleep(10000);/*from w ww . ja v a 2 s.co m*/ logR.debug("newFile " + newFile.getCanonicalPath()); String keystoreType = uri.getQuery(); String url = cfg.getProperty(Config.KEYSTORE_REMOTE_ROOT) + filename + "?" + keystoreType; KeystoreLocation k = KeystoreFactory.getDefault().create(url, cfg.getProperty(Config.KEYSTORE_COMMON_KEYSTORE_PW).toCharArray()); assertTrue("Remote Keystore exists", k.exists()); InputStream in = k.openInput(); in.close(); assertTrue(!k.isWriteable()); boolean openOutputSuccess = false; try { OutputStream o = k.openOutput(); openOutputSuccess = true; o.close(); } catch (Exception e) { // Expected as it's non-writeable } newFile.delete(); if (openOutputSuccess) { fail("Successfully opened output to a remote keystore!"); } } }
From source file:com.sap.core.odata.fit.basic.issues.TestIssue105.java
@Test public void checkContextForDifferentHostNamesRequests() throws ClientProtocolException, IOException, ODataException, URISyntaxException { URI uri1 = URI.create(getEndpoint().toString() + "$metadata"); HttpGet get1 = new HttpGet(uri1); HttpResponse response1 = getHttpClient().execute(get1); assertNotNull(response1);//from w w w . ja v a2 s . c o m URI serviceRoot1 = getService().getProcessor().getContext().getPathInfo().getServiceRoot(); assertEquals(uri1.getHost(), serviceRoot1.getHost()); get1.reset(); URI uri2 = new URI(uri1.getScheme(), uri1.getUserInfo(), "127.0.0.1", uri1.getPort(), uri1.getPath(), uri1.getQuery(), uri1.getFragment()); HttpGet get2 = new HttpGet(uri2); HttpResponse response2 = getHttpClient().execute(get2); assertNotNull(response2); URI serviceRoot2 = getService().getProcessor().getContext().getPathInfo().getServiceRoot(); assertEquals(uri2.getHost(), serviceRoot2.getHost()); }
From source file:org.apache.hadoop.fs.TestFileSystem.java
static void runTestCache(int port) throws Exception { Configuration conf = new Configuration(); MiniDFSCluster cluster = null;// w w w . ja v a 2 s . c o m try { cluster = new MiniDFSCluster(port, conf, 2, true, true, null, null); URI uri = cluster.getFileSystem().getUri(); LOG.info("uri=" + uri); { FileSystem fs = FileSystem.get(uri, new Configuration()); checkPath(cluster, fs); for (int i = 0; i < 100; i++) { assertTrue(fs == FileSystem.get(uri, new Configuration())); } } if (port == NameNode.DEFAULT_PORT) { //test explicit default port URI uri2 = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), NameNode.DEFAULT_PORT, uri.getPath(), uri.getQuery(), uri.getFragment()); LOG.info("uri2=" + uri2); FileSystem fs = FileSystem.get(uri2, conf); checkPath(cluster, fs); for (int i = 0; i < 100; i++) { assertTrue(fs == FileSystem.get(uri2, new Configuration())); } } } finally { if (cluster != null) cluster.shutdown(); } }