本文整理汇总了Java中org.glassfish.jersey.apache.connector.ApacheClientProperties类的典型用法代码示例。如果您正苦于以下问题:Java ApacheClientProperties类的具体用法?Java ApacheClientProperties怎么用?Java ApacheClientProperties使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ApacheClientProperties类属于org.glassfish.jersey.apache.connector包,在下文中一共展示了ApacheClientProperties类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
private void init() {
final URI originalUri = URI.create(DEFAULT_UNIX_ENDPOINT);
sanitizeUri = UnixFactory.sanitizeUri(originalUri);
final RegistryBuilder<ConnectionSocketFactory> registryBuilder =
RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", SSLConnectionSocketFactory.getSocketFactory())
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("unix", new UnixFactory(originalUri));
final PoolingHttpClientConnectionManager cm =
new PoolingHttpClientConnectionManager(registryBuilder.build());
final RequestConfig requestConfig = RequestConfig.custom()
.setConnectionRequestTimeout((int) SECONDS.toMillis(5))
.setConnectTimeout((int) SECONDS.toMillis(5))
.setSocketTimeout((int) SECONDS.toMillis(30))
.build();
final ClientConfig config = new ClientConfig()
.connectorProvider(new ApacheConnectorProvider())
.property(ApacheClientProperties.CONNECTION_MANAGER, cm)
.property(ApacheClientProperties.REQUEST_CONFIG, requestConfig);
client = ClientBuilder.newBuilder().withConfig(config).build();
}
示例2: AntiochClient
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
public AntiochClient(final URI antiochURI, SSLContext sslContext) {
this.antiochURI = antiochURI;
final ObjectMapper objectMapper = new ObjectMapper()//
.registerModule(new Jdk8Module())//
.registerModule(new JavaTimeModule());
final JacksonJaxbJsonProvider jacksonProvider = new JacksonJaxbJsonProvider();
jacksonProvider.setMapper(objectMapper);
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
cm.setMaxTotal(50);
cm.setDefaultMaxPerRoute(50);
ApacheConnectorProvider connectorProvider = new ApacheConnectorProvider();
ClientConfig clientConfig = new ClientConfig(jacksonProvider)//
.connectorProvider(connectorProvider)//
.property(ApacheClientProperties.CONNECTION_MANAGER, cm)//
.property(ClientProperties.CONNECT_TIMEOUT, 60000)//
.property(ClientProperties.READ_TIMEOUT, 60000);
if (sslContext == null) {
if ("https".equals(antiochURI.getScheme())) {
throw new RuntimeException("SSL connections need an SSLContext, use: new AntiochClient(uri, sslContext) instead.");
}
client = ClientBuilder.newClient(clientConfig);
} else {
client = ClientBuilder.newBuilder()//
.sslContext(sslContext)//
.withConfig(clientConfig)//
.build();
}
rootTarget = client.target(antiochURI);
}
示例3: ExtensionsService
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
@Autowired
public ExtensionsService(
@Value("${org.osiam.endpoint:}") String osiamEndpoint,
@Value("${org.osiam.resourceServerEndpoint:}") String resourceServerEndpoint,
GeneralSessionData sessionData, ObjectMapper mapper
) {
this.sessionData = sessionData;
this.mapper = mapper;
Client client = ClientBuilder.newClient(new ClientConfig()
.connectorProvider(new ApacheConnectorProvider())
.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED)
.property(ClientProperties.CONNECT_TIMEOUT, CONNECT_TIMEOUT)
.property(ClientProperties.READ_TIMEOUT, READ_TIMEOUT)
.property(ApacheClientProperties.CONNECTION_MANAGER, new PoolingHttpClientConnectionManager()));
if (!Strings.isNullOrEmpty(osiamEndpoint)) {
target = client.target(osiamEndpoint);
} else if (!Strings.isNullOrEmpty(resourceServerEndpoint)) {
target = client.target(resourceServerEndpoint);
} else {
throw new BeanCreationException("Error creating extension client. No OSIAM endpoint set.");
}
}
示例4: createClientConfig
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
private ClientConfig createClientConfig(final DNSAPIClientConfig config,
final JacksonJsonProvider jacksonJsonProvider,
final HttpParams httpParams,
final PoolingClientConnectionManager clientConnectionManager) {
final ClientConfig clientConfig = new ClientConfig();
clientConfig.register(jacksonJsonProvider);
clientConfig.property(
ClientProperties.BUFFER_RESPONSE_ENTITY_ON_EXCEPTION, true);
clientConfig.property(ClientProperties.CONNECT_TIMEOUT,
config.getTimeout());
clientConfig.property(ClientProperties.FEATURE_AUTO_DISCOVERY_DISABLE,
true);
clientConfig.property(ClientProperties.FOLLOW_REDIRECTS, false);
clientConfig.property(ClientProperties.JSON_PROCESSING_FEATURE_DISABLE,
false);
clientConfig.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE,
true);
clientConfig.property(ClientProperties.MOXY_JSON_FEATURE_DISABLE, true);
clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER,
clientConnectionManager);
clientConfig.property(ApacheClientProperties.DISABLE_COOKIES, true);
clientConfig.property(ApacheClientProperties.HTTP_PARAMS, httpParams);
clientConfig.property(
ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, false);
return clientConfig;
}
示例5: buildClient
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的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();
}
示例6: getClientConfig
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
@Test
public void getClientConfig() {
AuthenticationInfo info = new AuthenticationInfo("user1", "pass", "server1", "4display");
final ClientConfig config = RestClientHelper.getClientConfig(ServerContext.Type.TFS, info, false);
final Map<String, Object> properties = config.getProperties();
Assert.assertEquals(3, properties.size());
Assert.assertEquals(false, properties.get(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION));
Assert.assertEquals(RequestEntityProcessing.BUFFERED, properties.get(ClientProperties.REQUEST_ENTITY_PROCESSING));
final CredentialsProvider cp = (CredentialsProvider) properties.get(ApacheClientProperties.CREDENTIALS_PROVIDER);
final Credentials credentials = cp.getCredentials(AuthScope.ANY);
Assert.assertEquals(info.getPassword(), credentials.getPassword());
Assert.assertEquals(info.getUserName(), credentials.getUserPrincipal().getName());
// Make sure Fiddler properties get set if property is on
final ClientConfig config2 = RestClientHelper.getClientConfig(ServerContext.Type.TFS, info, true);
final Map<String, Object> properties2 = config2.getProperties();
//proxy setting doesn't automatically mean we need to setup ssl trust store anymore
Assert.assertEquals(4, properties2.size());
Assert.assertNotNull(properties2.get(ClientProperties.PROXY_URI));
Assert.assertNull(properties2.get(ApacheClientProperties.SSL_CONFIG));
info = new AuthenticationInfo("users1", "pass", "https://tfsonprem.test", "4display");
final ClientConfig config3 = RestClientHelper.getClientConfig(ServerContext.Type.TFS, info, false);
final Map<String, Object> properties3 = config3.getProperties();
Assert.assertEquals(4, properties3.size());
Assert.assertNull(properties3.get(ClientProperties.PROXY_URI));
Assert.assertNotNull(properties3.get(ApacheClientProperties.SSL_CONFIG));
}
示例7: createJaxrsClient
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
private static javax.ws.rs.client.Client createJaxrsClient(
final HttpClientConnectionManager connectionManager, final int connectionTimeout,
final int socketTimeout, @Nullable final ProxyConfig proxy) {
// Configure requests
final RequestConfig requestConfig = RequestConfig.custom()//
.setExpectContinueEnabled(false) //
.setRedirectsEnabled(false) //
.setConnectionRequestTimeout(connectionTimeout) //
.setConnectTimeout(connectionTimeout) //
.setSocketTimeout(socketTimeout)
.build();
// Configure client
final ClientConfig config = new ClientConfig();
config.connectorProvider(new ApacheConnectorProvider());
config.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
config.property(ApacheClientProperties.REQUEST_CONFIG, requestConfig);
config.property(ApacheClientProperties.DISABLE_COOKIES, true); // not needed
config.property(ClientProperties.REQUEST_ENTITY_PROCESSING,
RequestEntityProcessing.CHUNKED); // required to stream data to the server
if (proxy != null) {
config.property(ClientProperties.PROXY_URI, proxy.getURL());
config.property(ClientProperties.PROXY_USERNAME, proxy.getUsername());
config.property(ClientProperties.PROXY_PASSWORD, proxy.getPassword());
}
// Register filter and custom serializer
config.register(Serializer.class);
config.register(GZipEncoder.class);
// Create and return a configured JAX-RS client
return ClientBuilder.newClient(config);
}
示例8: setupProxy
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
public static void setupProxy(ClientConfig clientConfig, URI uri) {
CredentialsProvider cp = (CredentialsProvider) clientConfig.getProperty(ApacheClientProperties.CREDENTIALS_PROVIDER);
for (IProxyData d : proxyService.select(uri)) {
cp.setCredentials(new AuthScope(new HttpHost(d.getHost(), d.getPort())), getCredentials(d));
clientConfig.property(ApacheClientProperties.PROXY_URI, d.getHost());
break;
}
clientConfigs.put(clientConfig, uri);
}
示例9: auth
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
private void auth(String username, String password) {
client.close();
client = null;
CredentialsProvider credentials = new BasicCredentialsProvider();
credentials.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
Map<String, Object> props = new HashMap<>();
props.put(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, true);
props.put(ApacheClientProperties.CREDENTIALS_PROVIDER, credentials);
client = newClient(props);
}
示例10: getClientConfig
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
public static ClientConfig getClientConfig(PoolingHttpClientConnectionManager connectionManager) {
ClientConfig clientConfig = new ClientConfig();
// We want to use the Apache connector for chunk POST support.
clientConfig.connectorProvider(new ApacheConnectorProvider());
connectionManager.setDefaultMaxPerRoute(20);
connectionManager.setMaxTotal(80);
connectionManager.closeIdleConnections(30, TimeUnit.SECONDS);
clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
clientConfig.register(GZipEncoder.class);
clientConfig.register(new MoxyXmlFeature());
clientConfig.register(new LoggingFilter(java.util.logging.Logger.getGlobal(), true));
clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.CHUNKED);
// Apache specific configuration.
RequestConfig.Builder custom = RequestConfig.custom();
custom.setExpectContinueEnabled(true);
custom.setRelativeRedirectsAllowed(true);
custom.setRedirectsEnabled(true);
custom.setSocketTimeout(Integer.parseInt(System.getProperty(TCP_SO_TIMEOUT, Integer.toString(SO_TIMEOUT))));
custom.setConnectTimeout(Integer.parseInt(System.getProperty(TCP_CONNECT_TIMEOUT, Integer.toString(CONNECT_TIMEOUT))));
custom.setConnectionRequestTimeout(Integer.parseInt(System.getProperty(TCP_CONNECT_REQUEST_TIMEOUT, Integer.toString(CONNECT_REQUEST_TIMEOUT))));
clientConfig.property(ApacheClientProperties.REQUEST_CONFIG, custom.build());
return clientConfig;
}
示例11: makeClient
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
private static Client makeClient(long requestTimeout, int maxConnections, SSLContext sslContext) {
ClientConfig clientConfig = new ClientConfig();
int castRequestTimeout = Ints.checkedCast(requestTimeout);
clientConfig.register(makeGZipFeature());
clientConfig.property(ClientProperties.ASYNC_THREADPOOL_SIZE, maxConnections);
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, castRequestTimeout);
clientConfig.property(ClientProperties.READ_TIMEOUT, castRequestTimeout);
clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, makeConnectionManager(maxConnections));
clientConfig.connectorProvider(new ApacheConnectorProvider());
if (sslContext != null) {
return ClientBuilder.newBuilder().sslContext(sslContext).withConfig(clientConfig).build();
} else {
return ClientBuilder.newClient(clientConfig);
}
}
示例12: getClient
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
private Client getClient(URI uri, TfsClientFactoryImpl.ServiceProvider provider, String username, Secret password) {
ClientConfig clientConfig = new ClientConfig();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
if (TfsClientFactoryImpl.ServiceProvider.TFS == provider) {
/* NTLM auth for on premise installation */
String domain = null;
int idx = Math.max(username.indexOf('/'), username.indexOf('\\'));
if (idx > 0) {
domain = username.substring(0, idx);
username = username.substring(idx + 1);
}
credentialsProvider.setCredentials(
new AuthScope(uri.getHost(), uri.getPort(), AuthScope.ANY_REALM, AuthSchemes.NTLM),
new NTCredentials(username, Secret.toString(password), uri.getHost(), domain));
logger.info("Using NTLM authentication for on premise TeamFoundationServer");
} else if (TfsClientFactoryImpl.ServiceProvider.VSO == provider) {
// Basic Auth for VSO services
credentialsProvider.setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(username, Secret.toString(password)));
logger.info("Using user/pass authentication for Visual Studio Online services");
// Preemptive send basic auth header, or we will be redirected for oauth login
clientConfig.property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, true);
}
clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);
if (System.getProperty(PROXY_URL_PROPERTY) != null) {
clientConfig.property(ClientProperties.PROXY_URI, System.getProperty(PROXY_URL_PROPERTY));
clientConfig.property(ApacheClientProperties.SSL_CONFIG, getSslConfigurator());
}
clientConfig.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
clientConfig.connectorProvider(new ApacheConnectorProvider());
return ClientBuilder.newClient(clientConfig);
}
示例13: getClientConfig
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
public static ClientConfig getClientConfig(final ServerContext.Type type,
final Credentials credentials,
final String serverUri,
final boolean includeProxySettings) {
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, credentials);
final ConnectorProvider connectorProvider = new ApacheConnectorProvider();
// custom json provider ignores new fields that aren't recognized
final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider()
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
final ClientConfig clientConfig = new ClientConfig(jacksonJsonProvider).connectorProvider(connectorProvider);
clientConfig.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
clientConfig.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED);
// For TFS OnPrem we only support NTLM authentication right now. Since 2016 servers support Basic as well,
// we need to let the server and client negotiate the protocol instead of preemptively assuming Basic.
// TODO: This prevents PATs from being used OnPrem. We need to fix this soon to support PATs onPrem.
clientConfig.property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, type != ServerContext.Type.TFS);
//Define a local HTTP proxy
if (includeProxySettings) {
final HttpProxyService proxyService = PluginServiceProvider.getInstance().getHttpProxyService();
final String proxyUrl = proxyService.getProxyURL();
clientConfig.property(ClientProperties.PROXY_URI, proxyUrl);
if (proxyService.isAuthenticationRequired()) {
// To work with authenticated proxies and TFS, we provide the proxy credentials if they are registered
final AuthScope ntlmAuthScope =
new AuthScope(proxyService.getProxyHost(), proxyService.getProxyPort(),
AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);
credentialsProvider.setCredentials(ntlmAuthScope,
new UsernamePasswordCredentials(proxyService.getUserName(), proxyService.getPassword()));
}
}
// if this is a onPrem server and the uri starts with https, we need to setup ssl
if (isSSLEnabledOnPrem(type, serverUri)) {
clientConfig.property(ApacheClientProperties.SSL_CONFIG, getSslConfigurator());
}
// register a filter to set the User Agent header
clientConfig.register(new ClientRequestFilter() {
@Override
public void filter(final ClientRequestContext requestContext) throws IOException {
// The default user agent is something like "Jersey/2.6"
final String defaultUserAgent = VersionInfo.getUserAgent("Apache-HttpClient", "org.apache.http.client", HttpClientBuilder.class);
// We get the user agent string from the Telemetry context
final String userAgent = PluginServiceProvider.getInstance().getTelemetryContextInitializer().getUserAgent(defaultUserAgent);
// Finally, we can add the header
requestContext.getHeaders().add(HttpHeaders.USER_AGENT, userAgent);
}
});
return clientConfig;
}
示例14: connect
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
@Override
public boolean connect(IProgressMonitor monitor, ServerProfile sp) throws Exception {
monitor.subTask("Trying RESTv2");
super.connect(monitor, sp);
this.eh = new RESTv2ExceptionHandler(this);
ClientConfig clientConfig = new ClientConfig();
// values are in milliseconds
// clientConfig.property(ClientProperties.READ_TIMEOUT, sp.getTimeout());
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, sp.getTimeout());
if (sp.isChunked())
clientConfig.property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024);
clientConfig.property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, true);
// config your ssl for apache connector
SslConfigurator sslConfig = SslConfigurator.newInstance(true);
clientConfig.property(ApacheClientProperties.SSL_CONFIG, sslConfig);
connector = new JSSApacheConnector(clientConfig);
clientConfig.connector(connector);
HttpUtils.setupProxy(clientConfig, sp.getURL().toURI());
Client client = ClientBuilder.newBuilder().withConfig(clientConfig).build();
// String user = sp.getUser();
// if (!Misc.isNullOrEmpty(sp.getOrganisation()))
// user += "|" + sp.getOrganisation();
// client.register(new HttpBasicAuthFilter(user,
// Pass.getPass(sp.getPass())));
String url = sp.getUrl().trim();
if (url.endsWith("/services/repository/"))
url = url.substring(0, url.lastIndexOf("/services/repository/"));
else if (url.endsWith("services/repository"))
url = url.substring(0, url.lastIndexOf("/services/repository"));
if (!url.endsWith("/"))
url += "/";
try {
target = client.target(url + "j_spring_security_check");
target = target.queryParam("forceDefaultRedirect", "false");
if (sp.isUseSSO()) {
String token = CASUtil.getToken(sp, monitor);
target = target.queryParam("ticket", token);
} else {
target = target.queryParam("j_username", sp.getUser());
target = target.queryParam("j_password", Pass.getPass(sp.getPass()));
}
target = target.queryParam("orgId", sp.getOrganisation());
if (!Misc.isNullOrEmpty(sp.getLocale()))
target = target.queryParam("userLocale", "true");
if (!Misc.isNullOrEmpty(sp.getTimeZone()))
target = target.queryParam("userTimezone", "true");
Builder req = target.request();
toObj(connector.get(req, monitor), String.class, monitor);
} finally {
// ok, now check others
target = client.target(IDN.toASCII(url + SUFFIX));
}
getServerInfo(monitor);
return serverInfo != null && serverInfo.getVersion().compareTo("5.5") >= 0;
}
示例15: configureHttps
import org.glassfish.jersey.apache.connector.ApacheClientProperties; //导入依赖的package包/类
private static void configureHttps(ClientConfiguration clientConfiguration, ClientConfig clientConfig) {
SslConfigurator sslConfig = SslConfigurator.newInstance().securityProtocol("SSL");
PoolingHttpClientConnectionManager connectionManager = createConnectionManager(clientConfiguration, sslConfig);
clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
clientConfig.property(ApacheClientProperties.SSL_CONFIG, sslConfig);
}