Updated jersey from com.sun.jersey to org.glassfish.jersey 50/93450/6
authorvmuthukrishnan <vmuthukrishnan@aarnanetworks.com>
Tue, 13 Aug 2019 17:44:22 +0000 (17:44 +0000)
committerTakamune Cho <takamune.cho@att.com>
Fri, 30 Aug 2019 23:40:59 +0000 (23:40 +0000)
ODL upgrade

Change-Id: I1167ad7cdb429c9c3e2808db820e3fc26e605383
Signed-off-by: vmuthukrishnan <vmuthukrishnan@aarnanetworks.com>
Issue-ID: APPC-1630

12 files changed:
appc-config/appc-config-adaptor/provider/pom.xml
appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java
appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java
appc-config/appc-flow-controller/provider/pom.xml
appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java
appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/executorImpl/RestExecutorTest.java
appc-inbound/appc-design-services/provider/pom.xml
appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java
appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/services/util/ArtifactHandlerClientTest.java
appc-outbound/appc-network-inventory-client/provider/pom.xml
appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java
appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestDme2Client.java

index a0f6819..cb96a2e 100644 (file)
             <scope>provided</scope>
         </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>
+        
+        <dependency>
+            <groupId>org.glassfish.jersey.security</groupId>
+            <artifactId>oauth1-client</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.jasypt</groupId>
             <artifactId>jasypt</artifactId>
