summaryrefslogtreecommitdiffstats
path: root/message-router/publisher
diff options
context:
space:
mode:
Diffstat (limited to 'message-router/publisher')
-rwxr-xr-xmessage-router/publisher/README.md8
-rwxr-xr-xmessage-router/publisher/api/pom.xml27
-rwxr-xr-xmessage-router/publisher/api/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/api/PublisherApi.java5
-rw-r--r--message-router/publisher/installer/pom.xml133
-rw-r--r--message-router/publisher/installer/src/assembly/assemble_installer_zip.xml59
-rw-r--r--message-router/publisher/installer/src/assembly/assemble_mvnrepo_zip.xml49
-rw-r--r--message-router/publisher/installer/src/main/resources/scripts/install-feature.sh39
-rwxr-xr-xmessage-router/publisher/pom.xml20
-rwxr-xr-xmessage-router/publisher/provider/pom.xml39
-rwxr-xr-xmessage-router/publisher/provider/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/provider/impl/PublisherApiImpl.java178
-rwxr-xr-xmessage-router/publisher/provider/src/main/resources/OSGI-INF/blueprint/blueprint.xml14
-rw-r--r--message-router/publisher/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/provider/impl/PublisherApiImplTest.java51
-rwxr-xr-xmessage-router/publisher/sample.client/pom.xml39
-rwxr-xr-xmessage-router/publisher/sample.client/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/client/impl/ClientImpl.java58
-rwxr-xr-xmessage-router/publisher/sample.client/src/main/resources/OSGI-INF/blueprint/blueprint.xml16
-rw-r--r--message-router/publisher/sample.client/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/client/impl/ClientImplTest.java29
16 files changed, 764 insertions, 0 deletions
diff --git a/message-router/publisher/README.md b/message-router/publisher/README.md
new file mode 100755
index 000000000..58c1bf470
--- /dev/null
+++ b/message-router/publisher/README.md
@@ -0,0 +1,8 @@
+# Publisher
+
+## Modules
+- api - exports the publisher interface for clients and providers to import
+- features - used for managing the feature repository for publisher
+- installer - provides a simple install script
+- provider - provides an implementation of the publisher api, this implementation assumes the controller has a single identity for publishing to DMAAP message router
+- sample.client - a dummy client that posts a simple message to a configured topic during its initialization
diff --git a/message-router/publisher/api/pom.xml b/message-router/publisher/api/pom.xml
new file mode 100755
index 000000000..7831284cf
--- /dev/null
+++ b/message-router/publisher/api/pom.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.ccsdk.sli.adaptors.messagerouter</groupId>
+ <artifactId>publisher.aggregate</artifactId>
+ <version>1.1.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>publisher.api</artifactId>
+ <packaging>bundle</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package>org.onap.ccsdk.sli.adaptors.messagerouter.publisher.api</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/message-router/publisher/api/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/api/PublisherApi.java b/message-router/publisher/api/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/api/PublisherApi.java
new file mode 100755
index 000000000..3551e0441
--- /dev/null
+++ b/message-router/publisher/api/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/api/PublisherApi.java
@@ -0,0 +1,5 @@
+package org.onap.ccsdk.sli.adaptors.messagerouter.publisher.api;
+
+public interface PublisherApi {
+ public Boolean publish(String topic, String body);
+}
diff --git a/message-router/publisher/installer/pom.xml b/message-router/publisher/installer/pom.xml
new file mode 100644
index 000000000..bc0565e5b
--- /dev/null
+++ b/message-router/publisher/installer/pom.xml
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.ccsdk.sli.adaptors.messagerouter</groupId>
+ <artifactId>publisher.aggregate</artifactId>
+ <version>1.1.1-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.onap.ccsdk.sli.adaptors.messagerouter</groupId>
+ <artifactId>publisher.installer</artifactId>
+ <version>1.1.1-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <properties>
+ <application.name>messagerouter-publisher</application.name>
+ <features.boot>messagerouter-publisher</features.boot>
+ <features.repositories>mvn:${project.groupId}/publisher.features/${project.version}/xml/features</features.repositories>
+ <include.transitive.dependencies>false</include.transitive.dependencies>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>publisher.api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>publisher.provider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>sample.client</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <id>maven-repo-zip</id>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <attach>true</attach>
+ <finalName>stage/${application.name}-${project.version}</finalName>
+ <descriptors>
+ <descriptor>src/assembly/assemble_mvnrepo_zip.xml</descriptor>
+ </descriptors>
+ <appendAssemblyId>true</appendAssemblyId>
+ </configuration>
+ </execution>
+ <execution>
+ <id>installer-zip</id>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <attach>true</attach>
+ <finalName>${application.name}-${project.version}-installer</finalName>
+ <descriptors>
+ <descriptor>src/assembly/assemble_installer_zip.xml</descriptor>
+ </descriptors>
+ <appendAssemblyId>false</appendAssemblyId>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <phase>prepare-package</phase>
+ <configuration>
+ <transitive>false</transitive>
+ <outputDirectory>${project.build.directory}/assembly/system</outputDirectory>
+ <overWriteReleases>false</overWriteReleases>
+ <overWriteSnapshots>true</overWriteSnapshots>
+ <overWriteIfNewer>true</overWriteIfNewer>
+ <useRepositoryLayout>true</useRepositoryLayout>
+ <addParentPoms>false</addParentPoms>
+ <copyPom>false</copyPom>
+ <includeGroupIds>${project.groupId}</includeGroupIds>
+ <scope>provided</scope>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>2.6</version>
+ <executions>
+ <execution>
+ <id>copy-version</id>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals><!-- here the phase you need -->
+ <phase>validate</phase>
+ <configuration>
+ <outputDirectory>${basedir}/target/stage</outputDirectory>
+ <resources>
+ <resource>
+ <directory>src/main/resources/scripts</directory>
+ <includes>
+ <include>install-feature.sh</include>
+ </includes>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+
+ </executions>
+ </plugin>
+
+ </plugins>
+ </build>
+</project>
diff --git a/message-router/publisher/installer/src/assembly/assemble_installer_zip.xml b/message-router/publisher/installer/src/assembly/assemble_installer_zip.xml
new file mode 100644
index 000000000..c6169a879
--- /dev/null
+++ b/message-router/publisher/installer/src/assembly/assemble_installer_zip.xml
@@ -0,0 +1,59 @@
+<!--
+ ============LICENSE_START=======================================================
+ openECOMP : SDN-C
+ ================================================================================
+ Copyright (C) 2017 AT&T Intellectual Property. All rights
+ reserved.
+ ================================================================================
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ============LICENSE_END=========================================================
+ -->
+
+<!-- Defines how we build the .zip file which is our distribution. -->
+
+<assembly
+ xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+ <id>installer_zip</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <!-- we want "system" and related files right at the root level
+ as this file is suppose to be unzip on top of a karaf
+ distro. -->
+ <includeBaseDirectory>false</includeBaseDirectory>
+
+ <fileSets>
+ <fileSet>
+ <directory>target/stage/</directory>
+ <outputDirectory>${application.name}</outputDirectory>
+ <fileMode>755</fileMode>
+ <includes>
+ <include>*.sh</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>target/stage/</directory>
+ <outputDirectory>${application.name}</outputDirectory>
+ <fileMode>644</fileMode>
+ <excludes>
+ <exclude>*.sh</exclude>
+ </excludes>
+ </fileSet>
+ </fileSets>
+
+
+
+</assembly> \ No newline at end of file
diff --git a/message-router/publisher/installer/src/assembly/assemble_mvnrepo_zip.xml b/message-router/publisher/installer/src/assembly/assemble_mvnrepo_zip.xml
new file mode 100644
index 000000000..377b5b153
--- /dev/null
+++ b/message-router/publisher/installer/src/assembly/assemble_mvnrepo_zip.xml
@@ -0,0 +1,49 @@
+<!--
+ ============LICENSE_START=======================================================
+ openECOMP : SDN-C
+ ================================================================================
+ Copyright (C) 2017 AT&T Intellectual Property. All rights
+ reserved.
+ ================================================================================
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ ============LICENSE_END=========================================================
+ -->
+
+<!-- Defines how we build the .zip file which is our distribution. -->
+
+<assembly
+ xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
+ <id>repo</id>
+ <formats>
+ <format>zip</format>
+ </formats>
+
+ <!-- we want "system" and related files right at the root level
+ as this file is suppose to be unzip on top of a karaf
+ distro. -->
+ <includeBaseDirectory>false</includeBaseDirectory>
+
+ <fileSets>
+ <fileSet>
+ <directory>target/assembly/</directory>
+ <outputDirectory>.</outputDirectory>
+ <excludes>
+ </excludes>
+ </fileSet>
+ </fileSets>
+
+
+
+</assembly> \ No newline at end of file
diff --git a/message-router/publisher/installer/src/main/resources/scripts/install-feature.sh b/message-router/publisher/installer/src/main/resources/scripts/install-feature.sh
new file mode 100644
index 000000000..15dc0c27a
--- /dev/null
+++ b/message-router/publisher/installer/src/main/resources/scripts/install-feature.sh
@@ -0,0 +1,39 @@
+#!/bin/bash
+
+###
+# ============LICENSE_START=======================================================
+# openECOMP : SDN-C
+# ================================================================================
+# Copyright (C) 2017 AT&T Intellectual Property. All rights
+# reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+
+ODL_HOME=${ODL_HOME:-/opt/opendaylight/current}
+ODL_KARAF_CLIENT=${ODL_KARAF_CLIENT:-${ODL_HOME}/bin/client}
+INSTALLERDIR=$(dirname $0)
+
+REPOZIP=${INSTALLERDIR}/${features.boot}-${project.version}.zip
+
+if [ -f ${REPOZIP} ]
+then
+ unzip -d ${ODL_HOME} ${REPOZIP}
+else
+ echo "ERROR : repo zip ($REPOZIP) not found"
+ exit 1
+fi
+
+${ODL_KARAF_CLIENT} feature:repo-add ${features.repositories}
+${ODL_KARAF_CLIENT} feature:install ${features.boot} \ No newline at end of file
diff --git a/message-router/publisher/pom.xml b/message-router/publisher/pom.xml
new file mode 100755
index 000000000..6fb9c82d3
--- /dev/null
+++ b/message-router/publisher/pom.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.ccsdk.sli.adaptors.messagerouter</groupId>
+ <artifactId>messagerouter-root</artifactId>
+ <version>1.1.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>publisher.aggregate</artifactId>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>api</module>
+ <module>provider</module>
+ <module>sample.client</module>
+ <module>installer</module>
+ </modules>
+</project>
diff --git a/message-router/publisher/provider/pom.xml b/message-router/publisher/provider/pom.xml
new file mode 100755
index 000000000..7cd311448
--- /dev/null
+++ b/message-router/publisher/provider/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.ccsdk.sli.adaptors.messagerouter</groupId>
+ <artifactId>publisher.aggregate</artifactId>
+ <version>1.1.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>publisher.provider</artifactId>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>publisher.api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Private-Package>${project.groupId}.publisher.provider.impl</Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/message-router/publisher/provider/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/provider/impl/PublisherApiImpl.java b/message-router/publisher/provider/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/provider/impl/PublisherApiImpl.java
new file mode 100755
index 000000000..4aedc6071
--- /dev/null
+++ b/message-router/publisher/provider/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/provider/impl/PublisherApiImpl.java
@@ -0,0 +1,178 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ *
+ * Modifications Copyright (C) 2019 IBM.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.ccsdk.sli.adaptors.messagerouter.publisher.provider.impl;
+
+import java.io.BufferedReader;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.HttpURLConnection;
+import java.net.SocketException;
+import java.net.URL;
+import java.util.Base64;
+
+import org.onap.ccsdk.sli.adaptors.messagerouter.publisher.api.PublisherApi;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class PublisherApiImpl implements PublisherApi {
+ private static final Logger logger = LoggerFactory.getLogger(PublisherApiImpl.class);
+ protected static final Integer DEFAULT_CONNECT_TIMEOUT = 30000; // will be treated as 30 seconds
+ protected static final Integer DEFAULT_READ_TIMEOUT = 180000; // will be treated as 3 minutes
+ private String authorizationString;
+ protected Integer connectTimeout;
+ protected Integer readTimeout;
+ protected String baseUrl;
+ protected String username;
+ protected String[] hosts;
+ private String password;
+
+ public PublisherApiImpl() {
+ connectTimeout = DEFAULT_CONNECT_TIMEOUT;
+ readTimeout = DEFAULT_READ_TIMEOUT;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ setAuthorizationString();
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ setAuthorizationString();
+ }
+
+ public void setHost(String hostString) {
+ // a comma separated list of hosts can be passed in or a single host may be used
+ if (!hostString.contains(",")) {
+ this.hosts = new String[] { hostString };
+ } else {
+ this.hosts = hostString.split(",");
+ }
+ }
+
+ public void init() {
+ setAuthorizationString();
+ }
+
+ protected String buildUrlString(Integer hostIndex, String topic) {
+ return hosts[hostIndex] + "/events/" + topic;
+ }
+
+ protected void configureHttpURLConnection(HttpURLConnection httpUrlConnection) {
+ httpUrlConnection.setRequestProperty("Content-Type", "application/json");
+ }
+
+ public Boolean publish(String topic, String body) {
+ for (int hostIndex = 0; hostIndex < hosts.length; hostIndex++) {
+ HttpURLConnection httpUrlConnection = null;
+ URL url = null;
+ try {
+ url = new URL(buildUrlString(hostIndex, topic));
+ logger.info("Publishing body to topic {} using the url {}", topic, url);
+ logger.info("Message to publish is\n{}", body);
+ httpUrlConnection = buildHttpURLConnection(url);
+ httpUrlConnection.setDoInput(true);
+ httpUrlConnection.setDoOutput(true);
+ httpUrlConnection.setUseCaches(false);
+ httpUrlConnection.setRequestMethod("POST");
+
+ // Write message
+ httpUrlConnection.setRequestProperty("Content-Length", Integer.toString(body.length()));
+ DataOutputStream outStr = new DataOutputStream(httpUrlConnection.getOutputStream());
+ outStr.write(body.getBytes());
+ outStr.close();
+
+ int status = httpUrlConnection.getResponseCode();
+ logger.info("Publishing body for topic {} using url {} returned status {}.", topic, url, status);
+ if (status < 300) {
+ String responseFromDMaaP = readFromStream(httpUrlConnection.getInputStream());
+ logger.info("Message router response is\n{}", responseFromDMaaP);
+ return true;
+ } else {
+ if (httpUrlConnection.getErrorStream() != null) {
+ String responseFromDMaaP = readFromStream(httpUrlConnection.getErrorStream());
+ logger.warn("Publishing body for topic {} using url {} failed." + " Error message is\n{}",
+ topic, url, responseFromDMaaP);
+ }
+ return false;
+ }
+
+ } catch (SocketException socketException) {
+ logger.error("SocketException was thrown during publishing message to DMaaP on url {}.", url,
+ socketException);
+ if (hostIndex < hosts.length) {
+ logger.info("Message sent to {} failed with a SocketException, but will be tried on {}",
+ hosts[hostIndex], hosts[hostIndex + 1]);
+ }
+ } catch (Exception e) {
+ logger.warn("Exception was thrown during publishing message to DMaaP on url {}.", url, e);
+ return false;
+ } finally {
+ if (httpUrlConnection != null) {
+ httpUrlConnection.disconnect();
+ }
+ }
+ }
+ return false;
+ }
+
+ protected void setAuthorizationString() {
+ String str = buildAuthorizationString(this.username, this.password);
+ this.authorizationString = str;
+ //System.out.println(this.authorizationString);
+ }
+
+ protected String buildAuthorizationString(String username, String password) {
+ String basicAuthString = username + ":" + password;
+ basicAuthString = Base64.getEncoder().encodeToString(basicAuthString.getBytes());
+ return "Basic " + basicAuthString;
+ }
+
+ protected HttpURLConnection buildHttpURLConnection(URL url) throws IOException {
+ HttpURLConnection httpUrlConnection = (HttpURLConnection) url.openConnection();
+ if (authorizationString != null) {
+ System.out.println(authorizationString);
+ httpUrlConnection.setRequestProperty("Authorization", authorizationString);
+ }
+ httpUrlConnection.setRequestProperty("Accept", "application/json");
+ httpUrlConnection.setUseCaches(false);
+ httpUrlConnection.setConnectTimeout(connectTimeout);
+ httpUrlConnection.setReadTimeout(readTimeout);
+ configureHttpURLConnection(httpUrlConnection);
+ return httpUrlConnection;
+ }
+
+ protected String readFromStream(InputStream stream) throws IOException {
+ BufferedReader br = new BufferedReader(new InputStreamReader(stream));
+ StringBuilder sb = new StringBuilder();
+ String line;
+ while ((line = br.readLine()) != null) {
+ sb.append(line);
+ }
+ br.close();
+ return sb.toString();
+ }
+
+} \ No newline at end of file
diff --git a/message-router/publisher/provider/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/message-router/publisher/provider/src/main/resources/OSGI-INF/blueprint/blueprint.xml
new file mode 100755
index 000000000..4702a6260
--- /dev/null
+++ b/message-router/publisher/provider/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.2.0">
+
+ <bean id="publisher"
+ class="org.onap.ccsdk.sli.adaptors.messagerouter.publisher.provider.impl.PublisherApiImpl">
+ <cm:managed-properties
+ persistent-id="org.onap.ccsdk.sli.adaptors.messagerouter.publisher.provider"
+ update-strategy="container-managed" />
+ </bean>
+
+ <service ref="publisher" interface="org.onap.ccsdk.sli.adaptors.messagerouter.publisher.api.PublisherApi" />
+
+</blueprint> \ No newline at end of file
diff --git a/message-router/publisher/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/provider/impl/PublisherApiImplTest.java b/message-router/publisher/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/provider/impl/PublisherApiImplTest.java
new file mode 100644
index 000000000..53744f73e
--- /dev/null
+++ b/message-router/publisher/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/provider/impl/PublisherApiImplTest.java
@@ -0,0 +1,51 @@
+package org.onap.ccsdk.sli.adaptors.messagerouter.publisher.provider.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.junit.Test;
+
+public class PublisherApiImplTest {
+ @Test
+ public void verifyDefaultTimeouts() {
+ PublisherApiImpl pub = new PublisherApiImpl();
+ assertEquals(pub.DEFAULT_CONNECT_TIMEOUT, pub.connectTimeout);
+ assertEquals(pub.DEFAULT_READ_TIMEOUT, pub.readTimeout);
+ }
+
+ @Test
+ public void buildHttpURLConnection() throws Exception {
+ PublisherApiImpl pub = new PublisherApiImpl();
+ pub.init();
+
+ String myUserName = "Batman";
+ pub.setUsername(myUserName);
+ assertEquals(myUserName, pub.username);
+ String password = "P@$$";
+ pub.setPassword(password);
+
+ HttpURLConnection httpUrlConnection = pub.buildHttpURLConnection(new URL("http://localhost:7001"));
+ assertNotNull(httpUrlConnection.getReadTimeout());
+ assertNotNull(httpUrlConnection.getConnectTimeout());
+ assertEquals("application/json", httpUrlConnection.getRequestProperty("Content-Type"));
+ assertEquals("application/json", httpUrlConnection.getRequestProperty("Accept"));
+ }
+
+ @Test
+ public void testMultipleHosts() {
+ PublisherApiImpl pub = new PublisherApiImpl();
+ String myTopic = "worldNews";
+ String hostOne = "http://localhost:7001";
+ String hostTwo = "http://localhost:7002";
+ String hostThree = "http://localhost:7003";
+
+ pub.setHost(hostOne + "," + hostTwo + "," + hostThree);
+
+ assertEquals("http://localhost:7001/events/worldNews", pub.buildUrlString(0, myTopic));
+ assertEquals("http://localhost:7002/events/worldNews", pub.buildUrlString(1, myTopic));
+ assertEquals("http://localhost:7003/events/worldNews", pub.buildUrlString(2, myTopic));
+ }
+} \ No newline at end of file
diff --git a/message-router/publisher/sample.client/pom.xml b/message-router/publisher/sample.client/pom.xml
new file mode 100755
index 000000000..694af1f4a
--- /dev/null
+++ b/message-router/publisher/sample.client/pom.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onap.ccsdk.sli.adaptors.messagerouter</groupId>
+ <artifactId>publisher.aggregate</artifactId>
+ <version>1.1.1-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>sample.client</artifactId>
+ <packaging>bundle</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>publisher.api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Private-Package>${project.groupId}.publisher.client.impl</Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/message-router/publisher/sample.client/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/client/impl/ClientImpl.java b/message-router/publisher/sample.client/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/client/impl/ClientImpl.java
new file mode 100755
index 000000000..d1610305a
--- /dev/null
+++ b/message-router/publisher/sample.client/src/main/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/client/impl/ClientImpl.java
@@ -0,0 +1,58 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
+ *
+ * Modifications Copyright (C) 2019 IBM.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+
+package org.onap.ccsdk.sli.adaptors.messagerouter.publisher.client.impl;
+
+import org.onap.ccsdk.sli.adaptors.messagerouter.publisher.api.PublisherApi;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ClientImpl {
+ private static final Logger logger = LoggerFactory.getLogger(ClientImpl.class);
+ private String topic;
+ private PublisherApi publisher;
+
+ public ClientImpl() {
+
+ }
+
+ public void setPublisher(PublisherApi publisherApi) {
+ this.publisher = publisherApi;
+ }
+
+ public void setTopic(String topic) {
+ this.topic = topic;
+ }
+
+
+
+ public void init() {
+ for (int i = 0; i < 5; i++) {
+ String body = "{\"hello\":\"world " + Math.random() + "\"}";
+ logger.error("Loop iteration " + i + " sending body " + body + " to the topic " + topic);
+ Boolean result = publisher.publish(topic, body);
+ logger.error("Loop iteration " + i + " returned the boolean value " + result);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/message-router/publisher/sample.client/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/message-router/publisher/sample.client/src/main/resources/OSGI-INF/blueprint/blueprint.xml
new file mode 100755
index 000000000..c2e981da2
--- /dev/null
+++ b/message-router/publisher/sample.client/src/main/resources/OSGI-INF/blueprint/blueprint.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.2.0">
+
+ <bean id="client"
+ class="org.onap.ccsdk.sli.adaptors.messagerouter.publisher.client.impl.ClientImpl"
+ init-method="init">
+ <property name="publisher" ref="publisher" />
+ <cm:managed-properties
+ persistent-id="org.onap.ccsdk.sli.adaptors.messagerouter.publisher.client"
+ update-strategy="container-managed" />
+ </bean>
+
+ <reference id="publisher" interface="org.onap.ccsdk.sli.adaptors.messagerouter.publisher.api.PublisherApi" />
+
+</blueprint> \ No newline at end of file
diff --git a/message-router/publisher/sample.client/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/client/impl/ClientImplTest.java b/message-router/publisher/sample.client/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/client/impl/ClientImplTest.java
new file mode 100644
index 000000000..82a1566c3
--- /dev/null
+++ b/message-router/publisher/sample.client/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/publisher/client/impl/ClientImplTest.java
@@ -0,0 +1,29 @@
+package org.onap.ccsdk.sli.adaptors.messagerouter.publisher.client.impl;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.onap.ccsdk.sli.adaptors.messagerouter.publisher.api.PublisherApi;
+
+public class ClientImplTest {
+
+ @Test
+ public void testSetTopic() {
+ ClientImpl impl = new ClientImpl();
+ String myTopic = "stock updates";
+ impl.setTopic(myTopic);
+
+ PublisherApi publisherImpl = new PublisherApi() {
+
+ @Override
+ public Boolean publish(String topic, String body) {
+ assertEquals(myTopic,topic);
+ return true;
+ }
+
+ };
+ impl.setPublisher(publisherImpl);
+ impl.init();
+ }
+
+}