org.apache.http.HeaderIterator Java Examples

The following examples show how to use org.apache.http.HeaderIterator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApacheHttpClientConfig.java    From sfg-blog-posts with GNU General Public License v3.0 6 votes vote down vote up
@Bean
public ConnectionKeepAliveStrategy connectionKeepAliveStrategy() {
  return (httpResponse, httpContext) -> {
    HeaderIterator headerIterator = httpResponse.headerIterator(HTTP.CONN_KEEP_ALIVE);
    HeaderElementIterator elementIterator = new BasicHeaderElementIterator(headerIterator);

    while (elementIterator.hasNext()) {
      HeaderElement element = elementIterator.nextElement();
      String param = element.getName();
      String value = element.getValue();
      if (value != null && param.equalsIgnoreCase("timeout")) {
        return Long.parseLong(value) * 1000; // convert to ms
      }
    }

    return DEFAULT_KEEP_ALIVE_TIME;
  };
}
 
Example #2
Source File: NUHttpOptions.java    From neembuu-uploader with GNU General Public License v3.0 6 votes vote down vote up
public Set<String> getAllowedMethods(final HttpResponse response) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }

    HeaderIterator it = response.headerIterator("Allow");
    Set<String> methods = new HashSet<String>();
    while (it.hasNext()) {
        Header header = it.nextHeader();
        HeaderElement[] elements = header.getElements();
        for (HeaderElement element : elements) {
            methods.add(element.getName());
        }
    }
    return methods;
}
 
Example #3
Source File: AbstractWarcRecord.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
protected static void writeHeaders(final HeaderGroup headers, final OutputStream output) throws IOException {
	for (final HeaderIterator it = headers.iterator(); it.hasNext();) {
		final org.apache.http.Header header = it.nextHeader();
		Util.toOutputStream(BasicLineFormatter.formatHeader(header, null), output);
		output.write(ByteArraySessionOutputBuffer.CRLF);
	}
}
 
Example #4
Source File: InputStreamTestMocks.java    From BUbiNG with Apache License 2.0 5 votes vote down vote up
public static Set<String> keys(HeaderGroup hg) {
	Set<String> ret = new HashSet<>();
	for (HeaderIterator it = hg.iterator(); it.hasNext();) {
		Header header = it.nextHeader();
		ret.add(header.getName().toLowerCase());
	}
	return ret;
}
 
Example #5
Source File: HttpClientUtils.java    From onetwo with Apache License 2.0 5 votes vote down vote up
public static String toString(HttpResponse response) throws ParseException, IOException{
	StringBuilder str = new StringBuilder();
	str.append("statusCode:")
		.append(response.getStatusLine().getStatusCode())
		.append("\n");
	HeaderIterator headerIt = response.headerIterator();
	while(headerIt.hasNext()){
		Header header = headerIt.nextHeader();
		str.append(header).append("\n");
	}
	HttpEntity entity = response.getEntity();
	str.append(EntityUtils.toString(entity));
	return str.toString();
}
 
Example #6
Source File: HttpClientTest.java    From onetwo with Apache License 2.0 5 votes vote down vote up
static void printResponse(HttpResponse response) throws ParseException, IOException{
	System.out.println("statusCode:"+response.getStatusLine().getStatusCode());
	HeaderIterator headerIt = response.headerIterator();
	while(headerIt.hasNext()){
		Header header = headerIt.nextHeader();
		System.out.println(header);
	}
	HttpEntity entity = response.getEntity();
	System.out.println(EntityUtils.toString(entity));
}
 
Example #7
Source File: AbstractHttpTransport.java    From consul-api with Apache License 2.0 5 votes vote down vote up
private void logRequest(HttpUriRequest httpRequest) {
	StringBuilder sb = new StringBuilder();

	// method
	sb.append(httpRequest.getMethod());
	sb.append(" ");

	// url
	sb.append(httpRequest.getURI());
	sb.append(" ");

	// headers, if any
	HeaderIterator iterator = httpRequest.headerIterator();
	if (iterator.hasNext()) {
		sb.append("Headers:[");

		Header header = iterator.nextHeader();
		sb.append(header.getName()).append("=").append(header.getValue());

		while (iterator.hasNext()) {
			header = iterator.nextHeader();
			sb.append(header.getName()).append("=").append(header.getValue());
			sb.append(";");
		}

		sb.append("] ");
	}

	//
	log.finest(sb.toString());
}
 
