Search in sources :

Example 1 with ClientInvocation

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);
}
Also used : RestfulClientResponse(com.weibo.api.motan.protocol.restful.support.RestfulClientResponse) ClientResponse(org.jboss.resteasy.client.jaxrs.internal.ClientResponse) ClientContext(org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.ClientContext) ClientInvocation(org.jboss.resteasy.client.jaxrs.internal.ClientInvocation)

Example 2 with ClientInvocation

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;
}
Also used : ClientInvocation(org.jboss.resteasy.client.jaxrs.internal.ClientInvocation)

Example 3 with ClientInvocation

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);
}
Also used : ResteasyJackson2Provider(org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) GZIPDecodingInterceptor(org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) DefaultHttpRequestRetryHandler(org.apache.http.impl.client.DefaultHttpRequestRetryHandler) ClientInvocation(org.jboss.resteasy.client.jaxrs.internal.ClientInvocation) IOException(java.io.IOException) AcceptEncodingGZIPFilter(org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPFilter) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) HttpURLConnection(java.net.HttpURLConnection) GZIPEncodingInterceptor(org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor) HttpClient(org.apache.http.client.HttpClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Aggregations

ClientInvocation (org.jboss.resteasy.client.jaxrs.internal.ClientInvocation)3 RestfulClientResponse (com.weibo.api.motan.protocol.restful.support.RestfulClientResponse)1 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1 HttpClient (org.apache.http.client.HttpClient)1 DefaultHttpRequestRetryHandler (org.apache.http.impl.client.DefaultHttpRequestRetryHandler)1 ClientHttpEngine (org.jboss.resteasy.client.jaxrs.ClientHttpEngine)1 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)1 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)1 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)1 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)1 ClientResponse (org.jboss.resteasy.client.jaxrs.internal.ClientResponse)1 ClientContext (org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.ClientContext)1 AcceptEncodingGZIPFilter (org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPFilter)1 GZIPDecodingInterceptor (org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor)1 GZIPEncodingInterceptor (org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor)1 ResteasyJackson2Provider (org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider)1 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)1