Search in sources :

Example 1 with URLConnectionEngine

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;
    }
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) Form(javax.ws.rs.core.Form) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder) Response(javax.ws.rs.core.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) WebTarget(javax.ws.rs.client.WebTarget) Map(java.util.Map) URLConnectionEngine(org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with URLConnectionEngine

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;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) URLConnectionEngine(org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine)

Example 3 with URLConnectionEngine

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;
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ClientHttpEngine(org.jboss.resteasy.client.jaxrs.ClientHttpEngine) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) URLConnectionEngine(org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine)

Aggregations

ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)3 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)3 URLConnectionEngine (org.jboss.resteasy.client.jaxrs.engines.URLConnectionEngine)3 RequestConfig (org.apache.http.client.config.RequestConfig)2 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)2 ClientHttpEngine (org.jboss.resteasy.client.jaxrs.ClientHttpEngine)2 ApacheHttpClient43Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Map (java.util.Map)1 Builder (javax.ws.rs.client.Invocation.Builder)1 WebTarget (javax.ws.rs.client.WebTarget)1 Form (javax.ws.rs.core.Form)1 Response (javax.ws.rs.core.Response)1