diff options
author | Stan Bonev <sb5356@att.com> | 2019-05-06 10:09:48 -0400 |
---|---|---|
committer | Stan Bonev <sb5356@att.com> | 2019-05-06 10:09:48 -0400 |
commit | a8287a9b4c1b679e04307669fffee6eb1d5f4ab5 (patch) | |
tree | f3235679666c72d4aa9e7f7f2e2a76ffb48cfbb2 /restapi-call-node/provider | |
parent | ce7259104a94bbbffdeff508c61d23ac8132c157 (diff) |
Restapi: DELETE with payload doesn't work
Change-Id: I50eeea493197010aba4b37af97dcedb446ed5d10
Issue-ID: CCSDK-1305
Signed-off-by: Stan Bonev <sb5356@att.com>
Diffstat (limited to 'restapi-call-node/provider')
2 files changed, 64 insertions, 42 deletions
diff --git a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java index a7235fcb5..9b50eaa44 100644 --- a/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java +++ b/restapi-call-node/provider/src/main/java/org/onap/ccsdk/sli/plugins/restapicall/RestapiCallNode.java @@ -25,7 +25,6 @@ package org.onap.ccsdk.sli.plugins.restapicall; import static java.lang.Boolean.valueOf; import static javax.ws.rs.client.Entity.entity; import static org.onap.ccsdk.sli.plugins.restapicall.AuthType.fromString; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -52,8 +51,12 @@ import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Entity; import javax.ws.rs.client.Invocation; import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.*; - +import javax.ws.rs.core.EntityTag; +import javax.ws.rs.core.Feature; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; import org.apache.commons.lang3.StringUtils; import org.glassfish.jersey.client.ClientProperties; import org.glassfish.jersey.client.HttpUrlConnectorProvider; @@ -94,8 +97,8 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { try (FileInputStream in = new FileInputStream(configDir + "/" + DME2_PROPERTIES_FILE_NAME)) { Properties props = new Properties(); props.load(in); - this.retryPolicyStore = new RetryPolicyStore(); - this.retryPolicyStore.setProxyServers(props.getProperty("proxyUrl")); + retryPolicyStore = new RetryPolicyStore(); + retryPolicyStore.setProxyServers(props.getProperty("proxyUrl")); log.info("DME2 support enabled"); } catch (Exception e) { log.warn("DME2 properties could not be read, DME2 support will not be enabled.", e); @@ -104,7 +107,7 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { try (FileInputStream in = new FileInputStream(configDir + "/" + UEB_PROPERTIES_FILE_NAME)) { Properties props = new Properties(); props.load(in); - this.uebServers = props.getProperty("servers"); + uebServers = props.getProperty("servers"); log.info("UEB support enabled"); } catch (Exception e) { log.warn("UEB properties could not be read, UEB support will not be enabled.", e); @@ -462,7 +465,7 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { } long t2 = System.currentTimeMillis(); - log.info("Building {} completed. Time: {}", format, (t2 - t1)); + log.info("Building {} completed. Time: {}", format, t2 - t1); return req; } @@ -669,6 +672,8 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { invocationBuilder.header("X-ECOMP-RequestID", org.slf4j.MDC.get("X-ECOMP-RequestID")); + invocationBuilder.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true); + Response response; try { @@ -739,7 +744,7 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { } long t2 = System.currentTimeMillis(); - log.info(responseReceivedMessage, (t2 - t1)); + log.info(responseReceivedMessage, t2 - t1); log.info(responseHttpCodeMessage, r.code); log.info("HTTP response message: {}", r.message); logHeaders(r.headers); @@ -942,7 +947,7 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { } long t2 = System.currentTimeMillis(); - log.info(responseReceivedMessage, (t2 - t1)); + log.info(responseReceivedMessage, t2 - t1); log.info(responseHttpCodeMessage, r.code); log.info("HTTP response message: {}", r.message); logHeaders(r.headers); @@ -1035,7 +1040,7 @@ public class RestapiCallNode implements SvcLogicJavaPlugin { } long t2 = System.currentTimeMillis(); - log.info(responseReceivedMessage, (t2 - t1)); + log.info(responseReceivedMessage, t2 - t1); log.info(responseHttpCodeMessage, r.code); logHeaders(r.headers); log.info("HTTP response:\n {}", r.body); diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java index 52da46157..3752a9c3f 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java @@ -21,23 +21,21 @@ package jtest.org.onap.ccsdk.sli.plugins.restapicall; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; import java.net.URI; import java.util.HashMap; import java.util.Map; - import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.glassfish.jersey.server.ResourceConfig; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.glassfish.jersey.server.ResourceConfig; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; public class TestRestapiCallNode { @@ -48,7 +46,26 @@ public class TestRestapiCallNode { public void testDelete() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); + p.put("restapiUrl", "https://echo.getpostman.com/delete"); + p.put("restapiUser", "user1"); + p.put("restapiPassword", "pwd1"); + p.put("httpMethod", "delete"); + p.put("skipSending", "true"); + + RestapiCallNode rcn = new RestapiCallNode(); + rcn.sendRequest(p, ctx); + } + + @Test + public void testDeleteWithPayload() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + ctx.setAttribute("prop.name", "site1"); + + + Map<String, String> p = new HashMap<>(); + p.put("templateFileName", "src/test/resources/sdwan-site.json"); p.put("restapiUrl", "https://echo.getpostman.com/delete"); p.put("restapiUser", "user1"); p.put("restapiPassword", "pwd1"); @@ -79,7 +96,7 @@ public class TestRestapiCallNode { ctx.setAttribute("prop.siteAttachement[1].roles_length", "1"); ctx.setAttribute("prop.siteAttachement[1].roles[0]", "role2"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/sdwan-vpn-topology.json"); p.put("restapiUrl", "http://echo.getpostman.com"); p.put("restapiUser", "user1"); @@ -100,7 +117,7 @@ public class TestRestapiCallNode { ctx.setAttribute("prop.name", "site1"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/sdwan-site.json"); p.put("restapiUrl", "http://echo.getpostman.com"); p.put("restapiUser", "user1"); @@ -140,7 +157,7 @@ public class TestRestapiCallNode { ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1"); ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/test-template.json"); p.put("restapiUrl", "http://echo.getpostman.com"); p.put("restapiUser", "user1"); @@ -166,7 +183,7 @@ public class TestRestapiCallNode { ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1"); ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/test-template.json"); p.put("restapiUrl", "http://echo.getpostman.com"); p.put("restapiUser", "user1"); @@ -192,7 +209,7 @@ public class TestRestapiCallNode { ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1"); ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resourcess/test-template.json"); p.put("restapiUrl", "http://echo.getpostman.com"); p.put("restapiUser", "user1"); @@ -218,7 +235,7 @@ public class TestRestapiCallNode { ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1"); ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/test-template.json"); p.put("restapiUrl", "http://echo.getpostman.com"); p.put("restapiUser", "user1"); @@ -244,7 +261,7 @@ public class TestRestapiCallNode { ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1"); ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/test-template.json"); p.put("restapiUrl", "http://echo.getpostman.com"); p.put("restapiUser", "user1"); @@ -272,7 +289,7 @@ public class TestRestapiCallNode { ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1"); ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/test-template.json"); p.put("restapiUrl", "http://echo. getpostman.com"); p.put("restapiUser", "user1"); @@ -292,7 +309,7 @@ public class TestRestapiCallNode { ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001"); ctx.setAttribute("prop.l3vpn.topology", "point_to_point"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/l3smvpntemplate.json"); p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services"); p.put("restapiUser", "admin"); @@ -338,7 +355,7 @@ public class TestRestapiCallNode { ctx.setAttribute("prop.l3vpn.peer2-ip", "192.168.1.7"); ctx.setAttribute("prop.l3vpn.ac2_protocol_bgp_as", "200"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/l3smsitetemplate.json"); p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites"); p.put("restapiUser", "admin"); @@ -362,7 +379,7 @@ public class TestRestapiCallNode { ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006"); ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/l3smvrftemplate.json"); p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vrf-attributes"); p.put("restapiUser", "admin"); @@ -382,7 +399,7 @@ public class TestRestapiCallNode { ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001"); ctx.setAttribute("prop.l3vpn.topology", "point_to_point"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); //p.put("templateFileName", "src/test/resources/l3smvpntemplate.json"); p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services" + "/vpnservice=10000000-0000-0000-0000-000000000001"); @@ -410,7 +427,7 @@ public class TestRestapiCallNode { ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2"); ctx.setAttribute("prop.dci-connects.vni", "1"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json"); p.put("restapiUrl", "http://echo.getpostman.com"); p.put("restapiUser", "user1"); @@ -438,7 +455,7 @@ public class TestRestapiCallNode { ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2"); ctx.setAttribute("prop.dci-connects.vni", "1"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json"); p.put("restapiUrl", "http://echo.getpostman.com"); p.put("restapiUser", "user1"); @@ -459,7 +476,7 @@ public class TestRestapiCallNode { ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.user", "admin"); ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.password", "admin123"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/actokentemplate.json"); p.put("restapiUrl", "https://ipwan:18002/controller/v2/tokens"); p.put("format", "json"); @@ -476,7 +493,7 @@ public class TestRestapiCallNode { public void testDeleteNoneAsContentType() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("restapiUrl", "https://echo.getpostman.com/delete"); p.put("restapiUser", "user1"); p.put("restapiPassword", "pwd1"); @@ -494,7 +511,7 @@ public class TestRestapiCallNode { ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001"); ctx.setAttribute("prop.l3vpn.topology", "point_to_point"); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("templateFileName", "src/test/resources/l3smvpntemplate.json"); p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services"); p.put("restapiUser", "admin"); @@ -512,7 +529,7 @@ public class TestRestapiCallNode { public void testDeleteOAuthType() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("restapiUrl", "https://echo.getpostman.com/delete"); p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3"); p.put("oAuthConsumerSecret", "secret"); @@ -530,7 +547,7 @@ public class TestRestapiCallNode { public void testDeleteAuthTypeBasic() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("restapiUrl", "https://echo.getpostman.com/delete"); p.put("authType", "basic"); p.put("restapiUser", "admin"); @@ -547,7 +564,7 @@ public class TestRestapiCallNode { public void testDeleteAuthTypeDigest() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("restapiUrl", "https://echo.getpostman.com/delete"); p.put("authType", "digest"); p.put("restapiUser", "admin"); @@ -564,7 +581,7 @@ public class TestRestapiCallNode { public void testDeleteAuthTypeOAuth() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("restapiUrl", "https://echo.getpostman.com/delete"); p.put("authType", "oauth"); p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3"); @@ -583,7 +600,7 @@ public class TestRestapiCallNode { public void testDeleteAuthTypeNoneOAuth() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("restapiUrl", "https://echo.getpostman.com/delete"); p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3"); p.put("oAuthConsumerSecret", "secret"); @@ -600,7 +617,7 @@ public class TestRestapiCallNode { public void testDeleteAuthTypeNoneBasic() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("restapiUrl", "https://echo.getpostman.com/delete"); p.put("restapiUser", "admin"); p.put("restapiPassword", "admin123"); @@ -616,7 +633,7 @@ public class TestRestapiCallNode { public void testInvalidDeleteAuthTypeOAuth() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("restapiUrl", "https://echo.getpostman.com/delete"); p.put("authType", "oauth"); p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3"); @@ -633,7 +650,7 @@ public class TestRestapiCallNode { public void testInvalidDeleteAuthTypeBasic() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("restapiUrl", "https://echo.getpostman.com/delete"); p.put("authType", "basic"); p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3"); @@ -650,7 +667,7 @@ public class TestRestapiCallNode { public void testInvalidDeleteAuthTypeDigest() throws SvcLogicException { SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> p = new HashMap<String, String>(); + Map<String, String> p = new HashMap<>(); p.put("restapiUrl", "https://echo.getpostman.com/delete"); p.put("authType", "digest"); p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3"); |