Example usage for org.apache.http.params DefaultedHttpParams DefaultedHttpParams

List of usage examples for org.apache.http.params DefaultedHttpParams DefaultedHttpParams

Introduction

In this page you can find the example usage for org.apache.http.params DefaultedHttpParams DefaultedHttpParams.

Prototype

public DefaultedHttpParams(HttpParams httpParams, HttpParams httpParams2) 

Source Link

Usage

From source file:android.core.TestHttpClient.java

public HttpResponse execute(final HttpRequest request, final HttpHost targetHost,
        final HttpClientConnection conn) throws HttpException, IOException {
    this.context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
    this.context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost);
    this.context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
    request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
    this.httpexecutor.preProcess(request, this.httpproc, this.context);
    HttpResponse response = this.httpexecutor.execute(request, conn, this.context);
    response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
    this.httpexecutor.postProcess(response, this.httpproc, this.context);
    return response;
}

From source file:org.apache.axis2.transport.http.server.AxisHttpService.java

public void handleRequest(final AxisHttpConnection conn, final HttpContext context)
        throws IOException, HttpException {

    MessageContext msgContext = configurationContext.createMessageContext();
    msgContext.setIncomingTransportName(Constants.TRANSPORT_HTTP);

    if (conn != null) {
        msgContext.setProperty(MessageContext.REMOTE_ADDR, conn.getRemoteAddress().getHostAddress());
        msgContext.setProperty(MessageContext.TRANSPORT_ADDR, conn.getLocalAddress().getHostAddress());

        if (LOG.isDebugEnabled()) {
            LOG.debug("Remote address of the connection : " + conn.getRemoteAddress().getHostAddress());
        }/*  w  ww. j a va  2s .c  om*/
    }

    HttpResponse response;
    try {
        HttpRequest request = conn.receiveRequest();
        RequestLine requestLine = request.getRequestLine();
        if (requestLine != null) {
            msgContext.setProperty(HTTPConstants.HTTP_METHOD, requestLine.getMethod());
        }
        request.setParams(new DefaultedHttpParams(request.getParams(), this.params));
        ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
        if (!ver.lessEquals(HttpVersion.HTTP_1_1)) {
            // Downgrade protocol version if greater than HTTP/1.1 
            ver = HttpVersion.HTTP_1_1;
        }

        response = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_OK, context);
        response.setParams(new DefaultedHttpParams(response.getParams(), this.params));

        if (request instanceof HttpEntityEnclosingRequest) {
            if (((HttpEntityEnclosingRequest) request).expectContinue()) {
                HttpResponse ack = this.responseFactory.newHttpResponse(ver, HttpStatus.SC_CONTINUE, context);
                ack.setParams(new DefaultedHttpParams(ack.getParams(), this.params));
                conn.sendResponse(ack);
                conn.flush();
            }
        }

        // Create Axis request and response objects
        AxisHttpRequestImpl axisreq = new AxisHttpRequestImpl(conn, request, this.httpProcessor, context);
        AxisHttpResponseImpl axisres = new AxisHttpResponseImpl(conn, response, this.httpProcessor, context);

        // Prepare HTTP request
        axisreq.prepare();

        // Run the service
        doService(axisreq, axisres, context, msgContext);

        // Make sure the request content is fully consumed
        InputStream instream = conn.getInputStream();
        if (instream != null) {
            instream.close();
        }

        // Commit response if not committed
        if (!axisres.isCommitted()) {
            axisres.commit();
        }

        // Make sure the response content is properly terminated
        OutputStream outstream = conn.getOutputStream();
        if (outstream != null) {
            outstream.close();
        }

    } catch (HttpException ex) {
        response = this.responseFactory.newHttpResponse(HttpVersion.HTTP_1_0,
                HttpStatus.SC_INTERNAL_SERVER_ERROR, context);
        response.setParams(new DefaultedHttpParams(response.getParams(), this.params));
        handleException(ex, response);
        this.httpProcessor.process(response, context);
        conn.sendResponse(response);
    }

    conn.flush();
    if (!this.connStrategy.keepAlive(response, context)) {
        conn.close();
    } else {
        conn.reset();
    }
}

From source file:net.kungfoo.grizzly.proxy.impl.ConnectingHandler.java

/**
 * Triggered when the connection is ready to send an HTTP request.
 *
 * @see NHttpClientConnection//  www  . ja  va  2 s.  c  om
 *
 * @param conn HTTP connection that is ready to send an HTTP request
 */
public void requestReady(final NHttpClientConnection conn) {
    System.out.println(conn + " [proxy->origin] request ready");

    HttpContext context = conn.getContext();
    ProxyProcessingInfo proxyTask = (ProxyProcessingInfo) context.getAttribute(ProxyProcessingInfo.ATTRIB);

    // TODO: change it to ReentrantLock
    synchronized (proxyTask) {
        if (requestReadyValidateConnectionState(proxyTask))
            return;

        HttpRequest request = proxyTask.getRequest();
        if (request == null) {
            throw new IllegalStateException("HTTP request is null");
        }

        requestReadyCleanUpHeaders(request);

        HttpHost targetHost = proxyTask.getTarget();

        try {

            request.setParams(new DefaultedHttpParams(request.getParams(), this.params));

            // Pre-process HTTP request
            context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
            context.setAttribute(ExecutionContext.HTTP_TARGET_HOST, targetHost);

            this.httpProcessor.process(request, context);
            // and send it to the origin server
            Request originalRequest = proxyTask.getOriginalRequest();
            int length = originalRequest.getContentLength();
            if (length > 0) {
                BasicHttpEntity httpEntity = new BasicHttpEntity();
                httpEntity.setContentLength(originalRequest.getContentLengthLong());
                /*
                          httpEntity.setContent(((InternalInputBuffer) originalRequest.getInputBuffer()).getInputStream());
                          ((BasicHttpEntityEnclosingRequest) request).setEntity(httpEntity);
                */
            }
            conn.submitRequest(request);
            // Update connection state
            proxyTask.setOriginState(ConnState.REQUEST_SENT);

            System.out.println(conn + " [proxy->origin] >> " + request.getRequestLine().toString());

        } catch (IOException ex) {
            shutdownConnection(conn);
        } catch (HttpException ex) {
            shutdownConnection(conn);
        }

    }
}

From source file:org.fourthline.cling.transport.impl.apache.StreamClientImpl.java

protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
    HttpParams localParams = new BasicHttpParams();

    localParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
            requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0
                    : HttpVersion.HTTP_1_1);

    // DefaultHttpClient adds HOST header automatically in its default processor

    // Add the default user agent if not already set on the message
    if (!requestMessage.getHeaders().containsKey(UpnpHeader.Type.USER_AGENT)) {
        HttpProtocolParams.setUserAgent(localParams, getConfiguration()
                .getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion()));
    }/*from  w w  w  .j a v a  2  s  .c  om*/

    return new DefaultedHttpParams(localParams, globalParams);
}

From source file:org.teleal.cling.transport.impl.apache.StreamClientImpl.java

protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
    HttpParams localParams = new BasicHttpParams();

    localParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
            requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0
                    : HttpVersion.HTTP_1_1);

    // DefaultHttpClient adds HOST header automatically in its default
    // processor// w  w  w  .ja v  a2s  .  c  o m

    // Let's add the user-agent header on every request
    HttpProtocolParams.setUserAgent(localParams, getConfiguration()
            .getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion()));

    return new DefaultedHttpParams(localParams, globalParams);
}