Search in sources :

Example 96 with Scheme

use of org.apache.http.conn.scheme.Scheme in project java-chassis by ServiceComb.

the class HttpsClient method getHttpsClient.

public static HttpClient getHttpsClient(HttpsConfigInfoBean configBean) {
    try {
        SSLContext sslContext = createSSLContext(configBean);
        SSLSocketFactory sf = new SSLSocketFactory(sslContext);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
        HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
        HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), PORT_80));
        registry.register(new Scheme("https", sf, PORT_443));
        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
        return new DefaultHttpClient(ccm, params);
    } catch (RuntimeException e) {
        LOGGER.error("Get https client runtime exception: {}", FortifyUtils.getErrorInfo(e));
        return new DefaultHttpClient();
    } catch (GeneralSecurityException | IOException e) {
        LOGGER.error("Get https client exception: {}", FortifyUtils.getErrorInfo(e));
        return new DefaultHttpClient();
    }
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) GeneralSecurityException(java.security.GeneralSecurityException) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) ClientConnectionManager(org.apache.http.conn.ClientConnectionManager) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) BasicHttpParams(org.apache.http.params.BasicHttpParams)

Example 97 with Scheme

use of org.apache.http.conn.scheme.Scheme in project platform_external_apache-http by android.

the class DefaultRequestDirector method createConnectRequest.

/**
     * Creates the CONNECT request for tunnelling.
     * Called by {@link #createTunnelToTarget createTunnelToTarget}.
     *
     * @param route     the route to establish
     * @param context   the context for request execution
     *
     * @return  the CONNECT request for tunnelling
     */
protected HttpRequest createConnectRequest(HttpRoute route, HttpContext context) {
    // see RFC 2817, section 5.2 and 
    // INTERNET-DRAFT: Tunneling TCP based protocols through 
    // Web proxy servers
    HttpHost target = route.getTargetHost();
    String host = target.getHostName();
    int port = target.getPort();
    if (port < 0) {
        Scheme scheme = connManager.getSchemeRegistry().getScheme(target.getSchemeName());
        port = scheme.getDefaultPort();
    }
    StringBuilder buffer = new StringBuilder(host.length() + 6);
    buffer.append(host);
    buffer.append(':');
    buffer.append(Integer.toString(port));
    String authority = buffer.toString();
    ProtocolVersion ver = HttpProtocolParams.getVersion(params);
    HttpRequest req = new BasicHttpRequest("CONNECT", authority, ver);
    return req;
}
Also used : HttpRequest(org.apache.http.HttpRequest) BasicHttpRequest(org.apache.http.message.BasicHttpRequest) AbortableHttpRequest(org.apache.http.client.methods.AbortableHttpRequest) Scheme(org.apache.http.conn.scheme.Scheme) AuthScheme(org.apache.http.auth.AuthScheme) HttpHost(org.apache.http.HttpHost) ProtocolVersion(org.apache.http.ProtocolVersion) BasicHttpRequest(org.apache.http.message.BasicHttpRequest)

Example 98 with Scheme

use of org.apache.http.conn.scheme.Scheme in project platform_external_apache-http by android.

the class DefaultRequestDirector method updateAuthState.

private void updateAuthState(final AuthState authState, final HttpHost host, final CredentialsProvider credsProvider) {
    if (!authState.isValid()) {
        return;
    }
    String hostname = host.getHostName();
    int port = host.getPort();
    if (port < 0) {
        Scheme scheme = connManager.getSchemeRegistry().getScheme(host);
        port = scheme.getDefaultPort();
    }
    AuthScheme authScheme = authState.getAuthScheme();
    AuthScope authScope = new AuthScope(hostname, port, authScheme.getRealm(), authScheme.getSchemeName());
    if (this.log.isDebugEnabled()) {
        this.log.debug("Authentication scope: " + authScope);
    }
    Credentials creds = authState.getCredentials();
    if (creds == null) {
        creds = credsProvider.getCredentials(authScope);
        if (this.log.isDebugEnabled()) {
            if (creds != null) {
                this.log.debug("Found credentials");
            } else {
                this.log.debug("Credentials not found");
            }
        }
    } else {
        if (authScheme.isComplete()) {
            this.log.debug("Authentication failed");
            creds = null;
        }
    }
    authState.setAuthScope(authScope);
    authState.setCredentials(creds);
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) AuthScheme(org.apache.http.auth.AuthScheme) AuthScope(org.apache.http.auth.AuthScope) Credentials(org.apache.http.auth.Credentials) AuthScheme(org.apache.http.auth.AuthScheme)

