Add instructions to invoke the linter and code formatter plugins to the README and...
[aai/schema-service.git] / aai-schema-service / src / main / java / org / onap / aai / schemaservice / logging / LocalHostAccessLog.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.aai.schemaservice.logging;
22
23 import ch.qos.logback.access.jetty.RequestLogImpl;
24
25 import java.util.Arrays;
26
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;
36
37 @Configuration
38 public class LocalHostAccessLog {
39
40     @Bean
41     public AbstractServletWebServerFactory jettyConfigBean(
42         @Value("${jetty.threadPool.maxThreads:200}") final String maxThreads,
43         @Value("${jetty.threadPool.minThreads:8}") final String minThreads) {
44
45         JettyServletWebServerFactory jef = new JettyServletWebServerFactory();
46         jef.addServerCustomizers((JettyServerCustomizer) server -> {
47
48             HandlerCollection handlers = new HandlerCollection();
49
50             Arrays.stream(server.getHandlers()).forEach(handlers::addHandler);
51
52             RequestLogHandler requestLogHandler = new RequestLogHandler();
53             requestLogHandler.setServer(server);
54
55             RequestLogImpl requestLogImpl = new RequestLogImpl();
56             requestLogImpl.setResource("/localhost-access-logback.xml");
57             requestLogImpl.start();
58
59             requestLogHandler.setRequestLog(requestLogImpl);
60             handlers.addHandler(requestLogHandler);
61             server.setHandler(handlers);
62
63             final QueuedThreadPool threadPool = server.getBean(QueuedThreadPool.class);
64             threadPool.setMaxThreads(Integer.valueOf(maxThreads));
65             threadPool.setMinThreads(Integer.valueOf(minThreads));
66         });
67         return jef;
68     }
69 }