summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-10-02 10:55:06 +0300
committerEylon Malin <eylon.malin@intl.att.com>2019-10-02 10:55:06 +0300
commit0d422d4cc6a1580d38216ccf5a51a2acba0a884e (patch)
tree611f89fa2fc9014605603bfe1b6eb8e03e4adee3 /vid-app-common/src
parentfdea9e36bd95193d2e920398beee914e4953919c (diff)
enable mso rest client send DELETE request with body
config SUPPRESS_HTTP_COMPLIANCE_VALIDATION directly from RestMsoImplementation, instead of relaying on the jersey client configuration. Also remove Delete method from RestMsoImplementation since it's not used in production code. Issue-ID: VID-657 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com> Change-Id: If30d60c6aca9b7d9ab3e6d07b13c1246ed3d67e3
Diffstat (limited to 'vid-app-common/src')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java15
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java63
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java12
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java75
4 files changed, 11 insertions, 154 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java b/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java
index 3c061986c..5607018b0 100644
--- a/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/client/HttpBasicClient.java
@@ -21,14 +21,11 @@
package org.onap.vid.client;
-import org.glassfish.jersey.client.ClientConfig;
-import org.glassfish.jersey.client.ClientProperties;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.springframework.beans.factory.annotation.Autowired;
-
import javax.servlet.ServletContext;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.springframework.beans.factory.annotation.Autowired;
/**
* General HTTP client.
@@ -51,10 +48,8 @@ public class HttpBasicClient{
*/
public static Client getClient() {
- ClientConfig config = new ClientConfig();
- config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
-
- return ClientBuilder.newClient(config)
- .register(org.onap.vid.aai.util.CustomJacksonJaxBJsonProvider.class);
+ return ClientBuilder
+ .newClient()
+ .register(org.onap.vid.aai.util.CustomJacksonJaxBJsonProvider.class);
}
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java
index ee1eb0429..b07fe05a1 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/RestMsoImplementation.java
@@ -38,6 +38,7 @@ import javax.ws.rs.core.Response;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpException;
import org.eclipse.jetty.util.security.Password;
+import org.glassfish.jersey.client.ClientProperties;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.aai.ExceptionWithRequestInfo;
import org.onap.vid.aai.util.HttpClientMode;
@@ -211,64 +212,6 @@ public class RestMsoImplementation implements RestInterface {
return restObject;
}
- @Override
- public <T> void Delete(T t, Object r, String path, RestObject<T> restObject) {
-
- String methodName = "Delete";
- String url="";
- Response cres;
-
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + START_LOG);
-
- try {
- MultivaluedHashMap<String, Object> commonHeaders = initMsoClient();
-
- url = systemProperties.getProperty(MsoProperties.MSO_SERVER_URL) + path;
- loggingService.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url, r);
- cres = client.target(url)
- .request()
-
- .accept(APPLICATION_JSON)
- .headers(commonHeaders)
- //.entity(r)
- .build("DELETE", Entity.entity(r, MediaType.APPLICATION_JSON))
- .invoke();
- loggingService.logResponse(outgoingRequestsLogger, HttpMethod.DELETE, url, cres);
- int status = cres.getStatus();
- restObject.setStatusCode (status);
-
- if (status == 404) { // resource not found
- String msg = "Resource does not exist...: " + cres.getStatus();
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + msg);
- } else if (status == 200 || status == 204){
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + "Resource " + url + " deleted");
- } else if (status == 202) {
- String msg = "Delete in progress: " + status;
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + msg);
- }
- else {
- String msg = "Deleting Resource failed: " + status;
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + msg);
- }
-
- try {
- t = (T) cres.readEntity(t.getClass());
- restObject.set(t);
- }
- catch ( Exception e ) {
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + NO_RESPONSE_ENTITY_LOG
- + e.getMessage());
- throw e;
- }
-
- }
- catch (Exception e)
- {
- logger.debug(EELFLoggerDelegate.debugLogger,"<== " + methodName + WITH_URL_LOG +url+ EXCEPTION_LOG + e.toString());
- throw e;
- }
- }
-
public <T> RestObject<T> PostForObject(Object requestDetails, String path, Class<T> clazz) {
logger.debug(EELFLoggerDelegate.debugLogger, REST_MSG_TEMPLATE, getMethodCallerName(), getMethodName(), requestDetails, path, clazz);
return restCall(HttpMethod.POST, clazz, requestDetails, path);
@@ -320,7 +263,9 @@ public class RestMsoImplementation implements RestInterface {
final Invocation.Builder restBuilder = client.target(url)
.request()
.accept(APPLICATION_JSON)
- .headers(commonHeaders);
+ .headers(commonHeaders)
+ .property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true)
+ ;
Invocation restInvocation = payload==null ?
restBuilder.build(httpMethod.name()) :
diff --git a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java
index 3a0d8fd8e..2cc8e67b8 100644
--- a/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/mso/rest/RestInterface.java
@@ -42,18 +42,6 @@ public interface RestInterface {
<T> RestObjectWithRequestInfo<T> Get(T t, String path, RestObject<T> restObject, boolean warpException);
/**
- * Delete.
- *
- * @param <T> the generic type
- * @param t the t
- * @param r the r
- * @param path the path
- * @param restObject the rest object
- * @throws Exception the exception
- */
- <T> void Delete(T t, Object r, String path, RestObject<T> restObject);
-
- /**
* Post.
*
* @param t the t
diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java
index e1b78740a..ea83fde29 100644
--- a/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/mso/RestMsoImplementationTest.java
@@ -37,6 +37,7 @@ import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
+import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.JerseyInvocation;
import org.mockito.InjectMocks;
import org.mockito.Mock;
@@ -171,79 +172,6 @@ public class RestMsoImplementationTest {
assertThat(response.getRaw()).isEqualTo(rawData);
}
- @Test()
- public void shouldProperlyDeleteRestObjectWithStatusHttpAccepted() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
-
- prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE");
-
- // when
- restMsoImplementation.Delete(httpRequest, "testObject", path, restObject);
-
- // then
- assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.ACCEPTED.value());
- }
-
- @Test()
- public void shouldProperlyDeleteRestObjectWithStatusOK() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
-
- prepareMocks(rawData,HttpStatus.OK.value(),"DELETE");
-
- // when
- restMsoImplementation.Delete(httpRequest, "testObject", path, restObject);
-
- // then
- assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.OK.value());
- }
-
- @Test()
- public void shouldProperlyReturnFromDeleteWithStatusBadRequest() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
-
- prepareMocks(rawData,HttpStatus.BAD_REQUEST.value(),"DELETE");
-
- // when
- restMsoImplementation.Delete(httpRequest, "testObject", path, restObject);
-
- // then
- assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value());
- }
-
- @Test()
- public void shouldProperlyReturnFromDeleteWithStatusOtherThenAbove() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
- prepareMocks(rawData,HttpStatus.NOT_EXTENDED.value(),"DELETE");
-
- // when
- restMsoImplementation.Delete(httpRequest, "testObject", path, restObject);
-
- // then
- assertThat(restObject.getStatusCode()).isEqualTo(HttpStatus.NOT_EXTENDED.value());
- }
-
- @Test( expectedExceptions = MsoTestException.class)
- public void shouldThrowExceptionWhenCallsDeleteWithWrongParameters() {
- // given
- when(mockClient.target(any(String.class))).thenThrow(new MsoTestException("testDeleteException"));
-
- // when
- restMsoImplementation.Delete(httpRequest, "testObject", "", null);
- }
-
- @Test( expectedExceptions = NullPointerException.class)
- public void shouldThrowExceptionWhenCallsDeleteWithWrongObjectType() {
- // given
- RestObject<HttpRequest> restObject = new RestObject<>();
- prepareMocks(rawData,HttpStatus.ACCEPTED.value(),"DELETE");
-
- // when
- restMsoImplementation.Delete(null, "testObject", path, restObject);
- }
@Test
public void shouldProperlyPostForObject() {
@@ -411,6 +339,7 @@ public class RestMsoImplementationTest {
when(builder.accept(any(String.class))).thenReturn(builder);
when(builder.headers(any(MultivaluedMap.class))).thenReturn(builder);
+ when(builder.property(eq(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION), eq(true))).thenReturn(builder);
when(builder.get()).thenReturn(response);
when(builder.build( eq(httpMethod), any(Entity.class))).thenReturn(jerseyInvocation);