clientBuilder.property(ClientProperties.PROXY_URI, builder.proxyUri);
@Bean public JaxrsClientCustomizer propertyCustomizer() { // <1> return cb -> cb.property("test.jaxrs.client.customizers", "test"); }
public JerseyJaxRsClientFactory(SSLContext sslContext, HostnameVerifier hostnameVerifier, String userAgent) { /* * Configure client with some workarounds for HTTP/JAX-RS/Jersey issues. See: * https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/client/ClientProperties.html#SUPPRESS_HTTP_COMPLIANCE_VALIDATION * https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/client/HttpUrlConnectorProvider.html#SET_METHOD_WORKAROUND */ ClientBuilder builder = ClientBuilder.newBuilder() .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true) // Allow empty PUT. TODO: Fix API. .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) // Allow e.g. PATCH method. .property(ClientProperties.FOLLOW_REDIRECTS, true); if (sslContext != null) { builder.sslContext(sslContext); } if (hostnameVerifier != null) { builder.hostnameVerifier(hostnameVerifier); } if (userAgent != null) { builder.register((ClientRequestFilter) context -> context.getHeaders().put(HttpHeaders.USER_AGENT, Collections.singletonList(userAgent))); } this.client = builder.build(); }
public Client restClient() { return ClientBuilder.newBuilder() .register(HttpAuthenticationFeature.basic(username, password)) .property(ClientProperties.FOLLOW_REDIRECTS, Boolean.TRUE) .build(); }
@Produces @UiSpecProxy @ApplicationScoped public javax.ws.rs.client.Client client(final ProxyConfiguration configuration, @UiSpecProxy final ExecutorService executor) { final javax.ws.rs.client.Client client = ClientBuilder .newBuilder() .executorService(executor) .property("executorService", executor) // rx() .connectTimeout(configuration.getConnectTimeout(), MILLISECONDS) .readTimeout(configuration.getReadTimeout(), MILLISECONDS) .build(); ofNullable(configuration.getClientProviders()).ifPresent(list -> list.forEach(client::register)); return client; }
private OpenTsdb(String baseURL, Integer connectionTimeout, Integer readTimeout, boolean gzipEnabled) { ClientBuilder builder = ClientBuilder.newBuilder() .register(JacksonFeature.class); if (gzipEnabled) { builder = builder.register(GZipEncoder.class) .register(EncodingFilter.class) .property(ClientProperties.USE_ENCODING, "gzip"); } final Client client = builder.build(); client.property(ClientProperties.CONNECT_TIMEOUT, connectionTimeout); client.property(ClientProperties.READ_TIMEOUT, readTimeout); this.apiResource = client.target(baseURL); }
private WebTarget createRootTarget(String rootUrl) { Client client = ClientBuilder.newBuilder() .property(ClientProperties.FOLLOW_REDIRECTS, Boolean.TRUE) .build(); client.register(MultiPartFeature.class); return client.target(rootUrl); }
private HttpClient(HttpContext context) { ClientBuilder builder = ClientBuilder.newBuilder() .property(SET_METHOD_WORKAROUND, true) .property(SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true) .register(MultiPartFeature.class) .register(logAny()) .sslContext(context.isHttpSslVerify() ? getDefaultContext() : emptyContext()); if (!context.isHttpSslVerify()) { builder.hostnameVerifier(trustAll()); } this.client = builder.build(); this.context = context; }
private HttpClient(HttpContext context) { ClientBuilder builder = ClientBuilder.newBuilder() .property(SET_METHOD_WORKAROUND, true) .property(SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true) .register(MultiPartFeature.class) .register(logAny()) .sslContext(context.isHttpSslVerify() ? getDefaultContext() : emptyContext()); if (!context.isHttpSslVerify()) { builder.hostnameVerifier(trustAll()); } this.client = builder.build(); this.context = context; }
@Before public void setUp() throws Exception { InetSocketAddress address = testBase.getTestingCluster().getConfiguration().getSocketAddrVar(ConfVars.REST_SERVICE_ADDRESS); restServiceURI = new URI("http", null, address.getHostName(), address.getPort(), "/rest", null, null); sessionsURI = new URI(restServiceURI + "/sessions"); restClient = ClientBuilder.newBuilder() .register(new GsonFeature(PlanGsonHelper.registerAdapters())) .register(LoggingFilter.class) .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true) .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true) .build(); }
@Before public void setUp() throws Exception { InetSocketAddress address = testBase.getTestingCluster().getConfiguration().getSocketAddrVar(ConfVars.REST_SERVICE_ADDRESS); restServiceURI = new URI("http", null, address.getHostName(), address.getPort(), "/rest", null, null); tablesURI = new URI(restServiceURI + "/databases/" + defaultDatabaseName + "/tables"); queriesURI = new URI(restServiceURI + "/queries"); sessionsURI = new URI(restServiceURI + "/sessions"); restClient = ClientBuilder.newBuilder() .register(new GsonFeature(PlanGsonHelper.registerAdapters())) .register(LoggingFilter.class) .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true) .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true) .build(); }
ClientBuilder clientBuilder = JerseyClientBuilder.newBuilder() .withConfig(config) .property(ClientProperties.FOLLOW_REDIRECTS, Boolean.TRUE); if (conf.containsKey(SSL_CONFIGURATION_KEY)) { Map<String, String> sslConfigurations = (Map<String, String>) conf.get(SSL_CONFIGURATION_KEY);
@Before public void setUp() throws Exception { InetSocketAddress address = testBase.getTestingCluster().getConfiguration().getSocketAddrVar(ConfVars.REST_SERVICE_ADDRESS); restServiceURI = new URI("http", null, address.getHostName(), address.getPort(), "/rest", null, null); sessionsURI = new URI(restServiceURI + "/sessions"); queriesURI = new URI(restServiceURI + "/queries"); restClient = ClientBuilder.newBuilder() .register(new GsonFeature(PlanGsonHelper.registerAdapters())) .register(LoggingFilter.class) .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true) .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true) .build(); }
@Before public void setUp() throws Exception { InetSocketAddress address = testBase.getTestingCluster().getConfiguration().getSocketAddrVar(ConfVars.REST_SERVICE_ADDRESS); restServiceURI = new URI("http", null, address.getHostName(), address.getPort(), "/rest", null, null); sessionsURI = new URI(restServiceURI + "/sessions"); queriesURI = new URI(restServiceURI + "/queries"); restClient = ClientBuilder.newBuilder() .register(new GsonFeature(PlanGsonHelper.registerAdapters())) .register(LoggingFilter.class) .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true) .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true) .build(); }
@Before public void setUp() throws Exception { InetSocketAddress address = testBase.getTestingCluster().getConfiguration().getSocketAddrVar(ConfVars.REST_SERVICE_ADDRESS); restServiceURI = new URI("http", null, address.getHostName(), address.getPort(), "/rest", null, null); clusterURI = new URI(restServiceURI + "/cluster"); restClient = ClientBuilder.newBuilder() .register(new GsonFeature(PlanGsonHelper.registerAdapters())) .register(LoggingFilter.class) .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true) .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true) .build(); }
@Before public void setUp() throws Exception { InetSocketAddress address = testBase.getTestingCluster().getConfiguration().getSocketAddrVar(ConfVars.REST_SERVICE_ADDRESS); restServiceURI = new URI("http", null, address.getHostName(), address.getPort(), "/rest", null, null); databasesURI = new URI(restServiceURI + "/databases"); restClient = ClientBuilder.newBuilder() .register(new GsonFeature(PlanGsonHelper.registerAdapters())) .register(LoggingFilter.class) .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true) .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true) .build(); }
@Before public void setUp() throws Exception { InetSocketAddress address = testBase.getTestingCluster().getConfiguration().getSocketAddrVar(ConfVars.REST_SERVICE_ADDRESS); restServiceURI = new URI("http", null, address.getHostName(), address.getPort(), "/rest", null, null); functionsURI = new URI(restServiceURI + "/functions"); restClient = ClientBuilder.newBuilder() .register(new GsonFeature(PlanGsonHelper.registerAdapters())) .register(LoggingFilter.class) .property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE, true) .property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, true) .build(); }
private static Client buildClientFromConfig(Config config) { ClientConfig clientConfig = new ClientConfig(); if (config.getProxy() != null) { addProxy(clientConfig, config); } ClientBuilder cb = ClientBuilder.newBuilder() .withConfig(clientConfig) .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, "true") .register(JacksonFeature.class) .register(RESOLVER) .register(new RequestFilter()); if (config.getSslContext() != null) cb.sslContext(config.getSslContext()); else if (config.isIgnoreSSLVerification()) cb.sslContext(UntrustedSSL.getSSLContext()); if (config.getHostNameVerifier() != null) cb.hostnameVerifier(config.getHostNameVerifier()); else if (config.isIgnoreSSLVerification()) cb.hostnameVerifier(UntrustedSSL.getHostnameVerifier()); if (config.getReadTimeout() > 0) cb.property(ClientProperties.READ_TIMEOUT, config.getReadTimeout()); if (config.getConnectTimeout() > 0) cb.property(ClientProperties.CONNECT_TIMEOUT, config.getConnectTimeout()); return cb.build(); }
/** * Create an authenticating REST client for WebLogic Server interactions. * * @param config The client configuration * @param logger The Logger to use for client logging. * * @return A javax.ws.rs.Client based on the specified configuration */ public static Client getClient(CommonWebLogicConfiguration config, Logger logger) { HttpAuthenticationFeature httpAuthFeature = HttpAuthenticationFeature.universalBuilder().credentialsForBasic(config.getAdminUserName(), config.getAdminPassword()).build(); ClientBuilder restClientBuilder = ClientBuilder.newBuilder(); restClientBuilder.register(CsrfProtectionFilter.class); restClientBuilder.register(httpAuthFeature); restClientBuilder.register(MultiPartFeature.class); restClientBuilder.register(JsonProcessingFeature.class); restClientBuilder.property(JsonGenerator.PRETTY_PRINTING, true); // format JSON content for readability // Register the logging filter only if configured to log the REST requests/responses (or the REST entities). // The REST entity logging is a finer level of detail that requires the logging filter, so it overrides the other // configuration property. if (config.isLogRESTMessages() || config.isLogRESTEntities()) { // Honor the verbose logging property to determine whether REST entities should be printed restClientBuilder.register(new LoggingFilter(logger, config.isLogRESTEntities())); } return restClientBuilder.build(); }