Example usage for org.apache.http.client.entity UrlEncodedFormEntity getContentEncoding

List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity getContentEncoding

Introduction

In this page you can find the example usage for org.apache.http.client.entity UrlEncodedFormEntity getContentEncoding.

Prototype

public Header getContentEncoding() 

Source Link

Usage

From source file:com.am.rest.RestServiceClient.java

protected void setFormParams(HttpEntityEnclosingRequestBase request, List<NameValuePair> formParams)
        throws UnsupportedEncodingException {
    if (request == null || formParams == null)
        return;/*from   w w  w . j  a v a 2  s.c  o  m*/

    // Set HTTP request entity.
    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(formParams, HTTP.UTF_8);
    request.addHeader(formEntity.getContentType());
    request.addHeader(formEntity.getContentEncoding());
    request.setEntity(formEntity);
}

From source file:com.thoughtworks.go.util.HttpServiceTest.java

@Test
public void shouldSetTheAcceptHeaderWhilePostingProperties() throws Exception {
    HttpPost post = mock(HttpPost.class);
    String url = "http://url";
    when(httpClientFactory.createPost(url)).thenReturn(post);
    when(post.getURI()).thenReturn(new URI(url));
    CloseableHttpResponse response = mock(CloseableHttpResponse.class);
    when(response.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
    when(httpClient.execute(post)).thenReturn(response);

    ArgumentCaptor<UrlEncodedFormEntity> entityCaptor = ArgumentCaptor.forClass(UrlEncodedFormEntity.class);

    service.postProperty(url, "value");

    verify(post).setHeader("Confirm", "true");
    verify(post).setEntity(entityCaptor.capture());

    UrlEncodedFormEntity expected = new UrlEncodedFormEntity(
            Arrays.asList(new BasicNameValuePair("value", "value")));

    UrlEncodedFormEntity actual = entityCaptor.getValue();

    assertEquals(IOUtils.toString(expected.getContent()), IOUtils.toString(actual.getContent()));
    assertEquals(expected.getContentLength(), expected.getContentLength());
    assertEquals(expected.getContentType(), expected.getContentType());
    assertEquals(expected.getContentEncoding(), expected.getContentEncoding());
    assertEquals(expected.isChunked(), expected.isChunked());
}