Package com.volantis.shared.net.http.client

Examples of com.volantis.shared.net.http.client.HttpClient


                    "protocol-not-supported",
                    new String [] {url.getProtocol(), "http"}));
        }

        // create HTTPClient
        HttpClient httpClient = prepareHttpClient();

        // create request method and configure it
        final GetMethod method = new GetMethod(url.toExternalForm());
        method.setFollowRedirects(true);

        // create cache information object
        SystemClock clock = SystemClock.getDefaultInstance();
        CachedHttpContentStateBuilder cacheBuilder = new CachedHttpContentStateBuilder();
        cacheBuilder.setMethodAccessor(
            ResponseHeaderAccessorFactory.getDefaultInstance().
                createHttpClientResponseHeaderAccessor(method));
        cacheBuilder.setRequestTime(clock.getCurrentTime());

        // save request headers to request method
        setRequestHeaders(method, headers);

        DefaultRepresentation responseInfo = null;

        // execute request
        try {
            httpClient.executeMethod(method);
        } catch (IOException e) {
            throw new ResourceRetrieverException(exceptionLocalizer.format(
                    "connection-refused", url.toString()), e);
        }
View Full Code Here


        builder.setState(state);
        builder.setConnectionTimeout(timeout);
        builder.setRoundTripTimeout(timeout);

        // create the HTTPClient instance.
        final HttpClient httpClient = builder.buildHttpClient();

        // return an HTTPRequestExecutor that uses HttpClient to perform
        // the request
        return new HTTPRequestExecutor() {

            /**
             * The request method to use.
             */
            HttpMethod method = null;

            /**
             * The list of request parameters
             */
            List requestParameters = null;

            /**
             * A list containing the request headers.
             */
            List requestHeaders = null;

            // javadoc inherited
            public HTTPResponseAccessor execute() throws HTTPException {

                // create the request method this will be POST or GET depending
                // on the requestType argument. This will copy the request
                // parameters to the appropraite place.
                method = createMethod(url, requestType, requestParameters);

                transferRequestHeaders(method, requestHeaders);

                // set the http version for the request
                ((HttpMethodBase) method).setHttp11(
                        version == HTTPVersion.HTTP_1_1);

                if (proxyManager != null) {
                    try {
                        URL realUrl = new URL(url);

                        // Get the proxy config to use for the host.
                        Proxy proxy = proxyManager.getProxyForHost(
                                realUrl.getHost());
                        if (proxy != null) {
                            method.getHostConfiguration().
                                setProxy(proxy.getHost(), proxy.getPort());

                        if (proxy.useAuthorization()) {
                            method.setDoAuthentication(true);

                            // mock up a authentication challenge so we can get
                            // the response (which can be sent before the
                            // challenge if we want to save time and effort)
                            method.setRequestHeader(
                                HTTPAuthorizationScheme.PROXY_AUTHORIZATION_HEADER,
                                HTTPAuthorizationScheme.BASIC.
                                        createResponseForChallenge(HTTPAuthorizationScheme.MOCK_CHALLENGE_BASIC,
                                    proxy));
                        }
                        }
                    } catch (MalformedURLException mue) {
                        LOGGER.error(mue);
                    }
                }

                try {
                    HttpStatusCode statusCode = httpClient.executeMethod(method);
                    if (xmlPipelineContext != null) {
                        final DependencyContext dependencyContext =
                            xmlPipelineContext.getDependencyContext();
                        if (dependencyContext != null &&
                                dependencyContext.isTrackingDependencies()) {
View Full Code Here

        // in the specified period.
        final HttpClientFactory factory = HttpClientFactory.getDefaultInstance();
        final HttpClientBuilder builder = factory.createClientBuilder();
        builder.setConnectionTimeout(timeout);
        builder.setRoundTripTimeout(timeout);
        final HttpClient httpClient = builder.buildHttpClient();

        final GetMethod method = new GetMethod(url.toExternalForm());
        final HostConfiguration configuration = new HostConfiguration();
        configuration.setHost(url.getHost(), url.getPort(), url.getProtocol());
        method.setHostConfiguration(configuration);
        method.setFollowRedirects(true);

        // Get the proxy config to use for the host.
        final Proxy proxy = manager.getProxy(url.getHost());
        if (proxy != null) {
            configuration.setProxy(proxy.getHost(), proxy.getPort());

            if (proxy.useAuthorization()) {
                method.setDoAuthentication(true);

                // mock up a authentication challenge so we can get
                // the response (which can be sent before the
                // challenge if we want to save time and effort)
                method.setRequestHeader(
                        HTTPAuthorizationScheme.PROXY_AUTHORIZATION_HEADER,
                        HTTPAuthorizationScheme.BASIC.
                        createResponseForChallenge(
                                HTTPAuthorizationScheme.MOCK_CHALLENGE_BASIC,
                                proxy));
            }
        }

        // set the additional headers
        if (httpConfig != null) {
            for (Iterator iter = httpConfig.getHeaderNames(); iter.hasNext();) {

                final String headerName = (String) iter.next();
                final Iterator headerValues =
                    httpConfig.getHeaderValues(headerName);
                while (headerValues.hasNext()) {
                    final String headerValue = (String) headerValues.next();
                    method.addRequestHeader(headerName, headerValue);
                }
            }
        }

        // allow subclasses to add things to the method and to register the
        // start of the method execution
        preExecute(method);
        httpClient.executeMethod(method);
        return createHttpContent(url, method);
    }
View Full Code Here

        HttpClientFactory factory = HttpClientFactory.getDefaultInstance();
        HttpClientBuilder builder = factory.createClientBuilder();
        builder.setConnectionTimeout(connectionTimeout);
        builder.setRoundTripTimeout(connectionTimeout);
        HttpClient httpClient = builder.buildHttpClient();

        URL netURL = null;
        try {
            netURL = new URL(url);
        } catch (MalformedURLException e) {
View Full Code Here

                        url.getHost() + ":" + url.getPort());
            }

            HttpClientFactory factory = HttpClientFactory.getDefaultInstance();
            HttpClientBuilder builder = factory.createClientBuilder();
            HttpClient httpClient = builder.buildHttpClient();
            httpClient.executeMethod(method);
        }
        return method;
    }
View Full Code Here

TOP

Related Classes of com.volantis.shared.net.http.client.HttpClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.