1 /*******************************************************************************
2 * ============LICENSE_START==================================================
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
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 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 ******************************************************************************/
24 package org.onap.dmaap.datarouter.subscriber;
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;
33 import java.util.Arrays;
35 public class SubscriberMain {
37 private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.subscriber.SubscriberMain");
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"));
45 Server server = new Server();
46 HttpConfiguration httpConfig = new HttpConfiguration();
47 httpConfig.setRequestHeaderSize(8192);
50 ServletContextHandler ctxt;
51 try (ServerConnector httpServerConnector = new ServerConnector(server,
52 new HttpConnectionFactory(httpConfig))) {
53 httpServerConnector.setPort(httpPort);
54 httpServerConnector.setIdleTimeout(30000);
56 // SSL Context Factory
57 SslContextFactory sslContextFactory = new SslContextFactory();
59 // SSL HTTP Configuration
60 HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
61 httpsConfig.addCustomizer(new SecureRequestCustomizer());
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);
71 sslContextFactory.addExcludeProtocols("SSLv3");
72 logger.info("Excluded protocols for SubscriberMain:" + Arrays.toString(sslContextFactory.getExcludeProtocols()));
73 /*End of SSLv3 Fixes*/
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);
82 server.setConnectors(new Connector[]{ httpServerConnector });
84 ctxt = new ServletContextHandler(0);
85 ctxt.setContextPath("/");
86 server.setHandler(ctxt);
88 ctxt.addServlet(new ServletHolder(new SampleSubscriberServlet()), "/*");
91 } catch ( Exception e ) {
92 logger.info("Jetty failed to start. Reporting will be unavailable-"+e);
95 logger.info("org.onap.dmaap.datarouter.subscriber.SubscriberMain started-"+ server.getState());