Search in sources :

Example 61 with ResteasyClient

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

the class ClientFactory method createIntrospectionService.

public IntrospectionService createIntrospectionService(String p_url, ClientHttpEngine engine) {
    ResteasyClient client = ((ResteasyClientBuilder) ResteasyClientBuilder.newBuilder()).httpEngine(engine).build();
    ResteasyWebTarget target = client.target(UriBuilder.fromPath(p_url));
    IntrospectionService proxy = target.proxy(IntrospectionService.class);
    return proxy;
}
Also used : ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)

Example 62 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project java by wavefrontHQ.

the class HttpClientTest method httpClientTimeoutsWork.

@Test(expected = ProcessingException.class)
public void httpClientTimeoutsWork() throws Exception {
    ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
    factory.registerProvider(JsonNodeWriter.class);
    factory.registerProvider(ResteasyJackson2Provider.class);
    HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().setMaxConnTotal(200).setMaxConnPerRoute(100).setConnectionTimeToLive(1, TimeUnit.MINUTES).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(100).build()).setDefaultRequestConfig(RequestConfig.custom().setContentCompressionEnabled(true).setRedirectsEnabled(true).setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(60000).build()).setSSLSocketFactory(new LayeredConnectionSocketFactory() {

        @Override
        public Socket createLayeredSocket(Socket socket, String target, int port, HttpContext context) throws IOException, UnknownHostException {
            return SSLConnectionSocketFactory.getSystemSocketFactory().createLayeredSocket(socket, target, port, context);
        }

        @Override
        public Socket createSocket(HttpContext context) throws IOException {
            return SSLConnectionSocketFactory.getSystemSocketFactory().createSocket(context);
        }

        @Override
        public Socket connectSocket(int connectTimeout, Socket sock, HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context) throws IOException {
            assertTrue("Non-zero timeout passed to connect socket is expected", connectTimeout > 0);
            throw new ProcessingException("OK");
        }
    }).build();
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(new ApacheHttpClient4Engine(httpClient, true)).providerFactory(factory).build();
    SocketServerRunnable sr = new SocketServerRunnable();
    Thread serverThread = new Thread(sr);
    serverThread.start();
    ResteasyWebTarget target = client.target("https://localhost:" + sr.getPort());
    SimpleRESTEasyAPI proxy = target.proxy(SimpleRESTEasyAPI.class);
    proxy.search("resteasy");
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) LayeredConnectionSocketFactory(org.apache.http.conn.socket.LayeredConnectionSocketFactory) InetSocketAddress(java.net.InetSocketAddress) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpContext(org.apache.http.protocol.HttpContext) HttpHost(org.apache.http.HttpHost) HttpClient(org.apache.http.client.HttpClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Example 63 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project keycloak by keycloak.

the class UserInfoEndpointCorsTest method userInfoCorsInvalidRequestWithValidUrl.

// KEYCLOAK-15719 error response should still contain CORS headers
@Test
public void userInfoCorsInvalidRequestWithValidUrl() throws Exception {
    oauth.realm("test");
    oauth.clientId("test-app2");
    oauth.redirectUri(VALID_CORS_URL + "/realms/master/app");
    OAuthClient.AccessTokenResponse accessTokenResponse = oauth.doGrantAccessTokenRequest(null, "test-user@localhost", "password");
    // Set time offset to make sure that userInfo request will be invalid due the expired token
    setTimeOffset(600);
    ResteasyClient resteasyClient = AdminClientUtil.createResteasyClient();
    try {
        WebTarget userInfoTarget = UserInfoClientUtil.getUserInfoWebTarget(resteasyClient);
        Response userInfoResponse = userInfoTarget.request().header(HttpHeaders.AUTHORIZATION, "bearer " + accessTokenResponse.getAccessToken()).header("Origin", // manually trigger CORS handling
        VALID_CORS_URL).get();
        // We should have errorResponse, but CORS headers should be there as origin was valid
        assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), userInfoResponse.getStatus());
        assertCors(userInfoResponse);
    } finally {
        resteasyClient.close();
    }
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) OAuthClient(org.keycloak.testsuite.util.OAuthClient) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 64 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project keycloak by keycloak.

the class UserInfoEndpointCorsTest method userInfoCorsValidRequestWithInvalidUrlShouldFail.

@Test
public void userInfoCorsValidRequestWithInvalidUrlShouldFail() throws Exception {
    oauth.realm("test");
    oauth.clientId("test-app2");
    oauth.redirectUri(VALID_CORS_URL + "/realms/master/app");
    OAuthClient.AccessTokenResponse accessTokenResponse = oauth.doGrantAccessTokenRequest(null, "test-user@localhost", "password");
    ResteasyClient resteasyClient = AdminClientUtil.createResteasyClient();
    try {
        WebTarget userInfoTarget = UserInfoClientUtil.getUserInfoWebTarget(resteasyClient);
        Response userInfoResponse = userInfoTarget.request().header(HttpHeaders.AUTHORIZATION, "bearer " + accessTokenResponse.getAccessToken()).header("Origin", // manually trigger CORS handling
        INVALID_CORS_URL).get();
        UserInfoClientUtil.testSuccessfulUserInfoResponse(userInfoResponse, "test-user@localhost", "test-user@localhost");
        assertNotCors(userInfoResponse);
    } finally {
        resteasyClient.close();
    }
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) OAuthClient(org.keycloak.testsuite.util.OAuthClient) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Example 65 with ResteasyClient

use of org.jboss.resteasy.client.jaxrs.ResteasyClient in project keycloak by keycloak.

the class UserInfoEndpointCorsTest method userInfoCorsValidRequestWithValidUrl.

@Test
public void userInfoCorsValidRequestWithValidUrl() throws Exception {
    oauth.realm("test");
    oauth.clientId("test-app2");
    oauth.redirectUri(VALID_CORS_URL + "/realms/master/app");
    OAuthClient.AccessTokenResponse accessTokenResponse = oauth.doGrantAccessTokenRequest(null, "test-user@localhost", "password");
    ResteasyClient resteasyClient = AdminClientUtil.createResteasyClient();
    try {
        WebTarget userInfoTarget = UserInfoClientUtil.getUserInfoWebTarget(resteasyClient);
        Response userInfoResponse = userInfoTarget.request().header(HttpHeaders.AUTHORIZATION, "bearer " + accessTokenResponse.getAccessToken()).header("Origin", // manually trigger CORS handling
        VALID_CORS_URL).get();
        UserInfoClientUtil.testSuccessfulUserInfoResponse(userInfoResponse, "test-user@localhost", "test-user@localhost");
        assertCors(userInfoResponse);
    } finally {
        resteasyClient.close();
    }
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) OAuthClient(org.keycloak.testsuite.util.OAuthClient) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) AbstractKeycloakTest(org.keycloak.testsuite.AbstractKeycloakTest)

Aggregations

ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)66 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)42 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)28 Response (javax.ws.rs.core.Response)17 Test (org.junit.Test)14 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)10 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)8 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)7 ServicesInterface (com.baeldung.client.ServicesInterface)6 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)6 ProcessingException (javax.ws.rs.ProcessingException)5 IOException (java.io.IOException)4 Map (java.util.Map)4 WebTarget (javax.ws.rs.client.WebTarget)4 RequestConfig (org.apache.http.client.config.RequestConfig)4 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)4 ClientHttpEngine (org.jboss.resteasy.client.jaxrs.ClientHttpEngine)4 Locale (java.util.Locale)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 ApacheHttpClient4Resource (org.jboss.additional.testsuite.jdkall.present.jaxrs.client.resource.ApacheHttpClient4Resource)3