Search in sources :

Example 11 with ApacheHttpClient4

use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project pentaho-kettle by pentaho.

the class RestTest method testCallEndpointWithDeleteVerb.

@Test
public void testCallEndpointWithDeleteVerb() throws KettleException {
    MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
    headers.add("Content-Type", "application/json");
    ClientResponse response = mock(ClientResponse.class);
    doReturn(200).when(response).getStatus();
    doReturn(headers).when(response).getHeaders();
    doReturn("true").when(response).getEntity(String.class);
    WebResource.Builder builder = mock(WebResource.Builder.class);
    doReturn(response).when(builder).delete(ClientResponse.class);
    WebResource resource = mock(WebResource.class);
    doReturn(builder).when(resource).getRequestBuilder();
    ApacheHttpClient4 client = mock(ApacheHttpClient4.class);
    doReturn(resource).when(client).resource(anyString());
    mockStatic(ApacheHttpClient4.class);
    when(ApacheHttpClient4.create(any())).thenReturn(client);
    RestMeta meta = mock(RestMeta.class);
    doReturn(false).when(meta).isDetailed();
    doReturn(false).when(meta).isUrlInField();
    doReturn(false).when(meta).isDynamicMethod();
    RowMetaInterface rmi = mock(RowMetaInterface.class);
    doReturn(1).when(rmi).size();
    RestData data = mock(RestData.class);
    DefaultApacheHttpClient4Config config = mock(DefaultApacheHttpClient4Config.class);
    doReturn(new HashSet<>()).when(config).getSingletons();
    data.method = RestMeta.HTTP_METHOD_DELETE;
    data.inputRowMeta = rmi;
    data.resultFieldName = "result";
    data.resultCodeFieldName = "status";
    data.resultHeaderFieldName = "headers";
    data.config = config;
    Rest rest = mock(Rest.class);
    doCallRealMethod().when(rest).callRest(any());
    doCallRealMethod().when(rest).searchForHeaders(any());
    setInternalState(rest, "meta", meta);
    setInternalState(rest, "data", data);
    Object[] output = rest.callRest(new Object[] { 0 });
    verify(builder, times(1)).delete(ClientResponse.class);
    assertEquals("true", output[1]);
    assertEquals(200L, output[2]);
    assertEquals("{\"Content-Type\":\"application\\/json\"}", output[3]);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Matchers.anyString(org.mockito.Matchers.anyString) DefaultApacheHttpClient4Config(com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config) ApacheHttpClient4(com.sun.jersey.client.apache4.ApacheHttpClient4) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with ApacheHttpClient4

use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project camunda-bpm-platform by camunda.

the class AbstractWebIntegrationTest method createClient.

public void createClient(String ctxPath) throws Exception {
    testProperties = new TestProperties();
    APP_BASE_PATH = testProperties.getApplicationPath("/" + ctxPath);
    LOGGER.info("Connecting to application " + APP_BASE_PATH);
    ClientConfig clientConfig = new DefaultApacheHttpClient4Config();
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    client = ApacheHttpClient4.create(clientConfig);
    defaultHttpClient = (DefaultHttpClient) client.getClientHandler().getHttpClient();
    HttpParams params = defaultHttpClient.getParams();
    HttpConnectionParams.setConnectionTimeout(params, 3 * 60 * 1000);
    HttpConnectionParams.setSoTimeout(params, 10 * 60 * 1000);
}
Also used : DefaultApacheHttpClient4Config(com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config) HttpParams(org.apache.http.params.HttpParams) ClientConfig(com.sun.jersey.api.client.config.ClientConfig)

Aggregations

ApacheHttpClient4 (com.sun.jersey.client.apache4.ApacheHttpClient4)7 DefaultApacheHttpClient4Config (com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config)6 HttpParams (org.apache.http.params.HttpParams)4 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)3 Test (org.junit.Test)3 EurekaIdentityHeaderFilter (com.netflix.discovery.EurekaIdentityHeaderFilter)2 EurekaJerseyClientBuilder (com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl.EurekaJerseyClientBuilder)2 EurekaServerIdentity (com.netflix.eureka.EurekaServerIdentity)2 Client (com.sun.jersey.api.client.Client)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 WebResource (com.sun.jersey.api.client.WebResource)2 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)2 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 UnknownHostException (java.net.UnknownHostException)2 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)2 WebProxyData (code.satyagraha.gfm.support.api.WebProxyConfig.WebProxyData)1 WebServiceClient (code.satyagraha.gfm.support.api.WebServiceClient)1 ClientException (com.netflix.client.ClientException)1 AbstractSslContextFactory (com.netflix.client.ssl.AbstractSslContextFactory)1