Example 99 with Scheme

use of org.apache.http.conn.scheme.Scheme in project platform_external_apache-http by android.

the class DefaultHttpRoutePlanner method determineRoute.

// non-javadoc, see interface HttpRoutePlanner
public HttpRoute determineRoute(HttpHost target, HttpRequest request, HttpContext context) throws HttpException {
    if (request == null) {
        throw new IllegalStateException("Request must not be null.");
    }
    // If we have a forced route, we can do without a target.
    HttpRoute route = ConnRouteParams.getForcedRoute(request.getParams());
    if (route != null)
        return route;
    if (target == null) {
        throw new IllegalStateException("Target host must not be null.");
    }
    final InetAddress local = ConnRouteParams.getLocalAddress(request.getParams());
    final HttpHost proxy = ConnRouteParams.getDefaultProxy(request.getParams());
    final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
    // as it is typically used for TLS/SSL, we assume that
    // a layered scheme implies a secure connection
    final boolean secure = schm.isLayered();
    if (proxy == null) {
        route = new HttpRoute(target, local, secure);
    } else {
        route = new HttpRoute(target, local, proxy, secure);
    }
    return route;
}
Also used : HttpRoute(org.apache.http.conn.routing.HttpRoute) Scheme(org.apache.http.conn.scheme.Scheme) HttpHost(org.apache.http.HttpHost) InetAddress(java.net.InetAddress)

Example 100 with Scheme

use of org.apache.http.conn.scheme.Scheme in project jmeter by apache.

the class HTTPHC4Impl method createSchemeRegistry.

/**
     * Setup LazySchemeSocketFactory
     * @see "https://bz.apache.org/bugzilla/show_bug.cgi?id=58099"
     */
private static SchemeRegistry createSchemeRegistry() {
    final SchemeRegistry registry = new SchemeRegistry();
    registry.register(//$NON-NLS-1$
    new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    registry.register(//$NON-NLS-1$
    new Scheme("https", 443, new LazySchemeSocketFactory()));
    return registry;
}
Also used : BasicScheme(org.apache.http.impl.auth.BasicScheme) Scheme(org.apache.http.conn.scheme.Scheme) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry)

Aggregations

Scheme (org.apache.http.conn.scheme.Scheme)103 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)63 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)53 ClientConnectionManager (org.apache.http.conn.ClientConnectionManager)40 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)39 BasicHttpParams (org.apache.http.params.BasicHttpParams)32 HttpParams (org.apache.http.params.HttpParams)30 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)29 HttpClient (org.apache.http.client.HttpClient)19 AllowAllHostnameVerifier (org.apache.http.conn.ssl.AllowAllHostnameVerifier)17 SSLContext (javax.net.ssl.SSLContext)16 HttpResponse (org.apache.http.HttpResponse)15 CertificateException (java.security.cert.CertificateException)13 HttpHost (org.apache.http.HttpHost)13 MockResponse (com.google.mockwebserver.MockResponse)12 RecordedRequest (com.google.mockwebserver.RecordedRequest)12 IOException (java.io.IOException)12 TestSSLContext (libcore.javax.net.ssl.TestSSLContext)12 HttpGet (org.apache.http.client.methods.HttpGet)12 InetAddress (java.net.InetAddress)9