Example #8
Source File: WrappedHttpUriRequest.java    From soabase with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator(String name)
{
    return request.headerIterator(name);
}
 
Example #9
Source File: OptionsHttp11Response.java    From apigee-android-sdk with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator(String name) {
	return this.headergroup.iterator(name);
}
 
Example #10
Source File: OptionsHttp11Response.java    From apigee-android-sdk with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator() {
	return this.headergroup.iterator();
}
 
Example #11
Source File: HttpProtocol.java    From storm-crawler with Apache License 2.0 4 votes vote down vote up
@Override
public ProtocolResponse handleResponse(HttpResponse response)
        throws IOException {

    StatusLine statusLine = response.getStatusLine();
    int status = statusLine.getStatusCode();

    StringBuilder verbatim = new StringBuilder();
    if (storeHTTPHeaders) {
        verbatim.append(statusLine.toString()).append("\r\n");
    }

    Metadata metadata = new Metadata();
    HeaderIterator iter = response.headerIterator();
    while (iter.hasNext()) {
        Header header = iter.nextHeader();
        if (storeHTTPHeaders) {
            verbatim.append(header.toString()).append("\r\n");
        }
        metadata.addValue(header.getName().toLowerCase(Locale.ROOT),
                header.getValue());
    }

    MutableBoolean trimmed = new MutableBoolean();

    byte[] bytes = new byte[] {};

    if (!Status.REDIRECTION.equals(Status.fromHTTPCode(status))) {
        bytes = HttpProtocol.toByteArray(response.getEntity(), maxContent,
                trimmed);
        if (trimmed.booleanValue()) {
            metadata.setValue(ProtocolResponse.TRIMMED_RESPONSE_KEY, "true");
            LOG.warn("HTTP content trimmed to {}", bytes.length);
        }
    }

    if (storeHTTPHeaders) {
        verbatim.append("\r\n");
        metadata.setValue(ProtocolResponse.RESPONSE_HEADERS_KEY,
                verbatim.toString());
    }

    return new ProtocolResponse(bytes, status, metadata);
}
 
Example #12
Source File: BasicCloseableHttpResponse.java    From esigate with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator(String name) {
    return httpResponse.headerIterator(name);
}
 
Example #13
Source File: BasicCloseableHttpResponse.java    From esigate with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator() {
    return httpResponse.headerIterator();
}
 
Example #14
Source File: BceCloseableHttpResponse.java    From bce-sdk-java with Apache License 2.0 4 votes vote down vote up
public HeaderIterator headerIterator(final String name) {
    return original.headerIterator(name);
}
 
Example #15
Source File: BceCloseableHttpResponse.java    From bce-sdk-java with Apache License 2.0 4 votes vote down vote up
public HeaderIterator headerIterator() {
    return original.headerIterator();
}
 
Example #16
Source File: WrappedHttpRequest.java    From soabase with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator(String name)
{
    return implementation.headerIterator(name);
}
 
Example #17
Source File: WrappedHttpRequest.java    From soabase with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator()
{
    return implementation.headerIterator();
}
 
Example #18
Source File: WrappedHttpUriRequest.java    From soabase with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator()
{
    return request.headerIterator();
}
 
Example #19
Source File: MockHttpResponse.java    From carbon-device-mgt with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator(String s) {
    return null;
}
 
Example #20
Source File: MockHttpResponse.java    From carbon-device-mgt with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator() {
    return null;
}
 
Example #21
Source File: HttpResponseProxy.java    From ibm-cos-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator(final String name) {
    return original.headerIterator(name);
}
 
Example #22
Source File: HttpResponseProxy.java    From ibm-cos-sdk-java with Apache License 2.0 4 votes vote down vote up
@Override
public HeaderIterator headerIterator() {
    return original.headerIterator();
}
 
Example #23
Source File: Response.java    From docker-java-api with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public HeaderIterator headerIterator(final String name) {
    throw new UnsupportedOperationException("Not supported yet.");
}
 
Example #24
Source File: Response.java    From docker-java-api with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public HeaderIterator headerIterator() {
    throw new UnsupportedOperationException("Not supported yet.");
}