Merge "update websocketmanager"
[ccsdk/features.git] / sdnr / wt / data-provider / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / dataprovider / http / MsServlet.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK.apps.sdnr.wt.apigateway
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.ccsdk.features.sdnr.wt.dataprovider.http;
22
23 import java.io.IOException;
24 import javax.servlet.ServletException;
25 import javax.servlet.http.HttpServletRequest;
26 import javax.servlet.http.HttpServletResponse;
27
28 import org.onap.ccsdk.features.sdnr.wt.common.http.BaseServlet;
29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.MediatorServerDataProvider;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class MsServlet extends BaseServlet {
34
35         /**
36          *
37          */
38         private static Logger LOG = LoggerFactory.getLogger(MsServlet.class);
39         private static final long serialVersionUID = -5361461082028405171L;
40         private static final String OFFLINE_RESPONSE_MESSAGE = "MediatorServer interface is offline";
41         private static boolean trustAll = false;
42         private MediatorServerDataProvider entryProvider;
43         public MsServlet() {
44                 super(false);
45         }
46
47         @Override
48         protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
49                 resp.setStatus(200);
50         }
51         @Override
52         protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
53                 super.doGet(req, resp);
54         }
55         @Override
56         protected String getOfflineResponse() {
57                 return OFFLINE_RESPONSE_MESSAGE;
58         }
59
60         public void triggerReloadDatabaseEntries() {
61                 LOG.debug("external reload triggered");
62                 this.entryProvider.triggerReloadSync();
63         }
64
65         @Override
66         protected boolean isOff() {
67                 return false;
68         }
69
70         @Override
71         protected String getRemoteUrl(String uri) {
72                 String dbServerId = "0";
73                 if (uri == null)
74                         uri = "";
75                 if (uri.length() > 0) {
76                         uri = uri.substring("/ms/".length());
77                         int idx= uri.indexOf("/");
78                         dbServerId = uri.substring(0,idx);
79                         uri=uri.substring(idx);
80                 }
81                 LOG.debug("request for ms server with id={}",dbServerId);
82                 String url= this.getBaseUrl(dbServerId) + uri;
83                 LOG.debug("dest-url: {}",url);
84                 return url;
85         }
86
87         protected String getBaseUrl(String dbServerId) {
88                 return this.entryProvider.getHostUrl(dbServerId);
89         }
90         @Override
91         protected boolean doTrustAll() {
92                 return trustAll;
93         }
94         @Override
95         protected void trustAll(boolean trust) {
96                 trustAll = trust;
97         }
98
99         public void setDataProvider(MediatorServerDataProvider mediatorServerDataProvider) {
100                 this.entryProvider = mediatorServerDataProvider;
101         }
102 }