diff options
author | Leigh, Phillip (pl876u) <phillip.leigh@amdocs.com> | 2019-02-04 14:59:54 -0500 |
---|---|---|
committer | Leigh, Phillip (pl876u) <phillip.leigh@amdocs.com> | 2019-02-04 15:00:17 -0500 |
commit | 03a6609e1ffb981e7222fe938b6dd6337b287b87 (patch) | |
tree | e104c15975b71dfd6fb23f18c242c1b6b39c1733 /src/main | |
parent | 09e3af8778d9a84ecea2f2085708f22554bd04b8 (diff) |
Log request when no XFromAppId/ServiceInstance
Issue-ID: LOG-688
Change-Id: I909e589b0c1c5dc5998a2e2129585c900210b2c6
Signed-off-by: Leigh, Phillip (pl876u) <phillip.leigh@amdocs.com>
Diffstat (limited to 'src/main')
3 files changed, 38 insertions, 9 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; |