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.schemaservice.logging;
22 import ch.qos.logback.access.jetty.RequestLogImpl;
23 import org.eclipse.jetty.server.handler.HandlerCollection;
24 import org.eclipse.jetty.server.handler.RequestLogHandler;
25 import org.eclipse.jetty.util.thread.QueuedThreadPool;
26 import org.springframework.beans.factory.annotation.Value;
27 import org.springframework.boot.web.embedded.jetty.JettyServerCustomizer;
28 import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory;
29 import org.springframework.boot.web.servlet.server.AbstractServletWebServerFactory;
30 import org.springframework.context.annotation.Bean;
31 import org.springframework.context.annotation.Configuration;
33 import java.util.Arrays;
36 public class LocalHostAccessLog {
39 public AbstractServletWebServerFactory jettyConfigBean(
40 @Value("${jetty.threadPool.maxThreads:200}") final String maxThreads,
41 @Value("${jetty.threadPool.minThreads:8}") final String minThreads
44 JettyServletWebServerFactory jef = new JettyServletWebServerFactory();
45 jef.addServerCustomizers((JettyServerCustomizer) server -> {
47 HandlerCollection handlers = new HandlerCollection();
49 Arrays.stream(server.getHandlers()).forEach(handlers::addHandler);
51 RequestLogHandler requestLogHandler = new RequestLogHandler();
52 requestLogHandler.setServer(server);
54 RequestLogImpl requestLogImpl = new RequestLogImpl();
55 requestLogImpl.setResource("/localhost-access-logback.xml");
56 requestLogImpl.start();
58 requestLogHandler.setRequestLog(requestLogImpl);
59 handlers.addHandler(requestLogHandler);
60 server.setHandler(handlers);
62 final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
63 threadPool.setMaxThreads(Integer.valueOf(maxThreads));
64 threadPool.setMinThreads(Integer.valueOf(minThreads));