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.node;
26 import org.eclipse.jetty.http.HttpVersion;
27 import org.eclipse.jetty.servlet.*;
28 import org.eclipse.jetty.util.ssl.*;
29 import org.eclipse.jetty.server.*;
30 import org.apache.log4j.Logger;
32 import java.util.Arrays;
35 * The main starting point for the Data Router node
37 public class NodeMain {
42 private static Logger LOGGER = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeMain");
44 private static class WaitForConfig implements Runnable {
46 private NodeConfigManager localNodeConfigManager;
48 WaitForConfig(NodeConfigManager ncm) {
49 this.localNodeConfigManager = ncm;
52 public synchronized void run() {
56 synchronized void waitForConfig() {
57 localNodeConfigManager.registerConfigTask(this);
58 while (!localNodeConfigManager.isConfigured()) {
59 LOGGER.info("NODE0003 Waiting for Node Configuration");
62 } catch (Exception e) {
63 LOGGER.debug("NodeMain: waitForConfig exception. Exception Message:- " +e.getMessage());
66 localNodeConfigManager.deregisterConfigTask(this);
67 LOGGER.info("NODE0004 Node Configuration Data Received");
71 private static Delivery delivery;
72 private static NodeConfigManager nodeConfigManager;
75 * Reset the retry timer for a subscription
77 static void resetQueue(String subid, String ip) {
78 delivery.resetQueue(nodeConfigManager.getSpoolDir(subid, ip));
82 * Start the data router.
84 * The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.ConfigFile system
85 * property. By default, it is "etc/node.properties".
87 public static void main(String[] args) throws Exception {
88 LOGGER.info("NODE0001 Data Router Node Starting");
90 nodeConfigManager = NodeConfigManager.getInstance();
91 LOGGER.info("NODE0002 I am " + nodeConfigManager.getMyName());
92 (new WaitForConfig(nodeConfigManager)).waitForConfig();
93 delivery = new Delivery(nodeConfigManager);
94 Server server = new Server();
96 HttpConfiguration httpConfiguration = new HttpConfiguration();
97 httpConfiguration.setIdleTimeout(2000);
98 httpConfiguration.setRequestHeaderSize(2048);
101 ServletContextHandler ctxt;
102 try (ServerConnector httpServerConnector = new ServerConnector(server,
103 new HttpConnectionFactory(httpConfiguration))) {
104 httpServerConnector.setPort(nodeConfigManager.getHttpPort());
106 // HTTPS configuration
107 SslContextFactory sslContextFactory = new SslContextFactory();
108 sslContextFactory.setKeyStoreType(nodeConfigManager.getKSType());
109 sslContextFactory.setKeyStorePath(nodeConfigManager.getKSFile());
110 sslContextFactory.setKeyStorePassword(nodeConfigManager.getKSPass());
111 sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
112 /* Skip SSLv3 Fixes */
113 sslContextFactory.addExcludeProtocols("SSLv3");
114 LOGGER.info("Excluded protocols node-" + Arrays.toString(sslContextFactory.getExcludeProtocols()));
115 /* End of SSLv3 Fixes */
117 HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
118 httpsConfiguration.setRequestHeaderSize(8192);
120 SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer();
121 secureRequestCustomizer.setStsMaxAge(2000);
122 secureRequestCustomizer.setStsIncludeSubDomains(true);
123 httpsConfiguration.addCustomizer(secureRequestCustomizer);
126 ServerConnector httpsServerConnector = new ServerConnector(server,
127 new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
128 new HttpConnectionFactory(httpsConfiguration));
129 httpsServerConnector.setPort(nodeConfigManager.getHttpsPort());
130 httpsServerConnector.setIdleTimeout(500000);
131 httpsServerConnector.setAcceptQueueSize(2);
133 server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
135 ctxt = new ServletContextHandler(0);
136 ctxt.setContextPath("/");
137 server.setHandler(ctxt);
138 ctxt.addServlet(new ServletHolder(new NodeServlet()), "/*");
139 LOGGER.info("NODE0005 Data Router Node Activating Service");