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

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

Introduction

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

Prototype

public Header getContentType() 

Source Link

Usage

From source file:com.github.ignition.support.http.IgnitedHttpPost.java

public IgnitedHttpPost(IgnitedHttpClient ignitedHttp, String url, UrlEncodedFormEntity payload) {
    super(ignitedHttp);
    this.request = new org.apache.http.client.methods.HttpPost(url);
    ((HttpEntityEnclosingRequest) request).setEntity(payload);

    request.setHeader(HTTP_CONTENT_TYPE_HEADER, payload.getContentType().getValue());
}

From source file:com.github.ignition.support.http.IgnitedHttpPost.java

public IgnitedHttpPost(IgnitedHttpClient ignitedHttp, URI url, UrlEncodedFormEntity payload) {
    super(ignitedHttp);
    this.request = new org.apache.http.client.methods.HttpPost(url);
    ((HttpEntityEnclosingRequest) request).setEntity(payload);

    request.setHeader(HTTP_CONTENT_TYPE_HEADER, payload.getContentType().getValue());
}

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   ww  w .  jav  a2  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());
}