Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.HttpState


       
        HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
        handlerchain.appendHandler(new AuthRequestHandler(creds));
        handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

        HttpState state = new HttpState();
        AuthScope realm1 = new AuthScope(
            this.server.getLocalAddress(),
            this.server.getLocalPort(),
            "test");
        AuthScope realm2 = new AuthScope(
            this.server.getLocalAddress(),
            this.server.getLocalPort(),
            "test2");
        state.setCredentials(realm1, new UsernamePasswordCredentials("testuser","testpass"));
        state.setCredentials(realm2, new UsernamePasswordCredentials("testuser2","testpass2"));
        this.client.setState(state);

        this.server.setRequestHandler(handlerchain);
       
        GetMethod httpget = new GetMethod("/test/");
View Full Code Here


       
        HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
        handlerchain.appendHandler(new AuthRequestHandler(creds, "test2"));
        handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

        HttpState state = new HttpState();
        AuthScope realm1 = new AuthScope(
            this.server.getLocalAddress(),
            this.server.getLocalPort(),
            "test");
        AuthScope realm2 = new AuthScope(
            this.server.getLocalAddress(),
            this.server.getLocalPort(),
            "test2");
        state.setCredentials(realm1, new UsernamePasswordCredentials("testuser","testpass"));
        state.setCredentials(realm2, new UsernamePasswordCredentials("testuser2","testpass2"));
        this.client.setState(state);

        this.server.setRequestHandler(handlerchain);
       
        GetMethod httpget = new GetMethod("/test2/");
View Full Code Here

       
        HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
        handlerchain.appendHandler(new AuthRequestHandler(creds));
        handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

        HttpState state = new HttpState();
        state.setCredentials(AuthScope.ANY, creds);
        this.client.setState(state);
        this.client.getParams().setAuthenticationPreemptive(true);
       
        this.server.setRequestHandler(handlerchain);
View Full Code Here

       
        HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
        handlerchain.appendHandler(new AuthRequestHandler(creds));
        handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

        HttpState state = new HttpState();
        this.client.setState(state);
        this.client.getParams().setAuthenticationPreemptive(true);
       
        this.server.setRequestHandler(handlerchain);
View Full Code Here

       
        HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
        handlerchain.appendHandler(new AuthRequestHandler(creds));
        handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

        HttpState state = new HttpState();
        AuthScope authscope = new AuthScope(
            this.server.getLocalAddress(),
            this.server.getLocalPort(),
            "test");
        state.setCredentials(authscope, creds);
        this.client.setState(state);

        this.server.setRequestHandler(handlerchain);

        HeadMethod head = new HeadMethod("/test/");
View Full Code Here

       
        HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
        handlerchain.appendHandler(new AuthRequestHandler(creds));
        handlerchain.appendHandler(new HttpServiceHandler(new EchoService()));

        HttpState state = new HttpState();
        AuthScope authscope = new AuthScope(
            this.server.getLocalAddress(),
            this.server.getLocalPort(),
            "test");
        state.setCredentials(authscope, creds);
        this.client.setState(state);

        this.server.setRequestHandler(handlerchain);

        PostMethod post = new PostMethod("/test/");
View Full Code Here

       
        HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
        handlerchain.appendHandler(new AuthRequestHandler(creds));
        handlerchain.appendHandler(new HttpServiceHandler(new EchoService()));

        HttpState state = new HttpState();
        AuthScope authscope = new AuthScope(
            this.server.getLocalAddress(),
            this.server.getLocalPort(),
            "test");
        state.setCredentials(authscope, creds);
        this.client.setState(state);

        this.server.setRequestHandler(handlerchain);

        PutMethod put = new PutMethod("/test/");
View Full Code Here

               method.setRequestHeader(
                       new Header("Authorization",
                                  "Basic " + SourceUtil.encodeBASE64(this.authorization)));
            }

            method.execute(new HttpState(), conn);

            String ret = method.getResponseBodyAsString();
            return new XScriptObjectInlineXML(this.xscriptManager, ret);
        } catch (ProcessingException ex) {
            throw ex;
View Full Code Here

            URL targetURL =
                    new URL(msgContext.getStrProp(MessageContext.TRANS_URL));
            String host = targetURL.getHost();
            int port = targetURL.getPort();
            HttpConnection conn = null;
            HttpState state = new HttpState();

            // create socket based on the url protocol type
            if (targetURL.getProtocol().equalsIgnoreCase("https")) {
                conn = getSecureConnection(state, host, port);
            } else {
View Full Code Here

                                PluginResponse httpServletResponse,
                                History history) throws Exception {
        int intProxyResponseCode = 999;
        // Create a default HttpClient
        HttpClient httpClient = new HttpClient();
        HttpState state = new HttpState();

        try {
            httpMethodProxyRequest.setFollowRedirects(false);
            ArrayList<String> headersToRemove = getRemoveHeaders();

            httpClient.getParams().setSoTimeout(60000);

            httpServletRequest.setAttribute("com.groupon.odo.removeHeaders", headersToRemove);

            // exception handling for httpclient
            HttpMethodRetryHandler noretryhandler = new HttpMethodRetryHandler() {
                public boolean retryMethod(
                        final HttpMethod method,
                        final IOException exception,
                        int executionCount) {
                    return false;
                }
            };

            httpMethodProxyRequest.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, noretryhandler);

            intProxyResponseCode = httpClient.executeMethod(httpMethodProxyRequest.getHostConfiguration(), httpMethodProxyRequest, state);
        } catch (Exception e) {
            // Return a gateway timeout
            httpServletResponse.setStatus(504);
            httpServletResponse.setHeader(Constants.HEADER_STATUS, "504");
            httpServletResponse.flushBuffer();
            return;
        }
        logger.info("Response code: {}, {}", intProxyResponseCode,
                HttpUtilities.getURL(httpMethodProxyRequest.getURI().toString()));

        // Pass the response code back to the client
        httpServletResponse.setStatus(intProxyResponseCode);

        // Pass response headers back to the client
        Header[] headerArrayResponse = httpMethodProxyRequest.getResponseHeaders();
        for (Header header : headerArrayResponse) {
            // remove transfer-encoding header.  The http libraries will handle this encoding
            if (header.getName().toLowerCase().equals("transfer-encoding"))
                continue;

            httpServletResponse.setHeader(header.getName(), header.getValue());
        }

        // there is no data for a HTTP 304 or 204
        if (intProxyResponseCode != HttpServletResponse.SC_NOT_MODIFIED &&
                intProxyResponseCode != HttpServletResponse.SC_NO_CONTENT) {
            // Send the content to the client
            httpServletResponse.resetBuffer();
            httpServletResponse.getOutputStream().write(httpMethodProxyRequest.getResponseBody());
        }

        // copy cookies to servlet response
        for (Cookie cookie: state.getCookies()) {
            javax.servlet.http.Cookie servletCookie = new javax.servlet.http.Cookie(cookie.getName(), cookie.getValue());

            if (cookie.getPath() != null)
                servletCookie.setPath(cookie.getPath());
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.HttpState

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.