List of usage examples for org.apache.http.conn.routing HttpRoute getProxyHost
public final HttpHost getProxyHost()
From source file:com.navercorp.pinpoint.plugin.httpclient4.EndPointUtils.java
public static String getHostAndPort(HttpRoute route) { final HttpHost proxyHost = route.getProxyHost(); if (proxyHost != null) { final String hostName = proxyHost.getHostName(); final int port = HostAndPort.getPortOrNoPort(proxyHost.getPort()); return HostAndPort.toHostAndPortString(hostName, port); } else {/*from ww w . j a v a 2 s .c o m*/ final HttpHost targetHost = route.getTargetHost(); if (targetHost != null) { final String hostName = targetHost.getHostName(); final int port = HostAndPort.getPortOrNoPort(targetHost.getPort()); return HostAndPort.toHostAndPortString(hostName, port); } } return ""; }
From source file:com.eviware.soapui.support.components.BrowserComponent.java
public static void updateJXBrowserProxy() { ProxyConfig proxyConf = BrowserServices.getInstance().getProxyConfig(); if (proxyConf == null) return;/*from w ww . ja v a 2 s .co m*/ try { proxyConf.setAutoDetectForNetwork(false); if (!proxyAuthenticationInitialized) { proxyConf.setAuthenticationHandler(ServerType.HTTP, new AuthenticationHandler() { @Override public ProxyServerLogin authenticationRequired(ServerType arg0) { Settings settings = SoapUI.getSettings(); PropertyExpansionContext context = null; String proxyUsername = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.USERNAME, null)); String proxyPassword = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.PASSWORD, null)); return new ProxyServerLogin(proxyUsername, proxyPassword); } }); proxyAuthenticationInitialized = true; } if (ProxyUtils.isProxyEnabled()) { if (ProxyUtils.isAutoProxy()) { HttpRoutePlanner routePlanner = HttpClientSupport.getHttpClient().getRoutePlanner(); HttpRoute httpRoute = routePlanner.determineRoute(new HttpHost("soapui.org"), new HttpGet("http://soapui.org"), null); HttpHost proxyHost = httpRoute.getProxyHost(); if (proxyHost != null) { proxyConf.setProxy(ServerType.HTTP, new ProxyServer(proxyHost.getHostName(), proxyHost.getPort())); } else { proxyConf.setDirectConnection(); } } else { Settings settings = SoapUI.getSettings(); PropertyExpansionContext context = null; // check system properties first String proxyHost = System.getProperty("http.proxyHost"); String proxyPort = System.getProperty("http.proxyPort"); if (proxyHost == null) proxyHost = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.HOST, "")); if (proxyPort == null) proxyPort = PropertyExpander.expandProperties(context, settings.getString(ProxySettings.PORT, "")); proxyConf.setProxy(ServerType.HTTP, new ProxyServer(proxyHost, Integer.parseInt(proxyPort))); // check excludes proxyConf.setExceptions(PropertyExpander.expandProperties(context, settings.getString(ProxySettings.EXCLUDES, ""))); } } else { proxyConf.setDirectConnection(); } } catch (Exception e) { //ignore } }
From source file:com.navercorp.pinpoint.plugin.httpclient4.interceptor.HttpClientConnectionManagerConnectMethodInterceptor.java
@Override protected void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) { if (args != null && args.length >= 2 && args[1] != null && args[1] instanceof HttpRoute) { final HttpRoute route = (HttpRoute) args[1]; final StringBuilder sb = new StringBuilder(); if (route.getProxyHost() != null) { sb.append(route.getProxyHost().getHostName()); if (route.getProxyHost().getPort() > 0) { sb.append(":").append(route.getProxyHost().getPort()); }//ww w .ja v a2 s.c o m } else { if (route.getTargetHost() != null) { sb.append(route.getTargetHost().getHostName()); if (route.getTargetHost().getPort() > 0) { sb.append(":").append(route.getTargetHost().getPort()); } } } recorder.recordAttribute(AnnotationKey.HTTP_INTERNAL_DISPLAY, sb.toString()); } recorder.recordApi(methodDescriptor); recorder.recordServiceType(HttpClient4Constants.HTTP_CLIENT_4_INTERNAL); }
From source file:com.navercorp.pinpoint.plugin.httpclient4.interceptor.ManagedClientConnectionOpenMethodInterceptor.java
@Override protected void doInBeforeTrace(SpanEventRecorder recorder, Object target, Object[] args) { if (args != null && args.length >= 1 && args[0] != null && args[0] instanceof HttpRoute) { final HttpRoute route = (HttpRoute) args[0]; final StringBuilder sb = new StringBuilder(); if (route.getProxyHost() != null) { sb.append(route.getProxyHost().getHostName()); if (route.getProxyHost().getPort() > 0) { sb.append(":").append(route.getProxyHost().getPort()); }/* w ww . j a v a 2s .c o m*/ } else { if (route.getTargetHost() != null) { sb.append(route.getTargetHost().getHostName()); if (route.getTargetHost().getPort() > 0) { sb.append(":").append(route.getTargetHost().getPort()); } } } recorder.recordAttribute(AnnotationKey.HTTP_INTERNAL_DISPLAY, sb.toString()); } recorder.recordApi(methodDescriptor); recorder.recordServiceType(HttpClient4Constants.HTTP_CLIENT_4_INTERNAL); }
From source file:com.navercorp.pinpoint.plugin.httpclient4.EndPointUtilsTest.java
public void getHostAndPort() throws Exception { // TODO Support final class mocking HttpRoute httpRoute = mock(HttpRoute.class); HttpHost httpHost = mock(HttpHost.class); when(httpHost.getHostName()).thenReturn("127.0.0.1"); when(httpHost.getPort()).thenReturn(-1); when(httpRoute.getProxyHost()).thenReturn(httpHost); String hostAndPort = EndPointUtils.getHostAndPort(httpRoute); }
From source file:org.siddhiesb.transport.passthru.connections.TargetConnections.java
/** * Return a connection to the host:port pair. If a connection is not available * return <code>null</code>. If the particular host:port allows to create more connections * this method will try to connect asynchronously. If the connection is successful it will * be notified in a separate thread./* www. ja va 2 s . c o m*/ * * @param host host * @param port port * @return Either returns a connection if already available or returns null and notifies * the delivery agent when the connection is available */ public NHttpClientConnection getConnection(HttpRoute route) { if (log.isDebugEnabled()) { log.debug("Trying to get a connection " + route); } org.siddhiesb.transport.passthru.connections.HostConnections pool = getConnectionPool(route); // trying to get an existing connection NHttpClientConnection connection = pool.getConnection(); if (connection == null) { if (pool.canHaveMoreConnections()) { HttpHost host = route.getProxyHost() != null ? route.getProxyHost() : route.getTargetHost(); ioReactor.connect(new InetSocketAddress(host.getHostName(), host.getPort()), null, pool, callback); } else { log.warn("Connection pool reached maximum allowed connections for route " + route + ". Target server may have become slow"); } } return connection; }
From source file:com.serphacker.serposcope.scraper.http.extensions.CloseableBasicHttpClientConnectionManager.java
@Override public void connect(final HttpClientConnection conn, final HttpRoute route, final int connectTimeout, final HttpContext context) throws IOException { Args.notNull(conn, "Connection"); Args.notNull(route, "HTTP route"); Asserts.check(conn == this.conn, "Connection not obtained from this manager"); final HttpHost host; if (route.getProxyHost() != null) { host = route.getProxyHost();/*from w w w . j a v a 2 s . c o m*/ } else { host = route.getTargetHost(); } final InetSocketAddress localAddress = route.getLocalSocketAddress(); this.connectionOperator.connect(this.conn, host, localAddress, connectTimeout, this.socketConfig, context); }
From source file:org.callimachusproject.client.HttpAuthenticator.java
public boolean needAuthentication(final HttpRoute route, final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { final AuthState targetAuthState = getTargetAuthState(context); final AuthState proxyAuthState = getProxyAuthState(context); HttpHost target = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST); if (target == null) { target = route.getTargetHost();// w ww . ja v a2 s .c o m } HttpHost proxy = route.getProxyHost(); if (this.needAuthentication(target, proxy, targetAuthState, proxyAuthState, response, context)) { // discard previous auth headers request.removeHeaders(AUTH.WWW_AUTH_RESP); request.removeHeaders(AUTH.PROXY_AUTH_RESP); return true; } else { return false; } }
From source file:com.grendelscan.commons.http.apache_overrides.client.CustomClientRequestDirector.java
/** * Creates a tunnel to the target server. * The connection must be established to the (last) proxy. * A CONNECT request for tunnelling through the proxy will * be created and sent, the response received and checked. * This method does <i>not</i> update the connection with * information about the tunnel, that is left to the caller. * //from www. j av a2 s . com * @param route * the route to establish * @param context * the context for request execution * * @return <code>true</code> if the tunnelled route is secure, * <code>false</code> otherwise. * The implementation here always returns <code>false</code>, * but derived classes may override. * * @throws HttpException * in case of a problem * @throws IOException * in case of an IO problem */ private boolean createTunnelToTarget(HttpRoute route, HttpContext context) throws HttpException, IOException { HttpHost proxy = route.getProxyHost(); HttpHost target = route.getTargetHost(); HttpResponse response = null; boolean done = false; while (!done) { done = true; if (!managedConn.isOpen()) { managedConn.open(route, context, params); } HttpRequest connect = createConnectRequest(route); connect.setParams(params); // Populate the execution context context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, target); context.setAttribute(ExecutionContext.HTTP_PROXY_HOST, proxy); context.setAttribute(ExecutionContext.HTTP_CONNECTION, managedConn); context.setAttribute(ClientContext.TARGET_AUTH_STATE, targetAuthState); context.setAttribute(ClientContext.PROXY_AUTH_STATE, proxyAuthState); context.setAttribute(ExecutionContext.HTTP_REQUEST, connect); requestExec.preProcess(connect, httpProcessor, context); response = requestExec.execute(connect, managedConn, context); response.setParams(params); requestExec.postProcess(response, httpProcessor, context); int status = response.getStatusLine().getStatusCode(); if (status < 200) { throw new HttpException("Unexpected response to CONNECT request: " + response.getStatusLine()); } CredentialsProvider credsProvider = (CredentialsProvider) context .getAttribute(ClientContext.CREDS_PROVIDER); if ((credsProvider != null) && HttpClientParams.isAuthenticating(params)) { if (proxyAuthHandler.isAuthenticationRequested(response, context)) { LOGGER.debug("Proxy requested authentication"); Map<String, Header> challenges = proxyAuthHandler.getChallenges(response, context); try { processChallenges(challenges, proxyAuthState, proxyAuthHandler, response, context); } catch (AuthenticationException ex) { LOGGER.warn("Authentication error: " + ex.getMessage()); } updateAuthState(proxyAuthState, proxy, credsProvider); if (proxyAuthState.getCredentials() != null) { done = false; // Retry request if (reuseStrategy.keepAlive(response, context)) { LOGGER.debug("Connection kept alive"); // Consume response content HttpEntity entity = response.getEntity(); if (entity != null) { entity.consumeContent(); } } else { managedConn.close(); } } } else { // Reset proxy auth scope proxyAuthState.setAuthScope(null); } } } int status = response.getStatusLine().getStatusCode(); // can't be null if (status > 299) { // Buffer response content HttpEntity entity = response.getEntity(); if (entity != null) { response.setEntity(new BufferedHttpEntity(entity)); } managedConn.close(); throw new TunnelRefusedException("CONNECT refused by proxy: " + response.getStatusLine(), response); } managedConn.markReusable(); // How to decide on security of the tunnelled connection? // The socket factory knows only about the segment to the proxy. // Even if that is secure, the hop to the target may be insecure. // Leave it to derived classes, consider insecure by default here. return false; }