Example usage for org.apache.http.conn.scheme Scheme getDefaultPort

List of usage examples for org.apache.http.conn.scheme Scheme getDefaultPort

Introduction

In this page you can find the example usage for org.apache.http.conn.scheme Scheme getDefaultPort.

Prototype

public final int getDefaultPort() 

Source Link

Document

Obtains the default port.

Usage

From source file:com.googlecode.androidannotations.test15.SSLConnectionTest.java

@Test
public void truststoreProvided() {
    assertNotNull(activity.mHttpsClientTest1);
    ClientConnectionManager ccm = activity.mHttpsClientTest1.getConnectionManager();
    assertNotNull(ccm);/*from www.j a v a 2 s. com*/

    Scheme httpsScheme = ccm.getSchemeRegistry().getScheme("https");
    assertNotNull(httpsScheme);

    assertEquals(443, httpsScheme.getDefaultPort());
    SocketFactory socketFactHttps = httpsScheme.getSocketFactory();

    if (!(socketFactHttps instanceof SSLSocketFactory)) {
        Assert.fail("wrong instance should be org.apache.http.conn.ssl.SSLSocketFactory, getting "
                + socketFactHttps);
    }
    assertEquals(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER,
            ((SSLSocketFactory) socketFactHttps).getHostnameVerifier());
}

From source file:org.androidannotations.test.SSLConnectionTest.java

@Test
public void truststoreProvided() {
    assertNotNull(activity.mHttpsClientTest1);
    ClientConnectionManager ccm = activity.mHttpsClientTest1.getConnectionManager();
    assertNotNull(ccm);/*from w  w w .  j  av  a  2  s  .  c  o  m*/

    Scheme httpsScheme = ccm.getSchemeRegistry().getScheme("https");
    assertNotNull(httpsScheme);

    assertEquals(443, httpsScheme.getDefaultPort());
    SocketFactory socketFactHttps = httpsScheme.getSocketFactory();

    if (!(socketFactHttps instanceof SSLSocketFactory)) {
        fail("wrong instance should be org.apache.http.conn.ssl.SSLSocketFactory, getting " + socketFactHttps);
    }
    assertEquals(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER,
            ((SSLSocketFactory) socketFactHttps).getHostnameVerifier());
}

From source file:org.anhonesteffort.flock.test.registration.HttpClientFactoryTest.java

public void testScheme() throws Exception {
    final HttpClientFactory httpFactory = new HttpClientFactory(getInstrumentation().getContext());
    final DefaultHttpClient httpClient = httpFactory.buildClient();
    final SchemeRegistry schemes = httpClient.getConnectionManager().getSchemeRegistry();

    final Scheme httpScheme = schemes.getScheme("http");
    final Scheme httpsScheme = schemes.getScheme("https");

    assertTrue(httpScheme != null && httpsScheme != null);
    assertTrue(schemes.getSchemeNames().size() == 2);

    assertTrue(httpsScheme.getDefaultPort() == 443);
    assertTrue(httpsScheme.getSocketFactory() instanceof SSLSocketFactory);
}

From source file:x.y.z.DefaultRequestDirector.java

