Search in sources :

Example 36 with ResteasyClientBuilder

use of org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder in project oxAuth by GluuFederation.

the class JwtUtil method getJSONWebKeys.

public static JSONObject getJSONWebKeys(String jwksUri, ClientHttpEngine engine) {
    log.debug("Retrieving jwks " + jwksUri + "...");
    JSONObject jwks = null;
    try {
        if (!StringHelper.isEmpty(jwksUri)) {
            ClientBuilder clientBuilder = ResteasyClientBuilder.newBuilder();
            if (engine != null) {
                ((ResteasyClientBuilder) clientBuilder).httpEngine(engine);
            }
            javax.ws.rs.client.Client clientRequest = clientBuilder.build();
            try {
                Response clientResponse = clientRequest.target(jwksUri).request().buildGet().invoke();
                int status = clientResponse.getStatus();
                log.debug(String.format("Status: %n%d", status));
                if (status == 200) {
                    jwks = fromJson(clientResponse.readEntity(String.class));
                    log.debug(String.format("JWK: %s", jwks));
                }
            } finally {
                clientRequest.close();
            }
        }
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }
    return jwks;
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) JSONObject(org.json.JSONObject) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchProviderException(java.security.NoSuchProviderException) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ClientBuilder(javax.ws.rs.client.ClientBuilder)

Example 37 with ResteasyClientBuilder

use of org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder in project openstack4j by ContainX.

the class HttpCommand method initialize.

private void initialize() {
    resteasyWebTarget = new ResteasyClientBuilder().httpEngine(ApacheHttpClientEngine.create(request.getConfig())).providerFactory(ResteasyClientFactory.getInstance()).build().target(UriBuilder.fromUri(new EndpointURIFromRequestFunction().apply(request)));
    populateQueryParams(request);
    resteasyRequest = resteasyWebTarget.request();
    populateHeaders(request);
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) EndpointURIFromRequestFunction(org.openstack4j.core.transport.functions.EndpointURIFromRequestFunction)

Example 38 with ResteasyClientBuilder

use of org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder in project wildfly by wildfly.

the class WildFlyClientTracingRegistrarProvider method configure.

@Override
public ClientBuilder configure(ClientBuilder clientBuilder, ExecutorService executorService) {
    Tracer tracer = CDI.current().select(Tracer.class).get();
    ResteasyClientBuilder resteasyClientBuilder = (ResteasyClientBuilder) clientBuilder;
    return resteasyClientBuilder.executorService(new TracedExecutorService(executorService, tracer)).register(new SmallRyeClientTracingFeature(tracer));
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) SmallRyeClientTracingFeature(io.smallrye.opentracing.SmallRyeClientTracingFeature) Tracer(io.opentracing.Tracer) TracedExecutorService(io.opentracing.contrib.concurrent.TracedExecutorService)

Example 39 with ResteasyClientBuilder

use of org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder in project syndesis-qe by syndesisio.

the class EndpointClient method getClient.

public static Client getClient(ResteasyJackson2Provider jackson2Provider) {
    final ApacheHttpClient43Engine engine = new ApacheHttpClient43Engine(createAllTrustingClient());
    final ResteasyProviderFactory providerFactory = new LocalResteasyProviderFactory();
    providerFactory.register(jackson2Provider).register(// needed for GET application/octet-stream in PublicAPI to export zip
    new InputStreamProvider()).register(// needed to POST mutipart form data (necessary for API provider + PublicAPI)
    new MultipartFormDataWriter()).register(// needed to serialize text/plain (again for API provider)
    new StringTextStar()).register(new ErrorLogger());
    ResteasyClientBuilder clientBuilder = (ResteasyClientBuilder) ResteasyClientBuilder.newBuilder();
    clientBuilder.providerFactory(providerFactory);
    clientBuilder.httpEngine(engine);
    return clientBuilder.build();
}
Also used : MultipartFormDataWriter(org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataWriter) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) InputStreamProvider(org.jboss.resteasy.plugins.providers.InputStreamProvider) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) LocalResteasyProviderFactory(org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory) LocalResteasyProviderFactory(org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory) ApacheHttpClient43Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine) StringTextStar(org.jboss.resteasy.plugins.providers.StringTextStar)

Example 40 with ResteasyClientBuilder

use of org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder in project openremote by openremote.

the class KeycloakIdentityProvider method init.

