Package org.apache.http.protocol

Examples of org.apache.http.protocol.HttpContext


    public void requestReceived(final NHttpServerConnection conn) {
        HttpExchange httpExchange = ensureNotNull(getHttpExchange(conn));
        try {
            HttpRequest request = conn.getHttpRequest();
            HttpContext context = httpExchange.getContext();
            request.setParams(new DefaultedHttpParams(request.getParams(), this.params));

            context.setAttribute(ExecutionContext.HTTP_REQUEST, request);
            context.setAttribute(ExecutionContext.HTTP_CONNECTION, conn);
            this.httpProcessor.process(request, context);

            httpExchange.setRequest(request);
            HttpAsyncRequestHandler<Object> requestHandler = getRequestHandler(request);
            httpExchange.setRequestHandler(requestHandler);
View Full Code Here


    public void outputReady(final NHttpServerConnection conn, final ContentEncoder encoder) {
        HttpExchange httpExchange = ensureNotNull(getHttpExchange(conn));
        try {
            HttpAsyncResponseProducer responseProducer = httpExchange.getResponseProducer();
            HttpContext context = httpExchange.getContext();
            HttpResponse response = httpExchange.getResponse();

            responseProducer.produceContent(encoder, conn);
            httpExchange.setResponseState(MessageState.BODY_STREAM);
            if (encoder.isCompleted()) {
View Full Code Here

    private void processRequest(
            final NHttpServerConnection conn,
            final HttpExchange httpExchange) throws HttpException, IOException {
        HttpAsyncRequestHandler<Object> handler = httpExchange.getRequestHandler();
        HttpContext context = httpExchange.getContext();
        HttpAsyncRequestConsumer<?> consumer = httpExchange.getRequestConsumer();
        consumer.requestCompleted(context);
        httpExchange.setRequestState(MessageState.COMPLETED);
        Exception exception = consumer.getException();
        if (exception != null) {
View Full Code Here

    }

    private void commitResponse(
            final NHttpServerConnection conn,
            final HttpExchange httpExchange) throws IOException, HttpException {
        HttpContext context = httpExchange.getContext();
        HttpRequest request = httpExchange.getRequest();
        HttpAsyncResponseProducer responseProducer = httpExchange.getResponseProducer();
        HttpResponse response = responseProducer.generateResponse();
        response.setParams(new DefaultedHttpParams(response.getParams(), this.params));

        httpExchange.setResponse(response);

        context.setAttribute(ExecutionContext.HTTP_RESPONSE, response);
        this.httpProcessor.process(response, context);

        HttpEntity entity = response.getEntity();
        if (entity != null && !canResponseHaveBody(request, response)) {
            response.setEntity(null);
View Full Code Here

     * @param httpRequest the http Request to execute
     * @return the response
     * @throws IOException can be thrown
     */
    protected HttpResponse executeMethod(HttpUriRequest httpRequest) throws IOException {
        HttpContext localContext = new BasicHttpContext();
        if (getEndpoint().isAuthenticationPreemptive()) {
            BasicScheme basicAuth = new BasicScheme();
            localContext.setAttribute("preemptive-auth", basicAuth);
        }
        if (httpContext != null) {
            localContext = new BasicHttpContext(httpContext);
        }
        return httpClient.execute(httpRequest, localContext);
View Full Code Here

        String mimeType = "";
        String hostAddress = null;
       
        // Create a local instance of cookie store, and bind to local context
        // Without this we get killed w/lots of threads, due to sync() on single cookie store.
        HttpContext localContext = new BasicHttpContext();
        CookieStore cookieStore = new BasicCookieStore();
        localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

        StringBuilder fetchTrace = null;
        if (LOGGER.isTraceEnabled()) {
            fetchTrace = new StringBuilder("Fetched url: " + url);
        }
       
        try {
            request.setURI(new URI(url));
           
            readStartTime = System.currentTimeMillis();
            response = _httpClient.execute(request, localContext);

            Header[] headers = response.getAllHeaders();
            for (Header header : headers) {
                headerMap.add(header.getName(), header.getValue());
            }

            int httpStatus = response.getStatusLine().getStatusCode();
            if (LOGGER.isTraceEnabled()) {
                fetchTrace.append("; status code: " + httpStatus);
                if (headerMap.getFirst(HttpHeaderNames.CONTENT_LENGTH) != null) {
                    fetchTrace.append("; Content-Length: " + headerMap.getFirst(HttpHeaderNames.CONTENT_LENGTH));
                }

                if (headerMap.getFirst(HttpHeaderNames.LOCATION) != null) {
                    fetchTrace.append("; Location: " + headerMap.getFirst(HttpHeaderNames.LOCATION));
                }
            }
           
            if ((httpStatus < 200) || (httpStatus >= 300)) {
                // We can't just check against SC_OK, as some wackos return 201, 202, etc
                throw new HttpFetchException(url, "Error fetching " + url, httpStatus, headerMap);
            }

            redirectedUrl = extractRedirectedUrl(url, localContext);

            URI permRedirectUri = (URI)localContext.getAttribute(PERM_REDIRECT_CONTEXT_KEY);
            if (permRedirectUri != null) {
                newBaseUrl = permRedirectUri.toURL().toExternalForm();
            }

            Integer redirects = (Integer)localContext.getAttribute(REDIRECT_COUNT_CONTEXT_KEY);
            if (redirects != null) {
                numRedirects = redirects.intValue();
            }
           
            hostAddress = (String)(localContext.getAttribute(HOST_ADDRESS));
            if (hostAddress == null) {
                throw new UrlFetchException(url, "Host address not saved in context");
            }

            Header cth = response.getFirstHeader(HttpHeaderNames.CONTENT_TYPE);
View Full Code Here

   private String post(String path, HttpEntity entity) throws IOException
   {
      HttpPost post = new HttpPost(getBaseURL() + getContextPath() + path);
      post.setEntity(entity);
      HttpContext context = new BasicHttpContext();
      HttpResponse response = new DefaultHttpClient().execute(post, context);
      return Streams.toString(response.getEntity().getContent()).trim();
   }
View Full Code Here

   {
      HttpGet request = new HttpGet(getBaseURL() + getContextPath() + path);
      if (headers != null && headers.length > 0) {
         request.setHeaders(headers);
      }
      HttpContext context = new BasicHttpContext();
      HttpResponse response = client.execute(request, context);

      return new HttpAction<HttpGet>(client, context, request, response, getBaseURL(), getContextPath());
   }
View Full Code Here

   {
      DefaultHttpClient client = new DefaultHttpClient();
      try
      {
         HttpHead request = new HttpHead(getBaseURL() + getContextPath() + path);
         HttpContext context = new BasicHttpContext();
         HttpResponse response = client.execute(request, context);

         return new HttpAction<HttpHead>(client, context, request, response, getBaseURL(), getContextPath());
      }
      catch (Exception e)
View Full Code Here

              && AndroidRestClient.authorizationValue.length() > 0) {
            meth.addHeader("Authorization",
                AndroidRestClient.authorizationValue);
          }

          HttpContext localContext = new BasicHttpContext();
          HttpResponse response = client.execute(meth, localContext);
          callback.onSuccess(response.toString());

          // headers response
          HeaderIterator it = response.headerIterator();
View Full Code Here

TOP

Related Classes of org.apache.http.protocol.HttpContext

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.