List of usage examples for java.net URI getPort
public int getPort()
From source file:com.denimgroup.threadfix.remote.HttpRestUtils.java
private void importCert(SSLHandshakeException sslHandshakeException) { if (count < 2) { LOGGER.warn("Unsigned certificate found. Trying to import it to Java KeyStore."); try {/*from w ww .java2s . c om*/ URI uri = getURI(); String domain = uri.getHost(); domain = domain.startsWith("www.") ? domain.substring(4) : domain; if (InstallCert.install(domain, uri.getPort())) { count++; LOGGER.info("Successfully imported certificate. Please run your command again."); } } catch (Exception e) { LOGGER.error("Error when tried to import certificate. ", e); } } else { LOGGER.error("Unsigned certificate found. We tried to import it but was not successful." + "We recommend you import server certificate to the Java cacerts keystore, or add option -Dunsafe-ssl from command line to accept all unsigned certificates. " + "Check out https://github.com/denimgroup/threadfix/wiki/Importing-Self-Signed-Certificates on how to import Self Signed Certificates.", sslHandshakeException); } }
From source file:org.jclouds.http.httpnio.pool.NioHttpCommandConnectionPool.java
@Inject public NioHttpCommandConnectionPool(ExecutorService executor, Semaphore allConnections, BlockingQueue<HttpCommandRendezvous<?>> commandQueue, BlockingQueue<NHttpConnection> available, AsyncNHttpClientHandler clientHandler, DefaultConnectingIOReactor ioReactor, HttpParams params, URI endPoint) { super(executor, allConnections, commandQueue, available, endPoint); String host = checkNotNull(checkNotNull(endPoint, "endPoint").getHost(), String.format("Host null for endpoint %s", endPoint)); int port = endPoint.getPort(); if (endPoint.getScheme().equals("https")) { try {/* w w w . j av a 2 s . co m*/ this.dispatch = provideSSLClientEventDispatch(clientHandler, params); } catch (KeyManagementException e) { throw new RuntimeException("SSL error creating a connection to " + endPoint, e); } catch (NoSuchAlgorithmException e) { throw new RuntimeException("SSL error creating a connection to " + endPoint, e); } if (port == -1) port = 443; } else { this.dispatch = provideClientEventDispatch(clientHandler, params); if (port == -1) port = 80; } checkArgument(port > 0, String.format("Port %d not in range for endpoint %s", endPoint.getPort(), endPoint)); this.ioReactor = ioReactor; this.sessionCallback = new NHttpClientConnectionPoolSessionRequestCallback(); this.target = new InetSocketAddress(host, port); clientHandler.setEventListener(this); }
From source file:code.google.restclient.client.HitterClient.java
private ViewRequest prepareViewRequest(ViewRequest req, HttpHandler handler) { if (handler != null && req != null) { req.setReqLine(handler.getRequestLine()); // req.setUrl(handler.getUrl()); req.setHeaders(handler.getRequestHeaders()); URI uri = handler.getUri(); if (uri != null) { req.setHost(uri.getHost());/* w w w . j a v a 2 s . com*/ req.setPort(uri.getPort()); req.setPath(uri.getRawPath()); req.setScheme(uri.getScheme()); req.setQueryStrRaw(uri.getRawQuery()); } req.setProtocolVersion(handler.getProtocolVersion()); } return req; }
From source file:com.android.idtt.http.client.util.URIBuilder.java
private void digestURI(final URI uri) { this.scheme = uri.getScheme(); this.encodedSchemeSpecificPart = uri.getRawSchemeSpecificPart(); this.encodedAuthority = uri.getRawAuthority(); this.host = uri.getHost(); this.port = uri.getPort(); this.encodedUserInfo = uri.getRawUserInfo(); this.userInfo = uri.getUserInfo(); this.encodedPath = uri.getRawPath(); this.path = uri.getPath(); this.encodedQuery = uri.getRawQuery(); this.queryParams = parseQuery(uri.getRawQuery(), Charset.forName(HTTP.UTF_8)); this.encodedFragment = uri.getRawFragment(); this.fragment = uri.getFragment(); }
From source file:org.sonatype.nexus.testsuite.security.nexus4257.Nexus4257CookieVerificationIT.java
/** * Makes a request after setting the user agent and verifies that the session cookie is NOT set. *//*from w w w. ja v a2s . c o m*/ private void testCookieNotSetForKnownStateLessClients(final String userAgent) throws Exception { TestContext context = TestContainer.getInstance().getTestContext(); String username = context.getAdminUsername(); String password = context.getPassword(); String url = this.getBaseNexusUrl() + "content/"; URI uri = new URI(url); Header header = new BasicHeader("User-Agent", userAgent + "/1.6"); // user agent plus some version DefaultHttpClient httpClient = new DefaultHttpClient(); final BasicHttpContext localcontext = new BasicHttpContext(); final HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()); httpClient.getCredentialsProvider().setCredentials( new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(username, password)); AuthCache authCache = new BasicAuthCache(); BasicScheme basicAuth = new BasicScheme(); authCache.put(targetHost, basicAuth); localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache); HttpGet getMethod = new HttpGet(url); getMethod.addHeader(header); assertThat(executeAndRelease(httpClient, getMethod, localcontext), equalTo(200)); Cookie sessionCookie = this.getSessionCookie(httpClient.getCookieStore().getCookies()); assertThat("Session Cookie should not be set for user agent: " + userAgent, sessionCookie, nullValue()); }
From source file:com.github.fedorchuck.webstore.config.DataConfig.java
@SuppressWarnings("ConstantConditions") private void getConfigEnv(Map<String, String> env) { URI dbUri = null; try {//from ww w . j ava 2 s . c o m dbUri = new URI(System.getenv("DATABASE_URL")); } catch (URISyntaxException e) { logger.error("problem read config. reason: ", e); } driverClassName = "org.postgresql.Driver"; username = dbUri.getUserInfo().split(":")[0]; password = dbUri.getUserInfo().split(":")[1]; url = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath(); }
From source file:io.soabase.example.hello.HelloResourceApache.java
@GET public String getHello(@Context HttpHeaders headers) throws Exception { String result = "Service Name: " + info.getServiceName() + "\nInstance Name: " + info.getInstanceName() + "\nRequest Id: " + SoaRequestId.get(headers) + "\n"; URI uri = new URIBuilder().setHost(ClientUtils.serviceNameToHost("goodbye")).setPath("/goodbye").build(); HttpGet get = new HttpGet(uri); ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override/*from w w w .j ava2s .com*/ public String handleResponse(HttpResponse response) throws IOException { return CharStreams.toString(new InputStreamReader(response.getEntity().getContent())); } }; String value = client.execute(new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme()), get, responseHandler); return result + "\nGoodbye app says: \n\t" + value; }
From source file:org.apache.abdera2.common.protocol.BasicClient.java
/** * Add authentication credentials/* ww w . j a v a 2s. c om*/ */ public <T extends Client> T addCredentials(String target, String realm, String scheme, Credentials credentials) throws URISyntaxException { String host = AuthScope.ANY_HOST; int port = AuthScope.ANY_PORT; if (target != null) { URI uri = new URI(target); host = uri.getHost(); port = uri.getPort(); } HttpHost targetHost = new HttpHost(host, port, scheme); getDefaultHttpClient().getCredentialsProvider() .setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort(), realm != null ? realm : AuthScope.ANY_REALM, scheme != null ? scheme : AuthScope.ANY_SCHEME), credentials); return (T) this; }
From source file:com.pwc.sns.testsupport.WireMockTestClient.java
public WireMockResponse getViaProxy(String url, int proxyPort) { URI targetUri = URI.create(url); HttpHost proxy = new HttpHost(address, proxyPort, targetUri.getScheme()); DefaultHttpClient httpclient = new DefaultHttpClient(createClientConnectionManagerWithSSLSettings()); try {/* w ww . j ava2s. c o m*/ httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); HttpHost target = new HttpHost(targetUri.getHost(), targetUri.getPort(), targetUri.getScheme()); HttpGet req = new HttpGet( targetUri.getPath() + (isNullOrEmpty(targetUri.getQuery()) ? "" : "?" + targetUri.getQuery())); req.removeHeaders("Host"); System.out.println("executing request to " + targetUri + "(" + target + ") via " + proxy); HttpResponse httpResponse = httpclient.execute(target, req); return new WireMockResponse(httpResponse); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
From source file:nl.esciencecenter.octopus.webservice.mac.MacITCase.java
/** * Submit status to a callback server using MAC Access authentication. * * @throws URISyntaxException/*from w w w.ja v a2 s. co m*/ * @throws ClientProtocolException * @throws IOException */ @Test public void test() throws URISyntaxException, ClientProtocolException, IOException { Properties props = new Properties(); props.load(MacITCase.class.getClassLoader().getResourceAsStream("integration.props")); URI url = new URI(props.getProperty("integration.callback.url")); // TODO throw better exception than NullPointerException when property can not be found. String state = "STOPPED"; HttpPut request = new HttpPut(url); request.setEntity(new StringEntity(state)); String mac_id = props.getProperty("integration.callback.id"); String mac_key = props.getProperty("integration.callback.key"); URI scope = new URI(url.getScheme(), null, url.getHost(), url.getPort(), null, null, null); ImmutableList<MacCredential> macs = ImmutableList.of(new MacCredential(mac_id, mac_key, scope)); HttpClient httpClient = new DefaultHttpClient(); httpClient = JobLauncherService.macifyHttpClient((AbstractHttpClient) httpClient, macs); HttpResponse response = httpClient.execute(request); assertEquals(200, response.getStatusLine().getStatusCode()); }