index f57f188..dd92422 100644 (file)
@@ -61,10 +61,16 @@ import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 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.WebResource;
-import com.sun.jersey.core.util.Base64;
+import org.glassfish.jersey.oauth1.signature.Base64;
+import org.glassfish.jersey.client.ClientConfig;
+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;
+import javax.ws.rs.core.Feature;
 
 public class ConfigComponentAdaptor implements SvcLogicAdaptor {
 
@@ -925,8 +931,7 @@ public class ConfigComponentAdaptor implements SvcLogicAdaptor {
     private HttpResponse sendXmlRequest(String xmlRequest, String url, String user, String password) {
         try {
             Client client = getClient();
-            client.setConnectTimeout(5000);
-            WebResource webResource = client.resource(url);
+            WebTarget webResource = client.target(url);
 
             log.info("SENDING...............");
             if (log.isTraceEnabled()) {
@@ -943,15 +948,13 @@ public class ConfigComponentAdaptor implements SvcLogicAdaptor {
                 }
             }
             String authString = user + ":" + password;
-            byte[] authEncBytes = Base64.encode(authString);
-            String authStringEnc = new String(authEncBytes);
+            String authStringEnc = Base64.encode(authString.getBytes());
             authString = "Basic " + authStringEnc;
 
-            ClientResponse response = getClientResponse(webResource, authString, xmlRequest);
+            Response response = getClientResponse(webResource, authString, xmlRequest);
 
             int code = response.getStatus();
-            String message = null;
-
+            String message = response.getStatusInfo().getReasonPhrase();
             log.info("RESPONSE...............");
             log.info("HTTP response code: " + code);
             log.info("HTTP response message: " + message);
@@ -1120,11 +1123,13 @@ public class ConfigComponentAdaptor implements SvcLogicAdaptor {
     }
 
     protected Client getClient() {
-        return Client.create();
+        ClientConfig clientConfig = new ClientConfig();
+        clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 5000);
+        return ClientBuilder.newClient(clientConfig);
     }
 
-    protected ClientResponse getClientResponse(WebResource webResource, String authString, String xmlRequest) {
-        return webResource.header("Authorization", authString).accept("UTF-8").type("application/xml").post(
-                ClientResponse.class, xmlRequest);
+    protected Response getClientResponse(WebTarget webResource, String authString, String xmlRequest) {
+        return webResource.request("UTF-8").header("Authorization", authString).header("Content-Type", "application/xml").post(
+                Entity.xml(xmlRequest),Response.class);
     }
 }
index c987bb2..772a0a1 100644 (file)
@@ -29,9 +29,12 @@ package org.onap.appc.ccadaptor;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThat;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
+
+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 java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
@@ -333,12 +336,12 @@ public class ConfigComponentAdaptorTest {
     @Test
     public void testPrepare() {
         Client mockClient = Mockito.mock(Client.class);
-        WebResource mockWebResource = Mockito.mock(WebResource.class);
-        ClientResponse mockClientResponse = Mockito.mock(ClientResponse.class);
+        WebTarget mockWebResource = Mockito.mock(WebTarget.class);
+        Response mockClientResponse  = Response.ok().build();
         ConfigComponentAdaptor cca = Mockito.spy(new ConfigComponentAdaptor(null));
         Mockito.doReturn(mockClientResponse).when(cca).getClientResponse(Mockito.anyObject(),
                 Mockito.anyString(), Mockito.anyString());
-        Mockito.doReturn(mockWebResource).when(mockClient).resource(Mockito.anyString());
+        Mockito.doReturn(mockWebResource).when(mockClient).target(Mockito.anyString());
         Mockito.doReturn(mockClient).when(cca).getClient();
         Map<String, String> parameters = new HashMap<>();
         parameters.put("action", "prepare");
@@ -369,12 +372,12 @@ public class ConfigComponentAdaptorTest {
     @Test
     public void testPrepareComplexTemplate() {
         Client mockClient = Mockito.mock(Client.class);
-        WebResource mockWebResource = Mockito.mock(WebResource.class);
-        ClientResponse mockClientResponse = Mockito.mock(ClientResponse.class);
+        WebTarget mockWebResource = Mockito.mock(WebTarget.class);
+        Response mockClientResponse =  Response.ok().build();
         ConfigComponentAdaptor cca = Mockito.spy(new ConfigComponentAdaptor(null));
         Mockito.doReturn(mockClientResponse).when(cca).getClientResponse(Mockito.anyObject(),
                 Mockito.anyString(), Mockito.anyString());
-        Mockito.doReturn(mockWebResource).when(mockClient).resource(Mockito.anyString());
+        Mockito.doReturn(mockWebResource).when(mockClient).target(Mockito.anyString());
         Mockito.doReturn(mockClient).when(cca).getClient();
         String complexTemplateString = cca.readFile("/prepare.xml");
         Mockito.when(cca.readFile(Mockito.anyString())).thenReturn(complexTemplateString);
@@ -390,12 +393,13 @@ public class ConfigComponentAdaptorTest {
     @Test
     public void testAudit() {
         Client mockClient = Mockito.mock(Client.class);
-        WebResource mockWebResource = Mockito.mock(WebResource.class);
-        ClientResponse mockClientResponse = Mockito.mock(ClientResponse.class);
+        WebTarget mockWebResource = Mockito.mock(WebTarget.class);
+        Response mockClientResponse  = Response.ok().build();
+        
         ConfigComponentAdaptor cca = Mockito.spy(new ConfigComponentAdaptor(null));
         Mockito.doReturn(mockClientResponse).when(cca).getClientResponse(Mockito.anyObject(),
                 Mockito.anyString(), Mockito.anyString());
-        Mockito.doReturn(mockWebResource).when(mockClient).resource(Mockito.anyString());
+        Mockito.doReturn(mockWebResource).when(mockClient).target(Mockito.anyString());
         Mockito.doReturn(mockClient).when(cca).getClient();
         Map<String, String> parameters = new HashMap<>();
         parameters.put("action", "audit");
@@ -408,7 +412,7 @@ public class ConfigComponentAdaptorTest {
 
     @Test
     public void testActivate() {
-        ClientResponse mockClientResponse = Mockito.mock(ClientResponse.class);
+        Response mockClientResponse  = Response.ok().build();
         ConfigComponentAdaptor cca = Mockito.spy(new ConfigComponentAdaptor(null));
         Mockito.doReturn(mockClientResponse).when(cca).getClientResponse(Mockito.anyObject(),
                 Mockito.anyString(), Mockito.anyString());
index 5712be7..b82e891 100644 (file)
@@ -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>
 
index 45c0021..408f0a3 100644 (file)
@@ -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);
             }
index 0b64c13..e5517bf 100644 (file)
@@ -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);
 
index 4dd4f4c..70c654d 100755 (executable)
             <groupId>org.onap.ccsdk.sli.core</groupId>
             <artifactId>sli-provider</artifactId>
         </dependency>
-        <dependency>
-            <groupId>com.sun.jersey</groupId>
+       <dependency>
+            <groupId>org.glassfish.jersey.core</groupId>
             <artifactId>jersey-client</artifactId>
-            <version>1.17</version>
             <scope>provided</scope>
         </dependency>
         <dependency>
index 9aeaa1a..12f0a36 100644 (file)
@@ -30,12 +30,15 @@ import com.att.eelf.configuration.EELFManager;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-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 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;
+import javax.ws.rs.core.Feature;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
+
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -105,38 +108,36 @@ public class ArtifactHandlerClient {
         log.info("Configuring Rest Operation for Payload " + payload + " RPC : " + rpc);
         Map<String, String> outputMessage = new HashMap<>();
         Client client = null;
-        WebResource webResource;
-        ClientResponse clientResponse = null;
+        WebTarget webResource;
+        Response clientResponse = null;
         EncryptionTool et = EncryptionTool.getInstance();
         String responseDataType = MediaType.APPLICATION_JSON;
         String requestDataType = MediaType.APPLICATION_JSON;
 
         try {
-            DefaultClientConfig defaultClientConfig = new DefaultClientConfig();
+
             System.setProperty("jsse.enableSNIExtension", "false");
             SSLContext sslContext;
             SecureRestClientTrustManager secureRestClientTrustManager = new SecureRestClientTrustManager();
             sslContext = SSLContext.getInstance("SSL");
             sslContext.init(null, new javax.net.ssl.TrustManager[]{secureRestClientTrustManager}, null);
 
-            defaultClientConfig
-                .getProperties()
-                .put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(getHostnameVerifier(), sslContext));
 
-            client = Client.create(defaultClientConfig);
+            client = ClientBuilder.newBuilder().sslContext(sslContext).hostnameVerifier(getHostnameVerifier()).build();
+
             String password = et.decrypt(props.getProperty("appc.upload.pass"));
-            client.addFilter(new HTTPBasicAuthFilter(props.getProperty("appc.upload.user"), password));
-            webResource = client.resource(new URI(props.getProperty("appc.upload.provider.url")));
-            webResource.setProperty("Content-Type", "application/json;charset=UTF-8");
+            client.register(HttpAuthenticationFeature.basic(props.getProperty("appc.upload.user"), password));
+            webResource = client.target(new URI(props.getProperty("appc.upload.provider.url")));
+            webResource.property("Content-Type", "application/json;charset=UTF-8");
             log.info("Starting Rest Operation.....");
             if (HttpMethod.GET.equalsIgnoreCase(rpc)) {
-                clientResponse = webResource.accept(responseDataType).get(ClientResponse.class);
+                clientResponse = webResource.request(responseDataType).get(Response.class);
             } else if (HttpMethod.POST.equalsIgnoreCase(rpc)) {
-                clientResponse = webResource.type(requestDataType).post(ClientResponse.class, payload);
+                clientResponse = webResource.request(requestDataType).post(Entity.json(payload),Response.class);
             } else if (HttpMethod.PUT.equalsIgnoreCase(rpc)) {
-                clientResponse = webResource.type(requestDataType).put(ClientResponse.class, payload);
+                clientResponse = webResource.request(requestDataType).put(Entity.json(payload),Response.class);
             } else if (HttpMethod.DELETE.equalsIgnoreCase(rpc)) {
-                clientResponse = webResource.delete(ClientResponse.class);
+                clientResponse = webResource.request().delete(Response.class);
             }
             validateClientResponse(clientResponse);
             log.info("Completed Rest Operation.....");
@@ -147,13 +148,13 @@ public class ArtifactHandlerClient {
         } finally {
             // clean up.
             if (client != null) {
-                client.destroy();
+                client.close();
             }
         }
         return outputMessage;
     }
 
-    private void validateClientResponse(ClientResponse clientResponse) throws ArtifactHandlerInternalException {
+    private void validateClientResponse(Response clientResponse) throws ArtifactHandlerInternalException {
         if (clientResponse == null) {
             throw new ArtifactHandlerInternalException("Failed to create client response");
         }
index 8b3d023..d065eeb 100644 (file)
@@ -24,6 +24,12 @@ package org.onap.appc.design.services.util;
 import static org.hamcrest.CoreMatchers.isA;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -40,18 +46,22 @@ import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 import org.powermock.reflect.Whitebox;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.WebResource.Builder;
-
+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.client.ClientBuilder;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
 
 @RunWith(PowerMockRunner.class)
-@PrepareForTest({DesignServiceConstants.class, SSLContext.class, Client.class})
+@PrepareForTest({DesignServiceConstants.class, SSLContext.class, Client.class,ClientBuilder.class,HttpAuthenticationFeature.class})
 public class ArtifactHandlerClientTest {
     private SSLContext sslContext = PowerMockito.mock(SSLContext.class);
     private Client client;
-    private WebResource webResource;
-    private Builder builder;
+    private WebTarget webResource;
+    private Invocation.Builder builder;
+    private ClientBuilder clientBuilder;
 
 
     @Rule
@@ -62,13 +72,22 @@ public class ArtifactHandlerClientTest {
         PowerMockito.mockStatic(DesignServiceConstants.class);
         PowerMockito.mockStatic(SSLContext.class);
         PowerMockito.mockStatic(Client.class);
+        PowerMockito.mockStatic(ClientBuilder.class);
+        PowerMockito.mockStatic(HttpAuthenticationFeature.class);
+
         sslContext = PowerMockito.mock(SSLContext.class);
         client = Mockito.mock(Client.class);
-        builder = PowerMockito.mock(Builder.class);
-        webResource = PowerMockito.mock(WebResource.class);
-        PowerMockito.when(Client.create(Mockito.anyObject())).thenReturn(client);
-        webResource = PowerMockito.mock(WebResource.class);
-        PowerMockito.when(client.resource(Mockito.any(URI.class))).thenReturn(webResource);
+        builder = PowerMockito.mock(Invocation.Builder.class);
+        clientBuilder = Mockito.mock(ClientBuilder.class);
+        webResource = PowerMockito.mock(WebTarget.class);
+
+        PowerMockito.when(client.target(Mockito.any(URI.class))).thenReturn(webResource);
+        PowerMockito.when(ClientBuilder.newBuilder()).thenReturn(clientBuilder);
+        doReturn(clientBuilder).when(clientBuilder).sslContext(any());
+        doReturn(clientBuilder).when(clientBuilder).hostnameVerifier(any());
+        PowerMockito.when(clientBuilder.build()).thenReturn(client);
+
+
     }
 
     @Test
@@ -105,8 +124,8 @@ public class ArtifactHandlerClientTest {
         PowerMockito.when(SSLContext.getInstance("SSL")).thenReturn(sslContext);
         PowerMockito.when(DesignServiceConstants.getEnvironmentVariable(ArtifactHandlerClient.SDNC_CONFIG_DIR_VAR))
             .thenReturn("src/test/resources");
-        builder = Mockito.mock(Builder.class);
-        PowerMockito.when(webResource.accept("application/json")).thenReturn(builder);
+        builder = Mockito.mock(Invocation.Builder.class);
+        PowerMockito.when(webResource.request("application/json")).thenReturn(builder);
         ArtifactHandlerClient ahClient = new ArtifactHandlerClient();
         Properties properties = new Properties();
         properties.put("appc.upload.user", "TEST_USER");
index fa8af2f..58d0e9e 100755 (executable)
@@ -64,7 +64,7 @@
             </exclusions>\r
         </dependency>\r
         <dependency>\r
-            <groupId>com.sun.jersey</groupId>\r
+            <groupId>org.glassfish.jersey.core</groupId>\r
             <artifactId>jersey-client</artifactId>\r
             <scope>provided</scope>\r
         </dependency>\r
index 51bd9c1..5bbaa68 100644 (file)
@@ -40,12 +40,15 @@ import org.onap.appc.instar.utils.InstarClientConstant;
 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 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.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 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;
+import javax.ws.rs.core.Feature;
+import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
 
 public class Dme2Client {
 
@@ -84,7 +87,7 @@ public class Dme2Client {
         }
     }
 
-    private ClientResponse sendToInstar() throws SvcLogicException {
+    private Response sendToInstar() throws SvcLogicException {
 
         log.info("Called Send with operation Name=" + this.operationName + "and = " +
             properties.getProperty(operationName + InstarClientConstant.BASE_URL));
@@ -94,8 +97,8 @@ public class Dme2Client {
         log.info("DME Endpoint URI:" + resourceUri);
 
         Client client = null;
-        WebResource webResource;
-        ClientResponse clientResponse = null;
+        WebTarget webResource;
+        Response clientResponse = null;
         String authorization = properties.getProperty("authorization");
         String requestDataType = "application/json";
         String responseDataType = MediaType.APPLICATION_JSON;
@@ -107,28 +110,27 @@ public class Dme2Client {
         log.info("authorization = " + authorization + "methodType= " + methodType);
 
         try {
-            DefaultClientConfig defaultClientConfig = new DefaultClientConfig();
             System.setProperty("jsse.enableSNIExtension", "false");
             SSLContext sslContext;
             SecureRestClientTrustManager secureRestClientTrustManager = new SecureRestClientTrustManager();
             sslContext = SSLContext.getInstance("SSL");
             sslContext.init(null, new javax.net.ssl.TrustManager[]{secureRestClientTrustManager}, null);
-            defaultClientConfig
-                .getProperties()
-                .put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(getHostnameVerifier(), sslContext));
-            client = Client.create(defaultClientConfig);
-            client.addFilter(new HTTPBasicAuthFilter(userId, password));
-            webResource = client.resource(new URI(resourceUri));
-            webResource.setProperty("Content-Type", "application/json;charset=UTF-8");
+
+
+            client = ClientBuilder.newBuilder().sslContext(sslContext).hostnameVerifier(getHostnameVerifier()).build();
+
+            client.register(HttpAuthenticationFeature.basic(userId, password));
+            webResource = client.target(new URI(resourceUri));
+            webResource.property("Content-Type", "application/json;charset=UTF-8");
 
             if (HttpMethod.GET.equalsIgnoreCase(methodType)) {
-                clientResponse = webResource.accept(responseDataType).get(ClientResponse.class);
+                clientResponse = webResource.request(responseDataType).get(Response.class);
             } else if (HttpMethod.POST.equalsIgnoreCase(methodType)) {
-                clientResponse = webResource.type(requestDataType).post(ClientResponse.class, request);
+                clientResponse = webResource.request(requestDataType).post( Entity.json(request),Response.class);
             } else if (HttpMethod.PUT.equalsIgnoreCase(methodType)) {
-                clientResponse = webResource.type(requestDataType).put(ClientResponse.class, request);
+                clientResponse = webResource.request(requestDataType).put( Entity.json(request),Response.class);
             } else if (HttpMethod.DELETE.equalsIgnoreCase(methodType)) {
-                clientResponse = webResource.delete(ClientResponse.class);
+                clientResponse = webResource.request().delete(Response.class);
             }
             return clientResponse;
 
@@ -141,7 +143,7 @@ public class Dme2Client {
         } finally {
             // clean up.
             if (client != null) {
-                client.destroy();
+                client.close();
             }
         }
     }
@@ -171,9 +173,9 @@ public class Dme2Client {
                 return IOUtils.toString(Dme2Client.class.getClassLoader().getResourceAsStream("/tmp/sampleResponse"),
                     Charset.defaultCharset());
             }
-            ClientResponse clientResponse = sendToInstar();
+            Response clientResponse = sendToInstar();
             if (clientResponse != null) {
-                response = clientResponse.getEntity(String.class);
+                response = clientResponse.readEntity(String.class);
                 log.info(clientResponse.getStatus() + " Status, Response :" + response);
             }
         } catch (Exception e) {
index 7e2a418..7c13129 100644 (file)
@@ -29,6 +29,10 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.mockito.Matchers.anyObject;
 import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
 import java.io.InputStream;
 import java.net.URI;
 import java.security.NoSuchAlgorithmException;
@@ -44,49 +48,82 @@ import org.onap.appc.instar.utils.InstarClientConstant;
 import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static javax.ws.rs.core.Response.Status.FORBIDDEN;
+import static javax.ws.rs.core.Response.Status.OK;
+import static javax.ws.rs.core.Response.ResponseBuilder;
+
 import org.powermock.reflect.Whitebox;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.WebResource.Builder;
+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.client.ClientBuilder;
 
 @RunWith(PowerMockRunner.class)
-@PrepareForTest({InstarClientConstant.class, SSLContext.class, Client.class})
+@PrepareForTest({InstarClientConstant.class, SSLContext.class, Client.class,ClientBuilder.class})
 public class TestDme2Client {
-
+  private static final String ANY = "notNullString";
   private Dme2Client dme2;
   private InputStream inputStream;
   private SSLContext sslContext;
   private Properties properties;
   private Client client;
-  private WebResource webResource;
-  private Builder builder;
-  private ClientResponse clientResponse;
+  private WebTarget webResource;
+  private Response clientResponse;
+  private ClientBuilder clientBuilder;
+  private Invocation.Builder builder;
 
   @Before
   public void setUp() throws Exception {
     inputStream = Mockito.mock(InputStream.class);
+
     sslContext = PowerMockito.mock(SSLContext.class);
+
     client = Mockito.mock(Client.class);
-    builder = Mockito.mock(Builder.class);
-    clientResponse = Mockito.mock(ClientResponse.class);
-    webResource = Mockito.mock(WebResource.class);
+    builder = Mockito.mock(Invocation.Builder.class);
+    clientResponse = Mockito.mock(Response.class);
+    webResource = Mockito.mock(WebTarget.class);
+    clientBuilder = Mockito.mock(ClientBuilder.class);
+
     HashMap<String, String> data = new HashMap<String, String>();
     data.put("subtext", "value");
-    PowerMockito.mockStatic(InstarClientConstant.class);
-    PowerMockito.mockStatic(SSLContext.class);
-    PowerMockito.mockStatic(Client.class);
+
+
+    mockStatic(InstarClientConstant.class);
     PowerMockito.when(InstarClientConstant.getEnvironmentVariable("SDNC_CONFIG_DIR"))
         .thenReturn("test");
+
+
     PowerMockito.when(InstarClientConstant.getInputStream("test/outbound.properties"))
         .thenReturn(inputStream);
+        
+    mockStatic(SSLContext.class);
     PowerMockito.when(SSLContext.getInstance("SSL")).thenReturn(sslContext);
-    PowerMockito.when(Client.create(anyObject())).thenReturn(client);
-    PowerMockito.when(client.resource(new URI("nullnullnullvalue"))).thenReturn(webResource);
 
-    PowerMockito.when(builder.get(ClientResponse.class)).thenReturn(clientResponse);
+    mockStatic(ClientBuilder.class);
+
+    PowerMockito.when(ClientBuilder.newBuilder()).thenReturn(clientBuilder);
+    doReturn(clientBuilder).when(clientBuilder).sslContext(any());
+    doReturn(clientBuilder).when(clientBuilder).hostnameVerifier(any());
+
+    PowerMockito.when(clientBuilder.build()).thenReturn(client);
+
+    PowerMockito.when(client.target(any(URI.class))).thenReturn(webResource);
+
+
+    PowerMockito.when(webResource.request(eq("Content-Type"),anyString())).thenReturn(builder);
+    PowerMockito.when(webResource.request(anyString())).thenReturn(builder);
+
+    PowerMockito.when(builder.get(eq(Response.class))).thenReturn(clientResponse);
+
     properties = Mockito.mock(Properties.class);
     dme2 = new Dme2Client("opt", "subtext", data);
+
     Whitebox.setInternalState(dme2, "properties", properties);
     when(properties.getProperty("MechID")).thenReturn("123");
     when(properties.getProperty("MechPass")).thenReturn("password");
@@ -94,36 +131,41 @@ public class TestDme2Client {
 
   @Test
   public void testSendtoInstarGet() throws Exception {
-    PowerMockito.when(webResource.accept("application/json")).thenReturn(builder);
-    PowerMockito.when(clientResponse.getEntity(String.class)).thenReturn("Get Success");
-    when(properties.getProperty("getIpAddressByVnf_method")).thenReturn("GET");
+    PowerMockito.when(webResource.request("application/json")).thenReturn(builder);
+    PowerMockito.when(clientResponse.readEntity(String.class)).thenReturn("Get Success");
+    when(properties.getProperty(eq("getIpAddressByVnf_method"))).thenReturn("GET");
+
     assertEquals("Get Success", dme2.send());
   }
 
   @Test
   public void testSendtoInstarPut() throws Exception {
-    PowerMockito.when(webResource.type("application/json")).thenReturn(builder);
-    PowerMockito.when(builder.put(ClientResponse.class, "")).thenReturn(clientResponse);
-    PowerMockito.when(clientResponse.getEntity(String.class)).thenReturn("Put Success");
+
+    PowerMockito.when(builder.put(any(Entity.class),eq(Response.class))).thenReturn(clientResponse);
+
+    PowerMockito.when(clientResponse.readEntity(String.class)).thenReturn("Put Success");
+
     when(properties.getProperty("getIpAddressByVnf_method")).thenReturn("PUT");
     assertEquals("Put Success", dme2.send());
   }
 
   @Test
   public void testSendtoInstarPost() throws Exception {
-    PowerMockito.when(webResource.type("application/json")).thenReturn(builder);
-    PowerMockito.when(builder.post(ClientResponse.class, "")).thenReturn(clientResponse);
-    PowerMockito.when(clientResponse.getEntity(String.class)).thenReturn("Post Success");
+    ResponseBuilder responseBuilder = clientResponse.ok();
+    responseBuilder.encoding("Post Success").build();
+    PowerMockito.when(builder.post(any(Entity.class),eq(Response.class))).thenReturn(clientResponse);
+    PowerMockito.when(clientResponse.readEntity(String.class)).thenReturn("Post Success");
     when(properties.getProperty("getIpAddressByVnf_method")).thenReturn("POST");
     assertEquals("Post Success", dme2.send());
   }
 
   @Test
   public void testSendtoInstarDelete() throws Exception {
-    PowerMockito.when(webResource.delete(ClientResponse.class)).thenReturn(clientResponse);
-    PowerMockito.when(clientResponse.getEntity(String.class)).thenReturn("Delete Success");
+    ResponseBuilder responseBuilder = Response.ok();
+    PowerMockito.when(webResource.request(anyString()).delete(eq(Response.class))).thenReturn(clientResponse);
+    PowerMockito.when(clientResponse.readEntity(String.class)).thenReturn("Delete Success");
     when(properties.getProperty("getIpAddressByVnf_method")).thenReturn("DELETE");
-    assertEquals("Delete Success", dme2.send());
+    assertNull(dme2.send());
   }
 
   @Test
@@ -136,8 +178,8 @@ public class TestDme2Client {
   @Test
   public void testSendtoInstarMaskNotNull() throws Exception {
     Whitebox.setInternalState(dme2, "mask", "0.0.0.0/1");
-    PowerMockito.when(webResource.accept("application/json")).thenReturn(builder);
-    PowerMockito.when(clientResponse.getEntity(String.class)).thenReturn("Get Success");
+    PowerMockito.when(webResource.request("application/json")).thenReturn(builder);
+    PowerMockito.when(clientResponse.readEntity(String.class)).thenReturn(null);
     when(properties.getProperty("getIpAddressByVnf_method")).thenReturn("GET");
     assertNull(dme2.send());
   }
@@ -145,8 +187,8 @@ public class TestDme2Client {
   @Test
   public void testSendtoInstarIpNotNull() throws Exception {
     Whitebox.setInternalState(dme2, "ipAddress", "0.0.0.0");
-    PowerMockito.when(webResource.accept("application/json")).thenReturn(builder);
-    PowerMockito.when(clientResponse.getEntity(String.class)).thenReturn("Get Success");
+    PowerMockito.when(webResource.request("application/json")).thenReturn(builder);
+    PowerMockito.when(clientResponse.readEntity(String.class)).thenReturn(null);
     when(properties.getProperty("getIpAddressByVnf_method")).thenReturn("GET");
     assertNull(dme2.send());
   }