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() . 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 check out the related API usage on the sidebar.
Example 1
Source File: ESBJAVA5103CorrelateOnExpressionTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@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
Source File: ESBJAVA5103CorrelateOnExpressionTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@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
Source File: ESBJAVA4631PreserveHTTPHeadersTest.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@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
Source File: ESBJAVA4631PreserveHTTPHeadersTest.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@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");
}