use of org.jboss.resteasy.client.jaxrs.internal.ClientInvocation in project motan by weibocom.
the class RestfulClientInvoker method invoke.
public Object invoke(Object[] args, Request req, RestfulClientResponse resp) {
ClientInvocation request = createRequest(args, req);
ClientResponse response = (ClientResponse) request.invoke();
resp.setAttachments(RestfulUtil.decodeAttachments(response.getStringHeaders()));
resp.setHttpResponse(response);
ClientContext context = new ClientContext(request, response, entityExtractorFactory);
return extractor.extractEntity(context);
}
use of org.jboss.resteasy.client.jaxrs.internal.ClientInvocation in project motan by weibocom.
the class RestfulClientInvoker method createRequest.
protected ClientInvocation createRequest(Object[] args, Request request) {
ClientInvocation inv = super.createRequest(args);
RestfulUtil.encodeAttachments(inv.getHeaders().getHeaders(), request.getAttachments());
return inv;
}
use of org.jboss.resteasy.client.jaxrs.internal.ClientInvocation in project java by wavefrontHQ.
the class AbstractAgent method createAgentService.
/**
* Create RESTeasy proxies for remote calls via HTTP.
*/
protected WavefrontAPI createAgentService() {
ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
factory.registerProvider(JsonNodeWriter.class);
if (!factory.getClasses().contains(ResteasyJackson2Provider.class)) {
factory.registerProvider(ResteasyJackson2Provider.class);
}
if (httpUserAgent == null) {
httpUserAgent = "Wavefront-Proxy/" + props.getString("build.version");
}
ClientHttpEngine httpEngine;
if (javaNetConnection) {
httpEngine = new JavaNetConnectionEngine() {
@Override
protected HttpURLConnection createConnection(ClientInvocation request) throws IOException {
HttpURLConnection connection = (HttpURLConnection) request.getUri().toURL().openConnection();
connection.setRequestProperty("User-Agent", httpUserAgent);
connection.setRequestMethod(request.getMethod());
// 5s
connection.setConnectTimeout(httpConnectTimeout);
// 60s
connection.setReadTimeout(httpRequestTimeout);
if (connection instanceof HttpsURLConnection) {
HttpsURLConnection secureConnection = (HttpsURLConnection) connection;
secureConnection.setSSLSocketFactory(new SSLSocketFactoryImpl(HttpsURLConnection.getDefaultSSLSocketFactory(), httpRequestTimeout));
}
return connection;
}
};
} else {
HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().setUserAgent(httpUserAgent).setMaxConnTotal(httpMaxConnTotal).setMaxConnPerRoute(httpMaxConnPerRoute).setConnectionTimeToLive(1, TimeUnit.MINUTES).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(httpRequestTimeout).build()).setSSLSocketFactory(new SSLConnectionSocketFactoryImpl(SSLConnectionSocketFactory.getSystemSocketFactory(), httpRequestTimeout)).setRetryHandler(new DefaultHttpRequestRetryHandler(httpAutoRetries, true)).setDefaultRequestConfig(RequestConfig.custom().setContentCompressionEnabled(true).setRedirectsEnabled(true).setConnectTimeout(httpConnectTimeout).setConnectionRequestTimeout(httpConnectTimeout).setSocketTimeout(httpRequestTimeout).build()).build();
final ApacheHttpClient4Engine apacheHttpClient4Engine = new ApacheHttpClient4Engine(httpClient, true);
// avoid using disk at all
apacheHttpClient4Engine.setFileUploadInMemoryThresholdLimit(100);
apacheHttpClient4Engine.setFileUploadMemoryUnit(ApacheHttpClient4Engine.MemoryUnit.MB);
httpEngine = apacheHttpClient4Engine;
}
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(factory).register(GZIPDecodingInterceptor.class).register(gzipCompression ? GZIPEncodingInterceptor.class : DisableGZIPEncodingInterceptor.class).register(AcceptEncodingGZIPFilter.class).build();
ResteasyWebTarget target = client.target(server);
return target.proxy(WavefrontAPI.class);
}
Aggregations