public EurekaJerseyClientImpl(int connectionTimeout, int readTimeout, final int connectionIdleTimeout, ClientConfig clientConfig) { try { jerseyClientConfig = clientConfig; apacheHttpClient = ApacheHttpClient4.create(jerseyClientConfig); HttpParams params = apacheHttpClient.getClientHandler().getHttpClient().getParams(); HttpConnectionParams.setConnectionTimeout(params, connectionTimeout); HttpConnectionParams.setSoTimeout(params, readTimeout); this.apacheHttpClientConnectionCleaner = new ApacheHttpClientConnectionCleaner(apacheHttpClient, connectionIdleTimeout); } catch (Throwable e) { throw new RuntimeException("Cannot create Jersey client", e); } }
private JerseyEurekaHttpClientFactory buildExperimental(Map<String, String> additionalHeaders) { ThreadSafeClientConnManager cm = createConnectionManager(); ClientConfig clientConfig = new DefaultApacheHttpClient4Config(); if (proxyHost != null) { addProxyConfiguration(clientConfig); } DiscoveryJerseyProvider discoveryJerseyProvider = new DiscoveryJerseyProvider(encoderWrapper, decoderWrapper); clientConfig.getSingletons().add(discoveryJerseyProvider); // Common properties to all clients cm.setDefaultMaxPerRoute(maxConnectionsPerHost); cm.setMaxTotal(maxTotalConnections); clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, cm); String fullUserAgentName = (userAgent == null ? clientName : userAgent) + "/v" + buildVersion(); clientConfig.getProperties().put(CoreProtocolPNames.USER_AGENT, fullUserAgentName); // To pin a client to specific server in case redirect happens, we handle redirects directly // (see DiscoveryClient.makeRemoteCall methods). clientConfig.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, Boolean.FALSE); clientConfig.getProperties().put(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE); ApacheHttpClient4 apacheClient = ApacheHttpClient4.create(clientConfig); addFilters(apacheClient); return new JerseyEurekaHttpClientFactory(apacheClient, connectionIdleTimeout, additionalHeaders); }
when( ApacheHttpClient4.create( any() ) ).thenReturn( client );
client = ApacheHttpClient4.create( data.config ); if ( data.basicAuthentication != null ) { client.addFilter( data.basicAuthentication );
public EurekaJerseyClientImpl(int connectionTimeout, int readTimeout, final int connectionIdleTimeout, ClientConfig clientConfig) { try { jerseyClientConfig = clientConfig; apacheHttpClient = ApacheHttpClient4.create(jerseyClientConfig); HttpParams params = apacheHttpClient.getClientHandler().getHttpClient().getParams(); HttpConnectionParams.setConnectionTimeout(params, connectionTimeout); HttpConnectionParams.setSoTimeout(params, readTimeout); this.apacheHttpClientConnectionCleaner = new ApacheHttpClientConnectionCleaner(apacheHttpClient, connectionIdleTimeout); } catch (Throwable e) { throw new RuntimeException("Cannot create Jersey client", e); } }
private Client createClient() { Set<Class<?>> providers = new HashSet<Class<?>>(); providers.add(JacksonJsonProvider.class); ClientConfig config = new DefaultClientConfig(providers); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); Client client = ApacheHttpClient4.create(config); client.setFollowRedirects(true); client.addFilter(new ContentTypeFromTextToJsonClientFilter()); return client; }
Client client = ApacheHttpClient4.create(config); client.addFilter(new HTTPBasicAuthFilter(this.accessKey, this.secretKey)); WebResource webResource = client.resource(this.featuresUrl);
/** * 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; }
cc.getProperties().put(ApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD, abstractProxySettings.getPassword()); ApacheHttpClient4 client = ApacheHttpClient4.create(cc); return client; } else {
32 * 1024); client = ApacheHttpClient4.create(config);
private JerseyEurekaHttpClientFactory buildExperimental(Map<String, String> additionalHeaders) { ThreadSafeClientConnManager cm = createConnectionManager(); ClientConfig clientConfig = new DefaultApacheHttpClient4Config(); if (proxyHost != null) { addProxyConfiguration(clientConfig); } DiscoveryJerseyProvider discoveryJerseyProvider = new DiscoveryJerseyProvider(encoderWrapper, decoderWrapper); clientConfig.getSingletons().add(discoveryJerseyProvider); // Common properties to all clients cm.setDefaultMaxPerRoute(maxConnectionsPerHost); cm.setMaxTotal(maxTotalConnections); clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, cm); String fullUserAgentName = (userAgent == null ? clientName : userAgent) + "/v" + buildVersion(); clientConfig.getProperties().put(CoreProtocolPNames.USER_AGENT, fullUserAgentName); // To pin a client to specific server in case redirect happens, we handle redirects directly // (see DiscoveryClient.makeRemoteCall methods). clientConfig.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, Boolean.FALSE); clientConfig.getProperties().put(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE); ApacheHttpClient4 apacheClient = ApacheHttpClient4.create(clientConfig); addFilters(apacheClient); return new JerseyEurekaHttpClientFactory(apacheClient, connectionIdleTimeout, additionalHeaders); }
protected ApacheHttpClient4 doCreateHttpClientFor( final ConnectionInfo connectionInfo, final XStream xstream ) { final ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getSingletons().add( new XStreamXmlProvider( xstream, APPLICATION_XML_UTF8_TYPE ) ); // set _real_ URL for baseUrl, and not a redirection (typically http instead of https) config.getProperties().put( ApacheHttpClient4Config.PROPERTY_FOLLOW_REDIRECTS, Boolean.FALSE ); config.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE ); applyAuthenticationIfAny( connectionInfo, config ); applyProxyIfAny( connectionInfo, config ); final ApacheHttpClient4 client = ApacheHttpClient4.create( config ); // set UA client.getClientHandler().getHttpClient().getParams().setParameter( CoreProtocolPNames.USER_AGENT, "Nexus-Client/" + discoverClientVersion() ); // NXCM-4547 JERSEY-1293 Enforce proxy setting on httpclient enforceProxyUri( config, client ); if ( LOG.isDebugEnabled() ) { client.addFilter( new LoggingFilter() ); } return client; }
public Long upload(Long runId, String runName, String filePath) throws IOException, JSONException { config.getClasses().add(FormDataMultiPart.class); config.getClasses().add(MultiPartWriter.class); Client client = ApacheHttpClient4.create(config); client.addFilter(new HTTPBasicAuthFilter(this.accessKey, this.secretKey)); WebResource webResource = client.resource(this.reportUrl);
static ApacheHttpClient4Handler createApacheClientHandler(SmartConfig smartConfig) { ClientConfig clientConfig = new DefaultClientConfig(); // set up multi-threaded connection pool org.apache.http.impl.conn.PoolingClientConnectionManager connectionManager = new org.apache.http.impl.conn.PoolingClientConnectionManager(); // 999 maximum active connections (max allowed) connectionManager.setDefaultMaxPerRoute(999); connectionManager.setMaxTotal(999); clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_CONNECTION_MANAGER, connectionManager); // set proxy config if (smartConfig.getProxyUri() != null) clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_PROXY_URI, smartConfig.getProxyUri()); if (smartConfig.getProxyUser() != null) clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_PROXY_USERNAME, smartConfig.getProxyUser()); if (smartConfig.getProxyPass() != null) clientConfig.getProperties().put(ApacheHttpClient4Config.PROPERTY_PROXY_PASSWORD, smartConfig.getProxyPass()); // pass in jersey parameters from calling code (allows customization of client) for (String propName : smartConfig.getProperties().keySet()) { clientConfig.getProperties().put(propName, smartConfig.getProperty(propName)); } ApacheHttpClient4Handler handler = ApacheHttpClient4.create(clientConfig).getClientHandler(); // disable the retry handler if necessary if (smartConfig.getProperty(DISABLE_APACHE_RETRY) != null) { org.apache.http.impl.client.AbstractHttpClient httpClient = (org.apache.http.impl.client.AbstractHttpClient) handler.getHttpClient(); httpClient.setHttpRequestRetryHandler(new org.apache.http.impl.client.DefaultHttpRequestRetryHandler(0, false)); } return handler; }