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