use of org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder in project robozonky by RoboZonky.
the class ProxyFactory method newResteasyClient.
public static ResteasyClient newResteasyClient() {
final ResteasyClientBuilder builder = new ResteasyClientBuilder().readTimeout(Settings.INSTANCE.getSocketTimeout().get(ChronoUnit.SECONDS), TimeUnit.SECONDS).connectTimeout(Settings.INSTANCE.getConnectionTimeout().get(ChronoUnit.SECONDS), TimeUnit.SECONDS);
/*
* In order to enable redirects, we need to configure the HTTP Client to support that. Unfortunately, if we then
* provide such client to the RESTEasy client builder, it will take the client as is and don't do other things
* that it would have otherwise done to a client that it itself created. Therefore, we do these things
* ourselves, represented by calling the HTTP engine builder.
*/
final ApacheHttpClient43Engine engine = (ApacheHttpClient43Engine) new ClientHttpEngineBuilder43().resteasyClientBuilder(builder).build();
engine.setFollowRedirects(true);
/*
* Supply the provider factory singleton, as otherwise RESTEasy would create a new instance every time.
*/
return new ResteasyClientBuilder().providerFactory(ResteasyProviderFactory.getInstance()).httpEngine(engine).build();
}
use of org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder in project sandbox by irof.
the class MySpringBootClient method main.
public static void main(String[] args) throws Exception {
// RESTEasyのBuilderでやっちゃえば #disableTrustManager で手っ取り早い感ある。
// javadoc に "this is a security hole" って書いてるけど。
Client client = new ResteasyClientBuilder().disableTrustManager().build();
Response response = client.target("https://localhost:9000").path("hello").request().get();
System.out.println(response);
System.out.println(response.getStatusInfo());
System.out.println(response.readEntity(String.class));
}
use of org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder in project wildfly by wildfly.
the class ResteasyClientTracingRegistrarProvider method configure.
@Override
public ClientBuilder configure(ClientBuilder clientBuilder, ExecutorService executorService) {
ResteasyClientBuilder resteasyClientBuilder = (ResteasyClientBuilder) clientBuilder;
Tracer tracer = CDI.current().select(Tracer.class).get();
return resteasyClientBuilder.executorService(new TracedExecutorService(executorService, tracer)).register(new SmallRyeClientTracingFeature(tracer));
}
use of org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder in project dubbo by alibaba.
the class RestProtocol method doRefer.
@Override
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
// TODO more configs to add
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
// 20 is the default maxTotal of current PoolingClientConnectionManager
connectionManager.setMaxTotal(url.getParameter(CONNECTIONS_KEY, HTTPCLIENTCONNECTIONMANAGER_MAXTOTAL));
connectionManager.setDefaultMaxPerRoute(url.getParameter(CONNECTIONS_KEY, HTTPCLIENTCONNECTIONMANAGER_MAXPERROUTE));
if (connectionMonitor == null) {
connectionMonitor = new ConnectionMonitor();
connectionMonitor.start();
}
connectionMonitor.addConnectionManager(connectionManager);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(url.getParameter(CONNECT_TIMEOUT_KEY, DEFAULT_CONNECT_TIMEOUT)).setSocketTimeout(url.getParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT)).build();
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).setTcpNoDelay(true).build();
CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connectionManager).setKeepAliveStrategy((response, context) -> {
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase(TIMEOUT_KEY)) {
return Long.parseLong(value) * 1000;
}
}
return HTTPCLIENT_KEEPALIVEDURATION;
}).setDefaultRequestConfig(requestConfig).setDefaultSocketConfig(socketConfig).build();
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
clients.add(client);
client.register(RpcContextFilter.class);
for (String clazz : COMMA_SPLIT_PATTERN.split(url.getParameter(EXTENSION_KEY, ""))) {
if (!StringUtils.isEmpty(clazz)) {
try {
client.register(Thread.currentThread().getContextClassLoader().loadClass(clazz.trim()));
} catch (ClassNotFoundException e) {
throw new RpcException("Error loading JAX-RS extension class: " + clazz.trim(), e);
}
}
}
// TODO protocol
ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
return target.proxy(serviceType);
}
use of org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder in project oxTrust by GluuFederation.
the class RecaptchaUtil method verifyGoogleRecaptcha.
public boolean verifyGoogleRecaptcha(String gRecaptchaResponse, String secretKey) {
boolean result = false;
try {
String uriTemplate = "https://www.google.com/recaptcha/api/siteverify";
ResteasyClient resteasyClient;
if (ProxyUtil.isProxyRequied()) {
URLConnectionEngine engine = new URLConnectionEngine();
resteasyClient = ((ResteasyClientBuilder) ResteasyClientBuilder.newBuilder()).httpEngine(engine).build();
} else {
resteasyClient = (ResteasyClient) ResteasyClientBuilder.newClient();
}
WebTarget webTarget = resteasyClient.target(uriTemplate);
Builder clientRequest = webTarget.request();
clientRequest.accept("application/json");
Form requestForm = new Form();
requestForm.param("secret", secretKey);
requestForm.param("response", gRecaptchaResponse);
Response response = clientRequest.buildPost(Entity.form(requestForm)).invoke();
try {
ObjectMapper mapper = new ObjectMapper();
Map<String, String> map = mapper.readValue(new ByteArrayInputStream(response.readEntity(String.class).getBytes()), new TypeReference<Map<String, String>>() {
});
return Boolean.parseBoolean(map.get("success"));
} finally {
response.close();
if (resteasyClient.httpEngine() != null) {
resteasyClient.httpEngine().close();
}
}
} catch (Exception e) {
log.warn("Exception happened while verifying recaptcha, check your internet connection", e);
return result;
}
}
Aggregations