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=========================================================
21 package org.onap.aai.schemaservice.logging;
23 import ch.qos.logback.access.jetty.RequestLogImpl;
25 import java.util.Arrays;
27 import org.eclipse.jetty.server.handler.HandlerCollection;
28 import org.eclipse.jetty.server.handler.RequestLogHandler;
29 import org.eclipse.jetty.util.thread.QueuedThreadPool;
30 import org.springframework.beans.factory.annotation.Value;
31 import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
32 import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
33 import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory;
34 import org.springframework.context.annotation.Bean;
35 import org.springframework.context.annotation.Configuration;
38 public class LocalHostAccessLog {
41 public AbstractServletWebServerFactory jettyConfigBean(
42 @Value("${jetty.threadPool.maxThreads:200}") final String maxThreads,
43 @Value("${jetty.threadPool.minThreads:8}") final String minThreads) {
45 JettyServletWebServerFactory jef = new JettyServletWebServerFactory();
46 jef.addServerCustomizers((JettyServerCustomizer) server -> {
48 HandlerCollection handlers = new HandlerCollection();
50 Arrays.stream(server.getHandlers()).forEach(handlers::addHandler);
52 RequestLogHandler requestLogHandler = new RequestLogHandler();
53 requestLogHandler.setServer(server);
55 RequestLogImpl requestLogImpl = new RequestLogImpl();
56 requestLogImpl.setResource("/localhost-access-logback.xml");
57 requestLogImpl.start();
59 requestLogHandler.setRequestLog(requestLogImpl);
60 handlers.addHandler(requestLogHandler);
61 server.setHandler(handlers);
63 final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
64 threadPool.setMaxThreads(Integer.valueOf(maxThreads));
65 threadPool.setMinThreads(Integer.valueOf(minThreads));