diff --git a/appc-config/appc-config-adaptor/provider/pom.xml b/appc-config/appc-config-adaptor/provider/pom.xml index 418d9bd..2fa5aa4 100644 --- a/appc-config/appc-config-adaptor/provider/pom.xml +++ b/appc-config/appc-config-adaptor/provider/pom.xml @@ -105,11 +105,18 @@ provided - com.sun.jersey + org.glassfish.jersey.core jersey-client - 1.17 + 2.22.2 provided + + + org.glassfish.jersey.security + oauth1-client + 2.22.2 + + org.jasypt jasypt 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 f57f188..d0b36a2 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,14 @@ 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 = null; + message = response.getStatusInfo().getReasonPhrase(); log.info("RESPONSE..............."); log.info("HTTP response code: " + code); log.info("HTTP response message: " + message); @@ -1120,11 +1124,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 c987bb2..c30c318 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,13 @@ 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 +337,13 @@ 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 = Mockito.mock(Response.class); 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 parameters = new HashMap<>(); parameters.put("action", "prepare"); @@ -369,12 +374,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 = Mockito.mock(Response.class); 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 +395,12 @@ 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 = Mockito.mock(Response.class); 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 parameters = new HashMap<>(); parameters.put("action", "audit"); @@ -408,7 +413,7 @@ public class ConfigComponentAdaptorTest { @Test public void testActivate() { - ClientResponse mockClientResponse = Mockito.mock(ClientResponse.class); + Response mockClientResponse = Mockito.mock(Response.class); 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 b00ce7b..274cfee 100644 --- a/appc-config/appc-flow-controller/provider/pom.xml +++ b/appc-config/appc-flow-controller/provider/pom.xml @@ -93,9 +93,9 @@ sli-common - com.sun.jersey + org.glassfish.jersey.core jersey-client - 1.17 + 2.22.1 provided 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 45c0021..05cbe3c 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 getClientResponse(Transaction transaction, WebResource webResource) { + private Optional 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().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 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 0b64c13..2e673c1 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 @@ -32,14 +32,18 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; -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; import java.util.stream.Stream; import javax.ws.rs.HttpMethod; +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; + import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -60,11 +64,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; + private Response clientResponse; @Before @@ -77,18 +81,18 @@ 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(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(Response.class)).thenReturn(clientResponse); + when(webResourceBuilder.accept(MediaType.APPLICATION_JSON_TYPE).post(Entity.json(String.class),Response.class)).thenReturn(clientResponse); + when(webResourceBuilder.accept(MediaType.APPLICATION_JSON_TYPE).put(Entity.json(String.class),Response.class)).thenReturn(clientResponse); + when(webResource.request().delete(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 @@ -106,7 +110,8 @@ public class RestExecutorTest { transaction.setExecutionRPC(HttpMethod.POST); - outputMessage = restExecutor.execute(transaction, null); + outputMessage = restExecutor.execute(transaction, + null); assertResponseOK(); } @@ -116,7 +121,8 @@ public class RestExecutorTest { transaction.setExecutionRPC(HttpMethod.PUT); - outputMessage = restExecutor.execute(transaction, null); + outputMessage = restExecutor.execute(transaction, + null); assertResponseOK(); } @@ -135,7 +141,7 @@ public class RestExecutorTest { public void checkClienResponse_whenStatusNOK() throws Exception { try { when(clientResponse.getStatus()).thenReturn(FORBIDDEN.getStatusCode()); - when(clientResponse.getEntity(String.class)).thenReturn(FORBIDDEN.getReasonPhrase()); + when(clientResponse.readEntity(String.class)).thenReturn(FORBIDDEN.getReasonPhrase()); transaction.setExecutionRPC(HttpMethod.GET); outputMessage = restExecutor.execute(transaction, null); @@ -178,5 +184,5 @@ public class RestExecutorTest { assertTrue("HTTP Method: " + transaction.getExecutionRPC() + " is supported but was not handled", Stream.of(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE) .noneMatch(httpMethod -> httpMethod.equals(transaction.getExecutionRPC()))); - } + } } diff --git a/appc-inbound/appc-design-services/provider/pom.xml b/appc-inbound/appc-design-services/provider/pom.xml index abe814c..ea7da6b 100755 --- a/appc-inbound/appc-design-services/provider/pom.xml +++ b/appc-inbound/appc-design-services/provider/pom.xml @@ -135,10 +135,10 @@ org.onap.ccsdk.sli.core sli-provider - - com.sun.jersey + + org.glassfish.jersey.core jersey-client - 1.17 + 2.22.1 provided 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 9aeaa1a..2b87a59 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 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 8b3d023..1f84bde 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 @@ -40,9 +40,11 @@ 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; @RunWith(PowerMockRunner.class) @@ -50,8 +52,8 @@ import com.sun.jersey.api.client.WebResource.Builder; 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; @Rule @@ -64,11 +66,11 @@ public class ArtifactHandlerClientTest { PowerMockito.mockStatic(Client.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); + webResource = PowerMockito.mock(WebTarget.class); + PowerMockito.when(client.target(Mockito.any(URI.class))).thenReturn(webResource); + + } @Test @@ -105,8 +107,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"); diff --git a/appc-outbound/appc-network-inventory-client/provider/pom.xml b/appc-outbound/appc-network-inventory-client/provider/pom.xml index ae42164..9b462f9 100755 --- a/appc-outbound/appc-network-inventory-client/provider/pom.xml +++ b/appc-outbound/appc-network-inventory-client/provider/pom.xml @@ -63,9 +63,10 @@ - - com.sun.jersey + + org.glassfish.jersey.core jersey-client + 2.22.1 provided diff --git a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java index 51bd9c1..e167b10 100644 --- a/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java +++ b/appc-outbound/appc-network-inventory-client/provider/src/main/java/org/onap/appc/instar/dme2client/Dme2Client.java @@ -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) { diff --git a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestDme2Client.java b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestDme2Client.java index 7e2a418..df9de29 100644 --- a/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestDme2Client.java +++ b/appc-outbound/appc-network-inventory-client/provider/src/test/java/org/onap/appc/instar/node/TestDme2Client.java @@ -45,32 +45,34 @@ 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.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}) 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 Invocation.Builder builder; + private Response clientResponse; @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); HashMap data = new HashMap(); data.put("subtext", "value"); PowerMockito.mockStatic(InstarClientConstant.class); @@ -81,10 +83,10 @@ public class TestDme2Client { PowerMockito.when(InstarClientConstant.getInputStream("test/outbound.properties")) .thenReturn(inputStream); 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(ClientBuilder.newBuilder().build()).thenReturn(client); + PowerMockito.when(client.target(new URI("nullnullnullvalue"))).thenReturn(webResource); - PowerMockito.when(builder.get(ClientResponse.class)).thenReturn(clientResponse); + PowerMockito.when(builder.get(Response.class)).thenReturn(clientResponse); properties = Mockito.mock(Properties.class); dme2 = new Dme2Client("opt", "subtext", data); Whitebox.setInternalState(dme2, "properties", properties); @@ -94,34 +96,34 @@ 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"); + PowerMockito.when(webResource.request("application/json")).thenReturn(builder); + PowerMockito.when(clientResponse.readEntity(String.class)).thenReturn("Get Success"); when(properties.getProperty("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(webResource.request("application/json")).thenReturn(builder); + PowerMockito.when(builder.accept(ANY).put(Entity.json(""),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"); + PowerMockito.when(webResource.request("application/json")).thenReturn(builder); + PowerMockito.when(builder.accept(ANY).post(Entity.json(""),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"); + PowerMockito.when(webResource.request().delete(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()); } @@ -136,8 +138,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("Get Success"); when(properties.getProperty("getIpAddressByVnf_method")).thenReturn("GET"); assertNull(dme2.send()); } @@ -145,8 +147,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("Get Success"); when(properties.getProperty("getIpAddressByVnf_method")).thenReturn("GET"); assertNull(dme2.send()); } diff --git a/appc-sdc-listener/appc-yang-generator/dependency-reduced-pom.xml b/appc-sdc-listener/appc-yang-generator/dependency-reduced-pom.xml index 3f07d14..856dfd5 100644 --- a/appc-sdc-listener/appc-yang-generator/dependency-reduced-pom.xml +++ b/appc-sdc-listener/appc-yang-generator/dependency-reduced-pom.xml @@ -3,13 +3,13 @@ binding-parent org.onap.appc.parent - 1.5.0-SNAPSHOT + 2.6.0-SNAPSHOT pom.xml 4.0.0 org.onap.appc appc-yang-generator - 1.5.0-SNAPSHOT + 1.6.0-SNAPSHOT