Search in sources :

Example 16 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project scheduling by ow2-proactive.

the class SchedulerClient method init.

@Override
public void init(ConnectionInfo connectionInfo) throws Exception {
    HttpClient client = new HttpClientBuilder().insecure(connectionInfo.isInsecure()).useSystemProperties().build();
    SchedulerRestClient restApiClient = new SchedulerRestClient(connectionInfo.getUrl(), new ApacheHttpClient4Engine(client));
    ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
    factory.register(new WildCardTypeReader());
    factory.register(new OctetStreamReader());
    factory.register(new TaskResultReader());
    SchedulerRestClient.registerGzipEncoding(factory);
    setApiClient(restApiClient);
    this.connectionInfo = connectionInfo;
    this.initialized = true;
    renewSession();
}
Also used : WildCardTypeReader(org.ow2.proactive.scheduler.rest.readers.WildCardTypeReader) TaskResultReader(org.ow2.proactive.scheduler.rest.readers.TaskResultReader) OctetStreamReader(org.ow2.proactive.scheduler.rest.readers.OctetStreamReader) HttpClient(org.apache.http.client.HttpClient) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpClientBuilder(org.ow2.proactive.http.HttpClientBuilder) SchedulerRestClient(org.ow2.proactive_grid_cloud_portal.scheduler.client.SchedulerRestClient) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory)

Example 17 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project scheduling by ow2-proactive.

the class MyResteasyBootstrap method contextInitialized.

public void contextInitialized(ServletContextEvent event) {
    super.contextInitialized(event);
    ResteasyProviderFactory dispatcher = ResteasyProviderFactory.getInstance();
    dispatcher.registerProvider(OctetStreamWriter.class, false);
    dispatcher.registerProvider(PlainTextReader.class, false);
    restRuntime = new RestRuntime();
    initPortalConfiguration(event);
    restRuntime.start(dispatcher, findConfigurationFile(event.getServletContext(), "log4j.properties"), findConfigurationFile(event.getServletContext(), File.separator + "config" + File.separator + "network" + File.separator + "server.ini"));
}
Also used : ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory)

Example 18 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project fabric8 by fabric8io.

the class ResteasyGitRepoClient method createWebClient.

/**
 * Creates a JAXRS web client for the given JAXRS client
 */
protected <T> T createWebClient(Class<T> clientType) {
    String address = getAddress();
    ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
    providerFactory.register(ResteasyJackson2Provider.class);
    providerFactory.register(Jackson2JsonpInterceptor.class);
    providerFactory.register(StringTextStar.class);
    providerFactory.register(DefaultTextPlain.class);
    providerFactory.register(FileProvider.class);
    providerFactory.register(InputStreamProvider.class);
    providerFactory.register(new Authenticator());
    providerFactory.register(clientType);
    ResteasyClientBuilder builder = new ResteasyClientBuilder();
    builder.providerFactory(providerFactory);
    builder.connectionPoolSize(3);
    Client client = builder.build();
    ResteasyWebTarget target = (ResteasyWebTarget) client.target(address);
    return target.proxy(clientType);
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Client(javax.ws.rs.client.Client)

Example 19 with ResteasyProviderFactory

use of org.jboss.resteasy.spi.ResteasyProviderFactory in project java by wavefrontHQ.

the class HttpClientTest method httpClientTimeoutsWork.

@Test(expected = ProcessingException.class)
public void httpClientTimeoutsWork() throws Exception {
    ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
    factory.registerProvider(JsonNodeWriter.class);
    factory.registerProvider(ResteasyJackson2Provider.class);
    HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().setMaxConnTotal(200).setMaxConnPerRoute(100).setConnectionTimeToLive(1, TimeUnit.MINUTES).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(100).build()).setDefaultRequestConfig(RequestConfig.custom().setContentCompressionEnabled(true).setRedirectsEnabled(true).setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(60000).build()).setSSLSocketFactory(new LayeredConnectionSocketFactory() {

        @Override
        public Socket createLayeredSocket(Socket socket, String target, int port, HttpContext context) throws IOException, UnknownHostException {
            return SSLConnectionSocketFactory.getSystemSocketFactory().createLayeredSocket(socket, target, port, context);
        }

        @Override
        public Socket createSocket(HttpContext context) throws IOException {
            return SSLConnectionSocketFactory.getSystemSocketFactory().createSocket(context);
        }

        @Override
        public Socket connectSocket(int connectTimeout, Socket sock, HttpHost host, InetSocketAddress remoteAddress, InetSocketAddress localAddress, HttpContext context) throws IOException {
            assertTrue("Non-zero timeout passed to connect socket is expected", connectTimeout > 0);
            throw new ProcessingException("OK");
        }
    }).build();
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(new ApacheHttpClient4Engine(httpClient, true)).providerFactory(factory).build();
    SocketServerRunnable sr = new SocketServerRunnable();
    Thread serverThread = new Thread(sr);
    serverThread.start();
    ResteasyWebTarget target = client.target("https://localhost:" + sr.getPort());
    SimpleRESTEasyAPI proxy = target.proxy(SimpleRESTEasyAPI.class);
    proxy.search("resteasy");
}
Also used : ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) LayeredConnectionSocketFactory(org.apache.http.conn.socket.LayeredConnectionSocketFactory) InetSocketAddress(java.net.InetSocketAddress) ApacheHttpClient4Engine(org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine) HttpContext(org.apache.http.protocol.HttpContext) HttpHost(org.apache.http.HttpHost) HttpClient(org.apache.http.client.HttpClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Aggregations

ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)19 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)8 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)6 HttpClient (org.apache.http.client.HttpClient)5 ApacheHttpClient4Engine (org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine)5 Client (javax.ws.rs.client.Client)4 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)4 LocalResteasyProviderFactory (org.jboss.resteasy.client.jaxrs.internal.LocalResteasyProviderFactory)4 ResteasyJackson2Provider (org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider)4 HashMap (java.util.HashMap)2 ServletContext (javax.servlet.ServletContext)2 Configuration (javax.ws.rs.core.Configuration)2 Dispatcher (org.jboss.resteasy.core.Dispatcher)2 Registry (org.jboss.resteasy.spi.Registry)2 JaxRSBootstrapException (com.adeptj.modules.jaxrs.resteasy.JaxRSBootstrapException)1 JaxRSProviderTracker (com.adeptj.modules.jaxrs.resteasy.internal.JaxRSProviderTracker)1 JaxRSResourceTracker (com.adeptj.modules.jaxrs.resteasy.internal.JaxRSResourceTracker)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 GuiceRegistry (com.peterphi.std.guice.apploader.impl.GuiceRegistry)1