aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--aai-core/pom.xml15
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java49
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java91
-rw-r--r--aai-core/src/main/java/org/onap/aai/util/RestController.java162
-rw-r--r--aai-els-onap-logging/pom.xml15
-rw-r--r--aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientRequestLoggingInterceptor.java (renamed from aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptor.java)77
-rw-r--r--aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientResponseLoggingInterceptor.java91
-rw-r--r--aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptorTest.java24
-rw-r--r--aai-parent/pom.xml21
9 files changed, 297 insertions, 248 deletions
diff --git a/aai-core/pom.xml b/aai-core/pom.xml
index 2f5908b4..e53d233c 100644
--- a/aai-core/pom.xml
+++ b/aai-core/pom.xml
@@ -250,16 +250,12 @@ limitations under the License.
<artifactId>jackson-module-jaxb-annotations</artifactId>
</dependency>
<dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-core</artifactId>
- </dependency>
- <dependency>
- <groupId>com.sun.jersey</groupId>
+ <groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-json</artifactId>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tinkerpop</groupId>
@@ -417,11 +413,6 @@ limitations under the License.
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-configuration2</artifactId>
- <version>2.7</version>
- </dependency>
</dependencies>
<!-- Plugins and repositories -->
diff --git a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java
index f8f0b65e..b31bfcb8 100644
--- a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java
+++ b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthClient.java
@@ -20,13 +20,6 @@
package org.onap.aai.util;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.json.JSONConfiguration;
-import com.sun.jersey.client.urlconnection.HTTPSProperties;
-
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyManagementException;
@@ -41,8 +34,16 @@ import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
-
-import org.onap.aai.aailog.filter.RestControllerClientLoggingInterceptor;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import org.apache.commons.configuration2.JSONConfiguration;
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.client.ClientProperties;
+import org.onap.aai.aailog.filter.RestControllerClientRequestLoggingInterceptor;
+import org.onap.aai.aailog.filter.RestControllerClientResponseLoggingInterceptor;
import org.onap.aai.exceptions.AAIException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -62,12 +63,10 @@ public class HttpsAuthClient {
System.out.println("Making Jersey https call...");
Client client = HttpsAuthClient.getClient();
- ClientResponse res = client.resource(url).accept("application/json").header("X-TransactionId", "PROV001")
- .header("X-FromAppId", "AAI").type("application/json").get(ClientResponse.class);
-
- // System.out.println("Jersey result: ");
- // System.out.println(res.getEntity(String.class).toString());
-
+ Response res = client.target(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header("X-TransactionId", "PROV001")
+ .header("X-FromAppId", "AAI").get();
} catch (KeyManagementException e) {
logger.debug("HttpsAuthClient KeyManagement error : {}", e.getMessage());
} catch (Exception e) {
@@ -89,9 +88,9 @@ public class HttpsAuthClient {
String keystorePassword) throws KeyManagementException, UnrecoverableKeyException, CertificateException,
NoSuchAlgorithmException, KeyStoreException, IOException {
- ClientConfig config = new DefaultClientConfig();
- config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
- config.getClasses().add(org.onap.aai.restcore.CustomJacksonJaxBJsonProvider.class);
+ ClientConfig config = new ClientConfig();
+ config.register(org.onap.aai.restcore.CustomJacksonJaxBJsonProvider.class);
+
SSLContext ctx = null;
try {
System.setProperty("javax.net.ssl.trustStore", truststorePath);
@@ -117,20 +116,16 @@ public class HttpsAuthClient {
}
ctx.init(kmf.getKeyManagers(), null, null);
- config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
- new HTTPSProperties(new HostnameVerifier() {
- @Override
- public boolean verify(String s, SSLSession sslSession) {
- return true;
- }
- }, ctx));
+ config.property("jersey.config.client.ssl.context", ctx);
+ config.property("jersey.config.client.hostname.verifier", (HostnameVerifier) (s, sslSession) -> true);
} catch (Exception e) {
System.out.println("Error setting up config: exiting " + e.getMessage());
throw e;
}
- Client client = Client.create(config);
- client.addFilter(new RestControllerClientLoggingInterceptor());
+ Client client = ClientBuilder.newClient(config);
+ client.register(new RestControllerClientRequestLoggingInterceptor());
+ client.register(new RestControllerClientResponseLoggingInterceptor());
// uncomment this line to get more logging for the request/response
// client.addFilter(new LoggingFilter(System.out));
diff --git a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java
index 53e2d958..1ace66c7 100644
--- a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java
+++ b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java
@@ -20,21 +20,16 @@
package org.onap.aai.util;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.config.ClientConfig;
-import com.sun.jersey.api.client.config.DefaultClientConfig;
-import com.sun.jersey.api.json.JSONConfiguration;
-import com.sun.jersey.client.urlconnection.HTTPSProperties;
-
import java.io.FileInputStream;
-import java.security.KeyStore;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.SslConfigurator;
import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
-import javax.net.ssl.TrustManagerFactory;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
public class HttpsAuthExternalClient {
@@ -48,63 +43,45 @@ public class HttpsAuthExternalClient {
*/
public static Client getClient(String keystoreFileName, String keystorePassword) throws Exception {
- ClientConfig config = new DefaultClientConfig();
- config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
- config.getClasses().add(org.onap.aai.restcore.CustomJacksonJaxBJsonProvider.class);
- Client client = null;
- SSLContext ctx = null;
- String truststore_path = AAIConstants.AAI_HOME_ETC_AUTH + AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_FILENAME);
- try (FileInputStream tin = new FileInputStream(truststore_path)) {
- String truststore_password = AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_PASSWD);
- String keystore_path = AAIConstants.AAI_HOME_ETC_AUTH + keystoreFileName;
- String keystore_password = keystorePassword;
- // System.setProperty("javax.net.ssl.trustStore", truststore_path);
- // System.setProperty("javax.net.ssl.trustStorePassword", truststore_password);
- HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
- public boolean verify(String string, SSLSession ssls) {
- return true;
- }
- });
+ ClientConfig config = new ClientConfig();
+ config.register(org.onap.aai.restcore.CustomJacksonJaxBJsonProvider.class);
- ctx = SSLContext.getInstance("TLS");
- KeyManagerFactory kmf = null;
+ SSLContext sslContext = null;
+ String truststorePath = AAIConstants.AAI_HOME_ETC_AUTH + AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_FILENAME);
+ try (FileInputStream tin = new FileInputStream(truststorePath)) {
+ String truststorePassword = AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_PASSWD);
+ String keystorePath = AAIConstants.AAI_HOME_ETC_AUTH + keystoreFileName;
- /****
- * kmf = KeyManagerFactory.getInstance("SunX509");
- * FileInputStream fin = new FileInputStream(keystore_path);
- * KeyStore ks = KeyStore.getInstance("PKCS12");
- * char[] pwd = keystore_password.toCharArray();
- * ks.load(fin, pwd);
- * kmf.init(ks, pwd);
- ***/
+ SslConfigurator sslConfig = SslConfigurator.newInstance()
+ .trustStoreFile(truststorePath)
+ .trustStorePassword(truststorePassword)
+ .keyStoreFile(keystorePath)
+ .keyStorePassword(keystorePassword);
- String alg = TrustManagerFactory.getDefaultAlgorithm();
- TrustManagerFactory tmf = TrustManagerFactory.getInstance(alg);
+ sslContext = sslConfig.createSSLContext();
- KeyStore ts = KeyStore.getInstance("PKCS12");
- char[] tpwd = truststore_password.toCharArray();
- ts.load(tin, tpwd);
- tmf.init(ts);
+ HostnameVerifier hostnameVerifier = new HostnameVerifier() {
+ @Override
+ public boolean verify(String s, SSLSession sslSession) {
+ return true;
+ }
+ };
- // ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
- // Updating key manager to null, to disable two way SSL
- ctx.init(null, tmf.getTrustManagers(), null);
+ Client client = ClientBuilder.newBuilder()
+ .withConfig(config)
+ .sslContext(sslContext)
+ .hostnameVerifier(hostnameVerifier)
+ .build();
- config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES,
- new HTTPSProperties(new HostnameVerifier() {
- @Override
- public boolean verify(String s, SSLSession sslSession) {
- return true;
- }
- }, ctx));
+ // Uncomment this line to get more logging for the request/response
+ // client.register(new
+ // LoggingFeature(Logger.getLogger(LoggingFeature.DEFAULT_LOGGER_NAME),
+ // Level.INFO, LoggingFeature.Verbosity.PAYLOAD_ANY, 8192));
- client = Client.create(config);
- // uncomment this line to get more logging for the request/response
- // client.addFilter(new LoggingFilter(System.out));
+ return client;
} catch (Exception e) {
throw e;
}
- return client;
}
}
diff --git a/aai-core/src/main/java/org/onap/aai/util/RestController.java b/aai-core/src/main/java/org/onap/aai/util/RestController.java
index 1b050829..b72b5af5 100644
--- a/aai-core/src/main/java/org/onap/aai/util/RestController.java
+++ b/aai-core/src/main/java/org/onap/aai/util/RestController.java
@@ -22,9 +22,8 @@ package org.onap.aai.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientResponse;
+
+import javax.ws.rs.client.Entity;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
@@ -37,6 +36,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
+import javax.ws.rs.ClientErrorException;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
import org.onap.aai.exceptions.AAIException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -69,8 +73,7 @@ public class RestController implements RestControllerInterface {
public static final String REST_APIPATH_CLOUDREGION = "cloud-infrastructure/cloud-regions/cloud-region/";
public static final String REST_APIPATH_TENANT = "cloud-infrastructure/tenants/tenant/";
- public static final String REST_APIPATH_VIRTUAL_DATA_CENTER =
- "cloud-infrastructure/virtual-data-centers/virtual-data-center/";
+ public static final String REST_APIPATH_VIRTUAL_DATA_CENTER = "cloud-infrastructure/virtual-data-centers/virtual-data-center/";
public static final String REST_APIPATH_VIRTUAL_DATA_CENTERS = "cloud-infrastructure/virtual-data-centers/";
public static final String REST_APIPATH_GENERIC_VNF = "network/generic-vnfs/generic-vnf/";
public static final String REST_APIPATH_GENERIC_VNFS = "network/generic-vnfs";
@@ -173,8 +176,8 @@ public class RestController implements RestControllerInterface {
url = AAIConfig.get(AAIConstants.AAI_OLDSERVER_URL) + path;
} else {
if (overrideLocalHost == null) {
- overrideLocalHost =
- AAIConfig.get(AAIConstants.AAI_LOCAL_OVERRIDE, AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT);
+ overrideLocalHost = AAIConfig.get(AAIConstants.AAI_LOCAL_OVERRIDE,
+ AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT);
}
if (AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT.equals(overrideLocalHost)) {
url = String.format(AAIConstants.AAI_LOCAL_REST, port,
@@ -185,21 +188,26 @@ public class RestController implements RestControllerInterface {
}
}
LOGGER.debug(url + " for the get REST API");
- ClientResponse cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
- .header("X-FromAppId", sourceID).header("Real-Time", "true").type("application/json")
- .get(ClientResponse.class);
+ Response response = client.target(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header("X-TransactionId", transId)
+ .header("X-FromAppId", sourceID)
+ .header("Real-Time", "true")
+ .get();
- // System.out.println("cres.EntityInputSream()="+cres.getEntityInputStream().toString());
- // System.out.println("cres.tostring()="+cres.toString());
+ // System.out.println("response.EntityInputSream()="+response.getEntityInputStream().toString());
+ // System.out.println("response.tostring()="+response.toString());
- if (cres.getStatus() == 200) {
+ if (response.getStatus() == 200) {
// System.out.println(methodName + ": url=" + url);
- t = (T) cres.getEntity(t.getClass());
+ T entity = response.readEntity((Class<T>) t.getClass());
+ restObject.set(entity);
restObject.set(t);
LOGGER.debug(methodName + "REST api GET was successfull!");
} else {
- // System.out.println(methodName + ": url=" + url + " failed with status=" + cres.getStatus());
- throw new AAIException("AAI_7116", methodName + " with status=" + cres.getStatus() + ", url=" + url);
+ // System.out.println(methodName + ": url=" + url + " failed with status=" +
+ // response.getStatus());
+ throw new AAIException("AAI_7116", methodName + " with status=" + response.getStatus() + ", url=" + url);
}
}
@@ -229,21 +237,25 @@ public class RestController implements RestControllerInterface {
url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + apiVersion + "/" + path;
LOGGER.debug(url + " for the get REST API");
- ClientResponse cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
- .header("X-FromAppId", sourceID).header("Real-Time", "true").type("application/json")
- .get(ClientResponse.class);
+ Response response = client.target(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header("X-TransactionId", transId)
+ .header("X-FromAppId", sourceID)
+ .header("Real-Time", "true")
+ .get();
- // System.out.println("cres.EntityInputSream()="+cres.getEntityInputStream().toString());
- // System.out.println("cres.tostring()="+cres.toString());
+ // System.out.println("response.EntityInputSream()="+response.getEntityInputStream().toString());
+ // System.out.println("response.tostring()="+response.toString());
- if (cres.getStatus() == 200) {
+ if (response.getStatus() == 200) {
// System.out.println(methodName + ": url=" + url);
- t = (T) cres.getEntity(t.getClass());
- restObject.set(t);
+ T entity = response.readEntity((Class<T>) t.getClass());
+ restObject.set(entity);
LOGGER.debug(methodName + "REST api GET was successfull!");
} else {
- // System.out.println(methodName + ": url=" + url + " failed with status=" + cres.getStatus());
- throw new AAIException("AAI_7116", methodName + " with status=" + cres.getStatus() + ", url=" + url);
+ // System.out.println(methodName + ": url=" + url + " failed with status=" +
+ // response.getStatus());
+ throw new AAIException("AAI_7116", methodName + " with status=" + response.getStatus() + ", url=" + url);
}
}
@@ -318,8 +330,8 @@ public class RestController implements RestControllerInterface {
url = AAIConfig.get(AAIConstants.AAI_OLDSERVER_URL) + path;
} else {
if (overrideLocalHost == null) {
- overrideLocalHost =
- AAIConfig.get(AAIConstants.AAI_LOCAL_OVERRIDE, AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT);
+ overrideLocalHost = AAIConfig.get(AAIConstants.AAI_LOCAL_OVERRIDE,
+ AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT);
}
if (AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT.equals(overrideLocalHost)) {
url = String.format(AAIConstants.AAI_LOCAL_REST, port,
@@ -330,18 +342,21 @@ public class RestController implements RestControllerInterface {
}
}
- ClientResponse cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
- .header("X-FromAppId", sourceID).header("Real-Time", "true").type("application/json").entity(t)
- .put(ClientResponse.class);
+ Response response = client.target(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header("X-TransactionId", transId)
+ .header("X-FromAppId", sourceID)
+ .header("Real-Time", "true")
+ .put(Entity.entity(t, MediaType.APPLICATION_JSON));
- // System.out.println("cres.tostring()="+cres.toString());
+ // System.out.println("response.tostring()="+response.toString());
- int statuscode = cres.getStatus();
+ int statuscode = response.getStatus();
if (statuscode >= 200 && statuscode <= 299) {
LOGGER.debug(methodName + ": url=" + url + ", request=" + path);
} else {
throw new AAIException("AAI_7116", methodName + " with status=" + statuscode + ", url=" + url + ", msg="
- + cres.getEntity(String.class));
+ + response.readEntity(String.class));
}
}
@@ -365,18 +380,21 @@ public class RestController implements RestControllerInterface {
url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + apiVersion + "/" + path;
- ClientResponse cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
- .header("X-FromAppId", sourceID).header("Real-Time", "true").type("application/json").entity(t)
- .put(ClientResponse.class);
+ Response response = client.target(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header("X-TransactionId", transId)
+ .header("X-FromAppId", sourceID)
+ .header("Real-Time", "true")
+ .put(Entity.entity(t, MediaType.APPLICATION_JSON));
- // System.out.println("cres.tostring()="+cres.toString());
+ // System.out.println("response.tostring()="+response.toString());
- int statuscode = cres.getStatus();
+ int statuscode = response.getStatus();
if (statuscode >= 200 && statuscode <= 299) {
LOGGER.debug(methodName + ": url=" + url + ", request=" + path);
} else {
throw new AAIException("AAI_7116", methodName + " with status=" + statuscode + ", url=" + url + ", msg="
- + cres.getEntity(String.class));
+ + response.getEntity());
}
}
@@ -410,16 +428,20 @@ public class RestController implements RestControllerInterface {
url = String.format(AAIConstants.AAI_LOCAL_REST_OVERRIDE, overrideLocalHost,
AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP)) + path;
}
- ClientResponse cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
- .header("X-FromAppId", sourceID).header("Real-Time", "true").type("application/json").entity(request)
- .delete(ClientResponse.class);
-
- if (cres.getStatus() == 404) { // resource not found
- LOGGER.info("Resource does not exist...: " + cres.getStatus() + ":" + cres.getEntity(String.class));
- } else if (cres.getStatus() == 200 || cres.getStatus() == 204) {
+ Response response = client.target(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header("X-TransactionId", transId)
+ .header("X-FromAppId", sourceID)
+ .header("Real-Time", "true")
+ .delete();
+
+ if (response.getStatus() == 404) { // resource not found
+ LOGGER.info(
+ "Resource does not exist...: " + response.getStatus() + ":" + response.readEntity(String.class));
+ } else if (response.getStatus() == 200 || response.getStatus() == 204) {
LOGGER.info("Resource " + url + " deleted");
} else {
- LOGGER.error("Deleting Resource failed: " + cres.getStatus() + ":" + cres.getEntity(String.class));
+ LOGGER.error("Deleting Resource failed: " + response.getStatus() + ":" + response.readEntity(String.class));
throw new AAIException("AAI_7116", "Error during DELETE");
}
}
@@ -451,17 +473,20 @@ public class RestController implements RestControllerInterface {
url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + apiVersion + "/" + path;
- ClientResponse cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
- .header("X-FromAppId", sourceID).header("Real-Time", "true").type("application/json").entity(t)
- .post(ClientResponse.class);
+ Response response = client.target(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header("X-TransactionId", transId)
+ .header("X-FromAppId", sourceID)
+ .header("Real-Time", "true")
+ .post(Entity.entity(t, MediaType.APPLICATION_JSON));
- int statuscode = cres.getStatus();
+ int statuscode = response.getStatus();
if (statuscode >= 200 && statuscode <= 299) {
LOGGER.debug(methodName + "REST api POST was successful!");
- return cres.getEntity(String.class);
+ return response.readEntity(String.class);
} else {
throw new AAIException("AAI_7116", methodName + " with status=" + statuscode + ", url=" + url + ", msg="
- + cres.getEntity(String.class));
+ + response.readEntity(String.class));
}
} catch (AAIException e) {
@@ -503,17 +528,17 @@ public class RestController implements RestControllerInterface {
*/
/*
* DoesResourceExist
- *
+ *
* To check whether a resource exist or get a copy of the existing version of the resource
- *
+ *
* Resourcepath: should contain the qualified resource path (including encoded unique key identifier value),
* resourceClassName: is the canonical name of the resource class name,
* fromAppId:
* transId:
- *
+ *
* Will return null (if the resource doesn’t exist) (or)
* Will return the specified resource from the Graph.
- *
+ *
* Example:
* LogicalLink llink = new LogicalLink();
* String resourceClassName = llink.getClass().getCanonicalName();
@@ -536,7 +561,7 @@ public class RestController implements RestControllerInterface {
} catch (AAIException e) {
- } catch (ClientHandlerException che) {
+ } catch (ClientErrorException che) {
} catch (Exception e) {
@@ -560,13 +585,13 @@ public class RestController implements RestControllerInterface {
transId += ":" + UUID.randomUUID().toString();
int numRetries = 5;
- ClientResponse cres = null;
+ Response response = null;
int statusCode = -1;
try {
if (overrideLocalHost == null) {
- overrideLocalHost =
- AAIConfig.get(AAIConstants.AAI_LOCAL_OVERRIDE, AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT);
+ overrideLocalHost = AAIConfig.get(AAIConstants.AAI_LOCAL_OVERRIDE,
+ AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT);
}
if (AAIConstants.AAI_LOCAL_OVERRIDE_DEFAULT.equals(overrideLocalHost)) {
url = String.format(AAIConstants.AAI_LOCAL_REST, AAIConstants.AAI_RESOURCES_PORT,
@@ -578,11 +603,14 @@ public class RestController implements RestControllerInterface {
do {
- cres = client.resource(url).accept("application/json").header("X-TransactionId", transId)
- .header("X-FromAppId", sourceID).header("X-HTTP-Method-Override", "PATCH")
- .type("application/merge-patch+json").entity(t).post(ClientResponse.class);
+ response = client.target(url)
+ .request(MediaType.APPLICATION_JSON)
+ .header("X-TransactionId", transId)
+ .header("X-FromAppId", sourceID)
+ .header("X-HTTP-Method-Override", "PATCH")
+ .post(Entity.entity(t, "application/merge-patch+json"));
- statusCode = cres.getStatus();
+ statusCode = response.getStatus();
if (statusCode >= 200 && statusCode <= 299) {
LOGGER.debug(methodName + "REST api PATCH was successful!");
@@ -598,7 +626,7 @@ public class RestController implements RestControllerInterface {
LOGGER.debug(methodName + "Unable to make the patch request to url " + url + " even after trying = "
+ numRetries + " times.");
throw new AAIException("AAI_7116", methodName + " with status=" + statusCode + ", url=" + url + ", msg="
- + cres.getEntity(String.class));
+ + response.readEntity(String.class));
} catch (AAIException e) {
throw new AAIException("AAI_7116", methodName + " with url=" + url + ", Exception: " + e.toString());
diff --git a/aai-els-onap-logging/pom.xml b/aai-els-onap-logging/pom.xml
index 1f7cec5c..bf4c00f3 100644
--- a/aai-els-onap-logging/pom.xml
+++ b/aai-els-onap-logging/pom.xml
@@ -123,7 +123,7 @@
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
- <groupId>com.sun.jersey</groupId>
+ <groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
</dependency>
<dependency>
@@ -165,17 +165,4 @@
</exclusions>
</dependency>
</dependencies>
-
- <!-- <build>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- </plugin>
- </plugins>
- </build> -->
</project>
diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptor.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientRequestLoggingInterceptor.java
index c09023d1..7a90aff0 100644
--- a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptor.java
+++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientRequestLoggingInterceptor.java
@@ -20,57 +20,39 @@
package org.onap.aai.aailog.filter;
-import com.sun.jersey.api.client.ClientHandler;
-import com.sun.jersey.api.client.ClientHandlerException;
-import com.sun.jersey.api.client.ClientRequest;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.filter.ClientFilter;
-
+import java.io.IOException;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;
import javax.ws.rs.core.MultivaluedMap;
-
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientRequestFilter;
+import org.glassfish.jersey.client.ClientResponse;
import org.onap.aai.aailog.logs.ServiceName;
import org.onap.logging.filter.base.Constants;
import org.onap.logging.filter.base.MDCSetup;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.slf4j.*;
-public class RestControllerClientLoggingInterceptor extends ClientFilter {
- private static final Logger logger = LoggerFactory.getLogger(RestControllerClientLoggingInterceptor.class);
+public class RestControllerClientRequestLoggingInterceptor implements ClientRequestFilter {
+ private static final Logger logger = LoggerFactory.getLogger(RestControllerClientRequestLoggingInterceptor.class);
private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN");
private final MDCSetup mdcSetup;
private final String partnerName;
- public RestControllerClientLoggingInterceptor() {
+ public RestControllerClientRequestLoggingInterceptor() {
mdcSetup = new MDCSetup();
partnerName = getPartnerName();
}
- @Override
- public ClientResponse handle(ClientRequest clientRequest) throws ClientHandlerException {
- ClientResponse clientResponse = null;
- pre(clientRequest);
- // Call the next client handler in the filter chain
- ClientHandler nextHandler = getNext();
- if (nextHandler != null) {
- clientResponse = nextHandler.handle(clientRequest);
- }
- if (clientResponse != null) {
- post(clientResponse);
- }
- return clientResponse;
- }
-
- protected String getTargetServiceName(ClientRequest clientRequest) {
- return getServiceName(clientRequest);
+ protected String getTargetServiceName(ClientRequestContext requestContext) {
+ return getServiceName(requestContext);
}
- protected String getServiceName(ClientRequest clientRequest) {
- String path = clientRequest.getURI().getRawPath();
+ protected String getServiceName(ClientRequestContext requestContext) {
+ String path = requestContext.getUri().getRawPath();
return ServiceName.extractServiceName(path);
}
@@ -82,24 +64,29 @@ public class RestControllerClientLoggingInterceptor extends ClientFilter {
return String.valueOf(clientResponse.getStatus());
}
- protected String getTargetEntity(ClientRequest ClientRequest) {
+ protected String getTargetEntity(ClientRequestContext requestContext) {
return Constants.DefaultValues.UNKNOWN_TARGET_ENTITY;
};
- protected void pre(ClientRequest clientRequest) {
+ @Override
+ public void filter(ClientRequestContext requestContext) throws IOException {
+ pre(requestContext);
+ }
+
+ protected void pre(ClientRequestContext requestContext) {
try {
- setInvocationId(clientRequest);
- setupMDC(clientRequest);
- setupHeaders(clientRequest);
+ setInvocationId(requestContext);
+ setupMDC(requestContext);
+ setupHeaders(requestContext);
logger.info(ONAPLogConstants.Markers.INVOKE, "Invoke");
} catch (Exception e) {
logger.warn("Error in RestControllerClientLoggingInterceptor pre", e.getMessage());
}
}
- public void setInvocationId(ClientRequest clientRequest) {
+ public void setInvocationId(ClientRequestContext requestContext) {
String invocationId = null;
- MultivaluedMap<String, Object> requestHeaders = clientRequest.getHeaders();
+ MultivaluedMap<String, Object> requestHeaders = requestContext.getHeaders();
Object id = requestHeaders.get(ONAPLogConstants.Headers.INVOCATION_ID);
if (id != null) {
invocationId = (String) id;
@@ -111,9 +98,9 @@ public class RestControllerClientLoggingInterceptor extends ClientFilter {
MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
}
- protected void setupHeaders(ClientRequest clientRequest) {
- String requestId = extractRequestID(clientRequest);
- MultivaluedMap<String, Object> requestHeaders = clientRequest.getHeaders();
+ protected void setupHeaders(ClientRequestContext requestContext) {
+ String requestId = extractRequestID(requestContext);
+ MultivaluedMap<String, Object> requestHeaders = requestContext.getHeaders();
addHeader(requestHeaders, ONAPLogConstants.Headers.REQUEST_ID, requestId);
addHeader(requestHeaders, Constants.HttpHeaders.HEADER_REQUEST_ID, requestId);
Object requestIdObj = requestHeaders.getFirst(Constants.HttpHeaders.TRANSACTION_ID);
@@ -127,15 +114,15 @@ public class RestControllerClientLoggingInterceptor extends ClientFilter {
}
}
- protected void setupMDC(ClientRequest clientRequest) {
+ protected void setupMDC(ClientRequestContext requestContext) {
MDC.put(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP,
ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT));
- MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, getTargetServiceName(clientRequest));
+ MDC.put(ONAPLogConstants.MDCs.TARGET_SERVICE_NAME, getTargetServiceName(requestContext));
MDC.put(ONAPLogConstants.MDCs.RESPONSE_STATUS_CODE, ONAPLogConstants.ResponseStatus.INPROGRESS.toString());
mdcSetup.setInvocationIdFromMDC();
if (MDC.get(ONAPLogConstants.MDCs.TARGET_ENTITY) == null) {
- String targetEntity = getTargetEntity(clientRequest);
+ String targetEntity = getTargetEntity(requestContext);
if (targetEntity != null) {
MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, targetEntity);
} else {
@@ -144,15 +131,15 @@ public class RestControllerClientLoggingInterceptor extends ClientFilter {
}
if (MDC.get(ONAPLogConstants.MDCs.SERVICE_NAME) == null) {
- MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, getServiceName(clientRequest));
+ MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, getServiceName(requestContext));
}
mdcSetup.setServerFQDN();
}
- protected String extractRequestID(ClientRequest clientRequest) {
+ protected String extractRequestID(ClientRequestContext requestContext) {
String requestId = MDC.get(ONAPLogConstants.MDCs.REQUEST_ID);
if (requestId == null || requestId.isEmpty()) {
- MultivaluedMap<String, Object> requestHeaders = clientRequest.getHeaders();
+ MultivaluedMap<String, Object> requestHeaders = requestContext.getHeaders();
Object requestIdObj = requestHeaders.getFirst(Constants.HttpHeaders.TRANSACTION_ID);
if (requestIdObj != null) {
requestId = (String) requestIdObj;
diff --git a/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientResponseLoggingInterceptor.java b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientResponseLoggingInterceptor.java
new file mode 100644
index 00000000..f35e9490
--- /dev/null
+++ b/aai-els-onap-logging/src/main/java/org/onap/aai/aailog/filter/RestControllerClientResponseLoggingInterceptor.java
@@ -0,0 +1,91 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.aai.aailog.filter;
+
+import java.io.IOException;
+import java.util.UUID;
+
+import javax.ws.rs.client.ClientRequestContext;
+import javax.ws.rs.client.ClientResponseContext;
+import javax.ws.rs.client.ClientResponseFilter;
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.onap.logging.filter.base.Constants;
+import org.onap.logging.filter.base.MDCSetup;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.slf4j.*;
+
+public class RestControllerClientResponseLoggingInterceptor implements ClientResponseFilter {
+ private static final Logger logger = LoggerFactory.getLogger(RestControllerClientRequestLoggingInterceptor.class);
+ private static final Marker INVOKE_RETURN = MarkerFactory.getMarker("INVOKE-RETURN");
+ private final MDCSetup mdcSetup;
+ private final String partnerName;
+
+ public RestControllerClientResponseLoggingInterceptor() {
+ mdcSetup = new MDCSetup();
+ partnerName = getPartnerName();
+ }
+
+ @Override
+ public void filter(ClientRequestContext requestContext, ClientResponseContext responseContext) throws IOException {
+ post(responseContext);
+ }
+
+ protected void post(ClientResponseContext responseContext) {
+ try {
+ mdcSetup.setLogTimestamp();
+ mdcSetup.setElapsedTimeInvokeTimestamp();
+ mdcSetup.setResponseStatusCode(getHttpStatusCode(responseContext));
+ mdcSetup.setResponseDescription(getHttpStatusCode(responseContext));
+ MDC.put(ONAPLogConstants.MDCs.RESPONSE_CODE, getResponseCode(responseContext));
+ logger.info(INVOKE_RETURN, "InvokeReturn");
+ mdcSetup.clearClientMDCs();
+ } catch (Exception e) {
+ logger.warn("Error in RestControllerClientLoggingInterceptor post", e.getMessage());
+ }
+ }
+
+ protected int getHttpStatusCode(ClientResponseContext responseContext) {
+ return responseContext.getStatus();
+ }
+
+ protected String getResponseCode(ClientResponseContext responseContext) {
+ return String.valueOf(responseContext.getStatus());
+ }
+
+ public void setInvocationId(ClientRequestContext requestContext) {
+ String invocationId = null;
+ MultivaluedMap<String, Object> requestHeaders = requestContext.getHeaders();
+ Object id = requestHeaders.get(ONAPLogConstants.Headers.INVOCATION_ID);
+ if (id != null) {
+ invocationId = (String) id;
+ }
+ requestHeaders.remove(ONAPLogConstants.Headers.INVOCATION_ID);
+ if (invocationId == null) {
+ invocationId = UUID.randomUUID().toString();
+ }
+ MDC.put(ONAPLogConstants.MDCs.INVOCATION_ID, invocationId);
+ }
+
+ protected String getPartnerName() {
+ return mdcSetup.getProperty(Constants.Property.PARTNER_NAME);
+ }
+}
diff --git a/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptorTest.java b/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptorTest.java
index 9c4b2655..84e032d8 100644
--- a/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptorTest.java
+++ b/aai-els-onap-logging/src/test/java/org/onap/aai/aailog/filter/RestControllerClientLoggingInterceptorTest.java
@@ -22,14 +22,14 @@ package org.onap.aai.aailog.filter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-
-import com.sun.jersey.api.client.ClientRequest;
+import static org.mockito.Mockito.when;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
+import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
@@ -38,6 +38,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
+import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.logging.filter.base.Constants;
@@ -47,17 +48,24 @@ import org.slf4j.MDC;
@RunWith(MockitoJUnitRunner.class)
public class RestControllerClientLoggingInterceptorTest {
- private ClientRequest clientRequest;
+ @Spy
+ private ClientRequestContext clientRequest;
@Spy
@InjectMocks
- private RestControllerClientLoggingInterceptor restControllerClientLoggingInterceptor;
+ private RestControllerClientRequestLoggingInterceptor restControllerClientLoggingInterceptor;
@Before
public void init() throws URISyntaxException {
System.setProperty("javax.ws.rs.ext.RuntimeDelegate", "com.sun.ws.rs.ext.RuntimeDelegateImpl");
- clientRequest = ClientRequest.create().build(
- new URI("https://localhost:9999/aai/v1/cloud-infrastructure/complexes/complex/complex-1"), "GET");
+ when(clientRequest.getHeaders()).thenReturn(new MultivaluedHashMap<String, Object>());
+ when(clientRequest.getUri())
+ .thenReturn(new URI("https://localhost:9999/aai/v1/cloud-infrastructure/complexes/complex/complex-1"));
+
+ // clientRequest = ClientRequest.create().build(
+ // new
+ // URI("https://localhost:9999/aai/v1/cloud-infrastructure/complexes/complex/complex-1"),
+ // "GET");
}
@After
@@ -71,6 +79,10 @@ public class RestControllerClientLoggingInterceptorTest {
String transId = "37b3ab2a-e57e-4fe8-8d8f-eee3019efce6";
MultivaluedMap<String, Object> requestHeaders = new MultivaluedHashMap<String, Object>();
requestHeaders.add(Constants.HttpHeaders.TRANSACTION_ID, transId);
+ when(clientRequest.getHeaders()).thenReturn(requestHeaders);
+ when(clientRequest.getUri())
+ .thenReturn(new URI("https://localhost:9999/aai/v1/cloud-infrastructure/complexes/complex/complex-1"));
+
clientRequest.getHeaders().putAll(requestHeaders);
restControllerClientLoggingInterceptor.pre(clientRequest);
MultivaluedMap<String, Object> headers = clientRequest.getHeaders();
diff --git a/aai-parent/pom.xml b/aai-parent/pom.xml
index d9a80223..d9b0c6ad 100644
--- a/aai-parent/pom.xml
+++ b/aai-parent/pom.xml
@@ -52,7 +52,7 @@ limitations under the License.
<commons.compress.version>1.27.0</commons.compress.version>
<commons.configuration.version>1.10</commons.configuration.version>
<commons.io.version>2.16.1</commons.io.version>
- <commons.lang3.version>3.9</commons.lang3.version>
+ <commons.lang3.version>3.15.0</commons.lang3.version>
<commons.net.version>3.8.0</commons.net.version>
<commons.text.version>1.10.0</commons.text.version>
<docker.fabric.version>0.40.2</docker.fabric.version>
@@ -72,7 +72,6 @@ limitations under the License.
<old.jaxb.version>2.3.0.1</old.jaxb.version>
<jaxrs.version>2.1.1</jaxrs.version>
<jcommander.version>1.78</jcommander.version>
- <jersey.version>1.19.4</jersey.version>
<jnr.ffi.version>2.2.12</jnr.ffi.version>
<jolt.version>0.1.7</jolt.version>
<jopt.simple.version>5.0.4</jopt.simple.version>
@@ -496,24 +495,6 @@ limitations under the License.
</dependency>
<dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-core</artifactId>
- <version>${jersey.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-client</artifactId>
- <version>${jersey.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.sun.jersey</groupId>
- <artifactId>jersey-json</artifactId>
- <version>${jersey.version}</version>
- </dependency>
-
- <dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>${jaxrs.version}</version>