Package org.apache.http

Examples of org.apache.http.HttpRequest


        public int fillBuffer(final ReadableByteChannel channel) throws IOException {
            return this.parser.fillBuffer(channel);
        }

        public HttpRequest parse() throws IOException, HttpException {
            HttpRequest message = this.parser.parse();
            if (message != null && headerlog.isDebugEnabled()) {
                headerlog.debug(id + " >> " + message.getRequestLine().toString());
                Header[] headers = message.getAllHeaders();
                for (int i = 0; i < headers.length; i++) {
                    headerlog.debug(id + " >> " + headers[i].toString());
                }
            }
            return message;
View Full Code Here


        String httpMethod = (String) msgContext.getProperty(Constants.Configuration.HTTP_METHOD);
        if (httpMethod == null) {
            httpMethod = "POST";
        }
        endpointURLPrefix = (String) msgContext.getProperty(NhttpConstants.ENDPOINT_PREFIX);
        HttpRequest httpRequest;

        if ("POST".equals(httpMethod) || "PUT".equals(httpMethod)) {

            URL url = new URL(epr.getAddress());
            httpRequest = new BasicHttpEntityEnclosingRequest(
                httpMethod,
                msgContext.isPropertyTrue(NhttpConstants.POST_TO_URI) ?
                    epr.getAddress() : url.getPath()
                        + (url.getQuery() != null ? "?" + url.getQuery() : ""),
                msgContext.isPropertyTrue(NhttpConstants.FORCE_HTTP_1_0) ?
                    HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1);

            BasicHttpEntity entity = new BasicHttpEntity();

            if (msgContext.isPropertyTrue(NhttpConstants.FORCE_HTTP_1_0)) {
                setStreamAsTempData(entity);
            } else {
                entity.setChunked(chunked);
                if (!chunked) {
                    setStreamAsTempData(entity);
                }
            }
            ((BasicHttpEntityEnclosingRequest) httpRequest).setEntity(entity);

            httpRequest.setHeader(
                HTTP.CONTENT_TYPE,
                messageFormatter.getContentType(msgContext, format, msgContext.getSoapAction()));

        } else if ("GET".equals(httpMethod)) {

            URL reqURI = messageFormatter.getTargetAddress(
                    msgContext, format, new URL(epr.getAddress()));
            String path = (msgContext.isPropertyTrue(NhttpConstants.POST_TO_URI) ?
                    reqURI.toString() : reqURI.getPath() +
                    (reqURI.getQuery() != null ? "?" + reqURI.getQuery() : ""));

            httpRequest = new BasicHttpRequest(httpMethod, path,
                    msgContext.isPropertyTrue(NhttpConstants.FORCE_HTTP_1_0) ?
                            HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1);

            httpRequest.setHeader(HTTP.CONTENT_TYPE, messageFormatter.getContentType(
                    msgContext, format, msgContext.getSoapAction()));

        } else {

            httpRequest = new BasicHttpRequest(
                httpMethod,
                msgContext.isPropertyTrue(NhttpConstants.POST_TO_URI) ?
                    epr.getAddress() : new URL(epr.getAddress()).getPath(),
                msgContext.isPropertyTrue(NhttpConstants.FORCE_HTTP_1_0) ?
                    HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1);
        }

        // set any transport headers
        Object o = msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
        if (o != null && o instanceof Map) {
            Map<?,?> headers = (Map) o;
            for (Map.Entry entry : headers.entrySet()) {
                Object header = entry.getKey();
                Object value = entry.getValue();
                if (header instanceof String && value != null && value instanceof String) {
                    if (!HTTPConstants.HEADER_HOST.equalsIgnoreCase((String) header)) {
                        httpRequest.setHeader((String) header, (String) value);
                    }
                }
            }
        }

        // if the message is SOAP 11 (for which a SOAPAction is *required*), and
        // the msg context has a SOAPAction or a WSA-Action (give pref to SOAPAction)
        // use that over any transport header that may be available
        String soapAction = msgContext.getSoapAction();
        if (soapAction == null) {
            soapAction = msgContext.getWSAAction();
        }
        if (soapAction == null) {
            msgContext.getAxisOperation().getInputAction();
        }

        if (msgContext.isSOAP11() && soapAction != null &&
            soapAction.length() > 0) {
            Header existingHeader =
                httpRequest.getFirstHeader(HTTPConstants.HEADER_SOAP_ACTION);
            if (existingHeader != null) {
                httpRequest.removeHeader(existingHeader);
            }
            httpRequest.setHeader(HTTPConstants.HEADER_SOAP_ACTION,
                messageFormatter.formatSOAPAction(msgContext, null, soapAction));
        }

        if (NHttpConfiguration.getInstance().isKeepAliveDisabled() ||
            msgContext.isPropertyTrue(NhttpConstants.NO_KEEPALIVE)) {
            httpRequest.setHeader(HTTP.CONN_DIRECTIVE, HTTP.CONN_CLOSE);
        }

        return httpRequest;
    }
