aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--example-spring-boot/pom.xml35
-rw-r--r--example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/ContextRefreshedListener.java38
-rw-r--r--example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/EmployeeServiceClient.java24
-rw-r--r--example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/ExampleClient.java44
-rw-r--r--example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/SpringBootApp.java24
-rw-r--r--example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/common/MsbHelper.java50
-rw-r--r--example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/controller/EmployeeController.java25
-rw-r--r--example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/model/Employee.java74
8 files changed, 302 insertions, 12 deletions
diff --git a/example-spring-boot/pom.xml b/example-spring-boot/pom.xml
index 5989f75..be3ada7 100644
--- a/example-spring-boot/pom.xml
+++ b/example-spring-boot/pom.xml
@@ -2,21 +2,20 @@
<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.oparent</groupId>
+ <artifactId>oparent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </parent>
- <groupId>org.onap.boot.example</groupId>
- <artifactId>springBootService</artifactId>
+ <groupId>org.onap.msb.sdk</groupId>
+ <artifactId>msb-java-sdk-sprint-boot-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
- <name>springBootService</name>
- <description>msb skd Demo for Spring Boot</description>
-
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>1.5.6.RELEASE</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
+ <name>msb-java-sdk-sprint-boot-example</name>
+ <description>msb java skd Spring Boot example</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -24,6 +23,18 @@
<java.version>1.8</java.version>
</properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-parent</artifactId>
+ <version>1.5.6.RELEASE</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
@@ -54,9 +65,9 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
+ <version>1.5.6.RELEASE</version>
</plugin>
</plugins>
</build>
-
</project>
diff --git a/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/ContextRefreshedListener.java b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/ContextRefreshedListener.java
new file mode 100644
index 0000000..9f3e532
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/ContextRefreshedListener.java
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright 2017 Infosys Limited and others.
+ *------------------------------------------------------------------------------
+ * 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.
+ ******************************************************************************/
+package org.onap.msb.sdk.example.springboot;
+
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.stereotype.Component;
+import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
+import org.onap.msb.sdk.example.springboot.common.MsbHelper;
+
+@Component
+public class ContextRefreshedListener implements ApplicationListener<ContextRefreshedEvent>{
+
+ @Override
+ public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
+ System.out.println("Registring Service...");
+ String MSB_IP="127.0.0.1";
+ int MSB_Port=10081;
+
+ MSBServiceClient msbClient = new MSBServiceClient(MSB_IP, MSB_Port);
+ MsbHelper helper = new MsbHelper(msbClient);
+
+ try {
+ helper.registerMsb();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+} \ No newline at end of file
diff --git a/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/EmployeeServiceClient.java b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/EmployeeServiceClient.java
new file mode 100644
index 0000000..8017f04
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/EmployeeServiceClient.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright 2017 Infosys Limited and others.
+ *------------------------------------------------------------------------------
+ * 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.
+ ******************************************************************************/
+package org.onap.msb.sdk.example.springboot;
+
+import org.onap.msb.sdk.example.springboot.model.Employee;
+import org.onap.msb.sdk.httpclient.annotaion.ServiceHttpEndPoint;
+
+import retrofit2.Call;
+import retrofit2.http.GET;
+
+@ServiceHttpEndPoint(serviceName = "employee", serviceVersion = "v1")
+public interface EmployeeServiceClient {
+ @GET("employee")
+ Call<Employee> queryEmployee();
+}
diff --git a/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/ExampleClient.java b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/ExampleClient.java
new file mode 100644
index 0000000..ff0dee8
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/ExampleClient.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright 2017 Infosys Limited and others.
+ *------------------------------------------------------------------------------
+ * 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.
+ ******************************************************************************/
+package org.onap.msb.sdk.example.springboot;
+
+import java.io.IOException;
+
+import org.onap.msb.sdk.example.springboot.model.Employee;
+import org.onap.msb.sdk.httpclient.RestServiceCreater;
+import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
+
+
+public class ExampleClient {
+
+ /**
+ * @param args
+ * @throws IOException
+ */
+ public static void main(String[] args) throws IOException {
+ //For real use case, MSB IP and Port should come from configuration file instead of hard code here
+ String MSB_IP="192.168.0.110";
+ int MSB_Port=10081;
+
+ MSBServiceClient msbClient = new MSBServiceClient(MSB_IP, MSB_Port);
+
+ RestServiceCreater restServiceCreater =
+ new RestServiceCreater(msbClient);
+
+ EmployeeServiceClient implProxy =
+ restServiceCreater.createService(EmployeeServiceClient.class);
+
+ Employee employee = implProxy.queryEmployee().execute().body();
+ System.out.println("Employee:" + employee);
+ }
+
+}
diff --git a/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/SpringBootApp.java b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/SpringBootApp.java
new file mode 100644
index 0000000..4a37b58
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/SpringBootApp.java
@@ -0,0 +1,24 @@
+/*******************************************************************************
+ * Copyright 2017 Infosys Limited and others.
+ *------------------------------------------------------------------------------
+ * 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.
+ ******************************************************************************/
+package org.onap.msb.sdk.example.springboot;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SpringBootApp {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootApp.class, args);
+ }
+}
+
diff --git a/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/common/MsbHelper.java b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/common/MsbHelper.java
new file mode 100644
index 0000000..9c1642c
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/common/MsbHelper.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright 2017 Infosys Limited and others.
+ *------------------------------------------------------------------------------
+ * 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.
+ ******************************************************************************/
+package org.onap.msb.sdk.example.springboot.common;
+
+import java.net.InetAddress;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.onap.msb.sdk.discovery.entity.MicroServiceInfo;
+import org.onap.msb.sdk.discovery.entity.Node;
+import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
+
+public class MsbHelper {
+
+ private MSBServiceClient msbClient;
+
+ public MsbHelper(MSBServiceClient msbClient) {
+ super();
+ this.msbClient = msbClient;
+ }
+
+ public void registerMsb() throws Exception {
+
+
+ MicroServiceInfo msinfo = new MicroServiceInfo();
+
+ msinfo.setServiceName("employee");
+ msinfo.setVersion("v1");
+ msinfo.setUrl("/api/v1");
+ msinfo.setProtocol("REST");
+ msinfo.setVisualRange("0|1");
+
+ Set<Node> nodes = new HashSet<>();
+ Node node1 = new Node();
+ node1.setIp(InetAddress.getLocalHost().getHostAddress());
+ node1.setPort("8080");
+ nodes.add(node1);
+ msinfo.setNodes(nodes);
+ msbClient.registerMicroServiceInfo(msinfo, false);
+ }
+}
diff --git a/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/controller/EmployeeController.java b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/controller/EmployeeController.java
new file mode 100644
index 0000000..9223006
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/controller/EmployeeController.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright 2017 Infosys Limited and others.
+ *------------------------------------------------------------------------------
+ * 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.
+ ******************************************************************************/
+package org.onap.msb.sdk.example.springboot.controller;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import org.onap.msb.sdk.example.springboot.model.Employee;;
+
+@RestController
+public class EmployeeController {
+ @RequestMapping("/employee")
+ public Employee getEmployees() {
+ return (new Employee(1,"John","Kelly","john.kelly@gmail.com"));
+ }
+} \ No newline at end of file
diff --git a/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/model/Employee.java b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/model/Employee.java
new file mode 100644
index 0000000..43e6d88
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/model/Employee.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright 2017 Infosys Limited and others.
+ *------------------------------------------------------------------------------
+ * 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.
+ ******************************************************************************/
+package org.onap.msb.sdk.example.springboot.model;
+
+import java.io.Serializable;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class Employee implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @JsonProperty
+ private Integer id;
+
+ @JsonProperty
+ private String firstName;
+
+ @JsonProperty
+ private String lastName;
+
+ @JsonProperty
+ private String email;
+
+ public Employee() {}
+
+ public Employee(Integer id, String firstName, String lastName, String email) {
+ //super();
+ this.id = id;
+ this.firstName = firstName;
+ this.lastName = lastName;
+ this.email = email;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+ public void setId(Integer id) {
+ this.id = id;
+ }
+ public String getFirstName() {
+ return firstName;
+ }
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+ public String getLastName() {
+ return lastName;
+ }
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+ public String getEmail() {
+ return email;
+ }
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ @Override
+ public String toString() {
+ return "Employee [id=" + id + ", firstName=" + firstName
+ + ", lastName=" + lastName + ", email=" + email + "]";
+ }
+} \ No newline at end of file