Search in sources :

Example 6 with ApacheHttpClient4

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

the class AbstractWebappIntegrationTest method createClient.

@Before
public void createClient() throws Exception {
    testProperties = new TestProperties();
    String applicationContextPath = getApplicationContextPath();
    APP_BASE_PATH = testProperties.getApplicationPath("/" + applicationContextPath);
    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) Before(org.junit.Before)

Example 7 with ApacheHttpClient4

use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project ANNIS by korpling.

the class Helper method createRESTClient.

/**
 * Creates an authentificiated REST client
 *
 * @param userName
 * @param password
 * @return A newly created client.
 */
public static Client createRESTClient(String userName, String password) {
    DefaultApacheHttpClient4Config rc = new DefaultApacheHttpClient4Config();
    rc.getClasses().add(SaltProjectProvider.class);
    ThreadSafeClientConnManager clientConnMgr = new ThreadSafeClientConnManager();
    clientConnMgr.setDefaultMaxPerRoute(10);
    rc.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, clientConnMgr);
    if (userName != null && password != null) {
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
        rc.getProperties().put(ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER, credentialsProvider);
        rc.getProperties().put(ApacheHttpClient4Config.PROPERTY_PREEMPTIVE_BASIC_AUTHENTICATION, true);
    }
    Client c = ApacheHttpClient4.create(rc);
    return c;
}
Also used : DefaultApacheHttpClient4Config(com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) ThreadSafeClientConnManager(org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) Client(com.sun.jersey.api.client.Client) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Example 8 with ApacheHttpClient4

use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project spring-cloud-netflix by spring-cloud.

the class SpringClientFactoryTests method testCookiePolicy.

@SuppressWarnings("deprecation")
@Test
public void testCookiePolicy() {
    SpringClientFactory factory = new SpringClientFactory();
    AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
    addEnvironment(parent, "ribbon.restclient.enabled=true");
    parent.register(RibbonAutoConfiguration.class, ArchaiusAutoConfiguration.class);
    parent.refresh();
    factory.setApplicationContext(parent);
    RestClient client = factory.getClient("foo", RestClient.class);
    ApacheHttpClient4 jerseyClient = (ApacheHttpClient4) client.getJerseyClient();
    assertEquals(CookiePolicy.IGNORE_COOKIES, jerseyClient.getClientHandler().getHttpClient().getParams().getParameter(ClientPNames.COOKIE_POLICY));
    parent.close();
    factory.destroy();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) RestClient(com.netflix.niws.client.http.RestClient) ApacheHttpClient4(com.sun.jersey.client.apache4.ApacheHttpClient4) Test(org.junit.Test)

Example 9 with ApacheHttpClient4

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

the class AbstractWebIT 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 : TestProperties(org.camunda.bpm.TestProperties) DefaultApacheHttpClient4Config(com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config) HttpParams(org.apache.http.params.HttpParams) ClientConfig(com.sun.jersey.api.client.config.ClientConfig)

Example 10 with ApacheHttpClient4

use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project hop by apache.

the class RestTest method testCallEndpointWithDeleteVerb.

@Test
public void testCallEndpointWithDeleteVerb() throws HopException {
    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(nullable(String.class));
    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();
    IRowMeta rmi = mock(IRowMeta.class);
    doReturn(1).when(rmi).size();
    RestData data = mock(RestData.class);
    data.method = RestMeta.HTTP_METHOD_DELETE;
    data.inputRowMeta = rmi;
    data.resultFieldName = "result";
    data.resultCodeFieldName = "status";
    data.resultHeaderFieldName = "headers";
    Rest rest = mock(Rest.class, Answers.RETURNS_DEFAULTS);
    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) IRowMeta(org.apache.hop.core.row.IRowMeta) WebResource(com.sun.jersey.api.client.WebResource) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) ApacheHttpClient4(com.sun.jersey.client.apache4.ApacheHttpClient4) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

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