2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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=========================================================
20 package org.onap.aai.interceptors.pre;
22 import java.io.IOException;
24 import javax.annotation.Priority;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.ws.rs.container.ContainerRequestContext;
27 import javax.ws.rs.container.ContainerRequestFilter;
28 import javax.ws.rs.container.PreMatching;
30 import org.onap.aai.interceptors.AAIContainerFilter;
31 import org.onap.aai.interceptors.AAIHeaderProperties;
32 import org.onap.aai.logging.LoggingContext;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.core.env.Environment;
37 @Priority(AAIRequestFilterPriority.SET_LOGGING_CONTEXT)
38 public class SetLoggingContext extends AAIContainerFilter implements ContainerRequestFilter {
41 private Environment environment;
44 private HttpServletRequest httpServletRequest;
47 public void filter(ContainerRequestContext requestContext) throws IOException {
49 String uri = httpServletRequest.getRequestURI();
50 String queryString = httpServletRequest.getQueryString();
52 if(queryString != null && !queryString.isEmpty()){
53 uri = uri + "?" + queryString;
56 String httpMethod = requestContext.getMethod();
57 String transId = requestContext.getHeaderString(AAIHeaderProperties.TRANSACTION_ID);
58 String fromAppId = requestContext.getHeaderString(AAIHeaderProperties.FROM_APP_ID);
60 LoggingContext.init();
61 LoggingContext.requestId(transId);
62 LoggingContext.partnerName(fromAppId);
63 LoggingContext.targetEntity(environment.getProperty("spring.application.name"));
64 LoggingContext.component(fromAppId);
65 LoggingContext.serviceName(httpMethod + " " + uri);
66 LoggingContext.targetServiceName(httpMethod + " " + uri);