Search in sources :

Example 1 with ClientHttpEngine

use of org.jboss.resteasy.client.jaxrs.ClientHttpEngine 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)

Example 2 with ClientHttpEngine

use of org.jboss.resteasy.client.jaxrs.ClientHttpEngine in project eap-additional-testsuite by jboss-set.

the class ApacheHttpClient431TestCase method createEngine.

@SuppressWarnings(value = "unchecked")
private ResteasyClient createEngine(Class engine) {
    RequestConfig reqConfig = // apache HttpClient specific
    RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).setConnectionRequestTimeout(5000).build();
    CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(reqConfig).setMaxConnTotal(3).build();
    final ClientHttpEngine executor;
    if (engine.isAssignableFrom(ApacheHttpClient43Engine.class)) {
        executor = new ApacheHttpClient43Engine(httpClient);
    } else {
        executor = new URLConnectionEngine();
    }
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(executor).build();
    return client;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) URLConnectionEngine(org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine)

Example 3 with ClientHttpEngine

use of org.jboss.resteasy.client.jaxrs.ClientHttpEngine in project eap-additional-testsuite by jboss-set.

the class ApacheHttpClient43TestCase method createEngine.

@SuppressWarnings(value = "unchecked")
private ResteasyClient createEngine(Class engine) {
    RequestConfig reqConfig = // apache HttpClient specific
    RequestConfig.custom().setConnectTimeout(5000).setSocketTimeout(5000).setConnectionRequestTimeout(5000).build();
    CloseableHttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(reqConfig).setMaxConnTotal(3).build();
    final ClientHttpEngine executor;
    if (engine.isAssignableFrom(ApacheHttpClient43Engine.class)) {
        executor = new ApacheHttpClient43Engine(httpClient);
    } else {
        executor = new URLConnectionEngine();
    }
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(executor).build();
    return client;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) URLConnectionEngine(org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine)

Example 4 with ClientHttpEngine

use of org.jboss.resteasy.client.jaxrs.ClientHttpEngine in project eap-additional-testsuite by jboss-set.

the class ApacheHttpClient432TestCase method apacheHttpClient4EngineServletTest.

@Test
@OperateOnDeployment(DEPLOYMENT)
public void apacheHttpClient4EngineServletTest(@ArquillianResource URL url) throws Exception {
    SocketConfig socketConfig = SocketConfig.custom().setTcpNoDelay(true).setSoKeepAlive(true).setSoReuseAddress(true).build();
    PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
    connManager.setMaxTotal(100);
    connManager.setDefaultMaxPerRoute(100);
    connManager.setDefaultSocketConfig(socketConfig);
    RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(2000).setConnectTimeout(100).setConnectionRequestTimeout(3000).setStaleConnectionCheckEnabled(true).build();
    CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).setConnectionManager(connManager).build();
    final ClientHttpEngine executor;
    executor = new ApacheHttpClient43Engine(httpClient);
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(executor).build();
    final ApacheHttpClient43Resource proxy = client.target("http://127.0.0.1:8080/" + ApacheHttpClient432TestCase.class.getSimpleName()).proxy(ApacheHttpClient43Resource.class);
    WebTarget target = client.target("http://127.0.0.1:8080/" + ApacheHttpClient432TestCase.class.getSimpleName() + "/test2");
    Response response = target.request().get();
    Assert.assertEquals(HttpResponseCodes.SC_OK, response.getStatus());
    try {
        Response s = proxy.get();
        assertEquals(200, s.getStatus());
    } catch (ProcessingException e) {
        logger.warn("Exception occured." + e);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) SocketConfig(org.apache.http.config.SocketConfig) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) Response(javax.ws.rs.core.Response) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) ApacheHttpClient43Resource(org.jboss.additional.testsuite.jdkall.present.jaxrs.client.resource.ApacheHttpClient43Resource) WebTarget(javax.ws.rs.client.WebTarget) ProcessingException(javax.ws.rs.ProcessingException) OperateOnDeployment(org.jboss.arquillian.container.test.api.OperateOnDeployment) Test(org.junit.Test)

Example 5 with ClientHttpEngine

use of org.jboss.resteasy.client.jaxrs.ClientHttpEngine in project oxAuth by GluuFederation.

the class IntrospectionWsHttpTest method bearerWithResponseAsJwt.

@Test
@Parameters({ "umaPatClientId", "umaPatClientSecret" })
public void bearerWithResponseAsJwt(final String umaPatClientId, final String umaPatClientSecret) throws Exception {
    final ClientHttpEngine engine = clientEngine(true);
    final Token authorization = UmaClient.requestPat(tokenEndpoint, umaPatClientId, umaPatClientSecret, engine);
    final Token tokenToIntrospect = UmaClient.requestPat(tokenEndpoint, umaPatClientId, umaPatClientSecret, engine);
    final IntrospectionService introspectionService = ClientFactory.instance().createIntrospectionService(introspectionEndpoint, engine);
    final String jwtAsString = introspectionService.introspectTokenWithResponseAsJwt("Bearer " + authorization.getAccessToken(), tokenToIntrospect.getAccessToken(), true);
    final Jwt jwt = Jwt.parse(jwtAsString);
    assertTrue(Boolean.parseBoolean(jwt.getClaims().getClaimAsString("active")));
}
Also used : ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) Jwt(org.gluu.oxauth.model.jwt.Jwt) IntrospectionService(org.gluu.oxauth.client.service.IntrospectionService) Token(org.gluu.oxauth.model.uma.wrapper.Token) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Aggregations

ClientHttpEngine (org.jboss.resteasy.client.jaxrs.ClientHttpEngine)5 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)4 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)4 RequestConfig (org.apache.http.client.config.RequestConfig)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 ApacheHttpClient43Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine)3 URLConnectionEngine (org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine)2 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1 ProcessingException (javax.ws.rs.ProcessingException)1 WebTarget (javax.ws.rs.client.WebTarget)1 Response (javax.ws.rs.core.Response)1 HttpClient (org.apache.http.client.HttpClient)1 SocketConfig (org.apache.http.config.SocketConfig)1 DefaultHttpRequestRetryHandler (org.apache.http.impl.client.DefaultHttpRequestRetryHandler)1 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)1 BaseTest (org.gluu.oxauth.BaseTest)1 IntrospectionService (org.gluu.oxauth.client.service.IntrospectionService)1 Jwt (org.gluu.oxauth.model.jwt.Jwt)1