com.sun.jersey.client.apache4.ApacheHttpClient4 Java Examples
The following examples show how to use
com.sun.jersey.client.apache4.ApacheHttpClient4.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiClientConfiguration.java From occurrence with Apache License 2.0 | 6 votes |
/** * @return a new jersey client using a multithreaded http client */ public WebResource newApiClient() { ClientConfig cc = new DefaultClientConfig(); cc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true); cc.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, timeout); cc.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, timeout); cc.getClasses().add(JacksonJsonProvider.class); // use custom configured object mapper ignoring unknown properties cc.getClasses().add(ObjectMapperContextResolver.class); HttpClient http = HttpUtil.newMultithreadedClient(timeout, maxConnections, maxConnections); ApacheHttpClient4Handler hch = new ApacheHttpClient4Handler(http, null, false); Client client = new ApacheHttpClient4(hch, cc); LOG.info("Connecting to GBIF API: {}", url); return client.resource(url); }
Example #2
Source File: DockerClient.java From docker-java with Apache License 2.0 | 6 votes |
private DockerClient(Config config) { restEndpointUrl = config.url + "/v" + config.version; ClientConfig clientConfig = new DefaultClientConfig(); //clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", config.url.getPort(), PlainSocketFactory.getSocketFactory())); schemeRegistry.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory())); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(schemeRegistry); // Increase max total connection cm.setMaxTotal(1000); // Increase default max connection per route cm.setDefaultMaxPerRoute(1000); HttpClient httpClient = new DefaultHttpClient(cm); client = new ApacheHttpClient4(new ApacheHttpClient4Handler(httpClient, null, false), clientConfig); client.setReadTimeout(10000); //Experimental support for unix sockets: //client = new UnixSocketClient(clientConfig); client.addFilter(new JsonClientFilter()); client.addFilter(new LoggingFilter()); }
Example #3
Source File: QueueClientFactory.java From emodb with Apache License 2.0 | 5 votes |
static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) { HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator())); return new ApacheHttpClient4(handler, config); }
Example #4
Source File: TestUtil.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
public TestUtil(TestProperties testProperties) { this.testProperties = testProperties; // create admin user: ClientConfig clientConfig = new DefaultApacheHttpClient4Config(); clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); client = ApacheHttpClient4.create(clientConfig); defaultHttpClient = (DefaultHttpClient) client.getClientHandler().getHttpClient(); }
Example #5
Source File: AbstractWebIntegrationTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
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); }
Example #6
Source File: AbstractWebIT.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
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); }
Example #7
Source File: DatabusClientFactory.java From emodb with Apache License 2.0 | 5 votes |
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, MetricRegistry metricRegistry, String serviceName) { HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator())); return new ApacheHttpClient4(handler, config); }
Example #8
Source File: DedupQueueClientFactory.java From emodb with Apache License 2.0 | 5 votes |
static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) { HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator())); return new ApacheHttpClient4(handler, config); }
Example #9
Source File: DataStoreClientFactory.java From emodb with Apache License 2.0 | 5 votes |
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) { HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator())); return new ApacheHttpClient4(handler, config); }
Example #10
Source File: DataStoreClientFactory.java From emodb with Apache License 2.0 | 5 votes |
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration) { HttpClient httpClient = new HttpClientBuilder().using(configuration).build(); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); // For shading reasons we can't add a Jackson JSON message body provider. However, our client implementation will // handle wrapping all request and response entities using the shaded Jackson so this shouldn't matter. return new ApacheHttpClient4(handler, config); }
Example #11
Source File: DedupQueueClientFactory.java From emodb with Apache License 2.0 | 5 votes |
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration) { HttpClient httpClient = new HttpClientBuilder().using(configuration).build(); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); // For shading reasons we can't add a Jackson JSON message body provider. However, our client implementation will // handle wrapping all request and response entities using the shaded Jackson so this shouldn't matter. return new ApacheHttpClient4(handler, config); }
Example #12
Source File: QueueClientFactory.java From emodb with Apache License 2.0 | 5 votes |
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration) { HttpClient httpClient = new HttpClientBuilder().using(configuration).build(); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); // For shading reasons we can't add a Jackson JSON message body provider. However, our client implementation will // handle wrapping all request and response entities using the shaded Jackson so this shouldn't matter. return new ApacheHttpClient4(handler, config); }
Example #13
Source File: DatabusClientFactory.java From emodb with Apache License 2.0 | 5 votes |
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration) { HttpClient httpClient = new HttpClientBuilder().using(configuration).build(); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); // For shading reasons we can't add a Jackson JSON message body provider. However, our client implementation will // handle wrapping all request and response entities using the shaded Jackson so this shouldn't matter. return new ApacheHttpClient4(handler, config); }
Example #14
Source File: BlobStoreClientFactory.java From emodb with Apache License 2.0 | 5 votes |
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration) { HttpClient httpClient = new HttpClientBuilder().using(configuration).build(); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); // For shading reasons we can't add a Jackson JSON message body provider. However, our client implementation will // handle wrapping all request and response entities using the shaded Jackson so this shouldn't matter. return new ApacheHttpClient4(handler, config); }
Example #15
Source File: UserAccessControlClientFactory.java From emodb with Apache License 2.0 | 5 votes |
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) { HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator())); return new ApacheHttpClient4(handler, config); }
Example #16
Source File: PurgeDatabusEventsCommand.java From emodb with Apache License 2.0 | 5 votes |
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, MetricRegistry metricRegistry, String serviceName) { HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator())); return new ApacheHttpClient4(handler, config); }
Example #17
Source File: BlobStoreClientFactory.java From emodb with Apache License 2.0 | 5 votes |
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, MetricRegistry metricRegistry, String serviceName) { HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName); ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true); ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config(); config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator())); return new ApacheHttpClient4(handler, config); }
Example #18
Source File: RestTest.java From hop with Apache License 2.0 | 4 votes |
@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( 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(); 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 ); 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 ] ); }
Example #19
Source File: EurekaClientAutoConfigurationTests.java From spring-cloud-netflix with Apache License 2.0 | 4 votes |
@Bean public ApacheHttpClient4 apacheClient() { return Mockito.mock(ApacheHttpClient4.class); }
Example #20
Source File: RestTest.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@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] ); }