Java Code Examples for org.apache.http.impl.client.DefaultHttpClient#clearRequestInterceptors()

The following examples show how to use org.apache.http.impl.client.DefaultHttpClient#clearRequestInterceptors() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Test(groups = "wso2.esb", description = "Test CorrelateOn in Aggregate mediator ")
public void testAggregateWithCorrelateExpression() throws IOException {
    String expectedOutput1 = "<result><value>value1</value><value>value2</value></result>";
    String expectedOutput2 = "<result><value>value2</value><value>value1</value></result>";

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(getApiInvocationURL("testAggregate"));

    try {
        HttpResponse httpResponse = httpclient.execute(httpget);
        HttpEntity entity = httpResponse.getEntity();
        BufferedReader rd = new BufferedReader(new InputStreamReader(entity.getContent()));
        String result = "";
        String line;
        while ((line = rd.readLine()) != null) {
            result += line;
        }
        Assert.assertTrue(expectedOutput1.equals(result) || expectedOutput2.equals(result),
                "Aggregated response is not correct.");
    } finally {
        httpclient.clearRequestInterceptors();
    }
}
 
Example 2
@Test(groups = "wso2.esb", description = "Test CorrelateOn in Aggregate mediator ")
public void testAggregateWithCorrelateExpression() throws IOException{
    String expectedOutput1 = "<result><value>value1</value><value>value2</value></result>";
    String expectedOutput2 = "<result><value>value2</value><value>value1</value></result>";

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(getApiInvocationURL("testAggregate"));

    try {
        HttpResponse httpResponse = httpclient.execute(httpget);
        HttpEntity entity = httpResponse.getEntity();
        BufferedReader rd = new BufferedReader(new InputStreamReader(entity.getContent()));
        String result = "";
        String line;
        while ((line = rd.readLine()) != null) {
            result += line;
        }
        Assert.assertTrue(expectedOutput1.equals(result) || expectedOutput2.equals(result), "Aggregated response is not correct.");
    }
    finally {
        httpclient.clearRequestInterceptors();
    }
}
 
Example 3
@Test(groups = "wso2.esb", description = "Preserve Content-Type header test", enabled = true)
public void testPreserveContentTypeHeader() throws Exception {
    wireServer.start();

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(getApiInvocationURL("ContentTypePreserveAPI"));

    StringEntity postingString = new StringEntity("{\"sampleJson\" : \"sampleValue\"}");
    httppost.setEntity(postingString);
    httppost.setHeader("Content-type", "application/json");

    try {
        httpclient.execute(httppost);
    } finally {
        httpclient.clearRequestInterceptors();
    }

    String wireResponse = wireServer.getCapturedMessage();
    String[] wireResponseLines = wireResponse.split(System.lineSeparator());
    boolean isContentTypePresent = false;
    for (String line : wireResponseLines) {
        if (line.contains("Content-Type")) {
            isContentTypePresent = true;
            //charset encoding is appended to content-type header even preserve the content-type header as it is
            //This checks charset encoding is appended or not
            Assert.assertFalse(line.contains(";"), "Content-Type header was modified - " + line);
        }
    }
    //coming to this line means content type header is in expected state, hence passing the test
    Assert.assertTrue(isContentTypePresent, "Content-Type header is not present in the ESB request");
}
 
Example 4
@Test(groups = "wso2.esb", description = "Preserve Content-Type header test", enabled = true)
public void testPreserveContentTypeHeader() throws Exception {
    wireServer.start();

    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(getApiInvocationURL("ContentTypePreserveAPI"));

    StringEntity postingString = new StringEntity("{\"sampleJson\" : \"sampleValue\"}");
    httppost.setEntity(postingString);
    httppost.setHeader("Content-type", "application/json");

    try {
        httpclient.execute(httppost);
    } finally {
        httpclient.clearRequestInterceptors();
    }


    String wireResponse = wireServer.getCapturedMessage();
    String[] wireResponseLines = wireResponse.split(System.lineSeparator());
    boolean isContentTypePresent = false;
    for (String line : wireResponseLines) {
        if (line.contains("Content-Type")) {
            isContentTypePresent = true;
            //charset encoding is appended to content-type header even preserve the content-type header as it is
            //This checks charset encoding is appended or not
            Assert.assertFalse(line.contains(";"), "Content-Type header was modified - " + line);
        }
    }
    //coming to this line means content type header is in expected state, hence passing the test
    Assert.assertTrue(isContentTypePresent, "Content-Type header is not present in the ESB request");
}