本文整理汇总了Java中org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine类的典型用法代码示例。如果您正苦于以下问题:Java ApacheHttpClient4Engine类的具体用法?Java ApacheHttpClient4Engine怎么用?Java ApacheHttpClient4Engine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApacheHttpClient4Engine类属于org.jboss.resteasy.client.jaxrs.engines包,在下文中一共展示了ApacheHttpClient4Engine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
@Override
public Client create(final RestClientConfiguration configuration) {
checkNotNull(configuration);
try (TcclBlock tccl = TcclBlock.begin(ResteasyClientBuilder.class)) {
HttpContext httpContext = new BasicHttpContext();
if (configuration.getUseTrustStore()) {
httpContext.setAttribute(SSLContextSelector.USE_TRUST_STORE, true);
}
HttpClient client;
if (configuration.getHttpClient() != null) {
client = checkNotNull(configuration.getHttpClient().get());
}
else {
client = httpClient.get();
}
ClientHttpEngine httpEngine = new ApacheHttpClient4Engine(client, httpContext);
ResteasyClientBuilder builder = new ResteasyClientBuilder().httpEngine(httpEngine);
if (configuration.getCustomizer() != null) {
configuration.getCustomizer().apply(builder);
}
return builder.build();
}
}
示例2: init
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
@Override
public void init(ConnectionInfo connectionInfo) throws Exception {
HttpClient client = new HttpClientBuilder().insecure(connectionInfo.isInsecure()).useSystemProperties().build();
SchedulerRestClient restApiClient = new SchedulerRestClient(connectionInfo.getUrl(),
new ApacheHttpClient4Engine(client));
ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
factory.register(new WildCardTypeReader());
factory.register(new OctetStreamReader());
factory.register(new TaskResultReader());
setApiClient(restApiClient);
this.connectionInfo = connectionInfo;
this.initialized = true;
renewSession();
}
示例3: getClient
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
public static Client getClient() throws RestClientException {
final ResteasyJackson2Provider jackson2Provider = RestUtils.createJacksonProvider();
final ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(RestUtils.createAllTrustingClient());
final Client client = new ResteasyClientBuilder()
.providerFactory(new ResteasyProviderFactory()) // this is needed otherwise default jackson2provider is used, which causes problems with JDK8 Optional
.register(jackson2Provider)
.httpEngine(engine)
.build();
return client;
}
示例4: getClient
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
private static ResteasyClient getClient() {
// Setting digest credentials
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("admin", "admin");
credentialsProvider.setCredentials(AuthScope.ANY, credentials);
HttpClient httpclient = HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpclient, true);
// Creating HTTP client
return new ResteasyClientBuilder().httpEngine(engine).build();
}
示例5: getResteasyClient
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
private ResteasyClient getResteasyClient(String targetServerUri) throws RestInterfaceFactoryException {
ResteasyClient client = clients.get(targetServerUri);
if(client == null) {
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
ResteasyClientBuilder clientBuilder = new ResteasyClientBuilder();
clientBuilder.httpEngine(engine);
client = clientBuilder.build();
clients.put(targetServerUri, client);
}
return client;
}
示例6: getRestClientProxy
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
private RestClient getRestClientProxy() {
ResteasyClient client = new ResteasyClientBuilder().asyncExecutor(threadPool)
.httpEngine(new ApacheHttpClient4Engine(httpClient))
.build();
ResteasyWebTarget target = client.target(SchedulerConfig.get().getRestUrl());
return target.proxy(RestClient.class);
}
示例7: getRestClientProxy
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
private RestClient getRestClientProxy() {
ResteasyClient client = new ResteasyClientBuilder().asyncExecutor(threadPool)
.httpEngine(new ApacheHttpClient4Engine(httpClient))
.build();
ResteasyWebTarget target = client.target(RMConfig.get().getRestUrl());
return target.proxy(RestClient.class);
}
示例8: getRestClient
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
@Override
public SchedulerRestClient getRestClient() {
CommonHttpClientBuilder httpClientBuilder = new HttpClientBuilder().useSystemProperties();
if (canInsecureAccess()) {
httpClientBuilder.insecure(true);
}
return new SchedulerRestClient(restServerUrl, new ApacheHttpClient4Engine(httpClientBuilder.build()));
}
示例9: init
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
public void init(String restServerUrl, ISchedulerClient client) {
this.httpEngine = new ApacheHttpClient4Engine(new HttpClientBuilder().disableContentCompression()
.useSystemProperties()
.build());
this.restDataspaceUrl = restDataspaceUrl(restServerUrl);
this.sessionId = client.getSession();
if (log.isDebugEnabled()) {
log.debug("Error : trying to retrieve session from disconnected client.");
}
this.schedulerClient = client;
}
示例10: newClient
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
@Override
protected Client newClient() {
ResteasyClientBuilder resteasyClientBuilder = new ResteasyClientBuilder();
ResteasyClient client = resteasyClientBuilder.establishConnectionTimeout(getTimeout(), TimeUnit.MILLISECONDS).socketTimeout(getTimeout(), TimeUnit.MILLISECONDS).build();
AbstractHttpClient httpClient = (AbstractHttpClient) ((ApacheHttpClient4Engine) client.httpEngine()).getHttpClient();
httpClient.setRedirectStrategy(new DefaultRedirectStrategy() {
@Override
protected boolean isRedirectable(String method) {
return true;
}
});
httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
request.setParams(new AllowRedirectHttpParams(request.getParams()));
}
});
return client;
}
示例11: createAPI
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
public KubernetesAPI createAPI(URI uri, String userName, String password) {
// Configure HttpClient to authenticate preemptively
// by prepopulating the authentication data cache.
// http://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html/RESTEasy_Client_Framework.html#transport_layer
// http://hc.apache.org/httpcomponents-client-4.2.x/tutorial/html/authentication.html#d5e1032
HttpHost targetHost = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(targetHost.getHostName(), targetHost.getPort()),
new UsernamePasswordCredentials(userName, password));
// Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put(targetHost, basicAuth);
// Add AuthCache to the execution context
BasicHttpContext localcontext = new BasicHttpContext();
localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);
// 4. Create client executor and proxy
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpclient, localcontext);
ResteasyClient client = new ResteasyClientBuilder().connectionPoolSize(connectionPoolSize).httpEngine(engine)
.build();
client.register(JacksonJaxbJsonProvider.class).register(JacksonConfig.class);
ProxyBuilder<KubernetesAPI> proxyBuilder = client.target(uri).proxyBuilder(KubernetesAPI.class);
if (classLoader != null) {
proxyBuilder = proxyBuilder.classloader(classLoader);
}
return proxyBuilder.build();
}
示例12: initDefaultEngine
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
protected ClientHttpEngine initDefaultEngine() {
ApacheHttpClient4Engine httpEngine = (ApacheHttpClient4Engine) super.initDefaultEngine();
if (proxyCredentials != null) {
((DefaultHttpClient) httpEngine.getHttpClient()).setCredentialsProvider(proxyCredentials);
}
return httpEngine;
}
示例13: getOrCreateClient
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
private ResteasyClient getOrCreateClient(Consumer<HttpClientBuilder> httpCustomiser,
Consumer<ResteasyClientBuilder> resteasyCustomiser)
{
if (httpCustomiser == null && resteasyCustomiser == null)
{
// Recursively call self to create a shared client for other non-customised consumers
if (client == null)
client = getOrCreateClient(Objects:: requireNonNull, Objects:: requireNonNull);
return client; // use shared client
}
else
{
final CloseableHttpClient http = createHttpClient(httpCustomiser);
// Now build a resteasy client
{
ResteasyClientBuilder builder = new ResteasyClientBuilder();
builder.httpEngine(new ApacheHttpClient4Engine(http)).providerFactory(resteasyProviderFactory);
if (resteasyCustomiser != null)
resteasyCustomiser.accept(builder);
return builder.build();
}
}
}
示例14: doRefer
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
if (connectionMonitor == null) {
connectionMonitor = new ConnectionMonitor();
}
// TODO more configs to add
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
// 20 is the default maxTotal of current PoolingClientConnectionManager
connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));
connectionMonitor.addConnectionManager(connectionManager);
// BasicHttpContext localContext = new BasicHttpContext();
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
return Long.parseLong(value) * 1000;
}
}
// TODO constant
return 30 * 1000;
}
});
HttpParams params = httpClient.getParams();
// TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
HttpConnectionParams.setTcpNoDelay(params, true);
HttpConnectionParams.setSoKeepalive(params, true);
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/);
ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
clients.add(client);
client.register(RpcContextFilter.class);
for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
if (!StringUtils.isEmpty(clazz)) {
try {
client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
} catch (ClassNotFoundException e) {
throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
}
}
}
// TODO protocol
ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
return target.proxy(serviceType);
}
示例15: doRefer
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine; //导入依赖的package包/类
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
if (connectionMonitor == null) {
connectionMonitor = new ConnectionMonitor();
}
// TODO more configs to add
PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager();
// 20 is the default maxTotal of current PoolingClientConnectionManager
connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));
connectionMonitor.addConnectionManager(connectionManager);
// BasicHttpContext localContext = new BasicHttpContext();
DefaultHttpClient httpClient = new DefaultHttpClient(connectionManager);
httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
return Long.parseLong(value) * 1000;
}
}
// TODO constant
return 30 * 1000;
}
});
HttpParams params = httpClient.getParams();
// TODO currently no xml config for Constants.CONNECT_TIMEOUT_KEY so we directly reuse Constants.TIMEOUT_KEY for now
HttpConnectionParams.setConnectionTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
HttpConnectionParams.setSoTimeout(params, url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
HttpConnectionParams.setTcpNoDelay(params, true);
HttpConnectionParams.setSoKeepalive(params, true);
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/* , localContext */);
ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
clients.add(client);
client.register(RpcContextFilter.class);
for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.EXTENSION_KEY, ""))) {
if (!StringUtils.isEmpty(clazz)) {
try {
client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
} catch (ClassNotFoundException e) {
throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
}
}
}
// dubbo 服务多版本
String version = url.getParameter(Constants.VERSION_KEY);
String versionPath = "";
if (StringUtils.isNotEmpty(version)) {
versionPath = version + "/";
}
// TODO protocol
ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + versionPath + getContextPath(url));
return target.proxy(serviceType);
}