@Override protected Client newClient() { return new ResteasyClientBuilder() .httpEngine(new OkHttpClientEngine(ok)) .build(); }
protected ResteasyWebTarget innerCreateClient(URL url) { ResteasyClient client = new ResteasyClientBuilder().build(); String contextpath = url.getParameter("contextpath", "/"); if (!contextpath.startsWith("/")) contextpath = "/" + contextpath; return client.target("http://" + url.getHost() + ":" + url.getPort() + contextpath); }
@Override protected Client newClient(HttpTracing httpTracing) { return new ResteasyClientBuilder() .httpEngine(new OkHttpClientEngine(ok)) .register(TracingClientFilter.create(httpTracing)) .build(); }
.build(); ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/); ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build(); clients.add(client); client.register(RpcContextFilter.class); for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.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); ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url)); return target.proxy(serviceType);
@Override protected Object buildProxy(ClientTransportConfig transportConfig) throws SofaRpcException { SofaResteasyClientBuilder builder = new SofaResteasyClientBuilder(); ResteasyClient client = builder .registerProvider().logProviders() .establishConnectionTimeout(transportConfig.getConnectTimeout(), TimeUnit.MILLISECONDS) .socketTimeout(transportConfig.getInvokeTimeout(), TimeUnit.MILLISECONDS) .connectionPoolSize(Math.max(transportConfig.getConnectionNum(), MIN_CONNECTION_POOL_SIZE)) .build(); ProviderInfo provider = transportConfig.getProviderInfo(); String url = "http://" + provider.getHost() + ":" + provider.getPort() + StringUtils.CONTEXT_SEP + StringUtils.trimToEmpty(provider.getPath()); ResteasyWebTarget target = client.target(url); return target.proxy(ClassUtils.forName(transportConfig.getConsumerConfig().getInterfaceId())); }
.maxPooledPerRoute(30) .establishConnectionTimeout(connectionTimeout, TimeUnit.SECONDS) .socketTimeout(readTimeout, TimeUnit.SECONDS) .register(new JacksonJsonProvider()) .register(new JacksonConfig()) .register(new ApiHeaderTokenFilter(apiToken)) .register(new LoggingFilter()) .register(new RemoveAcceptEncodingFilter()) .register(new JaxrsFormProvider()) .build().target(url) .proxyBuilder(apiProxyClass) .classloader(apiProxyClass.getClassLoader()) .build();
ResteasyClient client = new ResteasyClientBuilder().build(); ResteasyWebTarget target = client.target(URL); MyService myService = target.proxy(MyService .class);
@Override public void safeReleaseResource(ResteasyWebTarget client, URL url) { String ipPort = url.getServerPortStr(); String protocolKey = MotanFrameworkUtil.getProtocolKey(url); synchronized (ipPort2ClientShareChannel) { if (client != ipPort2ClientShareChannel.get(ipPort)) { client.getResteasyClient().close(); return; } Set<String> urls = client2UrlsShareChannel.get(client); urls.remove(protocolKey); if (urls.isEmpty()) { client.getResteasyClient().close(); ipPort2ClientShareChannel.remove(ipPort); client2UrlsShareChannel.remove(client); } } }
@Override public void destroy() { super.destroy(); if (connectionMonitor != null) { connectionMonitor.shutdown(); } for (Map.Entry<String, RestServer> entry : servers.entrySet()) { try { if (logger.isInfoEnabled()) { logger.info("Closing the rest server at " + entry.getKey()); } entry.getValue().stop(); } catch (Throwable t) { logger.warn("Error closing rest server", t); } } servers.clear(); if (logger.isInfoEnabled()) { logger.info("Closing rest clients"); } for (ResteasyClient client : clients) { try { client.close(); } catch (Throwable t) { logger.warn("Error closing rest client", t); } } clients.clear(); }
@Override public <T> T proxy(Class<T> proxyInterface) { client.abortIfClosed(); return createProxyBuilder(proxyInterface, this).build(); }
@SuppressWarnings("UnusedReturnValue") ResteasyClientBuilder defaultProxy(String hostname, int port, final String scheme, String username, String password) { super.defaultProxy(hostname, port, scheme); if (username != null && password != null) { proxyCredentials = new BasicCredentialsProvider(); proxyCredentials.setCredentials(new AuthScope(hostname, port), new UsernamePasswordCredentials(username, password)); } return this; }
@Override public RestClientBuilder property(String name, Object value) { this.builderDelegate.property(name, value); return this; }
@SuppressWarnings("deprecation") @Override protected ClientHttpEngine initDefaultEngine() { ApacheHttpClient4Engine httpEngine = (ApacheHttpClient4Engine) super.initDefaultEngine(); if (proxyCredentials != null) { ((DefaultHttpClient) httpEngine.getHttpClient()).setCredentialsProvider(proxyCredentials); } return httpEngine; } }
public Map<Method, RestfulClientInvoker> build() { return proxy(iface, webTarget, new ProxyConfig(loader, serverConsumes, serverProduces)); }
@Override public Configuration getConfiguration() { client.abortIfClosed(); return configuration; }
@Override protected WebTarget apply(WebTarget target, Object object) { ResteasyWebTarget t = (ResteasyWebTarget)target; return t.queryParamNoTemplate(paramName, object); }
.build(); ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient/*, localContext*/); ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build(); clients.add(client); client.register(RpcContextFilter.class); for (String clazz : Constants.COMMA_SPLIT_PATTERN.split(url.getParameter(Constants.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); ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url)); return target.proxy(serviceType);
@Override protected Object buildProxy(ClientTransportConfig transportConfig) throws SofaRpcException { SofaResteasyClientBuilder builder = new SofaResteasyClientBuilder(); ResteasyClient client = builder .registerProvider().logProviders() .establishConnectionTimeout(transportConfig.getConnectTimeout(), TimeUnit.MILLISECONDS) .socketTimeout(transportConfig.getInvokeTimeout(), TimeUnit.MILLISECONDS) .connectionPoolSize(Math.max(transportConfig.getConnectionNum(), MIN_CONNECTION_POOL_SIZE)) .build(); ProviderInfo provider = transportConfig.getProviderInfo(); String url = "http://" + provider.getHost() + ":" + provider.getPort() + StringUtils.CONTEXT_SEP + StringUtils.trimToEmpty(provider.getPath()); ResteasyWebTarget target = client.target(url); return target.proxy(ClassUtils.forName(transportConfig.getConsumerConfig().getInterfaceId())); }
@Override public void destroy() { super.destroy(); if (connectionMonitor != null) { connectionMonitor.shutdown(); } for (Map.Entry<String, RestServer> entry : servers.entrySet()) { try { if (logger.isInfoEnabled()) { logger.info("Closing the rest server at " + entry.getKey()); } entry.getValue().stop(); } catch (Throwable t) { logger.warn("Error closing rest server", t); } } servers.clear(); if (logger.isInfoEnabled()) { logger.info("Closing rest clients"); } for (ResteasyClient client : clients) { try { client.close(); } catch (Throwable t) { logger.warn("Error closing rest client", t); } } clients.clear(); }
@Override public ResteasyClient getResteasyClient() { client.abortIfClosed(); return client; }