2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.interceptors.pre;
23 import java.io.IOException;
25 import javax.annotation.Priority;
26 import javax.servlet.http.HttpServletRequest;
27 import javax.ws.rs.container.ContainerRequestContext;
28 import javax.ws.rs.container.ContainerRequestFilter;
29 import javax.ws.rs.container.PreMatching;
31 import org.onap.aai.interceptors.AAIContainerFilter;
32 import org.onap.aai.interceptors.AAIHeaderProperties;
33 import org.onap.aai.logging.LoggingContext;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.core.env.Environment;
38 @Priority(AAIRequestFilterPriority.SET_LOGGING_CONTEXT)
39 public class SetLoggingContext extends AAIContainerFilter implements ContainerRequestFilter {
42 private Environment environment;
45 private HttpServletRequest httpServletRequest;
48 public void filter(ContainerRequestContext requestContext) throws IOException {
50 String uri = httpServletRequest.getRequestURI();
51 String queryString = httpServletRequest.getQueryString();
53 if(queryString != null && !queryString.isEmpty()){
54 uri = uri + "?" + queryString;
57 String httpMethod = requestContext.getMethod();
58 String transId = requestContext.getHeaderString(AAIHeaderProperties.TRANSACTION_ID);
59 String fromAppId = requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID);
61 LoggingContext.init();
62 LoggingContext.requestId(transId);
63 LoggingContext.partnerName(fromAppId);
64 LoggingContext.targetEntity(environment.getProperty("spring.application.name"));
65 LoggingContext.component(fromAppId);
66 LoggingContext.serviceName(httpMethod + " " + uri);
67 LoggingContext.targetServiceName(httpMethod + " " + uri);