Java Code Examples for org.glassfish.jersey.client.ClientConfig#register()
The following examples show how to use
org.glassfish.jersey.client.ClientConfig#register() .
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: RestDemoServiceIT.java From demo-restWS-spring-jersey-jpa2-hibernate with MIT License | 6 votes |
@Test public void testGetLegacyPodcast() throws JsonGenerationException, JsonMappingException, IOException { ClientConfig clientConfig = new ClientConfig(); clientConfig.register(JacksonFeature.class); Client client = ClientBuilder.newClient(clientConfig); WebTarget webTarget = client .target("http://localhost:8888/demo-rest-spring-jersey-jpa2-hibernate-0.0.1-SNAPSHOT/podcasts/2"); Builder request = webTarget.request(MediaType.APPLICATION_JSON); Response response = request.get(); Assert.assertTrue(response.getStatus() == 200); Podcast podcast = response.readEntity(Podcast.class); ObjectMapper mapper = new ObjectMapper(); System.out .print("Received podcast from database *************************** " + mapper.writerWithDefaultPrettyPrinter() .writeValueAsString(podcast)); }
Example 2
Source File: AdminApiKeyStoreTlsAuthTest.java From pulsar with Apache License 2.0 | 6 votes |
WebTarget buildWebClient() throws Exception { ClientConfig httpConfig = new ClientConfig(); httpConfig.property(ClientProperties.FOLLOW_REDIRECTS, true); httpConfig.property(ClientProperties.ASYNC_THREADPOOL_SIZE, 8); httpConfig.register(MultiPartFeature.class); ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(httpConfig) .register(JacksonConfigurator.class).register(JacksonFeature.class); SSLContext sslCtx = KeyStoreSSLContext.createClientSslContext( KEYSTORE_TYPE, CLIENT_KEYSTORE_FILE_PATH, CLIENT_KEYSTORE_PW, KEYSTORE_TYPE, BROKER_TRUSTSTORE_FILE_PATH, BROKER_TRUSTSTORE_PW); clientBuilder.sslContext(sslCtx).hostnameVerifier(NoopHostnameVerifier.INSTANCE); Client client = clientBuilder.build(); return client.target(brokerUrlTls.toString()); }
Example 3
Source File: RestDemoServiceIT.java From demo-restWS-spring-jersey-jpa2-hibernate with MIT License | 6 votes |
@Test public void testGetPodcast() throws JsonGenerationException, JsonMappingException, IOException { ClientConfig clientConfig = new ClientConfig(); clientConfig.register(JacksonFeature.class); Client client = ClientBuilder.newClient(clientConfig); WebTarget webTarget = client .target("http://localhost:8888/demo-rest-spring-jersey-jpa2-hibernate-0.0.1-SNAPSHOT/legacy/podcasts/2"); Builder request = webTarget.request(MediaType.APPLICATION_JSON); Response response = request.get(); Assert.assertTrue(response.getStatus() == 200); Podcast podcast = response.readEntity(Podcast.class); ObjectMapper mapper = new ObjectMapper(); System.out .print("Received podcast from LEGACY database *************************** " + mapper.writerWithDefaultPrettyPrinter() .writeValueAsString(podcast)); }
Example 4
Source File: RestDemoServiceIT.java From demo-rest-jersey-spring with MIT License | 6 votes |
@Test public void testGetLegacyPodcast() throws JsonGenerationException, JsonMappingException, IOException { ClientConfig clientConfig = new ClientConfig(); clientConfig.register(JacksonFeature.class); Client client = ClientBuilder.newClient(clientConfig); WebTarget webTarget = client .target("http://localhost:8888/demo-rest-jersey-spring/legacy/podcasts/2"); Builder request = webTarget.request(MediaType.APPLICATION_JSON); Response response = request.get(); Assert.assertTrue(response.getStatus() == 200); Podcast podcast = response.readEntity(Podcast.class); ObjectMapper mapper = new ObjectMapper(); System.out .print("Received podcast from LEGACY database *************************** " + mapper.writerWithDefaultPrettyPrinter() .writeValueAsString(podcast)); }
Example 5
Source File: CustomHttpClient.java From symphony-java-client with Apache License 2.0 | 5 votes |
/** * @param config SymphonyClientConfig * @return Jersey Client * @throws Exception from underlying REST API exceptions */ public static Client getDefaultHttpClient(SymphonyClientConfig config) throws Exception { Client httpClient; ClientConfig clientConfig = new ClientConfig(); clientConfig.register(new JSON()); clientConfig.register(JacksonFeature.class); //If a truststore file is provided.. if (config.get(SymphonyClientConfigID.TRUSTSTORE_FILE) != null) { httpClient = CustomHttpClient.getClient( config.get(SymphonyClientConfigID.USER_CERT_FILE), config.get(SymphonyClientConfigID.USER_CERT_PASSWORD), config.get(SymphonyClientConfigID.TRUSTSTORE_FILE), config.get(SymphonyClientConfigID.TRUSTSTORE_PASSWORD), clientConfig); } else { httpClient = CustomHttpClient.getClient( config.get(SymphonyClientConfigID.USER_CERT_FILE), config.get(SymphonyClientConfigID.USER_CERT_PASSWORD), clientConfig); } return httpClient; }
Example 6
Source File: RestDemoServiceIT.java From demo-restWS-spring-jersey-jpa2-hibernate with MIT License | 5 votes |
@Test public void testGetPodcasts() throws JsonGenerationException, JsonMappingException, IOException { ClientConfig clientConfig = new ClientConfig(); clientConfig.register(JacksonFeature.class); Client client = ClientBuilder.newClient(clientConfig); WebTarget webTarget = client .target("http://localhost:8888/demo-rest-spring-jersey-jpa2-hibernate-0.0.1-SNAPSHOT/podcasts/"); Builder request = webTarget.request(); request.header("Content-type", MediaType.APPLICATION_JSON); Response response = request.get(); Assert.assertTrue(response.getStatus() == 200); List<Podcast> podcasts = response .readEntity(new GenericType<List<Podcast>>() { }); ObjectMapper mapper = new ObjectMapper(); System.out.print(mapper.writerWithDefaultPrettyPrinter() .writeValueAsString(podcasts)); Assert.assertTrue("At least one podcast is present", podcasts.size() > 0); }
Example 7
Source File: RxJerseyClientFeature.java From rx-jersey with MIT License | 5 votes |
private Client createClient() { int cores = Runtime.getRuntime().availableProcessors(); ClientConfig config = new ClientConfig(); config.connectorProvider(new GrizzlyConnectorProvider()); config.property(ClientProperties.ASYNC_THREADPOOL_SIZE, cores); config.register(RxObservableInvokerProvider.class); return ClientBuilder.newClient(config); }
Example 8
Source File: AmbariServiceNodeDiscoverer.java From streamline with Apache License 2.0 | 5 votes |
private void setupClient() { HttpAuthenticationFeature feature = HttpAuthenticationFeature.basicBuilder() .credentials(username, password).build(); ClientConfig clientConfig = new ClientConfig(); clientConfig.register(feature); clientConfig.register(JsonToMapProvider.class); client = ClientBuilder.newClient(clientConfig); }
Example 9
Source File: TestsendformdataClient.java From raml-java-client-generator with Apache License 2.0 | 4 votes |
protected Client getClientWithMultipart() { ClientConfig cc = new ClientConfig(); cc.register(MultiPartFeature.class); javax.ws.rs.client.ClientBuilder clientBuilder = javax.ws.rs.client.ClientBuilder.newBuilder(); return clientBuilder.withConfig(cc).build(); }
Example 10
Source File: RequestMetricsFilterRegistry.java From cf-java-logging-support with Apache License 2.0 | 4 votes |
public static void registerClientFilters(ClientConfig clientConfig) { clientConfig.register(RequestMetricsClientRequestFilter.class); clientConfig.register(RequestMetricsClientResponseFilter.class); }
Example 11
Source File: DelimitedRestTest.java From mobi with GNU Affero General Public License v3.0 | 4 votes |
@Override protected void configureClient(ClientConfig config) { config.register(MultiPartFeature.class); }
Example 12
Source File: MCRJerseyTest.java From mycore with GNU General Public License v3.0 | 4 votes |
@Override protected void configureClient(ClientConfig config) { config.register(MultiPartFeature.class); }
Example 13
Source File: GroupRestTest.java From mobi with GNU Affero General Public License v3.0 | 4 votes |
@Override protected void configureClient(ClientConfig config) { config.register(MultiPartFeature.class); }
Example 14
Source File: JerseyExtendedNiFiRegistryClient.java From nifi with Apache License 2.0 | 4 votes |
public JerseyExtendedNiFiRegistryClient(final NiFiRegistryClient delegate, final NiFiRegistryClientConfig registryClientConfig) { this.delegate = delegate; // Copied from JerseyNiFiRegistryClient! if (registryClientConfig == null) { throw new IllegalArgumentException("NiFiRegistryClientConfig cannot be null"); } String baseUrl = registryClientConfig.getBaseUrl(); if (StringUtils.isBlank(baseUrl)) { throw new IllegalArgumentException("Base URL cannot be blank"); } if (baseUrl.endsWith("/")) { baseUrl = baseUrl.substring(0, baseUrl.length() - 1); } if (!baseUrl.endsWith(NIFI_REGISTRY_CONTEXT)) { baseUrl = baseUrl + "/" + NIFI_REGISTRY_CONTEXT; } try { new URI(baseUrl); } catch (final Exception e) { throw new IllegalArgumentException("Invalid base URL: " + e.getMessage(), e); } final SSLContext sslContext = registryClientConfig.getSslContext(); final HostnameVerifier hostnameVerifier = registryClientConfig.getHostnameVerifier(); final ClientBuilder clientBuilder = ClientBuilder.newBuilder(); if (sslContext != null) { clientBuilder.sslContext(sslContext); } if (hostnameVerifier != null) { clientBuilder.hostnameVerifier(hostnameVerifier); } final int connectTimeout = registryClientConfig.getConnectTimeout() == null ? DEFAULT_CONNECT_TIMEOUT : registryClientConfig.getConnectTimeout(); final int readTimeout = registryClientConfig.getReadTimeout() == null ? DEFAULT_READ_TIMEOUT : registryClientConfig.getReadTimeout(); final ClientConfig clientConfig = new ClientConfig(); clientConfig.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout); clientConfig.property(ClientProperties.READ_TIMEOUT, readTimeout); clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.CHUNKED); clientConfig.register(jacksonJaxbJsonProvider()); clientBuilder.withConfig(clientConfig); this.client = clientBuilder .register(MultiPartFeature.class) .build(); this.baseTarget = client.target(baseUrl); this.tenantsClient = new JerseyTenantsClient(baseTarget); this.policiesClient = new JerseyPoliciesClient(baseTarget); }
Example 15
Source File: MergeRequestRestTest.java From mobi with GNU Affero General Public License v3.0 | 4 votes |
@Override protected void configureClient(ClientConfig config) { config.register(MultiPartFeature.class); }
Example 16
Source File: PulsarAdmin.java From pulsar with Apache License 2.0 | 4 votes |
public PulsarAdmin(String serviceUrl, ClientConfigurationData clientConfigData, int connectTimeout, TimeUnit connectTimeoutUnit, int readTimeout, TimeUnit readTimeoutUnit, int requestTimeout, TimeUnit requestTimeoutUnit) throws PulsarClientException { this.connectTimeout = connectTimeout; this.connectTimeoutUnit = connectTimeoutUnit; this.readTimeout = readTimeout; this.readTimeoutUnit = readTimeoutUnit; this.requestTimeout = requestTimeout; this.requestTimeoutUnit = requestTimeoutUnit; this.clientConfigData = clientConfigData; this.auth = clientConfigData != null ? clientConfigData.getAuthentication() : new AuthenticationDisabled(); LOG.debug("created: serviceUrl={}, authMethodName={}", serviceUrl, auth != null ? auth.getAuthMethodName() : null); if (auth != null) { auth.start(); } if (StringUtils.isBlank(clientConfigData.getServiceUrl())) { clientConfigData.setServiceUrl(serviceUrl); } AsyncHttpConnectorProvider asyncConnectorProvider = new AsyncHttpConnectorProvider(clientConfigData); ClientConfig httpConfig = new ClientConfig(); httpConfig.property(ClientProperties.FOLLOW_REDIRECTS, true); httpConfig.property(ClientProperties.ASYNC_THREADPOOL_SIZE, 8); httpConfig.register(MultiPartFeature.class); httpConfig.connectorProvider(asyncConnectorProvider); ClientBuilder clientBuilder = ClientBuilder.newBuilder() .withConfig(httpConfig) .connectTimeout(this.connectTimeout, this.connectTimeoutUnit) .readTimeout(this.readTimeout, this.readTimeoutUnit) .register(JacksonConfigurator.class).register(JacksonFeature.class); boolean useTls = clientConfigData.getServiceUrl().startsWith("https://"); this.client = clientBuilder.build(); this.serviceUrl = serviceUrl; root = client.target(serviceUrl); this.httpAsyncClient = asyncConnectorProvider.getConnector( Math.toIntExact(connectTimeoutUnit.toMillis(this.connectTimeout)), Math.toIntExact(readTimeoutUnit.toMillis(this.readTimeout)), Math.toIntExact(requestTimeoutUnit.toMillis(this.requestTimeout))).getHttpClient(); long readTimeoutMs = readTimeoutUnit.toMillis(this.readTimeout); this.clusters = new ClustersImpl(root, auth, readTimeoutMs); this.brokers = new BrokersImpl(root, auth, readTimeoutMs); this.brokerStats = new BrokerStatsImpl(root, auth, readTimeoutMs); this.proxyStats = new ProxyStatsImpl(root, auth, readTimeoutMs); this.tenants = new TenantsImpl(root, auth, readTimeoutMs); this.properties = new TenantsImpl(root, auth, readTimeoutMs); this.namespaces = new NamespacesImpl(root, auth, readTimeoutMs); this.topics = new TopicsImpl(root, auth, readTimeoutMs); this.nonPersistentTopics = new NonPersistentTopicsImpl(root, auth, readTimeoutMs); this.resourceQuotas = new ResourceQuotasImpl(root, auth, readTimeoutMs); this.lookups = new LookupImpl(root, auth, useTls, readTimeoutMs); this.functions = new FunctionsImpl(root, auth, httpAsyncClient, readTimeoutMs); this.sources = new SourcesImpl(root, auth, httpAsyncClient, readTimeoutMs); this.sinks = new SinksImpl(root, auth, httpAsyncClient, readTimeoutMs); this.worker = new WorkerImpl(root, auth, readTimeoutMs); this.schemas = new SchemasImpl(root, auth, readTimeoutMs); this.bookies = new BookiesImpl(root, auth, readTimeoutMs); }
Example 17
Source File: UserRestTest.java From mobi with GNU Affero General Public License v3.0 | 4 votes |
@Override protected void configureClient(ClientConfig config) { config.register(MultiPartFeature.class); }
Example 18
Source File: SparqlRestTest.java From mobi with GNU Affero General Public License v3.0 | 4 votes |
@Override protected void configureClient(ClientConfig config) { config.register(MultiPartFeature.class); }
Example 19
Source File: QuestionnairResourceTest.java From gazpachoquest with GNU General Public License v3.0 | 4 votes |
@Override protected void configureClient(final ClientConfig config) { config.register(new Jackson2Feature()); }
Example 20
Source File: UsergridExternalProvider.java From usergrid with Apache License 2.0 | 4 votes |
private Client getJerseyClient() { if (jerseyClient == null) { synchronized (this) { // create HTTPClient and with configured connection pool int poolSize = 100; // connections final String poolSizeStr = properties.getProperty(CENTRAL_CONNECTION_POOL_SIZE); if (poolSizeStr != null) { poolSize = Integer.parseInt(poolSizeStr); } PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(); connectionManager.setMaxTotal(poolSize); int timeout = 20000; // ms final String timeoutStr = properties.getProperty(CENTRAL_CONNECTION_TIMEOUT); if (timeoutStr != null) { timeout = Integer.parseInt(timeoutStr); } int readTimeout = 20000; // ms final String readTimeoutStr = properties.getProperty(CENTRAL_READ_TIMEOUT); if (readTimeoutStr != null) { readTimeout = Integer.parseInt(readTimeoutStr); } ClientConfig clientConfig = new ClientConfig(); clientConfig.register(new JacksonFeature()); clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager); clientConfig.connectorProvider(new ApacheConnectorProvider()); jerseyClient = ClientBuilder.newClient(clientConfig); jerseyClient.property(ClientProperties.CONNECT_TIMEOUT, timeout); jerseyClient.property(ClientProperties.READ_TIMEOUT, readTimeout); } } return jerseyClient; }