aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config
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
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')
-rw-r--r--appc-config/appc-config-adaptor/provider/pom.xml9
-rw-r--r--appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java35
-rw-r--r--appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java30
-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
6 files changed, 98 insertions, 77 deletions
diff --git a/appc-config/appc-config-adaptor/provider/pom.xml b/appc-config/appc-config-adaptor/provider/pom.xml
index a0f681977..cb96a2e35 100644
--- a/appc-config/appc-config-adaptor/provider/pom.xml
+++ b/appc-config/appc-config-adaptor/provider/pom.xml
@@ -105,11 +105,16 @@
<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>
diff --git a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java
index f57f188d9..dd924229e 100644
--- a/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java
+++ b/appc-config/appc-config-adaptor/provider/src/main/java/org/onap/appc/ccadaptor/ConfigComponentAdaptor.java
@@ -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);
}
}
diff --git a/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java b/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java
index c987bb2c9..772a0a14d 100644
--- a/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java
+++ b/appc-config/appc-config-adaptor/provider/src/test/java/org/onap/appc/ccadaptor/ConfigComponentAdaptorTest.java
@@ -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());
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);