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;
}
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");
}
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();
}
}
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();
}
}
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();
}
}
Aggregations