aboutsummaryrefslogtreecommitdiffstats
path: root/example-spring-boot/src
diff options
context:
space:
mode:
authorvirajput <vijendra_rajput@infosys.com>2017-08-31 15:46:27 +0530
committervirajput <vijendra_rajput@infosys.com>2017-08-31 15:49:51 +0530
commite638628b22fef6f480fa104cd696834dddf6c030 (patch)
treedd66e5f9c794eca6b6239ee5dbff980a2f8bf647 /example-spring-boot/src
parentde0c3cac5c259a83eba9711aa295ddf919fd6df5 (diff)
added spring boot example using msb java sdk
Issue-Id: MSB-23 Change-Id: Ic3caf7d63a4588aab73df1b07da3d15d6edfa485 Signed-off-by: virajput <vijendra_rajput@infosys.com>
Diffstat (limited to 'example-spring-boot/src')
-rw-r--r--example-spring-boot/src/main/java/org/onap/boot/example/demo/ContextRefreshedListener.java27
-rw-r--r--example-spring-boot/src/main/java/org/onap/boot/example/demo/EmployeeServiceClient.java13
-rw-r--r--example-spring-boot/src/main/java/org/onap/boot/example/demo/ExampleClient.java35
-rw-r--r--example-spring-boot/src/main/java/org/onap/boot/example/demo/SpringBootApp.java13
-rw-r--r--example-spring-boot/src/main/java/org/onap/boot/example/demo/controller/EmployeeController.java22
-rw-r--r--example-spring-boot/src/main/java/org/onap/boot/example/demo/model/Employee.java63
-rw-r--r--example-spring-boot/src/main/java/org/onap/boot/example/demo/msb/MsbHelper.java39
-rw-r--r--example-spring-boot/src/main/resources/application.properties1
-rw-r--r--example-spring-boot/src/test/java/org/onap/boot/example/demo/SpringBootServiceApplicationTests.java16
9 files changed, 229 insertions, 0 deletions
diff --git a/example-spring-boot/src/main/java/org/onap/boot/example/demo/ContextRefreshedListener.java b/example-spring-boot/src/main/java/org/onap/boot/example/demo/ContextRefreshedListener.java
new file mode 100644
index 0000000..c352f80
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/boot/example/demo/ContextRefreshedListener.java
@@ -0,0 +1,27 @@
+package org.onap.boot.example.demo;
+
+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.boot.example.demo.msb.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/boot/example/demo/EmployeeServiceClient.java b/example-spring-boot/src/main/java/org/onap/boot/example/demo/EmployeeServiceClient.java
new file mode 100644
index 0000000..8a7670b
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/boot/example/demo/EmployeeServiceClient.java
@@ -0,0 +1,13 @@
+package org.onap.boot.example.demo;
+
+import org.onap.boot.example.demo.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/boot/example/demo/ExampleClient.java b/example-spring-boot/src/main/java/org/onap/boot/example/demo/ExampleClient.java
new file mode 100644
index 0000000..720264b
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/boot/example/demo/ExampleClient.java
@@ -0,0 +1,35 @@
+package org.onap.boot.example.demo;
+
+import java.io.IOException;
+
+import org.onap.boot.example.demo.model.Employee;
+import org.onap.msb.sdk.httpclient.RestServiceCreater;
+import org.onap.msb.sdk.httpclient.msb.MSBServiceClient;
+
+import retrofit2.Response;
+
+
+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/boot/example/demo/SpringBootApp.java b/example-spring-boot/src/main/java/org/onap/boot/example/demo/SpringBootApp.java
new file mode 100644
index 0000000..b00b2e1
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/boot/example/demo/SpringBootApp.java
@@ -0,0 +1,13 @@
+package org.onap.boot.example.demo;
+
+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/boot/example/demo/controller/EmployeeController.java b/example-spring-boot/src/main/java/org/onap/boot/example/demo/controller/EmployeeController.java
new file mode 100644
index 0000000..a0046ad
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/boot/example/demo/controller/EmployeeController.java
@@ -0,0 +1,22 @@
+package org.onap.boot.example.demo.controller;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
+
+import org.onap.boot.example.demo.model.Employee;;
+
+@RestController
+public class EmployeeController
+{
+ @RequestMapping("/employee")
+ public Employee getEmployees()
+ {
+ //List<Employee> employeesList = new ArrayList<Employee>();
+ //employeesList.add(new Employee(1,"John","Kelly","john.kelly@gmail.com"));
+ 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/boot/example/demo/model/Employee.java b/example-spring-boot/src/main/java/org/onap/boot/example/demo/model/Employee.java
new file mode 100644
index 0000000..b5cd629
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/boot/example/demo/model/Employee.java
@@ -0,0 +1,63 @@
+package org.onap.boot.example.demo.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
diff --git a/example-spring-boot/src/main/java/org/onap/boot/example/demo/msb/MsbHelper.java b/example-spring-boot/src/main/java/org/onap/boot/example/demo/msb/MsbHelper.java
new file mode 100644
index 0000000..8e81f66
--- /dev/null
+++ b/example-spring-boot/src/main/java/org/onap/boot/example/demo/msb/MsbHelper.java
@@ -0,0 +1,39 @@
+package org.onap.boot.example.demo.msb;
+
+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/resources/application.properties b/example-spring-boot/src/main/resources/application.properties
new file mode 100644
index 0000000..001e1f0
--- /dev/null
+++ b/example-spring-boot/src/main/resources/application.properties
@@ -0,0 +1 @@
+server.contextPath=/api/v1 \ No newline at end of file
diff --git a/example-spring-boot/src/test/java/org/onap/boot/example/demo/SpringBootServiceApplicationTests.java b/example-spring-boot/src/test/java/org/onap/boot/example/demo/SpringBootServiceApplicationTests.java
new file mode 100644
index 0000000..8dfe937
--- /dev/null
+++ b/example-spring-boot/src/test/java/org/onap/boot/example/demo/SpringBootServiceApplicationTests.java
@@ -0,0 +1,16 @@
+package org.onap.boot.example.demo;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest
+public class SpringBootServiceApplicationTests {
+
+ @Test
+ public void contextLoads() {
+ }
+
+}