From 83559ddc77a0217391212f2abcdcba2c3ff56937 Mon Sep 17 00:00:00 2001 From: "Agarwal, Ruchira (ra1926)" Date: Tue, 5 Nov 2019 18:16:50 +0000 Subject: minor updates to clean up code clean up code to sync with internal Issue-ID: CCSDK-1873 Signed-off-by: Agarwal, Ruchira (ra1926) Change-Id: Idcc7186d5aaa783c527de3986e7a1ecd9bfcf651 --- aai-service/provider/pom.xml | 8 ++---- .../org/onap/ccsdk/sli/adaptors/aai/AAIClient.java | 5 +++- .../ccsdk/sli/adaptors/aai/AAIDeclarations.java | 1 + .../ccsdk/sli/adaptors/aai/GenericRequest.java | 10 +++++--- .../ccsdk/sli/adaptors/aai/EchoRequestTest.java | 22 ++++++++++++++++ ansible-adapter/ansible-adapter-bundle/pom.xml | 2 ++ .../ccsdk-ansible-adapter/pom.xml | 1 + base/http/provider/pom.xml | 1 - .../sli/adaptors/base/http/BasicAuthFilter.java | 6 ++--- .../adaptors/base/http/BasicAuthFilterTest.java | 2 +- .../features/ccsdk-mdsal-resource/pom.xml | 1 + .../sli/adaptors/resource/mdsal/RestService.java | 5 +++- netbox-client/features/ccsdk-netbox-client/pom.xml | 8 ++---- netbox-client/provider/pom.xml | 8 +++--- .../sli/adaptors/resource/sql/SqlResource.java | 29 +++++++++++++--------- 15 files changed, 70 insertions(+), 39 deletions(-) diff --git a/aai-service/provider/pom.xml b/aai-service/provider/pom.xml index 9650087e5..f63bc424e 100755 --- a/aai-service/provider/pom.xml +++ b/aai-service/provider/pom.xml @@ -96,10 +96,6 @@ org.springframework spring-core test - - - org.apache.httpcomponents - httpcore org.apache.httpcomponents @@ -112,7 +108,7 @@ org.jvnet.jaxb2.maven2 maven-jaxb2-plugin - 0.13.1 + 0.14.0 gen-xjc @@ -139,7 +135,7 @@ org.jvnet.jaxb2_commons jaxb2-basics-annotate - 0.6.4 + 0.6.5 diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java index 4b4c439a9..28b4955a4 100755 --- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java +++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIClient.java @@ -37,6 +37,9 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin; import org.onap.ccsdk.sli.core.sli.SvcLogicResource; import org.onap.ccsdk.sli.adaptors.aai.data.notify.NotifyEvent; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + public interface AAIClient extends SvcLogicResource, SvcLogicJavaPlugin { public SearchResults requestServiceInstanceURL(String svcInstanceId) throws AAIServiceException; @@ -76,7 +79,7 @@ public interface AAIClient extends SvcLogicResource, SvcLogicJavaPlugin { public void logKeyError(String keys); - public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, Map nameValues, String modifier) throws IOException, AAIServiceException ; + public QueryStatus processResponseData(String rv, String resource, AAIRequest request, String prefix, SvcLogicContext ctx, Map nameValues, String modifier) throws JsonParseException, JsonMappingException, IOException, AAIServiceException ; public String getPathTemplateForResource(String resoourceName, String join, SvcLogicContext ctx) throws MalformedURLException; public boolean isDeprecatedFormat(String resource, Map nameValues); diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java index c57b3a45d..8b8aaaab6 100755 --- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java +++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIDeclarations.java @@ -1636,6 +1636,7 @@ public abstract class AAIDeclarations implements AAIClient { try { obj = getMetadataMethod.invoke(instance); } catch (InvocationTargetException x) { + Throwable cause = x.getCause(); } } if(obj != null && obj instanceof Metadata){ diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/GenericRequest.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/GenericRequest.java index 7c6234e5c..7f15c03f5 100755 --- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/GenericRequest.java +++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/GenericRequest.java @@ -189,9 +189,13 @@ public class GenericRequest extends AAIRequest { queryParams.put(splitKey[1], encodeQuery(value)); } else { - String token = String.format("%s/{%s}", splitKey[0], splitKey[1]); - String encoded_vnf = encodeQuery(value); - request_url = request_url.replace(token, String.format("%s/%s", splitKey[0], encoded_vnf)); + String encoded_vnf = encodeQuery(value); + if(!resourceName.equals(splitKey[0]) && resourceName.contains(splitKey[0])) { + queryParams.put(splitKey[1], encoded_vnf); + } else { + String token = String.format("%s/{%s}", splitKey[0], splitKey[1]); + request_url = request_url.replace(token, String.format("%s/%s", splitKey[0], encoded_vnf)); + } } } diff --git a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/EchoRequestTest.java b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/EchoRequestTest.java index 69541301b..3e0a72f3a 100755 --- a/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/EchoRequestTest.java +++ b/aai-service/provider/src/test/java/org/onap/ccsdk/sli/adaptors/aai/EchoRequestTest.java @@ -34,6 +34,8 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import org.onap.ccsdk.sli.adaptors.aai.data.AAIDatum; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -111,4 +113,24 @@ public class EchoRequestTest { } } + +// @Test + public void EchoTest() { + LOG.info("----------------------- Test: " + new Object(){}.getClass().getEnclosingMethod().getName() + " -----------------------"); + try + { + SvcLogicContext ctx = new SvcLogicContext(); + + QueryStatus resp = null; + +// (String resource, boolean localOnly, String select, String key, String prefix, String orderBy, SvcLogicContext ctx) + resp = aaiService.query("echo", false, null, "", "aaidata", null, ctx); + assert(resp == QueryStatus.SUCCESS); + } + catch (Throwable e) + { + LOG.error("Caught exception", e); +// fail("Caught exception"); + } + } } diff --git a/ansible-adapter/ansible-adapter-bundle/pom.xml b/ansible-adapter/ansible-adapter-bundle/pom.xml index c73018b28..614fe6d57 100644 --- a/ansible-adapter/ansible-adapter-bundle/pom.xml +++ b/ansible-adapter/ansible-adapter-bundle/pom.xml @@ -90,11 +90,13 @@ org.onap.ccsdk.sli.core sli-common + provided org.onap.ccsdk.sli.core sli-provider + provided diff --git a/ansible-adapter/ansible-adapter-features/ccsdk-ansible-adapter/pom.xml b/ansible-adapter/ansible-adapter-features/ccsdk-ansible-adapter/pom.xml index bf0b5b543..523d45069 100644 --- a/ansible-adapter/ansible-adapter-features/ccsdk-ansible-adapter/pom.xml +++ b/ansible-adapter/ansible-adapter-features/ccsdk-ansible-adapter/pom.xml @@ -28,6 +28,7 @@ ${ccsdk.sli.core.version} xml features + provided diff --git a/base/http/provider/pom.xml b/base/http/provider/pom.xml index aabeca268..642238cd2 100644 --- a/base/http/provider/pom.xml +++ b/base/http/provider/pom.xml @@ -28,7 +28,6 @@ org.glassfish.jersey.core jersey-client - ${jersey.version} test diff --git a/base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilter.java b/base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilter.java index 48d996ef3..5d3d463c9 100644 --- a/base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilter.java +++ b/base/http/provider/src/main/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilter.java @@ -6,13 +6,9 @@ import javax.ws.rs.client.ClientRequestContext; import javax.ws.rs.client.ClientRequestFilter; import javax.ws.rs.core.MultivaluedMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class BasicAuthFilter implements ClientRequestFilter { private final String basicAuthValue; - public BasicAuthFilter(String basicAuthValue) { this.basicAuthValue = basicAuthValue; } @@ -21,4 +17,6 @@ public class BasicAuthFilter implements ClientRequestFilter { MultivaluedMap headers = requestContext.getHeaders(); headers.add("Authorization", basicAuthValue); } + + } diff --git a/base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilterTest.java b/base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilterTest.java index b9565ba67..d9d552dac 100644 --- a/base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilterTest.java +++ b/base/http/provider/src/test/java/org/onap/ccsdk/sli/adaptors/base/http/BasicAuthFilterTest.java @@ -8,7 +8,7 @@ public class BasicAuthFilterTest { @Test public void notNullParameters() throws Exception { - BasicAuthFilter myFilter = new BasicAuthFilter("helloworld"); + BasicAuthFilter myFilter = new BasicAuthFilter("hello"); assertNotNull(myFilter); } diff --git a/mdsal-resource/features/ccsdk-mdsal-resource/pom.xml b/mdsal-resource/features/ccsdk-mdsal-resource/pom.xml index 41b0ef326..ab512ed63 100644 --- a/mdsal-resource/features/ccsdk-mdsal-resource/pom.xml +++ b/mdsal-resource/features/ccsdk-mdsal-resource/pom.xml @@ -29,6 +29,7 @@ ${ccsdk.sli.core.version} xml features + provided diff --git a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java index 2991e6bef..30859a492 100644 --- a/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java +++ b/mdsal-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/mdsal/RestService.java @@ -34,6 +34,7 @@ import java.net.URL; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSession; +import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -180,9 +181,11 @@ public class RestService { LOG.info("Response body :\n"+respString); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); + dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); DocumentBuilder db = dbf.newDocumentBuilder(); - response = db.parse(new ByteArrayInputStream(respString.getBytes())); } catch (Exception e) { diff --git a/netbox-client/features/ccsdk-netbox-client/pom.xml b/netbox-client/features/ccsdk-netbox-client/pom.xml index e006b1976..13dc8bf97 100644 --- a/netbox-client/features/ccsdk-netbox-client/pom.xml +++ b/netbox-client/features/ccsdk-netbox-client/pom.xml @@ -38,12 +38,6 @@ - - org.opendaylight.controller - odl-mdsal-broker - xml - features - org.onap.ccsdk.sli.core @@ -51,6 +45,7 @@ ${ccsdk.sli.core.version} xml features + provided @@ -59,6 +54,7 @@ ${ccsdk.sli.core.version} xml features + provided diff --git a/netbox-client/provider/pom.xml b/netbox-client/provider/pom.xml index 475eeb593..b8fa494ad 100644 --- a/netbox-client/provider/pom.xml +++ b/netbox-client/provider/pom.xml @@ -71,13 +71,13 @@ org.onap.ccsdk.sli.core sli-common - compile + provided org.onap.ccsdk.sli.core sliPluginUtils-provider - ${project.version} - compile + ${ccsdk.sli.core.version} + provided org.osgi @@ -101,7 +101,7 @@ com.github.tomakehurst wiremock - 2.23.2 + 2.23.2 test diff --git a/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java b/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java index 767fdac79..69965d101 100755 --- a/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java +++ b/sql-resource/provider/src/main/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResource.java @@ -100,7 +100,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { return (QueryStatus.FAILURE); } - String theStmt = resolveCtxVars(key, ctx); + String theStmt = resolveCtxVars(key, ctx, resource); try { CachedRowSet results = dblibSvc.getData(theStmt, null, null); @@ -131,8 +131,9 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { if (dblibSvc == null) { return (QueryStatus.FAILURE); } + + String sqlQuery = resolveCtxVars(key, ctx, resource); - String sqlQuery = resolveCtxVars(key, ctx); try { @@ -230,7 +231,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { return (QueryStatus.FAILURE); } - String sqlStmt = resolveCtxVars(key, ctx); + String sqlStmt = resolveCtxVars(key, ctx, ""); LOG.debug("key = [" + key + "]; sqlStmt = [" + sqlStmt + "]"); try { @@ -247,7 +248,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { } - private String resolveCtxVars(String key, SvcLogicContext ctx) { + private String resolveCtxVars(String key, SvcLogicContext ctx, String resource) { if (key == null) { return (null); } @@ -257,16 +258,20 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { LOG.debug("Stripped outer single quotes - key is now [" + key + "]"); } - String[] keyTerms = key.split("\\s+"); + //"SQL-TRUE" allows for the key to be used as is. + if (!resource.equals("SQL-TRUE")) { + String[] keyTerms = key.split("\\s+"); - StringBuffer sqlBuffer = new StringBuffer(); + StringBuffer sqlBuffer = new StringBuffer(); - for (int i = 0; i < keyTerms.length; i++) { - sqlBuffer.append(resolveTerm(keyTerms[i], ctx)); - sqlBuffer.append(" "); - } + for (int i = 0; i < keyTerms.length; i++) { + sqlBuffer.append(resolveTerm(keyTerms[i], ctx)); + sqlBuffer.append(" "); + } + key = sqlBuffer.toString(); + } - return (sqlBuffer.toString()); + return (key); } private String resolveTerm(String term, SvcLogicContext ctx) { @@ -441,7 +446,7 @@ public class SqlResource implements SvcLogicResource, SvcLogicJavaPlugin { return (strValue); } else { ResultSet results = null; - try (Connection conn = dblibSvc.getConnection(); + try (Connection conn = dblibSvc.getConnection(); PreparedStatement stmt = conn.prepareStatement("SELECT CAST(AES_DECRYPT(?, ?) AS CHAR(50)) FROM DUAL")) { stmt.setBytes(1, colValue); -- cgit 1.2.3-korg