summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java8
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java14
-rw-r--r--src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java25
-rw-r--r--src/test/java/org/onap/logging_analytics/pomba/pomba_aai_context_builder/RestUtilTest.java23
4 files changed, 58 insertions, 12 deletions
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java
index 39a24ef..b30b76d 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestService.java
@@ -19,9 +19,11 @@ package org.onap.pomba.contextbuilder.aai.service.rs;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
@@ -31,7 +33,6 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.onap.pomba.contextbuilder.aai.model.GenericResponse;
-
@Api
@Path("{version: v2}/service")
@Produces({MediaType.APPLICATION_JSON})
@@ -53,6 +54,9 @@ public interface RestService {
@ApiResponse(code = 500, message = "Unexpected Runtime error")
})
public Response getContext(@Context HttpHeaders headers,
- @QueryParam("serviceInstanceId") String serviceInstanceId
+ @HeaderParam(HttpHeaders.AUTHORIZATION) @ApiParam(hidden=true) String authorization,
+ @HeaderParam(org.onap.pomba.contextbuilder.aai.util.RestUtil.FROM_APP_ID) @ApiParam(required=true) String xFromAppId,
+ @HeaderParam(org.onap.pomba.contextbuilder.aai.util.RestUtil.TRANSACTION_ID) String xTransactionId,
+ @QueryParam("serviceInstanceId") @ApiParam(required=true) String serviceInstanceId
);
} \ No newline at end of file
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java
index b99c87b..7fd27fb 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/service/rs/RestServiceImpl.java
@@ -31,6 +31,7 @@ import org.onap.pomba.contextbuilder.aai.util.RestUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.UUID;
public class RestServiceImpl implements RestService {
private static Logger log = LoggerFactory.getLogger(RestService.class);
@@ -43,16 +44,23 @@ public class RestServiceImpl implements RestService {
private String httpBasicAuthorization;
@Override
- public Response getContext(HttpHeaders headers, String serviceInstanceId) {
+ public Response getContext(HttpHeaders headers,
+ String authorization,
+ String fromAppId,
+ String transactionId,
+ String serviceInstanceId) {
String url = "serviceInstanceId=" + serviceInstanceId;
if(log.isDebugEnabled()) {
log.debug(LogMessages.AAI_CONTEXT_BUILDER_URL, url);
}
+ if (transactionId == null || transactionId.isEmpty()) {
+ transactionId = UUID.randomUUID().toString();
+ log.info(String.format("%s is missing; using newly generated value: %s", org.onap.pomba.contextbuilder.aai.util.RestUtil.TRANSACTION_ID, transactionId));
+ }
Response response = null;
- String transactionId = null;
ModelContext aaiContext= null;
Gson gson = new GsonBuilder().create();
@@ -61,7 +69,7 @@ public class RestServiceImpl implements RestService {
// Do some validation on Http headers and URL parameters
RestUtil.validateBasicAuthorization(headers, httpBasicAuthorization);
RestUtil.validateHeader(headers);
- RestUtil.validateURL(serviceInstanceId);
+ RestUtil.validateServiceInstanceId(serviceInstanceId);
// Keep the same transaction id for logging purpose
transactionId= RestUtil.extractTranIdHeader(headers);
diff --git a/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java b/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java
index 958f656..29fd8d0 100644
--- a/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java
+++ b/src/main/java/org/onap/pomba/contextbuilder/aai/util/RestUtil.java
@@ -73,9 +73,9 @@ public class RestUtil {
private static final String SERVICE_INSTANCE_ID = "serviceInstanceId";
// HTTP headers
- private static final String TRANSACTION_ID = "X-TransactionId";
- private static final String FROM_APP_ID = "X-FromAppId";
- private static final String AUTHORIZATION = "Authorization";
+ public static final String TRANSACTION_ID = "X-TransactionId";
+ public static final String FROM_APP_ID = "X-FromAppId";
+ public static final String AUTHORIZATION = "Authorization";
private static final String APP_NAME = "aaiCtxBuilder";
@@ -144,16 +144,33 @@ public class RestUtil {
*
* @throws AuditException if there is missing parameter
*/
- public static void validateURL(String serviceInstanceId)
+ public static void validateServiceInstanceId(String serviceInstanceId)
throws AuditException {
if (serviceInstanceId == null || serviceInstanceId.isEmpty()) {
+ log.info("Null %s", SERVICE_INSTANCE_ID);
throw new AuditException(AuditError.INVALID_REQUEST_URL_MISSING_PARAMETER + SERVICE_INSTANCE_ID,
Status.BAD_REQUEST);
}
}
+ /**
+ * Validates the URL parameter.
+ *
+ * @throws AuditException if there is missing parameter
+ */
+ public static void validateXFromAppId(String xFromAppId)
+ throws AuditException {
+
+ if (xFromAppId == null || xFromAppId.isEmpty()) {
+ log.info("Null %s", FROM_APP_ID);
+ throw new AuditException(AuditError.INVALID_REQUEST_URL_MISSING_PARAMETER + FROM_APP_ID,
+ Status.BAD_REQUEST);
+ }
+
+ }
+
public static void validateBasicAuthorization(HttpHeaders headers, String basicAuthorization) throws AuditException {
String authorization = null;
diff --git a/src/test/java/org/onap/logging_analytics/pomba/pomba_aai_context_builder/RestUtilTest.java b/src/test/java/org/onap/logging_analytics/pomba/pomba_aai_context_builder/RestUtilTest.java
index 5ded51f..969e567 100644
--- a/src/test/java/org/onap/logging_analytics/pomba/pomba_aai_context_builder/RestUtilTest.java
+++ b/src/test/java/org/onap/logging_analytics/pomba/pomba_aai_context_builder/RestUtilTest.java
@@ -70,16 +70,16 @@ public class RestUtilTest {
public WireMockRule aaiEnricherRule = new WireMockRule(wireMockConfig().port(9808));
@Test
- public void testValidateURL() {
+ public void testValidateServiceInstanceId() {
// Missing ServiceInstanceId or it is null
try {
- RestUtil.validateURL("");
+ RestUtil.validateServiceInstanceId("");
} catch (AuditException e) {
assertTrue(e.getMessage().contains("Invalid request URL, missing parameter: serviceInstanceId"));
}
try {
- RestUtil.validateURL(null);
+ RestUtil.validateServiceInstanceId(null);
} catch (AuditException e) {
assertTrue(e.getMessage().contains("Invalid request URL, missing parameter: serviceInstanceId"));
}
@@ -87,6 +87,23 @@ public class RestUtilTest {
}
@Test
+ public void testValidateXFromAppId() {
+ // Missing ServiceInstanceId or it is null
+ try {
+ RestUtil.validateXFromAppId("");
+ } catch (AuditException e) {
+ assertTrue(e.getMessage().contains("Invalid request URL, missing parameter: X-FromAppId"));
+ }
+
+ try {
+ RestUtil.validateXFromAppId(null);
+ } catch (AuditException e) {
+ assertTrue(e.getMessage().contains("Invalid request URL, missing parameter: X-FromAppId"));
+ }
+
+ }
+
+ @Test
public void testIsEmptyJson() {
assertTrue(RestUtil.isEmptyJson("{}"));
assertTrue(!RestUtil.isEmptyJson("{Not Empty}"));