@Override
public void init(Container container) {
    if (httpClient != null) {
        return;
    }
    sessionMaxSeconds = getInteger(container.getConfig(), IDENTITY_SESSION_MAX_MINUTES, IDENTITY_SESSION_MAX_MINUTES_DEFAULT) * 60;
    if (sessionMaxSeconds < 60) {
        throw new IllegalArgumentException(IDENTITY_SESSION_MAX_MINUTES + " must be more than 1 minute");
    }
    // Use the same, as a session is never idle because we periodically check if the refresh token is
    // still good in frontend code, this check will reset the idle timeout anyway
    sessionTimeoutSeconds = sessionMaxSeconds;
    sessionOfflineTimeoutSeconds = getInteger(container.getConfig(), IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES, IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES_DEFAULT) * 60;
    if (sessionOfflineTimeoutSeconds < 60) {
        throw new IllegalArgumentException(IDENTITY_SESSION_OFFLINE_TIMEOUT_MINUTES + " must be more than 1 minute");
    }
    keycloakServiceUri = UriBuilder.fromPath("/").scheme("http").host(getString(container.getConfig(), KEYCLOAK_HOST, KEYCLOAK_HOST_DEFAULT)).port(getInteger(container.getConfig(), KEYCLOAK_PORT, KEYCLOAK_PORT_DEFAULT)).path(KEYCLOAK_AUTH_PATH);
    LOG.info("Keycloak service URL: " + keycloakServiceUri.build());
    ResteasyClientBuilder clientBuilder = new ResteasyClientBuilder().connectTimeout(getInteger(container.getConfig(), KEYCLOAK_CONNECT_TIMEOUT, KEYCLOAK_CONNECT_TIMEOUT_DEFAULT), TimeUnit.MILLISECONDS).readTimeout(getInteger(container.getConfig(), KEYCLOAK_REQUEST_TIMEOUT, KEYCLOAK_REQUEST_TIMEOUT_DEFAULT), TimeUnit.MILLISECONDS).connectionPoolSize(getInteger(container.getConfig(), KEYCLOAK_CLIENT_POOL_SIZE, KEYCLOAK_CLIENT_POOL_SIZE_DEFAULT));
    httpClient = WebClient.registerDefaults(clientBuilder).build();
    setActiveCredentials(getDefaultKeycloakGrant(container));
    keycloakDeploymentCache = createKeycloakDeploymentCache();
    keycloakConfigResolver = request -> {
        // The realm we authenticate against must be available as a request header
        String realm = request.getHeader(REALM_PARAM_NAME);
        if (realm == null || realm.length() == 0) {
            LOG.finer("No realm in request, no authentication will be attempted: " + request.getURI());
            return notAuthenticatedKeycloakDeployment;
        }
        KeycloakDeployment keycloakDeployment = getKeycloakDeployment(realm, KEYCLOAK_CLIENT_ID);
        if (keycloakDeployment == null) {
            LOG.fine("No Keycloak deployment available for realm, no authentication will be attempted: " + request.getURI());
            return notAuthenticatedKeycloakDeployment;
        }
        return keycloakDeployment;
    };
    if (container.isDevMode()) {
        authProxyHandler = ProxyHandler.builder().setProxyClient(new LoadBalancingProxyClient().addHost(keycloakServiceUri.clone().replacePath("").build())).setMaxRequestTime(getInteger(container.getConfig(), KEYCLOAK_REQUEST_TIMEOUT, KEYCLOAK_REQUEST_TIMEOUT_DEFAULT)).setNext(ResponseCodeHandler.HANDLE_404).setReuseXForwarded(true).build();
    }
    // TODO Not a great way to block startup while we wait for other services (Hystrix?)
    waitForKeycloak();
    LOG.info("Keycloak identity provider available: " + keycloakServiceUri.build());
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) KeycloakDeployment(org.keycloak.adapters.KeycloakDeployment) LoadBalancingProxyClient(io.undertow.server.handlers.proxy.LoadBalancingProxyClient)

Aggregations

ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)40 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)22 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)18 Response (javax.ws.rs.core.Response)11 Test (org.junit.Test)9 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)8 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)7 ServicesInterface (com.baeldung.client.ServicesInterface)6 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)6 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)6 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)6 RequestConfig (org.apache.http.client.config.RequestConfig)5 ApacheHttpClient43Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient43Engine)5 IOException (java.io.IOException)4 Client (javax.ws.rs.client.Client)4 HttpClient (org.apache.http.client.HttpClient)4 ProcessingException (javax.ws.rs.ProcessingException)3 ClientHttpEngine (org.jboss.resteasy.client.jaxrs.ClientHttpEngine)3 Movie (com.baeldung.model.Movie)2 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)2