Package org.apache.commons.httpclient

Examples of org.apache.commons.httpclient.Header


   {
       HttpClient client = new HttpClient();
       GetMethod method = new GetMethod(MessageReceiverGetURL);
       Base64 base64 = new Base64();
       String base64Credentials = new String(base64.encode("admin:admin".getBytes()));
       method.addRequestHeader(new Header("Authorization", "Basic " + base64Credentials));
       int status = client.executeMethod(method);
       if (HttpResponseCodes.SC_OK != status) {
           throw new RuntimeException("Messages can not be received");
       }
       String message = method.getResponseBodyAsString();
View Full Code Here


    {
       HttpClient client = new HttpClient();
       GetMethod method = new GetMethod(MessageReceiverSubscriberGetURL);
       Base64 base64 = new Base64();
       String base64Credentials = new String(base64.encode("admin:admin".getBytes()));
       method.addRequestHeader(new Header("Authorization", "Basic " + base64Credentials));
       int status = client.executeMethod(method);
       if (HttpResponseCodes.SC_OK != status) {
           throw new RuntimeException("Messages can not be received");
       }
       String message = method.getResponseBodyAsString();
View Full Code Here

    HttpMethod meth = fetch(tureq, httpClientInstance);
    if (meth == null) {
      setFetchError();
    }else{

      Header responseHeader = meth.getResponseHeader("Content-Type");
      String mimeType;
      if (responseHeader == null) {
        setFetchError();
        mimeType = null;
      } else {
        mimeType = responseHeader.getValue();
      }
 
      if (mimeType != null && mimeType.startsWith("text/html")) {
        // we have html content, let doDispatch handle it for
        // inline rendering, update hreq for next content request
View Full Code Here

    if (meth == null) {
      setFetchError();
      return null;
    }

    Header responseHeader = meth.getResponseHeader("Content-Type");
    if (responseHeader == null) {
      setFetchError();
      return null;
    }

    String mimeType = responseHeader.getValue();
    if (mimeType != null && mimeType.startsWith("text/html")) {
      // we have html content, let doDispatch handle it for
      // inline rendering, update hreq for next content request
      String body;
      try {
View Full Code Here

            meth.releaseConnection();
            return new NotFoundMediaResource(relPath);
          }
 
          // get or post successfully
          Header responseHeader = meth.getResponseHeader("Content-Type");
          if (responseHeader == null) {
            // error
            return new NotFoundMediaResource(relPath);
          }
          mr = new HttpRequestMediaResource(meth);
View Full Code Here

        assertNull("Saving SampleResult with HttpMethod & 404 response should not make cache entry.", getThreadCacheEntry(this.httpMethod.getPath()));
    }

    public void testSetHeadersHttpMethodWithSampleResultWithResponseCode200GivesCacheEntry() throws Exception {
        this.httpMethod.setURI(this.uri);
        this.httpMethod.addRequestHeader(new Header(HTTPConstantsInterface.IF_MODIFIED_SINCE, this.currentTimeInGMT, false));
        this.httpMethod.addRequestHeader(new Header(HTTPConstantsInterface.ETAG, EXPECTED_ETAG, false));
        saveDetailsWithHttpMethodAndSampleResultWithResponseCode("200");
        setHeadersWithUrlAndHttpMethod();
        checkRequestHeader(HTTPConstantsInterface.IF_NONE_MATCH, EXPECTED_ETAG);
        checkRequestHeader(HTTPConstantsInterface.IF_MODIFIED_SINCE, this.currentTimeInGMT);
    }
View Full Code Here

        this.cacheManager.clear();
        assertTrue("ThreadCache should be emptied by call to clear.", getThreadCache().isEmpty());
    }

    private void checkRequestHeader(String requestHeader, String expectedValue) {
        Header header = this.httpMethod.getRequestHeader(requestHeader);
        assertEquals("Wrong name in header for " + requestHeader, requestHeader, header.getName());
        assertEquals("Wrong value for header " + header, expectedValue, header.getValue());
    }
View Full Code Here

        private Header etagHeader;
        private String expires;
        private String cacheControl;
       
        HttpMethodStub() {
            this.lastModifiedHeader = new Header(HTTPConstantsInterface.LAST_MODIFIED, currentTimeInGMT);
            this.etagHeader = new Header(HTTPConstantsInterface.ETAG, EXPECTED_ETAG);
        }
View Full Code Here

            if (HTTPConstantsInterface.LAST_MODIFIED.equals(headerName)) {
                return this.lastModifiedHeader;
            } else if (HTTPConstantsInterface.ETAG.equals(headerName)) {
                return this.etagHeader;
            } else if (HTTPConstantsInterface.EXPIRES.equals(headerName)) {
                return expires == null ? null : new Header(HTTPConstantsInterface.EXPIRES, expires);
            } else if (HTTPConstantsInterface.CACHE_CONTROL.equals(headerName)) {
                return cacheControl == null ? null : new Header(HTTPConstantsInterface.CACHE_CONTROL, cacheControl);
            }
            return null;
        }
View Full Code Here

            InputStream instream = httpMethod.getResponseBodyAsStream();

            if (instream != null) {// will be null for HEAD
                instream = new CountingInputStream(instream);
                try {
                    Header responseHeader = httpMethod.getResponseHeader(HEADER_CONTENT_ENCODING);
                    if (responseHeader!= null && ENCODING_GZIP.equals(responseHeader.getValue())) {
                        InputStream tmpInput = new GZIPInputStream(instream); // tmp inputstream needs to have a good counting
                        res.setResponseData(readResponse(res, tmpInput, (int) httpMethod.getResponseContentLength()));                       
                    } else {
                        res.setResponseData(readResponse(res, instream, (int) httpMethod.getResponseContentLength()));
                    }
                } finally {
                    JOrphanUtils.closeQuietly(instream);
                }
            }

            res.sampleEnd();
            // Done with the sampling proper.

            // Now collect the results into the HTTPSampleResult:

            res.setSampleLabel(httpMethod.getURI().toString());
            // Pick up Actual path (after redirects)

            res.setResponseCode(Integer.toString(statusCode));
            res.setSuccessful(isSuccessCode(statusCode));

            res.setResponseMessage(httpMethod.getStatusText());

            String ct = null;
            Header h = httpMethod.getResponseHeader(HEADER_CONTENT_TYPE);
            if (h != null)// Can be missing, e.g. on redirect
            {
                ct = h.getValue();
                res.setContentType(ct);// e.g. text/html; charset=ISO-8859-1
                res.setEncodingAndType(ct);
            }

            res.setResponseHeaders(getResponseHeaders(httpMethod));
            if (res.isRedirect()) {
                final Header headerLocation = httpMethod.getResponseHeader(HEADER_LOCATION);
                if (headerLocation == null) { // HTTP protocol violation, but avoids NPE
                    throw new IllegalArgumentException("Missing location header");
                }
                res.setRedirectLocation(headerLocation.getValue());
            }

            // record some sizes to allow HTTPSampleResult.getBytes() with different options
            if (instream != null) {
                res.setBodySize(((CountingInputStream) instream).getCount());
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.Header

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.