Search in sources :

Example 81 with HttpPost

use of org.apache.http.client.methods.HttpPost in project camel by apache.

the class RestletContentTypeTest method postRequestMessage.

private void postRequestMessage(String message) throws Exception {
    HttpPost post = new HttpPost("http://localhost:" + portNum + "/users/");
    post.addHeader(Exchange.CONTENT_TYPE, "text/xml");
    post.setEntity(new StringEntity(message));
    HttpResponse response = doExecute(post);
    assertHttpResponse(response, 200, "text/xml");
    String s = context.getTypeConverter().convertTo(String.class, response.getEntity().getContent());
    assertEquals("<status>OK</status>", s);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse)

Example 82 with HttpPost

use of org.apache.http.client.methods.HttpPost in project camel by apache.

the class RestletMultiUriTemplatesEndpointTest method testPostUserUriPattern.

@Test
public void testPostUserUriPattern() throws Exception {
    HttpResponse response = doExecute(new HttpPost("http://localhost:" + portNum + "/users/homer"));
    assertHttpResponse(response, 200, "text/plain", "POST homer");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 83 with HttpPost

use of org.apache.http.client.methods.HttpPost in project camel by apache.

the class RestletPostFormTest method testPostBody.

@Test
public void testPostBody() throws Exception {
    HttpUriRequest method = new HttpPost("http://localhost:" + portNum + "/users");
    List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
    urlParameters.add(new BasicNameValuePair("foo", "bar"));
    ((HttpEntityEnclosingRequestBase) method).setEntity(new UrlEncodedFormEntity(urlParameters));
    HttpResponse response = doExecute(method);
    assertHttpResponse(response, 200, "text/plain");
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpPost(org.apache.http.client.methods.HttpPost) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) Test(org.junit.Test)

Example 84 with HttpPost

use of org.apache.http.client.methods.HttpPost in project camel by apache.

the class RestletPostXmlTest method postRequestMessage.

private void postRequestMessage(String message) throws Exception {
    HttpPost post = new HttpPost("http://localhost:" + portNum + "/users/");
    post.addHeader(Exchange.CONTENT_TYPE, "application/xml");
    post.setEntity(new StringEntity(message));
    HttpResponse response = doExecute(post);
    assertHttpResponse(response, 200, "application/xml");
    String s = context.getTypeConverter().convertTo(String.class, response.getEntity().getContent());
    assertEquals("<status>OK</status>", s);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse)

Example 85 with HttpPost

use of org.apache.http.client.methods.HttpPost in project camel by apache.

the class RestletResponseTest method getCustomResponse.

private void getCustomResponse(String address) throws Exception {
    HttpResponse response = doExecute(new HttpPost("http://localhost:" + portNum + address));
    assertHttpResponse(response, 417, "application/JSON");
    String s = response.getFirstHeader(HeaderConstants.HEADER_CACHE_CONTROL).toString().toLowerCase(Locale.US);
    assertEquals("Get a wrong http header", "cache-control: max-age=20", s);
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpResponse(org.apache.http.HttpResponse)

Aggregations

HttpPost (org.apache.http.client.methods.HttpPost)531 HttpResponse (org.apache.http.HttpResponse)238 StringEntity (org.apache.http.entity.StringEntity)220 Test (org.junit.Test)153 IOException (java.io.IOException)143 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)107 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)99 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)90 ArrayList (java.util.ArrayList)86 NameValuePair (org.apache.http.NameValuePair)84 HttpEntity (org.apache.http.HttpEntity)83 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)68 HttpClient (org.apache.http.client.HttpClient)64 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)63 HttpGet (org.apache.http.client.methods.HttpGet)55 TestHttpClient (io.undertow.testutils.TestHttpClient)54 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)49 ClientProtocolException (org.apache.http.client.ClientProtocolException)49 JsonNode (com.fasterxml.jackson.databind.JsonNode)39 InputStream (java.io.InputStream)29