本文整理匯總了Java中org.glassfish.jersey.client.ClientConfig.property方法的典型用法代碼示例。如果您正苦於以下問題:Java ClientConfig.property方法的具體用法?Java ClientConfig.property怎麽用?Java ClientConfig.property使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.glassfish.jersey.client.ClientConfig
的用法示例。
在下文中一共展示了ClientConfig.property方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createConfig
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
protected ClientConfig createConfig(Set<Feature> features) {
ClientConfig config = new ClientConfig();
config.property(ClientProperties.FOLLOW_REDIRECTS, followRedirects);
config.property(ClientProperties.READ_TIMEOUT, readTimeoutMs);
config.property(ClientProperties.CONNECT_TIMEOUT, connectTimeoutMs);
config.property(ClientProperties.ASYNC_THREADPOOL_SIZE, asyncThreadPoolSize);
features.forEach(f -> config.register(f));
if (compression) {
config.register(new EncodingFeature(GZipEncoder.class));
}
configRequestLogging(config);
return config;
}
示例2: createClientConfig
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
protected ClientConfig createClientConfig() {
ClientConfig config = new ClientConfig();
if ( proxy != null && proxy.getUri() != null ) {
config.property(ClientProperties.PROXY_URI, proxy.getUriString());
config.property(ClientProperties.PROXY_USERNAME, proxy.getUserName());
config.property(ClientProperties.PROXY_PASSWORD, proxy.getPassword());
}
config.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);
config.property(ApacheClientProperties.CREDENTIALS_PROVIDER, getCredentialsProvider());
config.property(ApacheClientProperties.SERVICE_UNAVAILABLE_RETRY_STRATEGY, getServiceUnavailableRetryStrategy());
config.property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, doPreemptiveBasicAuthentication());
config.connectorProvider(new ApacheConnectorProvider());
config.register(JacksonFeature.class);
config.register(new LoggingFeature(Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME), Level.FINE, LoggingFeature.Verbosity.PAYLOAD_ANY, 10000));
return config;
}
示例3: build
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
public Client build(final Configuration config) {
// setup client
ClientConfig clientConfig = new ClientConfig();
if (config.isVerbose()) {
clientConfig.register(new LoggingFilter(logger("jersey"), false));
}
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, config.getTimeout() * 1000);
clientConfig.property(ClientProperties.READ_TIMEOUT, config.getTimeout() * 1000);
javax.ws.rs.client.Client client;
if (config.isVerifySSL()) {
client = ClientBuilder.newBuilder().withConfig(clientConfig).hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
return config.isVerifySSL();
}
}).build();
} else {
client = ClientBuilder.newClient(clientConfig);
}
return client;
}
示例4: addProxyConfiguration
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
private static void addProxyConfiguration(ClientConfig config, String baseUrl) {
String protocol = URI.create(baseUrl).getScheme().toLowerCase();
Optional<String> proxyHost = Optional.ofNullable(System.getProperty(protocol + ".proxyHost"));
if (!proxyHost.isPresent()) {
return;
}
String host = proxyHost.get();
String port = Optional.ofNullable(System.getProperty(protocol + ".proxyPort")).orElse("8080");
String proxyProtocol = Optional.ofNullable(System.getProperty(protocol + ".proxyProtocol")).orElse("http");
String url = proxyProtocol + "://" + host + ":" + port;
config.property(ClientProperties.PROXY_URI, url);
Optional<String> username = Optional.ofNullable(System.getProperty(protocol + ".proxyUser"));
Optional<String> password = Optional.ofNullable(System.getProperty(protocol + ".proxyPassword"));
if (username.isPresent() && password.isPresent()) {
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username.get(), password.get());
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, credentials);
}
}
示例5: configureProxy
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
private void configureProxy(ClientConfig clientConfig, URI originalUri, String protocol) {
List<Proxy> proxies = ProxySelector.getDefault().select(originalUri);
for (Proxy proxy : proxies) {
InetSocketAddress address = (InetSocketAddress) proxy.address();
if (address != null) {
String hostname = address.getHostName();
int port = address.getPort();
clientConfig.property(ClientProperties.PROXY_URI, "http://" + hostname + ":" + port);
String httpProxyUser = System.getProperty(protocol + ".proxyUser");
if (httpProxyUser != null) {
clientConfig.property(ClientProperties.PROXY_USERNAME, httpProxyUser);
String httpProxyPassword = System.getProperty(protocol + ".proxyPassword");
if (httpProxyPassword != null) {
clientConfig.property(ClientProperties.PROXY_PASSWORD, httpProxyPassword);
}
}
}
}
}
示例6: createClient
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
public static Client createClient(String serverCert, String clientCert, String clientKey, boolean debug, Class debugClass) throws Exception {
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(KeyStoreUtil.createTrustStore(serverCert), null)
.loadKeyMaterial(KeyStoreUtil.createKeyStore(clientCert, clientKey), "consul".toCharArray())
.build();
ClientConfig config = new ClientConfig();
config.property(ClientProperties.FOLLOW_REDIRECTS, "false");
config.property(ClientProperties.CONNECT_TIMEOUT, CONNECT_TIMEOUT_MS);
config.register(MultiPartFeature.class);
ClientBuilder builder = ClientBuilder.newBuilder().withConfig(config);
builder.sslContext(sslContext);
builder.hostnameVerifier(CertificateTrustManager.hostnameVerifier());
if (debug) {
builder = builder.register(new LoggingFilter(java.util.logging.Logger.getLogger(debugClass.getName()), true));
}
Client client = builder.build();
LOGGER.debug("Jax rs client has been constructed: {}, sslContext: {}", client, sslContext);
return client;
}
示例7: buildClient
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
private static void buildClient() {
if ( USE_PROXY ) {
ClientConfig config = new ClientConfig();
config.connectorProvider(new ApacheConnectorProvider());
CredentialsProvider credentials = new BasicCredentialsProvider();
credentials.setCredentials(AuthScope.ANY, new NTCredentials(PROXY_USER, PROXY_PASS, null, PROXY_DOMAIN));
config.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentials);
config.property(ClientProperties.PROXY_URI, PROXY_PROTOCOL + PROXY_SERVER);
client = ClientBuilder.newClient(config);
}
else
client = ClientBuilder.newClient();
}
示例8: Pandora
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
public Pandora(AnnaConfig config) {
this.appId = config.getPandora().getAppId();
this.userKey = config.getPandora().getUserKey();
this.pandoraBot = config.getPandora().getBot();
ClientConfig cfg = new ClientConfig(JacksonJsonProvider.class);
cfg.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
client = JerseyClientBuilder.createClient(cfg);
}
示例9: create
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
@Override
public WebTarget create() {
ClientConfig configuration = new ClientConfig();
configuration = configuration.property(ClientProperties.CONNECT_TIMEOUT, CONNECTION_TIMEOUT_MS);
configuration = configuration.property(ClientProperties.READ_TIMEOUT, CONNECTION_TIMEOUT_MS);
Client client = ClientBuilder.newClient(configuration).register(JacksonJsonProvider.class);
return client.target(uri);
}
示例10: get
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
@Override
public WebTarget get() {
ClientConfig configuration = new ClientConfig();
configuration = configuration.property(ClientProperties.CONNECT_TIMEOUT, CONNECTION_TIMEOUT_MS);
configuration = configuration.property(ClientProperties.READ_TIMEOUT, CONNECTION_TIMEOUT_MS);
Client client = ClientBuilder.newClient(configuration).register(JacksonJsonProvider.class)
.register(ErrorResponseFilter.class);
return client.target("http://localhost:38081");
}
示例11: RESTClient
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
/**
* Creates a new REST Client for an entity of Type T. The client interacts with a Server providing
* CRUD functionalities
* @param hostURL The url of the host. Common Pattern: "http://[hostname]:[port]/servicename/"
* @param application The name of the rest application, usually {@link #DEFAULT_REST_APPLICATION} "rest" (no "/"!)
* @param endpoint The name of the rest endpoint, typically the all lower case name of the entity in a plural form.
* E.g., "products" for the entity "Product" (no "/"!)
* @param entityClass Classtype of the Entitiy to send/receive. Note that the use of this Class type is
* open for interpretation by the inheriting REST clients.
*/
public RESTClient(String hostURL, String application, String endpoint, final Class<T> entityClass) {
if (!hostURL.endsWith("/")) {
hostURL += "/";
}
if (!hostURL.contains("://")) {
hostURL = "http://" + hostURL;
}
ClientConfig config = new ClientConfig();
config.property(ClientProperties.CONNECT_TIMEOUT, CONNECT_TIMEOUT);
config.property(ClientProperties.READ_TIMEOUT, readTimeout);
client = ClientBuilder.newClient(config);
service = client.target(UriBuilder.fromUri(hostURL).build());
applicationURI = application;
endpointURI = endpoint;
this.entityClass = entityClass;
parameterizedGenericType = new ParameterizedType() {
public Type[] getActualTypeArguments() {
return new Type[] { entityClass };
}
public Type getRawType() {
return List.class;
}
public Type getOwnerType() {
return List.class;
}
};
genericListType = new GenericType<List<T>>(parameterizedGenericType) { };
}
示例12: getInvocationBuilder
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
protected Builder getInvocationBuilder(String url, Map<String, String> queryParameters) {
ClientConfig clientConfig = new ClientConfig();
if (getProxyAddress() != null) {
clientConfig.connectorProvider(new ApacheConnectorProvider());
clientConfig.property(ClientProperties.PROXY_URI, getProxyAddress());
}
Client client = ClientBuilder.newClient(clientConfig);
client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
WebTarget webTarget = client.target(url);
if (queryParameters != null) {
for (Map.Entry<String, String> queryParameter: queryParameters.entrySet())
// webTarget = webTarget.queryParam(queryParameter.getKey(), queryParameter.getValue().replace("_", "_1").replace("%", "_0"));
webTarget = webTarget.queryParam(queryParameter.getKey(), queryParameter.getValue());
}
return webTarget.request(MediaType.APPLICATION_JSON).accept("application/ld+json").header("Authorization", getCloudTokenValue());
}
示例13: configure
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
@Override
public void configure(HttpConfig config, ScriptContext context) {
ClientConfig cc = new ClientConfig();
// support request body for DELETE (non-standard)
cc.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
if (!config.isFollowRedirects()) {
cc.property(ClientProperties.FOLLOW_REDIRECTS, false);
}
ClientBuilder clientBuilder = ClientBuilder.newBuilder()
.withConfig(cc)
.register(new LoggingInterceptor(context)) // must be first
.register(MultiPartFeature.class);
if (config.isSslEnabled()) {
SSLContext sslContext;
if (config.getSslTrustStore() != null) {
String trustStoreFile = config.getSslTrustStore();
String password = config.getSslTrustStorePassword();
char[] passwordChars = password == null ? null : password.toCharArray();
String algorithm = config.getSslAlgorithm();
String type = config.getSslTrustStoreType();
if (type == null) {
type = KeyStore.getDefaultType();
}
try {
KeyStore trustStore = KeyStore.getInstance(type);
InputStream is = FileUtils.getFileStream(trustStoreFile, context);
trustStore.load(is, passwordChars);
context.logger.debug("trust store key count: {}", trustStore.size());
sslContext = SslConfigurator.newInstance()
.securityProtocol(algorithm) // will default to TLS if null
.trustStore(trustStore)
// .keyStore(trustStore)
.createSSLContext();
} catch (Exception e) {
context.logger.error("ssl config failed: {}", e.getMessage());
throw new RuntimeException(e);
}
} else {
sslContext = HttpUtils.getSslContext(config.getSslAlgorithm());
}
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
clientBuilder.sslContext(sslContext);
clientBuilder.hostnameVerifier((host, session) -> true);
}
client = clientBuilder.build();
client.property(ClientProperties.CONNECT_TIMEOUT, config.getConnectTimeout());
client.property(ClientProperties.READ_TIMEOUT, config.getReadTimeout());
if (config.getProxyUri() != null) {
client.property(ClientProperties.PROXY_URI, config.getProxyUri());
if (config.getProxyUsername() != null && config.getProxyPassword() != null) {
client.property(ClientProperties.PROXY_USERNAME, config.getProxyUsername());
client.property(ClientProperties.PROXY_PASSWORD, config.getProxyPassword());
}
}
}
示例14: createClient
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
private Client createClient() {
ClientConfig config = new ClientConfig();
config.property(ClientProperties.CONNECT_TIMEOUT, configuration.getClientConnectTimeout());
config.property(ClientProperties.READ_TIMEOUT, configuration.getClientReadTimeout());
config.register(new LoggingFeature());
return ClientBuilder.newClient(config);
}
示例15: provide
import org.glassfish.jersey.client.ClientConfig; //導入方法依賴的package包/類
@Override
public Client provide() {
ClientConfig config = new ClientConfig();
config.property(ClientProperties.CONNECT_TIMEOUT, 1500);
config.property(ClientProperties.READ_TIMEOUT, 1500);
config.register(new LoggingFeature());
Client client = ClientBuilder.newClient(config);
LOGGER.debug(" *** Created client: {}", client);
return client;
}