Package org.apache.http

Examples of org.apache.http.Header$BufferedHeader


         public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException
         {
            HttpEntity entity = response.getEntity();
            if (entity != null)
            {
               Header header = entity.getContentEncoding();
               if (header != null)
               {
                  HeaderElement[] codecs = header.getElements();
                  for (int i = 0; i < codecs.length; i++)
                  {
                     if (codecs[i].getName().equalsIgnoreCase("gzip"))
                     {
                        response.setEntity(new GzipDecompressingEntity(response.getEntity()));
View Full Code Here


       * org.tigris.noodle.filters.CheckForRedirect
       */
      if (statusCode >= HttpServletResponse.SC_MULTIPLE_CHOICES /* 300 */
               && statusCode < HttpServletResponse.SC_NOT_MODIFIED /* 304 */)
      {
         Header locationHeader = proxyResponse.getLastHeader(HttpHeaders.LOCATION);
         if (locationHeader == null)
         {
            throw new ServletException("Received status code: " + statusCode
                     + " but no " + HttpHeaders.LOCATION + " header was found in the response");
         }
         /*
          * Modify the redirect to go to this proxy servlet rather that the proxied host
          */
         String locStr = rewriteUrlFromResponse(servletRequest, locationHeader.getValue());

         servletResponse.sendRedirect(locStr);
         return true;
      }
      /*
 
View Full Code Here

   
    //设置响应拦截器
        httpClient.addResponseInterceptor(new HttpResponseInterceptor() {
            public void process(final HttpResponse response, final HttpContext context) throws HttpException, IOException {
                HttpEntity entity = response.getEntity();
                Header contentEncoding = entity.getContentEncoding();
                if (contentEncoding != null) {
                    HeaderElement[] codecs = contentEncoding.getElements();
                    for (HeaderElement codec : codecs) {
                      //处理GZIP解压缩
                        if (codec.getName().equalsIgnoreCase("gzip")) {
                            response.setEntity(new GzipDecompressingEntity(response.getEntity()));
                            return;
View Full Code Here

      entity = response.getEntity();
      //服务端返回的状态码
      int statusCode = response.getStatusLine().getStatusCode();
      if (statusCode != HttpStatus.SC_OK) {
        if (statusCode != HttpStatus.SC_NOT_FOUND) {
          Header locationHeader = response.getFirstHeader("Location");
          //如果是301、302跳转,获取跳转URL即可返回
          if (locationHeader != null && (statusCode == HttpStatus.SC_MOVED_PERMANENTLY || statusCode == HttpStatus.SC_MOVED_TEMPORARILY))
            fetchResult.setMovedToUrl(URLCanonicalizer.getCanonicalURL(locationHeader.getValue(), toFetchURL));
        }
        //只要不是OK的除了设置跳转URL外设置statusCode即可返回
        //判断是否有忽略状态码的设置
        if (this.site.getSkipStatusCode() != null && this.site.getSkipStatusCode().trim().length() > 0){
          String[] scs = this.site.getSkipStatusCode().split(",");
View Full Code Here

  private Page load(HttpEntity entity) throws Exception {
    Page page = new Page();
   
    //设置返回内容的ContentType
    String contentType = null;
    Header type = entity.getContentType();
    if (type != null)
      contentType = type.getValue();
    page.setContentType(contentType);
   
    //设置返回内容的字符编码
    String contentEncoding = null;
    Header encoding = entity.getContentEncoding();
    if (encoding != null)
      contentEncoding = encoding.getValue();
    page.setEncoding(contentEncoding);
   
    //设置返回内容的字符集
    String contentCharset = EntityUtils.getContentCharSet(entity);
    page.setCharset(contentCharset);
View Full Code Here

            // check for post redirect as post redirects are not handled
            // automatically
            // RFC2616 (10.3 Redirection 3xx).
            // The second request (forwarded method) can only be a GET or HEAD.
            Header locationHeader = response.getFirstHeader("location");

            if(locationHeader != null
                && req instanceof HttpPost
                &&  (response.getStatusLine().getStatusCode()
                        == HttpStatus.SC_MOVED_PERMANENTLY
                     || response.getStatusLine().getStatusCode()
                        == HttpStatus.SC_MOVED_TEMPORARILY
                     || response.getStatusLine().getStatusCode()
                        == HttpStatus.SC_SEE_OTHER)
                && redirects < MAX_REDIRECTS)
            {
                HttpRequestBase oldreq = req;
                oldreq.abort();

                String newLocation = locationHeader.getValue();

                // append query string if any
                HttpEntity en = ((HttpPost) oldreq).getEntity();
                if(en != null && en instanceof StringEntity)
                {
View Full Code Here

            // check for post redirect as post redirects are not handled
            // automatically
            // RFC2616 (10.3 Redirection 3xx).
            // The second request (forwarded method) can only be a GET or HEAD.
            Header locationHeader = response.getFirstHeader("location");

            if(locationHeader != null
                && req instanceof HttpPost
                &&  (response.getStatusLine().getStatusCode()
                        == HttpStatus.SC_MOVED_PERMANENTLY
                     || response.getStatusLine().getStatusCode()
                        == HttpStatus.SC_MOVED_TEMPORARILY
                     || response.getStatusLine().getStatusCode()
                        == HttpStatus.SC_SEE_OTHER)
                && redirects < MAX_REDIRECTS)
            {
                HttpRequestBase oldreq = req;
                oldreq.abort();

                String newLocation = locationHeader.getValue();

                // append query string if any
                HttpEntity en = ((HttpPost) oldreq).getEntity();
                if(en != null && en instanceof StringEntity)
                {
View Full Code Here

          callback.onSuccess(response.toString());

          // headers response
          HeaderIterator it = response.headerIterator();
          while (it.hasNext()) {
            Header header = it.nextHeader();
            responseHeaders
                .put(header.getName(), header.getValue());
          }

        } catch (Exception ex) {
          callback.onException(ex);
        } finally {
View Full Code Here

            //parsing responseHeaders
          
            HeaderIterator it = httpResponse.headerIterator();
            while (it.hasNext()){
              Header header = it.nextHeader();
              responseHeaders.put(header.getName(), header.getValue());
            }
           
            //Parsing response
            this.response = FileUtils.readInputStream(httpResponse.getEntity().getContent());
           
View Full Code Here

                    + " body: "
                    + note);
            }
           
            if (statusCode == 201) {
                Header loc = response.getFirstHeader("Location");
                if (loc != null) {
                    String locS = loc.getValue();
                    if (!StringUtils.isBlank(locS) && locS.matches(".*/[0-9]+$")) {
                        try {
                            return NumberUtils.createLong(
                                    locS.substring(locS.lastIndexOf("/") + 1));
                        } catch (NumberFormatException e) {
View Full Code Here

TOP

Related Classes of org.apache.http.Header$BufferedHeader

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.