bbe5e325a10b805b1a95431cfd41cae5a3949fd1
[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 org.apache.log4j.Logger;
27 import org.eclipse.jetty.http.HttpVersion;
28 import org.eclipse.jetty.server.*;
29 import org.eclipse.jetty.servlet.ServletContextHandler;
30 import org.eclipse.jetty.servlet.ServletHolder;
31 import org.eclipse.jetty.util.ssl.SslContextFactory;
32
33 import java.util.Arrays;
34
35 public class SubscriberMain {
36
37     private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.subscriber.SubscriberMain");
38
39     public static void main(String[] args) throws Exception {
40         SubscriberProps props = SubscriberProps.getInstance(
41                 System.getProperty("org.onap.dmaap.datarouter.subscriber.properties", "subscriber.properties"));
42         int httpsPort = Integer.parseInt(props.getValue("org.onap.dmaap.datarouter.subscriber.https.port", "8443"));
43         int httpPort = Integer.parseInt(props.getValue("org.onap.dmaap.datarouter.subscriber.http.port", "8080"));
44
45         Server server = new Server();
46         HttpConfiguration httpConfig = new HttpConfiguration();
47         httpConfig.setRequestHeaderSize(8192);
48
49         // HTTP connector
50         ServletContextHandler ctxt;
51         try (ServerConnector httpServerConnector = new ServerConnector(server,
52                 new HttpConnectionFactory(httpConfig))) {
53             httpServerConnector.setPort(httpPort);
54             httpServerConnector.setIdleTimeout(30000);
55
56             // SSL Context Factory
57             SslContextFactory sslContextFactory = new SslContextFactory();
58
59             // SSL HTTP Configuration
60             HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
61             httpsConfig.addCustomizer(new SecureRequestCustomizer());
62
63             // SSL Connector
64             ServerConnector sslConnector = new ServerConnector(server,
65                     new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
66                     new HttpConnectionFactory(httpsConfig));
67             sslConnector.setPort(httpsPort);
68             server.addConnector(sslConnector);
69
70             /*Skip SSLv3 Fixes*/
71             sslContextFactory.addExcludeProtocols("SSLv3");
72             logger.info("Excluded protocols for SubscriberMain:" + Arrays.toString(sslContextFactory.getExcludeProtocols()));
73             /*End of SSLv3 Fixes*/
74
75             // HTTPS Configuration
76             try (ServerConnector https = new ServerConnector(server,
77                     new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
78                     new HttpConnectionFactory(httpsConfig))) {
79                 https.setPort(httpsPort);
80                 https.setIdleTimeout(30000);
81             }
82             server.setConnectors(new Connector[]{ httpServerConnector });
83         }
84         ctxt = new ServletContextHandler(0);
85         ctxt.setContextPath("/");
86         server.setHandler(ctxt);
87
88         ctxt.addServlet(new ServletHolder(new SampleSubscriberServlet()), "/*");
89         try {
90             server.start();
91         } catch ( Exception e ) {
92             logger.info("Jetty failed to start. Reporting will be unavailable-"+e);
93         }
94         server.join();
95         logger.info("org.onap.dmaap.datarouter.subscriber.SubscriberMain started-"+ server.getState());
96
97     }
98 }