use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project kie-wb-common by kiegroup.
the class RuntimeEndpointsTestIT method checkOpenShiftService.
/**
* Can be used if internal to red hat.
* TODO: replace with more lightweight image and non-internal (minishift?) environment
* @throws Exception
*/
@Ignore
public void checkOpenShiftService() throws Exception {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(APP_URL);
ResteasyWebTarget restEasyTarget = (ResteasyWebTarget) target;
RuntimeProvisioningService proxy = restEasyTarget.proxy(RuntimeProvisioningService.class);
ProviderTypeList allProviderTypes = proxy.getProviderTypes(0, 10, "", true);
assertNotNull(allProviderTypes);
assertEquals(3, allProviderTypes.getItems().size());
OpenShiftProviderConfigImpl openshiftProviderConfig = createProviderConfig();
proxy.registerProvider(openshiftProviderConfig);
ProviderList allProviders = proxy.getProviders(0, 10, "", true);
assertEquals(1, allProviders.getItems().size());
assertTrue(allProviders.getItems().get(0) instanceof OpenShiftProvider);
OpenShiftProvider openshiftProvider = (OpenShiftProvider) allProviders.getItems().get(0);
OpenShiftRuntimeConfig runtimeConfig = createRuntimeConfig(openshiftProvider, "coss1");
@SuppressWarnings("unused") OpenShiftRuntime openshiftRuntime = getOpenShiftRuntime(proxy, 0, null);
String runtimeId = proxy.newRuntime(runtimeConfig);
openshiftRuntime = getOpenShiftRuntime(proxy, 1, OpenShiftRuntimeState.READY);
proxy.startRuntime(runtimeId);
openshiftRuntime = getOpenShiftRuntime(proxy, 1, OpenShiftRuntimeState.RUNNING);
proxy.stopRuntime(runtimeId);
openshiftRuntime = getOpenShiftRuntime(proxy, 1, OpenShiftRuntimeState.READY);
proxy.destroyRuntime(runtimeId, true);
openshiftRuntime = getOpenShiftRuntime(proxy, 0, null);
}
use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project dubbo by alibaba.
the class RestProtocol method doRefer.
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
if (connectionMonitor == null) {
connectionMonitor = new ConnectionMonitor();
}
// TODO more configs to add
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
// 20 is the default maxTotal of current PoolingClientConnectionManager
connectionManager.setMaxTotal(url.getParameter(Constants.CONNECTIONS_KEY, 20));
connectionManager.setDefaultMaxPerRoute(url.getParameter(Constants.CONNECTIONS_KEY, 20));
connectionMonitor.addConnectionManager(connectionManager);
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)).setSocketTimeout(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT)).build();
SocketConfig socketConfig = SocketConfig.custom().setSoKeepAlive(true).setTcpNoDelay(true).build();
CloseableHttpClient httpClient = HttpClientBuilder.create().setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
HeaderElement he = it.nextElement();
String param = he.getName();
String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
return Long.parseLong(value) * 1000;
}
}
// TODO constant
return 30 * 1000;
}
}).setDefaultRequestConfig(requestConfig).setDefaultSocketConfig(socketConfig).build();
ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
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);
}
}
}
// TODO protocol
ResteasyWebTarget target = client.target("http://" + url.getHost() + ":" + url.getPort() + "/" + getContextPath(url));
return target.proxy(serviceType);
}
use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project java by wavefrontHQ.
the class AbstractAgent method createAgentService.
/**
* Create RESTeasy proxies for remote calls via HTTP.
*/
protected WavefrontAPI createAgentService() {
ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
factory.registerProvider(JsonNodeWriter.class);
if (!factory.getClasses().contains(ResteasyJackson2Provider.class)) {
factory.registerProvider(ResteasyJackson2Provider.class);
}
if (httpUserAgent == null) {
httpUserAgent = "Wavefront-Proxy/" + props.getString("build.version");
}
ClientHttpEngine httpEngine;
if (javaNetConnection) {
httpEngine = new JavaNetConnectionEngine() {
@Override
protected HttpURLConnection createConnection(ClientInvocation request) throws IOException {
HttpURLConnection connection = (HttpURLConnection) request.getUri().toURL().openConnection();
connection.setRequestProperty("User-Agent", httpUserAgent);
connection.setRequestMethod(request.getMethod());
// 5s
connection.setConnectTimeout(httpConnectTimeout);
// 60s
connection.setReadTimeout(httpRequestTimeout);
if (connection instanceof HttpsURLConnection) {
HttpsURLConnection secureConnection = (HttpsURLConnection) connection;
secureConnection.setSSLSocketFactory(new SSLSocketFactoryImpl(HttpsURLConnection.getDefaultSSLSocketFactory(), httpRequestTimeout));
}
return connection;
}
};
} else {
HttpClient httpClient = HttpClientBuilder.create().useSystemProperties().setUserAgent(httpUserAgent).setMaxConnTotal(httpMaxConnTotal).setMaxConnPerRoute(httpMaxConnPerRoute).setConnectionTimeToLive(1, TimeUnit.MINUTES).setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(httpRequestTimeout).build()).setSSLSocketFactory(new SSLConnectionSocketFactoryImpl(SSLConnectionSocketFactory.getSystemSocketFactory(), httpRequestTimeout)).setRetryHandler(new DefaultHttpRequestRetryHandler(httpAutoRetries, true)).setDefaultRequestConfig(RequestConfig.custom().setContentCompressionEnabled(true).setRedirectsEnabled(true).setConnectTimeout(httpConnectTimeout).setConnectionRequestTimeout(httpConnectTimeout).setSocketTimeout(httpRequestTimeout).build()).build();
final ApacheHttpClient4Engine apacheHttpClient4Engine = new ApacheHttpClient4Engine(httpClient, true);
// avoid using disk at all
apacheHttpClient4Engine.setFileUploadInMemoryThresholdLimit(100);
apacheHttpClient4Engine.setFileUploadMemoryUnit(ApacheHttpClient4Engine.MemoryUnit.MB);
httpEngine = apacheHttpClient4Engine;
}
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(factory).register(GZIPDecodingInterceptor.class).register(gzipCompression ? GZIPEncodingInterceptor.class : DisableGZIPEncodingInterceptor.class).register(AcceptEncodingGZIPFilter.class).build();
ResteasyWebTarget target = client.target(server);
return target.proxy(WavefrontAPI.class);
}
use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project openremote by openremote.
the class KeycloakIdentityProvider method waitForKeycloak.
protected void waitForKeycloak() {
boolean keycloakAvailable = false;
WebTargetBuilder targetBuilder = new WebTargetBuilder(httpClient, keycloakServiceUri.build());
ResteasyWebTarget target = targetBuilder.build();
KeycloakResource keycloakResource = target.proxy(KeycloakResource.class);
while (!keycloakAvailable) {
LOG.info("Connecting to Keycloak server: " + keycloakServiceUri.build());
try {
pingKeycloak(keycloakResource);
keycloakAvailable = true;
} catch (Exception ex) {
LOG.info("Keycloak server not available, waiting...");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
}
use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project scheduling by ow2-proactive.
the class DataSpaceClient method delete.
@Override
public boolean delete(IRemoteSource source) throws NotConnectedException, PermissionException {
if (log.isDebugEnabled()) {
log.debug("Trying to delete " + source);
}
StringBuffer uriTmpl = (new StringBuffer()).append(restDataspaceUrl).append(source.getDataspace().value());
ResteasyClient client = new ResteasyClientBuilder().providerFactory(providerFactory).httpEngine(httpEngine).build();
ResteasyWebTarget target = client.target(uriTmpl.toString()).path(source.getPath());
List<String> includes = source.getIncludes();
if (includes != null && !includes.isEmpty()) {
target = target.queryParam("includes", includes.toArray(new Object[includes.size()]));
}
List<String> excludes = source.getExcludes();
if (excludes != null && !excludes.isEmpty()) {
target = target.queryParam("excludes", excludes.toArray(new Object[excludes.size()]));
}
Response response = null;
try {
response = target.request().header("sessionid", sessionId).delete();
boolean noContent = false;
if (response.getStatus() != HttpURLConnection.HTTP_NO_CONTENT) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedException("User not authenticated or session timeout.");
} else {
throw new RuntimeException("Cannot delete file(s). Status :" + response.getStatusInfo() + " Entity : " + response.getEntity());
}
} else {
noContent = true;
log.debug("No action performed for deletion since source " + source + " was not found remotely");
}
if (!noContent && log.isDebugEnabled()) {
log.debug("Removal of " + source + " performed with success");
}
return true;
} finally {
if (response != null) {
response.close();
}
}
}
Aggregations