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.servlet.*;
28 import org.eclipse.jetty.util.ssl.*;
29 import org.eclipse.jetty.server.*;
30 import org.eclipse.jetty.http.HttpVersion;
32 import java.io.FileInputStream;
33 import java.io.IOException;
34 import java.util.Arrays;
35 import java.util.Properties;
37 public class Subscriber {
39 private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.subscriber.Subscriber");
41 private static final String CONTEXT_PATH = "/";
42 private static final String URL_PATTERN = "/*";
44 static Properties props;
46 private static void loadProps() {
48 props = new Properties();
50 props.load(new FileInputStream(System.getProperty(
51 "org.onap.dmaap.datarouter.subscriber.properties",
52 "/opt/app/subscriber/etc/subscriber.properties")));
53 } catch (IOException e) {
54 logger.fatal("SubServlet: Exception opening properties: " + e.getMessage());
60 public static void main(String[] args) throws Exception {
64 int httpsPort = Integer.parseInt(props.getProperty("org.onap.dmaap.datarouter.subscriber.https.port", "8443"));
65 int httpPort = Integer.parseInt(props.getProperty("org.onap.dmaap.datarouter.subscriber.http.port", "8080"));
67 Server server = new Server();
68 HttpConfiguration httpConfig = new HttpConfiguration();
69 httpConfig.setRequestHeaderSize(8192);
72 ServletContextHandler ctxt;
73 try (ServerConnector httpServerConnector = new ServerConnector(server,
74 new HttpConnectionFactory(httpConfig))) {
75 httpServerConnector.setPort(httpPort);
76 httpServerConnector.setIdleTimeout(30000);
78 // SSL Context Factory
79 SslContextFactory sslContextFactory = new SslContextFactory();
81 // SSL HTTP Configuration
82 HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
83 httpsConfig.addCustomizer(new SecureRequestCustomizer());
86 ServerConnector sslConnector = new ServerConnector(server,
87 new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
88 new HttpConnectionFactory(httpsConfig));
89 sslConnector.setPort(httpsPort);
90 server.addConnector(sslConnector);
93 sslContextFactory.addExcludeProtocols("SSLv3");
94 logger.info("Excluded protocols for Subscriber:" + Arrays.toString(sslContextFactory.getExcludeProtocols()));
95 /*End of SSLv3 Fixes*/
97 // HTTPS Configuration
98 try (ServerConnector https = new ServerConnector(server,
99 new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
100 new HttpConnectionFactory(httpsConfig))) {
101 https.setPort(httpsPort);
102 https.setIdleTimeout(30000);
104 server.setConnectors(new Connector[]{ httpServerConnector });
106 ctxt = new ServletContextHandler(0);
107 ctxt.setContextPath(CONTEXT_PATH);
108 server.setHandler(ctxt);
110 ctxt.addServlet(new ServletHolder(new SubscriberServlet()), URL_PATTERN);
113 } catch ( Exception e ) {
114 logger.info("Jetty failed to start. Reporting will be unavailable-"+e);
117 logger.info("org.onap.dmaap.datarouter.subscriber.Subscriber started-"+ server.getState());