Search in sources :

Example 76 with HttpPost

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

the class UIUtils method getHttpResponse.

public static Response getHttpResponse(String url) {
    Response res;
    try {
        // 1. proxy call the task host log view service
        HttpClient client = HttpClientBuilder.create().build();
        HttpPost post = new HttpPost(url);
        HttpResponse response = client.execute(post);
        int status = response.getStatusLine().getStatusCode();
        String data = EntityUtils.toString(response.getEntity());
        res = new Response(status, data);
    } catch (Exception e) {
        res = new Response(-1, e.getMessage());
    }
    return res;
}
Also used : HttpResponse(org.apache.http.HttpResponse) HttpPost(org.apache.http.client.methods.HttpPost) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) FileNotFoundException(java.io.FileNotFoundException)

Example 77 with HttpPost

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

the class RestletExceptionResponseTest method testExceptionResponse.

@Test
public void testExceptionResponse() throws Exception {
    HttpResponse response = doExecute(new HttpPost("http://localhost:" + portNum + "/users/homer"));
    String body = EntityUtils.toString(response.getEntity());
    assertHttpResponse(response, 500, "text/plain");
    assertTrue(body.contains("IllegalArgumentException"));
    assertTrue(body.contains("Damn something went wrong"));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 78 with HttpPost

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

the class RestletFaultTest method testFaultResponse.

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

Example 79 with HttpPost

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

the class RestletHttpsWithSSLContextParametersTest method postRequestMessage.

private void postRequestMessage(String message) throws Exception {
    // ensure jsse clients can validate the self signed dummy localhost cert, 
    // use the server keystore as the trust store for these tests
    URL trustStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks");
    System.setProperty("javax.net.ssl.trustStore", trustStoreUrl.toURI().getPath());
    HttpPost post = new HttpPost("https://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) URL(java.net.URL)

Example 80 with HttpPost

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

the class RestletMultiRoutesEndpointTest method testPostMethod.

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

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