Add instructions to invoke the linter and code formatter plugins to the README and...
[aai/schema-service.git] / aai-schema-service / src / main / java / org / onap / aai / schemaservice / interceptors / post / ResponseTransactionLogging.java
index 11f3737..f89440a 100644 (file)
@@ -8,7 +8,7 @@
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- *    http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * limitations under the License.
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.aai.schemaservice.interceptors.post;
 
 import com.google.gson.JsonObject;
+
 import java.io.IOException;
 import java.util.Objects;
 import java.util.Optional;
+
 import javax.annotation.Priority;
 import javax.servlet.http.HttpServletResponse;
 import javax.ws.rs.HttpMethod;
 import javax.ws.rs.container.ContainerRequestContext;
 import javax.ws.rs.container.ContainerResponseContext;
 import javax.ws.rs.container.ContainerResponseFilter;
+
 import org.onap.aai.logging.ErrorLogHelper;
 import org.onap.aai.schemaservice.interceptors.AAIContainerFilter;
 import org.onap.aai.schemaservice.interceptors.AAIHeaderProperties;
@@ -40,39 +44,42 @@ import org.springframework.web.context.request.RequestContextHolder;
 import org.springframework.web.context.request.ServletRequestAttributes;
 
 @Priority(AAIResponseFilterPriority.RESPONSE_TRANS_LOGGING)
-public class ResponseTransactionLogging extends AAIContainerFilter implements ContainerResponseFilter {
+public class ResponseTransactionLogging extends AAIContainerFilter
+    implements ContainerResponseFilter {
 
-    private static final Logger TRANSACTION_LOGGER = LoggerFactory.getLogger(ResponseTransactionLogging.class);
+    private static final Logger TRANSACTION_LOGGER =
+        LoggerFactory.getLogger(ResponseTransactionLogging.class);
 
     @Override
-    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
-        throws IOException {
+    public void filter(ContainerRequestContext requestContext,
+        ContainerResponseContext responseContext) throws IOException {
 
         this.transLogging(requestContext, responseContext);
 
     }
 
-    private void transLogging(ContainerRequestContext requestContext, ContainerResponseContext responseContext) {
+    private void transLogging(ContainerRequestContext requestContext,
+        ContainerResponseContext responseContext) {
 
         String logValue = AAIConfig.get("aai.transaction.logging", "true");
-        String isGetTransactionResponseLoggingEnabled = AAIConfig.get("aai.transaction.logging.get", "false");
+        String isGetTransactionResponseLoggingEnabled =
+            AAIConfig.get("aai.transaction.logging.get", "false");
 
         String httpMethod = requestContext.getMethod();
 
-        if(Boolean.parseBoolean(logValue)){
+        if (Boolean.parseBoolean(logValue)) {
 
             String transId = requestContext.getHeaderString(AAIHeaderProperties.TRANSACTION_ID);
             String fromAppId = requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID);
             String fullUri = requestContext.getUriInfo().getRequestUri().toString();
-            String requestTs = (String) requestContext.getProperty(AAIHeaderProperties.AAI_REQUEST_TS);
-
+            String requestTs =
+                (String) requestContext.getProperty(AAIHeaderProperties.AAI_REQUEST_TS);
 
             String status = Integer.toString(responseContext.getStatus());
 
             String request = (String) requestContext.getProperty(AAIHeaderProperties.AAI_REQUEST);
             String response = this.getResponseString(responseContext);
 
-
             JsonObject logEntry = new JsonObject();
             logEntry.addProperty("transactionId", transId);
             logEntry.addProperty("status", status);
@@ -82,7 +89,8 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co
             logEntry.addProperty("resourceId", fullUri);
             logEntry.addProperty("resourceType", httpMethod);
             logEntry.addProperty("rqstBuf", Objects.toString(request, ""));
-            if(Boolean.parseBoolean(isGetTransactionResponseLoggingEnabled) || (!HttpMethod.GET.equals(httpMethod))) {
+            if (Boolean.parseBoolean(isGetTransactionResponseLoggingEnabled)
+                || (!HttpMethod.GET.equals(httpMethod))) {
                 logEntry.addProperty("respBuf", Objects.toString(response, ""));
             }
 
@@ -97,7 +105,8 @@ public class ResponseTransactionLogging extends AAIContainerFilter implements Co
     private String getHttpServletResponseContentType() {
         final RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
         if (requestAttributes != null) {
-            HttpServletResponse response = ((ServletRequestAttributes) requestAttributes).getResponse();
+            HttpServletResponse response =
+                ((ServletRequestAttributes) requestAttributes).getResponse();
             return response == null ? null : response.getContentType();
         }
         return null;