use of org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine 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;
}
}
use of org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine 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.engines.URLConnectionEngine 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;
}
Aggregations