Examples of BasicHttpContext


Examples of org.apache.http.protocol.BasicHttpContext

        private volatile HttpResponse response;
        private volatile Cancellable asyncProcess;

        HttpExchange() {
            super();
            this.context = new BasicHttpContext();
            this.requestState = MessageState.READY;
            this.responseState = MessageState.READY;
        }
View Full Code Here

Examples of org.apache.http.protocol.BasicHttpContext

    authCache.put(
        new HttpHost( host, port, "http" ),
        new BasicScheme()
        );

    BasicHttpContext localContext = new BasicHttpContext();
    localContext.setAttribute( ClientContext.AUTH_CACHE, authCache );

    return new ResteasyClientBuilder()
    .httpEngine( new ApacheHttpClient4Engine( httpClient, localContext ) )
    .build();
  }
View Full Code Here

Examples of org.apache.http.protocol.BasicHttpContext

     * @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

Examples of org.apache.http.protocol.BasicHttpContext

        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

Examples of org.apache.http.protocol.BasicHttpContext

   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

Examples of org.apache.http.protocol.BasicHttpContext

   {
      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

Examples of org.apache.http.protocol.BasicHttpContext

   {
      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

Examples of org.apache.http.protocol.BasicHttpContext

              && 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

Examples of org.apache.http.protocol.BasicHttpContext

    protected abstract BasicHttpProcessor createHttpProcessor();


    protected HttpContext createHttpContext() {
        HttpContext context = new BasicHttpContext();
        context.setAttribute(
                ClientContext.SCHEME_REGISTRY,
                getConnectionManager().getSchemeRegistry());
        context.setAttribute(
                ClientContext.AUTHSCHEME_REGISTRY,
                getAuthSchemes());
        context.setAttribute(
                ClientContext.COOKIESPEC_REGISTRY,
                getCookieSpecs());
        context.setAttribute(
                ClientContext.COOKIE_STORE,
                getCookieStore());
        context.setAttribute(
                ClientContext.CREDS_PROVIDER,
                getCredentialsProvider());
        return context;
    }
View Full Code Here

Examples of org.apache.http.protocol.BasicHttpContext

        CountDownLatch awaitLatch = new CountDownLatch(1);
        final ConMan conMan = new ConMan(connLatch, awaitLatch);
        final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>();
        final CountDownLatch getLatch = new CountDownLatch(1);
        final DefaultHttpClient client = new DefaultHttpClient(conMan, new BasicHttpParams());
        final HttpContext context = new BasicHttpContext();
        final HttpGet httpget = new HttpGet("http://www.example.com/a");

        new Thread(new Runnable() {
            public void run() {
                try {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.