summaryrefslogtreecommitdiffstats
path: root/appc-inbound/appc-design-services/provider
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-inbound/appc-design-services/provider
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-inbound/appc-design-services/provider')
-rwxr-xr-xappc-inbound/appc-design-services/provider/pom.xml5
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java45
-rw-r--r--appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/services/util/ArtifactHandlerClientTest.java47
3 files changed, 58 insertions, 39 deletions
diff --git a/appc-inbound/appc-design-services/provider/pom.xml b/appc-inbound/appc-design-services/provider/pom.xml
index 4dd4f4c0b..70c654d2b 100755
--- a/appc-inbound/appc-design-services/provider/pom.xml
+++ b/appc-inbound/appc-design-services/provider/pom.xml
@@ -135,10 +135,9 @@
<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>
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java
index 9aeaa1aa5..12f0a368d 100644
--- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java
+++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/services/util/ArtifactHandlerClient.java
@@ -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");
}
diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/services/util/ArtifactHandlerClientTest.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/services/util/ArtifactHandlerClientTest.java
index 8b3d023cc..d065eebc3 100644
--- a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/services/util/ArtifactHandlerClientTest.java
+++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/services/util/ArtifactHandlerClientTest.java
@@ -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");