* 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;
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);
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, ""));
}
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;