Search in sources :

Example 1 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 2 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 3 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 4 with ApacheHttpClient4

use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project eureka by Netflix.

the class JerseyReplicationClient method createReplicationClient.

public static JerseyReplicationClient createReplicationClient(EurekaServerConfig config, ServerCodecs serverCodecs, String serviceUrl) {
    String name = JerseyReplicationClient.class.getSimpleName() + ": " + serviceUrl + "apps/: ";
    EurekaJerseyClient jerseyClient;
    try {
        String hostname;
        try {
            hostname = new URL(serviceUrl).getHost();
        } catch (MalformedURLException e) {
            hostname = serviceUrl;
        }
        String jerseyClientName = "Discovery-PeerNodeClient-" + hostname;
        EurekaJerseyClientBuilder clientBuilder = new EurekaJerseyClientBuilder().withClientName(jerseyClientName).withUserAgent("Java-EurekaClient-Replication").withEncoderWrapper(serverCodecs.getFullJsonCodec()).withDecoderWrapper(serverCodecs.getFullJsonCodec()).withConnectionTimeout(config.getPeerNodeConnectTimeoutMs()).withReadTimeout(config.getPeerNodeReadTimeoutMs()).withMaxConnectionsPerHost(config.getPeerNodeTotalConnectionsPerHost()).withMaxTotalConnections(config.getPeerNodeTotalConnections()).withConnectionIdleTimeout(config.getPeerNodeConnectionIdleTimeoutSeconds());
        if (serviceUrl.startsWith("https://") && "true".equals(System.getProperty("com.netflix.eureka.shouldSSLConnectionsUseSystemSocketFactory"))) {
            clientBuilder.withSystemSSLConfiguration();
        }
        jerseyClient = clientBuilder.build();
    } catch (Throwable e) {
        throw new RuntimeException("Cannot Create new Replica Node :" + name, e);
    }
    String ip = null;
    try {
        ip = InetAddress.getLocalHost().getHostAddress();
    } catch (UnknownHostException e) {
        logger.warn("Cannot find localhost ip", e);
    }
    ApacheHttpClient4 jerseyApacheClient = jerseyClient.getClient();
    jerseyApacheClient.addFilter(new DynamicGZIPContentEncodingFilter(config));
    EurekaServerIdentity identity = new EurekaServerIdentity(ip);
    jerseyApacheClient.addFilter(new EurekaIdentityHeaderFilter(identity));
    return new JerseyReplicationClient(jerseyClient, serviceUrl);
}
Also used : MalformedURLException(java.net.MalformedURLException) EurekaJerseyClientBuilder(com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl.EurekaJerseyClientBuilder) UnknownHostException(java.net.UnknownHostException) DynamicGZIPContentEncodingFilter(com.netflix.eureka.cluster.DynamicGZIPContentEncodingFilter) EurekaJerseyClient(com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient) URL(java.net.URL) EurekaIdentityHeaderFilter(com.netflix.discovery.EurekaIdentityHeaderFilter) EurekaServerIdentity(com.netflix.eureka.EurekaServerIdentity) ApacheHttpClient4(com.sun.jersey.client.apache4.ApacheHttpClient4)

Example 5 with ApacheHttpClient4

use of com.sun.jersey.client.apache4.ApacheHttpClient4 in project eureka by Netflix.

the class JerseyRemoteRegionClientFactory method getOrCreateJerseyClient.

private EurekaJerseyClient getOrCreateJerseyClient(String region, EurekaEndpoint endpoint) {
    if (jerseyClient != null) {
        return jerseyClient;
    }
    synchronized (lock) {
        if (jerseyClient == null) {
            EurekaJerseyClientBuilder clientBuilder = new EurekaJerseyClientBuilder().withUserAgent("Java-EurekaClient-RemoteRegion").withEncoderWrapper(serverCodecs.getFullJsonCodec()).withDecoderWrapper(serverCodecs.getFullJsonCodec()).withConnectionTimeout(serverConfig.getRemoteRegionConnectTimeoutMs()).withReadTimeout(serverConfig.getRemoteRegionReadTimeoutMs()).withMaxConnectionsPerHost(serverConfig.getRemoteRegionTotalConnectionsPerHost()).withMaxTotalConnections(serverConfig.getRemoteRegionTotalConnections()).withConnectionIdleTimeout(serverConfig.getRemoteRegionConnectionIdleTimeoutSeconds());
            if (endpoint.isSecure()) {
                clientBuilder.withClientName("Discovery-RemoteRegionClient-" + region);
            } else if ("true".equals(System.getProperty("com.netflix.eureka.shouldSSLConnectionsUseSystemSocketFactory"))) {
                clientBuilder.withClientName("Discovery-RemoteRegionSystemSecureClient-" + region).withSystemSSLConfiguration();
            } else {
                clientBuilder.withClientName("Discovery-RemoteRegionSecureClient-" + region).withTrustStoreFile(serverConfig.getRemoteRegionTrustStore(), serverConfig.getRemoteRegionTrustStorePassword());
            }
            jerseyClient = clientBuilder.build();
            ApacheHttpClient4 discoveryApacheClient = jerseyClient.getClient();
            // Add gzip content encoding support
            boolean enableGZIPContentEncodingFilter = serverConfig.shouldGZipContentFromRemoteRegion();
            if (enableGZIPContentEncodingFilter) {
                discoveryApacheClient.addFilter(new GZIPContentEncodingFilter(false));
            }
            // always enable client identity headers
            String ip = null;
            try {
                ip = InetAddress.getLocalHost().getHostAddress();
            } catch (UnknownHostException e) {
                logger.warn("Cannot find localhost ip", e);
            }
            EurekaServerIdentity identity = new EurekaServerIdentity(ip);
            discoveryApacheClient.addFilter(new EurekaIdentityHeaderFilter(identity));
        }
    }
    return jerseyClient;
}
Also used : EurekaServerIdentity(com.netflix.eureka.EurekaServerIdentity) EurekaJerseyClientBuilder(com.netflix.discovery.shared.transport.jersey.EurekaJerseyClientImpl.EurekaJerseyClientBuilder) UnknownHostException(java.net.UnknownHostException) ApacheHttpClient4(com.sun.jersey.client.apache4.ApacheHttpClient4) GZIPContentEncodingFilter(com.sun.jersey.api.client.filter.GZIPContentEncodingFilter) EurekaIdentityHeaderFilter(com.netflix.discovery.EurekaIdentityHeaderFilter)

Aggregations

ApacheHttpClient4 (com.sun.jersey.client.apache4.ApacheHttpClient4)5 DefaultApacheHttpClient4Config (com.sun.jersey.client.apache4.config.DefaultApacheHttpClient4Config)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 URISyntaxException (java.net.URISyntaxException)2 URL (java.net.URL)2 UnknownHostException (java.net.UnknownHostException)2 ThreadSafeClientConnManager (org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager)2 HttpParams (org.apache.http.params.HttpParams)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 ClientSslSocketFactoryException (com.netflix.client.ssl.ClientSslSocketFactoryException)1 URLSslContextFactory (com.netflix.client.ssl.URLSslContextFactory)1 EurekaEndpoint (com.netflix.discovery.shared.resolver.EurekaEndpoint)1 TransportClientFactory (com.netflix.discovery.shared.transport.TransportClientFactory)1 EurekaJerseyClient (com.netflix.discovery.shared.transport.jersey.EurekaJerseyClient)1