Package org.apache.http.impl.client

Examples of org.apache.http.impl.client.CloseableHttpClient


        HttpPost post = new HttpPost(simpleEndpointAddress);
        post.addHeader("Accept" , "text/xml");
       
        StringEntity entity = new StringEntity(ECHO_REQUEST, ContentType.create("text/xml", "ISO-8859-1"));
        post.setEntity(entity);
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(post);
            assertEquals(200, response.getStatusLine().getStatusCode());
            String responseBody = EntityUtils.toString(response.getEntity());
           
            assertEquals("Get a wrong response", ECHO_RESPONSE, responseBody);
        } finally {
            httpclient.close();
        }

    }
View Full Code Here


    // END SNIPPET: example
   
    private void invokeGetCustomer(String uri, String expect) throws Exception {
        HttpGet get = new HttpGet(uri);
        get.addHeader("Accept" , "application/json");
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(get);
            assertEquals(200, response.getStatusLine().getStatusCode());
            assertEquals(expect,
                         EntityUtils.toString(response.getEntity()));
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

            + "<soap:Body><GetPerson xmlns=\"http://camel.apache.org/wsdl-first/types\">"
            + "<personId>hello</personId></GetPerson></soap:Body></soap:Envelope>";
       
        StringEntity entity = new StringEntity(body, ContentType.create("text/xml", "ISO-8859-1"));
        post.setEntity(entity);
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(post);
            assertEquals(200, response.getStatusLine().getStatusCode());
            String responseBody = EntityUtils.toString(response.getEntity());
            String correct = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>"
                + "<GetPersonResponse xmlns=\"http://camel.apache.org/wsdl-first/types\">"
                + "<personId>hello</personId><ssn>000-000-0000</ssn><name>Bye</name></GetPersonResponse></soap:Body></soap:Envelope>";
           
            assertEquals("Get a wrong response", correct, responseBody);
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

            + "<soap:Body><GetPerson xmlns=\"http://camel.apache.org/wsdl-first/types\">"
            + "<personId>hello</personId></GetPerson></soap:Body></soap:Envelope>";
       
        StringEntity entity = new StringEntity(body, ContentType.create("text/xml", "ISO-8859-1"));
        post.setEntity(entity);
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(post);
            assertEquals(200, response.getStatusLine().getStatusCode());
            String responseBody = EntityUtils.toString(response.getEntity());
            String correct = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>"
                + "<GetPersonResponse xmlns=\"http://camel.apache.org/wsdl-first/types\">"
                + "<personId>hello</personId><ssn>000-000-0000</ssn><name>Bonjour</name></GetPersonResponse></soap:Body></soap:Envelope>";
           
            assertEquals("Get a wrong response", correct, responseBody);
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

   
    private void invokeRsService(String getUrl, String expected) throws Exception {
        HttpGet get = new HttpGet(getUrl);
        get.addHeader("Accept" , "application/json");
        get.addHeader("key", "customer");
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(get);
            assertEquals(200, response.getStatusLine().getStatusCode());
            assertEquals(expected,
                         EntityUtils.toString(response.getEntity()));
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

    public void testPutConsumer() throws Exception {
        HttpPut put = new HttpPut("http://localhost:" + PORT1 + "/customerservice/customers");
        StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
        entity.setContentType("text/xml; charset=ISO-8859-1");
        put.setEntity(entity);
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(put);
            assertEquals(200, response.getStatusLine().getStatusCode());
            assertEquals("", EntityUtils.toString(response.getEntity()));
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

        HttpPost post = new HttpPost("http://localhost:" + PORT1 + "/customerservice/customers");
        post.addHeader("Accept" , "text/xml");
        StringEntity entity = new StringEntity(POST_REQUEST, "ISO-8859-1");
        entity.setContentType("text/xml; charset=ISO-8859-1");
        post.setEntity(entity);
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(post);
            assertEquals(200, response.getStatusLine().getStatusCode());
            String id = getCustomerId("Jack");
            assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>" + id + "</id><name>Jack</name></Customer>",
                         EntityUtils.toString(response.getEntity()));
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

        HttpPost post = new HttpPost("http://localhost:" + PORT1 + "/customerservice/customersUniqueResponseCode");
        post.addHeader("Accept" , "text/xml");
        StringEntity entity = new StringEntity(POST2_REQUEST, "ISO-8859-1");
        entity.setContentType("text/xml; charset=ISO-8859-1");
        post.setEntity(entity);
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(post);
            assertEquals(201, response.getStatusLine().getStatusCode());
            String id = getCustomerId("James");
            assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Customer><id>" + id + "</id><name>James</name></Customer>",
                         EntityUtils.toString(response.getEntity()));
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

    }

    private String getCustomerId(String name) throws Exception {
        HttpGet get = new HttpGet("http://localhost:" + PORT1 + "/customerservice/customers/");
        get.addHeader("Accept", "application/xml");
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(get);
            assertEquals(200, response.getStatusLine().getStatusCode());
            String customers = EntityUtils.toString(response.getEntity());
            String before = ObjectHelper.before(customers, "</id><name>" + name + "</name></Customer>");
            String answer = before.substring(before.lastIndexOf(">") + 1, before.length());
            return answer;
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

            + "<personId>hello</personId></GetPerson></soap:Body></soap:Envelope>";
       
        StringEntity entity = new StringEntity(body, "ISO-8859-1");
        entity.setContentType("text/xml; charset=ISO-8859-1");
        post.setEntity(entity);
        CloseableHttpClient httpclient = HttpClientBuilder.create().build();

        try {
            HttpResponse response = httpclient.execute(post);
            assertEquals(200, response.getStatusLine().getStatusCode());
            String responseBody = EntityUtils.toString(response.getEntity());
            String correct = "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>"
                + "<GetPersonResponse xmlns=\"http://camel.apache.org/wsdl-first/types\">"
                + "<personId>hello</personId><ssn>000-000-0000</ssn><name>Bonjour</name></GetPersonResponse></soap:Body></soap:Envelope>";
           
            assertEquals("Get a wrong response", correct, responseBody);
        } finally {
            httpclient.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.impl.client.CloseableHttpClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.