View Full Code Here

        if (conn != null) {
            this.connectionCreationTime = (Long) conn.getContext().getAttribute(
                    ClientHandler.CONNECTION_CREATION_TIME);
            try {
                HttpRequest request = axis2Req.getRequest();
                RequestLine requestLine = request.getRequestLine();
                this.lastRequestProtocol = requestLine.getProtocolVersion().toString();
                this.lastRequestHTTPMethod = requestLine.getMethod();
                this.headers = request.getAllHeaders();
            } catch (IOException ignore) {}
        }

        if (this.lastRequestStartTime != 0) {
            if (previousRequestAttempts == null) {
View Full Code Here

            if (remoteAddr != null) {
                this.remoteClientIP = remoteAddr.getHostAddress();
            }
        }

        HttpRequest req = conn.getHttpRequest();
        this.headers = req.getAllHeaders();
    }
View Full Code Here

            new ProxySelectorRoutePlanner(createSchemeRegistry(),
                                          new ProxySelectorMockup(null));

        HttpHost target =
            new HttpHost("www.test.invalid", 80, "http");
        HttpRequest request =
            new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);

        HttpRoute route = hrp.determineRoute(target, request, null);

        assertEquals("wrong target", target, route.getTargetHost());
View Full Code Here

            new ProxySelectorRoutePlanner(createSchemeRegistry(),
                                          new ProxySelectorMockup(proxies));

        HttpHost target =
            new HttpHost("www.test.invalid", 80, "http");
        HttpRequest request =
            new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);

        HttpRoute route = hrp.determineRoute(target, request, null);

        assertEquals("wrong target", target, route.getTargetHost());
View Full Code Here

        }

        public HttpMessage parse() throws IOException, HttpException {
            HttpMessage message = this.parser.parse();
            if (message != null && headerlog.isDebugEnabled()) {
                HttpRequest request = (HttpRequest) message;
                headerlog.debug(">> " + request.getRequestLine().toString());
                Header[] headers = request.getAllHeaders();
                for (int i = 0; i < headers.length; i++) {
                    headerlog.debug(">> " + headers[i].toString());
                }
            }
            return message;
View Full Code Here

            this.writer.reset();
        }

        public void write(final HttpMessage message) throws IOException, HttpException {
            if (message != null && headerlog.isDebugEnabled()) {
                HttpRequest request = (HttpRequest) message;
                headerlog.debug(">> " + request.getRequestLine().toString());
                Header[] headers = request.getAllHeaders();
                for (int i = 0; i < headers.length; i++) {
                    headerlog.debug(">> " + headers[i].toString());
                }
            }
            this.writer.write(message);
View Full Code Here

        final String      uri = "/random/" + rsplen;

        ExecReqThread[] threads = new ExecReqThread [COUNT];
        for (int i=0; i<COUNT; i++) {

            HttpRequest request = new BasicHttpRequest
                ("GET", uri, HttpVersion.HTTP_1_1);

            ExecReqThread.RequestSpec ertrs = new ExecReqThread.RequestSpec();
            ertrs.executor = httpExecutor;
            ertrs.processor = httpProcessor;
View Full Code Here

        final HttpHost target = getServerHttp();
        final HttpRoute route = new HttpRoute(target, null, false);
        final int      rsplen = 8;
        final String      uri = "/random/" + rsplen;

        HttpRequest request =
            new BasicHttpRequest("GET", uri, HttpVersion.HTTP_1_1);

        ManagedClientConnection conn = getConnection(mgr, route);
        conn.open(route, httpContext, defaultParams);
View Full Code Here

TOP

Related Classes of org.apache.http.HttpRequest

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.