Remaining checkstyle changes
[dmaap/datarouter.git] / datarouter-subscriber / src / main / java / org / onap / dmaap / datarouter / subscriber / SubscriberMain.java
1 /*******************************************************************************
2  * ============LICENSE_START==================================================
3  * * org.onap.dmaap
4  * * ===========================================================================
5  * * Copyright © 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
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  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  * *
22  ******************************************************************************/
23
24 package org.onap.dmaap.datarouter.subscriber;
25
26 import java.util.Arrays;
27 import org.apache.log4j.Logger;
28 import org.eclipse.jetty.http.HttpVersion;
29 import org.eclipse.jetty.server.Connector;
30 import org.eclipse.jetty.server.HttpConfiguration;
31 import org.eclipse.jetty.server.HttpConnectionFactory;
32 import org.eclipse.jetty.server.SecureRequestCustomizer;
33 import org.eclipse.jetty.server.Server;
34 import org.eclipse.jetty.server.ServerConnector;
35 import org.eclipse.jetty.server.SslConnectionFactory;
36 import org.eclipse.jetty.servlet.ServletContextHandler;
37 import org.eclipse.jetty.servlet.ServletHolder;
38 import org.eclipse.jetty.util.ssl.SslContextFactory;
39
40
41 public class SubscriberMain {
42
43     private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.subscriber.SubscriberMain");
44
45     /**
46      * Main class for Subscriber.
47      * @param args standard args array
48      * @throws Exception generic exception
49      */
50     public static void main(String[] args) throws Exception {
51         SubscriberProps props = SubscriberProps.getInstance(
52                 System.getProperty("org.onap.dmaap.datarouter.subscriber.properties", "subscriber.properties"));
53         int httpsPort = Integer.parseInt(props.getValue("org.onap.dmaap.datarouter.subscriber.https.port", "8443"));
54         int httpPort = Integer.parseInt(props.getValue("org.onap.dmaap.datarouter.subscriber.http.port", "8080"));
55
56         Server server = new Server();
57         HttpConfiguration httpConfig = new HttpConfiguration();
58         httpConfig.setRequestHeaderSize(8192);
59
60         // HTTP connector
61         ServletContextHandler ctxt;
62         try (ServerConnector httpServerConnector = new ServerConnector(server,
63                 new HttpConnectionFactory(httpConfig))) {
64             httpServerConnector.setPort(httpPort);
65             httpServerConnector.setIdleTimeout(30000);
66
67             // SSL Context Factory
68             SslContextFactory sslContextFactory = new SslContextFactory();
69
70             // SSL HTTP Configuration
71             HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
72             httpsConfig.addCustomizer(new SecureRequestCustomizer());
73
74             // SSL Connector
75             ServerConnector sslConnector = new ServerConnector(server,
76                     new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
77                     new HttpConnectionFactory(httpsConfig));
78             sslConnector.setPort(httpsPort);
79             server.addConnector(sslConnector);
80
81             /*Skip SSLv3 Fixes*/
82             sslContextFactory.addExcludeProtocols("SSLv3");
83             logger.info("Excluded protocols for SubscriberMain:"
84                                 + Arrays.toString(sslContextFactory.getExcludeProtocols()));
85             /*End of SSLv3 Fixes*/
86
87             // HTTPS Configuration
88             try (ServerConnector https = new ServerConnector(server,
89                     new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
90                     new HttpConnectionFactory(httpsConfig))) {
91                 https.setPort(httpsPort);
92                 https.setIdleTimeout(30000);
93             }
94             server.setConnectors(new Connector[]{ httpServerConnector });
95         }
96         ctxt = new ServletContextHandler(0);
97         ctxt.setContextPath("/");
98         server.setHandler(ctxt);
99
100         ctxt.addServlet(new ServletHolder(new SampleSubscriberServlet()), "/*");
101         try {
102             server.start();
103         } catch ( Exception e ) {
104             logger.info("Jetty failed to start. Reporting will be unavailable-" + e);
105         }
106         server.join();
107         logger.info("org.onap.dmaap.datarouter.subscriber.SubscriberMain started-" + server.getState());
108
109     }
110 }