Search in sources :

Example 36 with BasicHeader

use of org.apache.http.message.BasicHeader in project pentaho-kettle by pentaho.

the class WebServiceTest method getLocationFrom.

@Test
public void getLocationFrom() {
    HttpPost postMethod = mock(HttpPost.class);
    Header locationHeader = new BasicHeader(LOCATION_HEADER, TEST_URL);
    doReturn(locationHeader).when(postMethod).getFirstHeader(LOCATION_HEADER);
    assertEquals(TEST_URL, WebService.getLocationFrom(postMethod));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) BasicHeader(org.apache.http.message.BasicHeader) Test(org.junit.Test)

Example 37 with BasicHeader

use of org.apache.http.message.BasicHeader in project coprhd-controller by CoprHD.

the class NTLMDecryptedEntity method buildContentTypeHeader.

/**
 * Builds the content type header that would have existed in a decrypted message.
 *
 * @param type
 *            the original content type
 * @param encoding
 *            the original charset
 *
 * @return the new content type header
 */
private Header buildContentTypeHeader(String type, String encoding) {
    NameValuePair[] nvps = new NameValuePair[] { new BasicNameValuePair(NTLMConstants.CHARSET, encoding) };
    BasicHeaderElement elem = new BasicHeaderElement(type, null, nvps);
    return new BasicHeader(HttpHeaders.CONTENT_TYPE, BasicHeaderValueFormatter.formatHeaderElement(elem, false, null));
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) BasicHeaderElement(org.apache.http.message.BasicHeaderElement) BasicHeader(org.apache.http.message.BasicHeader)

Example 38 with BasicHeader

use of org.apache.http.message.BasicHeader in project TaEmCasa by Dionen.

the class HttpHeaderParserTest method parseCaseInsensitive.

@Test
public void parseCaseInsensitive() {
    long now = System.currentTimeMillis();
    Header[] headersArray = new Header[5];
    headersArray[0] = new BasicHeader("eTAG", "Yow!");
    headersArray[1] = new BasicHeader("DATE", rfc1123Date(now));
    headersArray[2] = new BasicHeader("expires", rfc1123Date(now + ONE_HOUR_MILLIS));
    headersArray[3] = new BasicHeader("cache-control", "public, max-age=86400");
    headersArray[4] = new BasicHeader("content-type", "text/plain");
    Map<String, String> headers = BasicNetwork.convertHeaders(headersArray);
    NetworkResponse response = new NetworkResponse(0, null, headers, false);
    Cache.Entry entry = HttpHeaderParser.parseCacheHeaders(response);
    assertNotNull(entry);
    assertEquals("Yow!", entry.etag);
    assertEqualsWithin(now + ONE_DAY_MILLIS, entry.ttl, ONE_MINUTE_MILLIS);
    assertEquals(entry.softTtl, entry.ttl);
    assertEquals("ISO-8859-1", HttpHeaderParser.parseCharset(headers));
}
Also used : Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) NetworkResponse(com.android.volley.NetworkResponse) BasicHeader(org.apache.http.message.BasicHeader) Cache(com.android.volley.Cache) Test(org.junit.Test)

Example 39 with BasicHeader

use of org.apache.http.message.BasicHeader in project gerrit by GerritCodeReview.

the class RestSession method postWithHeader.

public RestResponse postWithHeader(String endPoint, Object content, Header header) throws IOException {
    Request post = Request.Post(getUrl(endPoint));
    if (header != null) {
        post.addHeader(header);
    }
    if (content != null) {
        post.addHeader(new BasicHeader("Content-Type", "application/json"));
        post.body(new StringEntity(OutputFormat.JSON_COMPACT.newGson().toJson(content), UTF_8));
    }
    return execute(post);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) Request(org.apache.http.client.fluent.Request) BasicHeader(org.apache.http.message.BasicHeader)

Example 40 with BasicHeader

use of org.apache.http.message.BasicHeader in project gerrit by GerritCodeReview.

the class RestSession method putWithHeader.

public RestResponse putWithHeader(String endPoint, Header header, Object content) throws IOException {
    Request put = Request.Put(getUrl(endPoint));
    if (header != null) {
        put.addHeader(header);
    }
    if (content != null) {
        put.addHeader(new BasicHeader("Content-Type", "application/json"));
        put.body(new StringEntity(OutputFormat.JSON_COMPACT.newGson().toJson(content), UTF_8));
    }
    return execute(put);
}
Also used : StringEntity(org.apache.http.entity.StringEntity) Request(org.apache.http.client.fluent.Request) BasicHeader(org.apache.http.message.BasicHeader)

Aggregations

BasicHeader (org.apache.http.message.BasicHeader)233 Header (org.apache.http.Header)120 IOException (java.io.IOException)54 HttpResponse (org.apache.http.HttpResponse)50 Test (org.junit.Test)50 StringEntity (org.apache.http.entity.StringEntity)36 List (java.util.List)25 HashMap (java.util.HashMap)24 URISyntaxException (java.net.URISyntaxException)23 HttpGet (org.apache.http.client.methods.HttpGet)22 StatusLine (org.apache.http.StatusLine)20 HttpPost (org.apache.http.client.methods.HttpPost)20 BasicStatusLine (org.apache.http.message.BasicStatusLine)19 RestResponse (com.google.gerrit.acceptance.RestResponse)18 ArrayList (java.util.ArrayList)18 ProtocolVersion (org.apache.http.ProtocolVersion)18 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)17 File (java.io.File)17 HttpEntity (org.apache.http.HttpEntity)17 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)17