aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorefiacor <fiachra.corcoran@est.tech>2022-12-09 07:28:54 +0000
committerefiacor <fiachra.corcoran@est.tech>2022-12-12 13:26:46 +0000
commita4d9c6bfc2a648a6892e94ad45e8ab9f64327dc4 (patch)
tree7d4be952e5c571ebb3d63c7965ea0437a77916db
parent86532163d19990e3acfa645a367ed0e0a1c787e0 (diff)
[DMAAP-BC] Add http connect to Data Router2.0.11
Signed-off-by: efiacor <fiachra.corcoran@est.tech> Change-Id: I71991bab2987a99e5cb9fd5ca79583d7f3566efa Issue-ID: DMAAP-1643
-rw-r--r--dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java69
-rw-r--r--dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java11
-rw-r--r--dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/util/DmaapConfig.java2
-rw-r--r--dmaap-bc/src/main/resources/docker/Dockerfile2
-rw-r--r--dmaap-bc/src/test/resources/dmaapbc.properties3
5 files changed, 54 insertions, 33 deletions
diff --git a/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java b/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java
index dffe830..0e4ae09 100644
--- a/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java
+++ b/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java
@@ -28,9 +28,12 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ConnectException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.SocketException;
import java.net.URL;
+import java.net.UnknownHostException;
import java.util.Arrays;
import javax.net.ssl.HttpsURLConnection;
import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
@@ -53,9 +56,8 @@ public class DrProvConnection extends BaseLoggingClass {
private String subContentType;
private String unit_test;
private String provURI;
-
- private HttpsURLConnection uc;
+ private HttpURLConnection uc;
public DrProvConnection() {
provURL = new DmaapService().getDmaap().getDrProvUrl();
@@ -71,45 +73,44 @@ public class DrProvConnection extends BaseLoggingClass {
logger.info( "provURL=" + provURL + " provApi=" + provApi + " behalfHeader=" + behalfHeader
+ " feedContentType=" + feedContentType + " subContentType=" + subContentType );
unit_test = p.getProperty( "UnitTest", "No" );
-
}
public boolean makeFeedConnection() {
- return makeConnection( provURL );
+ return makeDrConnection( provURL );
}
public boolean makeFeedConnection(String feedId) {
- return makeConnection( provURL + "/feed/" + feedId );
+ return makeDrConnection( provURL + "/feed/" + feedId );
}
public boolean makeSubPostConnection( String subURL ) {
String[] parts = subURL.split("/");
String revisedURL = provURL + "/" + parts[3] + "/" + parts[4];
logger.info( "mapping " + subURL + " to " + revisedURL );
- return makeConnection( revisedURL );
+ return makeDrConnection( revisedURL );
}
public boolean makeSubPutConnection( String subId ) {
String revisedURL = provURL + "/subs/" + subId;
logger.info( "mapping " + subId + " to " + revisedURL );
- return makeConnection( revisedURL );
+ return makeDrConnection( revisedURL );
}
public boolean makeIngressConnection( String feed, String user, String subnet, String nodep ) {
String uri = String.format("/internal/route/ingress/?feed=%s&user=%s&subnet=%s&nodepatt=%s",
feed, user, subnet, nodep );
- return makeConnection( provURL + uri );
+ return makeDrConnection( provURL + uri );
}
public boolean makeEgressConnection( String sub, String nodep ) {
String uri = String.format("/internal/route/egress/?sub=%s&node=%s",
sub, nodep );
- return makeConnection( provURL + uri );
+ return makeDrConnection( provURL + uri );
}
public boolean makeDumpConnection() {
String url = provURL + provURI;
- return makeConnection( url );
+ return makeDrConnection( url );
}
public boolean makeNodesConnection( String varName ) {
String uri = String.format("/internal/api/%s", varName);
- return makeConnection( provURL + uri );
+ return makeDrConnection( provURL + uri );
}
public boolean makeNodesConnection( String varName, String val ) {
@@ -120,23 +121,55 @@ public class DrProvConnection extends BaseLoggingClass {
String cv = val.replaceAll("\\|", "%7C");
String uri = String.format( "/internal/api/%s?val=%s", varName, cv );
- return makeConnection( provURL + uri );
+ return makeDrConnection( provURL + uri );
+ }
+
+ public boolean makeDrConnection(String provUrl) {
+ boolean rc = false;
+ logger.info( "connect to data router at: {}", provUrl);
+ try {
+ URL pUrl = new URL(provUrl);
+ if (pUrl.getProtocol().equals( "https" )) {
+ rc = makeSecureConnection(pUrl);
+ } else {
+ rc = makeDrConnection(pUrl);
+ }
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ }
+
+ return rc;
}
- private boolean makeConnection( String pURL ) {
-
+ private boolean makeSecureConnection(URL u) {
try {
- URL u = new URL( pURL );
uc = (HttpsURLConnection) u.openConnection();
uc.setInstanceFollowRedirects(false);
- logger.info( "successful connect to " + pURL );
- uc.setSSLSocketFactory(DmaapConfig.getSSLSocketFactory());
+ logger.info( "successful connect to {}", u);
+ HttpsURLConnection ucs = (HttpsURLConnection) uc;
+ ucs.setSSLSocketFactory(DmaapConfig.getSSLSocketFactory());
return(true);
} catch (Exception e) {
- errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_ERROR, pURL, e.getMessage() );
+ logger.error("Unexpected error during openConnection of {}", u, e.getMessage());
return(false);
}
}
+
+ private boolean makeDrConnection(URL u) {
+ try {
+ uc = (HttpURLConnection) u.openConnection();
+ uc.setInstanceFollowRedirects(false);
+ logger.info( "successful connect to {}", u);
+ return(true);
+ } catch(UnknownHostException uhe){
+ logger.error("Caught UnknownHostException for {}", u);
+ return(false);
+ } catch (Exception e) {
+ logger.error("Unexpected error during openConnection of {}", u, e.getMessage());
+ return(false);
+ }
+
+ }
public String bodyToString( InputStream is ) {
logger.info( "is=" + is );
diff --git a/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java b/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java
index 52d7570..2f2ac00 100644
--- a/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java
+++ b/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java
@@ -51,7 +51,6 @@ public class JettyServer extends BaseLoggingClass {
new CertficateManagerFactory(DmaapConfig.getConfig()).initCertificateManager();
private final Server server;
-
public Server getServer() {
return server;
}
@@ -61,37 +60,30 @@ public class JettyServer extends BaseLoggingClass {
}
public JettyServer(Properties params) {
-
server = new Server();
int httpPort = Integer.parseInt(params.getProperty("IntHttpPort", "80"));
int sslPort = Integer.parseInt(params.getProperty("IntHttpsPort", "443"));
boolean allowHttp = Boolean.parseBoolean(params.getProperty("HttpAllowed", "false"));
serverLogger.info("port params: http=" + httpPort + " https=" + sslPort);
serverLogger.info("allowHttp=" + allowHttp);
-
// HTTP Server
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecureScheme("https");
httpConfig.setSecurePort(sslPort);
httpConfig.setOutputBufferSize(32768);
-
try (ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfig))) {
httpConnector.setPort(httpPort);
httpConnector.setIdleTimeout(30000);
-
// HTTPS Server
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
SslContextFactory sslContextFactory = new SslContextFactory.Server();
sslContextFactory.setWantClientAuth(true);
-
- if ( ! certificateManager.isReady()) {
+ if (!certificateManager.isReady()) {
serverLogger.error("CertificateManager is not ready. NOT starting https!");
} else {
setUpKeystore(sslContextFactory);
setUpTrustStore(sslContextFactory);
-
-
if (sslPort != 0) {
try (ServerConnector sslConnector = new ServerConnector(server,
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
@@ -111,7 +103,6 @@ public class JettyServer extends BaseLoggingClass {
serverLogger.info("NOT starting httpConnector because HttpAllowed param is " + allowHttp);
}
}
-
// Set context for servlet. This is shared for http and https
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
diff --git a/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/util/DmaapConfig.java b/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/util/DmaapConfig.java
index e95ebab..3247748 100644
--- a/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/util/DmaapConfig.java
+++ b/dmaap-bc/src/main/java/org/onap/dmaap/dbcapi/util/DmaapConfig.java
@@ -49,7 +49,7 @@ public class DmaapConfig extends Properties {
try (InputStream is = new FileInputStream(CONFIG_FILE_NAME)){
load(is);
} catch (Exception e) {
- logger.error("Unable to load configuration file " + CONFIG_FILE_NAME);
+ logger.error("Unable to load configuration file " + CONFIG_FILE_NAME, e.getMessage());
System.exit(1);
}
}
diff --git a/dmaap-bc/src/main/resources/docker/Dockerfile b/dmaap-bc/src/main/resources/docker/Dockerfile
index f9c913f..4050afc 100644
--- a/dmaap-bc/src/main/resources/docker/Dockerfile
+++ b/dmaap-bc/src/main/resources/docker/Dockerfile
@@ -19,7 +19,7 @@
# limitations under the License.
# ============LICENSE_END====================================================
-FROM nexus3.onap.org:10001/onap/integration-java11:8.0.0
+FROM nexus3.onap.org:10001/onap/integration-java11:10.0.0
MAINTAINER DMAAP Team
diff --git a/dmaap-bc/src/test/resources/dmaapbc.properties b/dmaap-bc/src/test/resources/dmaapbc.properties
index 5290032..d6f1776 100644
--- a/dmaap-bc/src/test/resources/dmaapbc.properties
+++ b/dmaap-bc/src/test/resources/dmaapbc.properties
@@ -252,9 +252,6 @@ IntHttpPort: 8080
# set to 0 if no certificates are available.
IntHttpsPort: 0
-
-inHttpsPort: 0
-
#####################################################
#
# Deprecated properties