protected RoutedRequest handleResponse(final RoutedRequest roureq, final HttpResponse response,
            final HttpContext context) throws HttpException, IOException {
        test();//from w  w  w .  j  av  a  2 s  .  c  o m
        String something = new String();
        String somethingElse = "";
        List<Something> somethingList = null;
        test(something);
        final HttpRoute route = roureq.getRoute();
        final RequestWrapper request = roureq.getRequest();
        final HttpParams params = request.getParams();
        int i = org.apache.http.params.HttpConnectionParams.getConnectionTimeout(parmas);
        javax.rmi.CORBA obj;
        if (HttpClientParams.isAuthenticating(params)) {
            HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
            if (target == null) {
                target = route.getTargetHost();
            }
            if (target.getPort() < 0) {
                final Scheme scheme = connManager.getSchemeRegistry().getScheme(target);
                target = new HttpHost(target.getHostName(), scheme.getDefaultPort(), target.getSchemeName());
            }
            final boolean targetAuthRequested = this.authenticator.isAuthenticationRequested(target, response,
                    this.targetAuthStrategy, targetAuthState, context);
            HttpHost proxy = route.getProxyHost();
            if (proxy == null) {
                proxy = route.getTargetHost();
            }
            final boolean proxyAuthRequested = this.authenticator.isAuthenticationRequested(proxy, response,
                    this.proxyAuthStrategy, proxyAuthState, context);
            if (targetAuthRequested) {
                if (this.authenticator.authenticate(target, response, this.targetAuthStrategy, this.targetAuthState,
                        context)) {
                    return roureq;
                }
            }
            if (proxyAuthRequested) {
                if (this.authenticator.authenticate(proxy, response, this.proxyAuthStrategy, this.proxyAuthState,
                        context)) {
                    return roureq;
                }
            }
        }
        if (HttpClientParams.isRedirecting(params)
                && this.redirectStrategy.isRedirected(request, response, context)) {
            if (redirectCount >= maxRedirects) {
                throw new RedirectException("Maximum redirects (" + maxRedirects + ") exceeded");
            }
            redirectCount++;
            virtualHost = null;
            final HttpUriRequest redirect = redirectStrategy.getRedirect(request, response, context);
            final HttpRequest orig = request.getOriginal();
            redirect.setHeaders(orig.getAllHeaders());
            final URI uri = redirect.getURI();
            final HttpHost newTarget = URIUtils.extractHost(uri);
            if (newTarget == null) {
                throw new ProtocolException("Redirect URI does not specify a valid host name: " + uri);
            }
            if (!route.getTargetHost().equals(newTarget)) {
                this.log.debug("Resetting target auth state");
                targetAuthState.reset();
                final AuthScheme authScheme = proxyAuthState.getAuthScheme();
                if (authScheme != null && authScheme.isConnectionBased()) {
                    this.log.debug("Resetting proxy auth state");
                    proxyAuthState.reset();
                }
            }
            final RequestWrapper wrapper = wrapRequest(redirect);
            wrapper.setParams(params);
            final HttpRoute newRoute = determineRoute(newTarget, wrapper, context);
            final RoutedRequest newRequest = new RoutedRequest(wrapper, newRoute);
            if (this.log.isDebugEnabled()) {
                this.log.debug("Redirecting to '" + uri + "' via " + newRoute);
            }
            return newRequest;
        }
        return null;
    }

From source file:com.grendelscan.commons.http.apache_overrides.client.CustomClientRequestDirector.java

private void updateAuthState(final AuthState authState, final HttpHost host,
        final CredentialsProvider credsProvider) {
    if (!authState.isValid()) {
        return;/*from   ww w .jav a  2  s  .  com*/
    }

    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());

    LOGGER.trace("Authentication scope: " + authScope);
    Credentials creds = authState.getCredentials();
    if (creds == null) {
        creds = credsProvider.getCredentials(authScope);
        if (creds != null) {
            LOGGER.trace("Found credentials");
        } else {
            LOGGER.trace("Credentials not found");
        }
    } else {
        if (authScheme.isComplete()) {
            LOGGER.debug("Authentication failed");
            creds = null;
        }
    }
    authState.setAuthScope(authScope);
    authState.setCredentials(creds);
}

From source file:com.grendelscan.commons.http.apache_overrides.client.CustomClientRequestDirector.java

/**
 * Creates the CONNECT request for tunnelling.
 * Called by {@link #createTunnelToTarget createTunnelToTarget}.
 * //from ww  w.j  av a2s.  co  m
 * @param route
 *            the route to establish
 * @param context
 *            the context for request execution
 * 
 * @return the CONNECT request for tunnelling
 */
private HttpRequest createConnectRequest(HttpRoute route) {
    // 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;
}

From source file:org.robolectric.shadows.httpclient.DefaultRequestDirector.java

private void updateAuthState(final AuthState authState, final HttpHost host,
        final CredentialsProvider credsProvider) {

    if (!authState.isValid()) {
        return;/*from w w w . jav a 2s. co m*/
    }

    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);
}

From source file:org.robolectric.shadows.httpclient.DefaultRequestDirector.java

/**
 * 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
 *//* w  w w .j  av a  2s.  c  om*/
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;
}