aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-flow-controller
diff options
context:
space:
mode:
authorvmuthukrishnan <vmuthukrishnan@aarnanetworks.com>2019-08-13 17:44:22 +0000
committerTakamune Cho <takamune.cho@att.com>2019-08-30 23:40:59 +0000
commit35d8f73bfed6211b4d0e799880f991b001dbe0a6 (patch)
tree37511ceeca250948888432c28011046439dbdf17 /appc-config/appc-flow-controller
parenta0c771eb01a35f907394582f3febb42d39f25799 (diff)
Updated jersey from com.sun.jersey to org.glassfish.jersey
ODL upgrade Change-Id: I1167ad7cdb429c9c3e2808db820e3fc26e605383 Signed-off-by: vmuthukrishnan <vmuthukrishnan@aarnanetworks.com> Issue-ID: APPC-1630
Diffstat (limited to 'appc-config/appc-flow-controller')
-rw-r--r--appc-config/appc-flow-controller/provider/pom.xml3
-rw-r--r--appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java59
-rw-r--r--appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/executorImpl/RestExecutorTest.java39
3 files changed, 54 insertions, 47 deletions
diff --git a/appc-config/appc-flow-controller/provider/pom.xml b/appc-config/appc-flow-controller/provider/pom.xml
index 5712be7fc..b82e89190 100644
--- a/appc-config/appc-flow-controller/provider/pom.xml
+++ b/appc-config/appc-flow-controller/provider/pom.xml
@@ -93,9 +93,8 @@
<artifactId>sli-common</artifactId>
</dependency>
<dependency>
- <groupId>com.sun.jersey</groupId>
+ <groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
- <version>1.17</version>
<scope>provided</scope>
</dependency>
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);
}
diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/executorImpl/RestExecutorTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/executorImpl/RestExecutorTest.java
index 0b64c1390..e5517bfe8 100644
--- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/executorImpl/RestExecutorTest.java
+++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/executorImpl/RestExecutorTest.java
@@ -28,13 +28,12 @@ import static javax.ws.rs.core.Response.Status.OK;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.mock;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
@@ -47,6 +46,13 @@ import org.mockito.MockitoAnnotations;
import org.mockito.Spy;
import org.onap.appc.flow.controller.data.Transaction;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.client.Invocation;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+
public class RestExecutorTest {
private static final String ANY = "notNullString";
@@ -60,11 +66,11 @@ public class RestExecutorTest {
@Mock
private Client client;
@Mock
- private WebResource webResource;
+ private WebTarget webResource;
@Mock
- private WebResource.Builder webResourceBuilder;
+ private Invocation.Builder webResourceBuilder;
@Mock
- private ClientResponse clientResponse;
+ final private Response clientResponse = mock(Response.class);
@Before
@@ -77,18 +83,19 @@ public class RestExecutorTest {
MockitoAnnotations.initMocks(this);
doReturn(client).when(restExecutor).createClient(any());
- when(client.resource(any(URI.class))).thenReturn(webResource);
+ when(client.target(any(URI.class))).thenReturn(webResource);
- when(webResource.accept(anyString())).thenReturn(webResourceBuilder);
- when(webResource.type(anyString())).thenReturn(webResourceBuilder);
+ when(webResource.request(eq("Content-Type"),anyString())).thenReturn(webResourceBuilder);
+ when(webResource.request(anyString())).thenReturn(webResourceBuilder);
- when(webResourceBuilder.get(ClientResponse.class)).thenReturn(clientResponse);
- when(webResourceBuilder.post(ClientResponse.class, ANY)).thenReturn(clientResponse);
- when(webResourceBuilder.put(ClientResponse.class, ANY)).thenReturn(clientResponse);
- when(webResource.delete(ClientResponse.class)).thenReturn(clientResponse);
+ when(webResourceBuilder.get(eq(Response.class))).thenReturn(clientResponse);
+ when(webResourceBuilder.post(any(Entity.class),eq(Response.class))).thenReturn(clientResponse);
+ when(webResourceBuilder.put(any(Entity.class),eq(Response.class))).thenReturn(clientResponse);
+ when(webResource.request(anyString()).delete(eq(Response.class))).thenReturn(clientResponse);
+ when(webResourceBuilder.delete(eq(Response.class))).thenReturn(clientResponse);
when(clientResponse.getStatus()).thenReturn(OK.getStatusCode());
- when(clientResponse.getEntity(String.class)).thenReturn(OK.getReasonPhrase());
+ when(clientResponse.readEntity(String.class)).thenReturn(OK.getReasonPhrase());
}
@Test
@@ -135,8 +142,8 @@ public class RestExecutorTest {
public void checkClienResponse_whenStatusNOK() throws Exception {
try {
when(clientResponse.getStatus()).thenReturn(FORBIDDEN.getStatusCode());
- when(clientResponse.getEntity(String.class)).thenReturn(FORBIDDEN.getReasonPhrase());
- transaction.setExecutionRPC(HttpMethod.GET);
+ when(clientResponse.readEntity(String.class)).thenReturn(FORBIDDEN.getReasonPhrase());
+ transaction.setExecutionRPC(HttpMethod.GET);
outputMessage = restExecutor.execute(transaction, null);