Example usage for org.apache.http.impl.client DefaultHttpClient clearRequestInterceptors

List of usage examples for org.apache.http.impl.client DefaultHttpClient clearRequestInterceptors

Introduction

In this page you can find the example usage for org.apache.http.impl.client DefaultHttpClient clearRequestInterceptors.

Prototype

public synchronized void clearRequestInterceptors() 

Source Link

Usage

From source file:com.subgraph.vega.internal.http.requests.BasicHttpClientFactory.java

static HttpClient createHttpClient() {
    final HttpParams params = createHttpParams();
    final ClientConnectionManager ccm = createConnectionManager(params);
    final DefaultHttpClient client = new DefaultHttpClient(ccm, params);

    client.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
    client.clearRequestInterceptors();
    client.clearResponseInterceptors();/*  w ww .  ja  va 2  s .co  m*/
    client.addRequestInterceptor(new RequestCopyHeadersInterceptor());
    return client;
}

From source file:org.wso2.carbon.esb.passthru.transport.test.ESBJAVA4631PreserveHTTPHeadersTest.java

@Test(groups = "wso2.esb", description = "Preserve Content-Type header test", enabled = true)
public void testPreserveContentTypeHeader() throws Exception {
    wireServer.start();//from   w w  w.  j av a2s  . c  o m

    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");
}

From source file:org.wso2.carbon.esb.mediators.aggregate.ESBJAVA5103CorrelateOnExpressionTestCase.java

@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 {/* www . j ava 2 s .c  o  m*/
        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();
    }
}

From source file:org.wso2.carbon.esb.endpoint.test.ESBJAVA5017DroppedPayloadInFailoverLoadBalanceEndpoint.java

@Test(groups = "wso2.esb", description = "Test sending request to LoadBalancing Endpoint with application/json content type", enabled = false)
public void testHTTPPostRequestJSONLoadBalanceEPScenario() throws Exception {

    String JSON_PAYLOAD = "{\"action\":\"ping\"}";
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(getProxyServiceURLHttp("LBProxy"));
    StringEntity postingString = new StringEntity(JSON_PAYLOAD);
    httppost.setEntity(postingString);/*  w  w w .  j av a 2  s . c o m*/
    httppost.setHeader(HTTPConstants.CONTENT_TYPE, HTTPConstants.MEDIA_TYPE_APPLICATION_JSON);

    try {
        HttpResponse httpResponse = httpclient.execute(httppost);
        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(result.contains("pong"), "Response doesn't contains the desired phrase.");
    } finally {
        httpclient.clearRequestInterceptors();
    }

}