aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java
diff options
context:
space:
mode:
Diffstat (limited to 'appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java')
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java59
1 files changed, 30 insertions, 29 deletions
diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java
index 45c00215e..408f0a305 100644
--- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java
+++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java
@@ -1,5 +1,4 @@
-/*-
- * ============LICENSE_START=======================================================
+/*
* ONAP : APPC
* ================================================================================
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
@@ -21,13 +20,16 @@ package org.onap.appc.flow.controller.executorImpl;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.ClientResponse.Status;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
-import com.sun.jersey.client.urlconnection.HTTPSProperties;
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+import org.glassfish.jersey.client.ClientProperties;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.Feature;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
@@ -58,17 +60,14 @@ public class RestExecutor implements FlowExecutorInterface {
System.setProperty("jsse.enableSNIExtension", "false");
SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new javax.net.ssl.TrustManager[] {new SecureRestClientTrustManager()}, null);
- DefaultClientConfig defaultClientConfig = new DefaultClientConfig();
- defaultClientConfig.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
- new HTTPSProperties(getHostnameVerifier(), sslContext));
- client = createClient(defaultClientConfig);
+ client = createClient(sslContext);
if ((transaction.getuId() != null) && (transaction.getPswd() != null)) {
- client.addFilter(new HTTPBasicAuthFilter(transaction.getuId(), transaction.getPswd()));
+ client.register(HttpAuthenticationFeature.basic(transaction.getuId(), transaction.getPswd()));
}
- WebResource webResource = client.resource(new URI(transaction.getExecutionEndPoint()));
- webResource.setProperty("Content-Type", "application/json;charset=UTF-8");
+ WebTarget webResource = client.target(new URI(transaction.getExecutionEndPoint()));
+ webResource.property("Content-Type", "application/json;charset=UTF-8");
- ClientResponse clientResponse = getClientResponse(transaction, webResource).orElseThrow(() -> new Exception(
+ javax.ws.rs.core.Response clientResponse = getClientResponse(transaction, webResource).orElseThrow(() -> new Exception(
"Cannot determine the state of : " + transaction.getActionLevel() + " HTTP response is null"));
processClientResponse(clientResponse, transaction, outputMessage);
@@ -82,7 +81,7 @@ public class RestExecutor implements FlowExecutorInterface {
} finally {
if (client != null) {
- client.destroy();
+ client.close();
}
}
return outputMessage;
@@ -92,38 +91,40 @@ public class RestExecutor implements FlowExecutorInterface {
return (hostname, sslSession) -> true;
}
- Client createClient(DefaultClientConfig defaultClientConfig) {
- return Client.create(defaultClientConfig);
+ Client createClient(SSLContext ctx) {
+ return ClientBuilder.newBuilder().sslContext(ctx).hostnameVerifier(getHostnameVerifier()).build();
}
- private Optional<ClientResponse> getClientResponse(Transaction transaction, WebResource webResource) {
+ private Optional<javax.ws.rs.core.Response> getClientResponse(Transaction transaction, WebTarget webResource) {
String responseDataType = MediaType.APPLICATION_JSON;
String requestDataType = MediaType.APPLICATION_JSON;
- ClientResponse clientResponse = null;
+ javax.ws.rs.core.Response clientResponse = null;
log.info("Starting Rest Operation.....");
if (HttpMethod.GET.equalsIgnoreCase(transaction.getExecutionRPC())) {
- clientResponse = webResource.accept(responseDataType).get(ClientResponse.class);
+ clientResponse = webResource.request(responseDataType).get(javax.ws.rs.core.Response.class);
} else if (HttpMethod.POST.equalsIgnoreCase(transaction.getExecutionRPC())) {
- clientResponse = webResource.type(requestDataType).post(ClientResponse.class, transaction.getPayload());
+ clientResponse = webResource.request(requestDataType).post(Entity.json(transaction.getPayload()),
+ javax.ws.rs.core.Response.class);
} else if (HttpMethod.PUT.equalsIgnoreCase(transaction.getExecutionRPC())) {
- clientResponse = webResource.type(requestDataType).put(ClientResponse.class, transaction.getPayload());
+ clientResponse = webResource.request(requestDataType).put(Entity.json(transaction.getPayload()),
+ javax.ws.rs.core.Response.class);
} else if (HttpMethod.DELETE.equalsIgnoreCase(transaction.getExecutionRPC())) {
- clientResponse = webResource.delete(ClientResponse.class);
+ clientResponse = webResource.request(requestDataType).delete(javax.ws.rs.core.Response.class);
}
return Optional.ofNullable(clientResponse);
}
- private void processClientResponse(ClientResponse clientResponse, Transaction transaction,
+ private void processClientResponse(javax.ws.rs.core.Response clientResponse, Transaction transaction,
Map<String, String> outputMessage) throws Exception {
if (clientResponse.getStatus() == Status.OK.getStatusCode()) {
Response response = new Response();
response.setResponseCode(String.valueOf(Status.OK.getStatusCode()));
transaction.setResponses(Collections.singletonList(response));
- outputMessage.put("restResponse", clientResponse.getEntity(String.class));
+ outputMessage.put("restResponse", clientResponse.readEntity(String.class));
} else {
- String errorMsg = clientResponse.getEntity(String.class);
+ String errorMsg = clientResponse.readEntity(String.class);
if (StringUtils.isNotBlank(errorMsg)) {
log.debug("Error Message from Client Response" + errorMsg);
}