From 4673d50960034dddd0620dbde0f86d8f61e12b4e Mon Sep 17 00:00:00 2001 From: virajput Date: Fri, 1 Sep 2017 21:43:34 +0530 Subject: added spring boot example using msb java sdk Issue-Id: MSB-23 Change-Id: I789dc5f101a3e511f9f4ccc6f023c57489ea28f6 Signed-off-by: virajput --- example-spring-boot/pom.xml | 24 +++++++++------------- .../springboot/ContextRefreshedListener.java | 14 +++++++------ .../example/springboot/EmployeeServiceClient.java | 8 +++++--- .../msb/sdk/example/springboot/ExampleClient.java | 7 ++++--- .../msb/sdk/example/springboot/SpringBootApp.java | 8 ++++---- .../sdk/example/springboot/common/MsbHelper.java | 6 ++++-- .../springboot/controller/EmployeeController.java | 9 ++++---- .../msb/sdk/example/springboot/model/Employee.java | 17 +++++++-------- 8 files changed, 49 insertions(+), 44 deletions(-) diff --git a/example-spring-boot/pom.xml b/example-spring-boot/pom.xml index be3ada7..07a02c2 100644 --- a/example-spring-boot/pom.xml +++ b/example-spring-boot/pom.xml @@ -2,11 +2,11 @@ 4.0.0 - + - org.onap.oparent - oparent - 1.0.0-SNAPSHOT + org.onap.oparent + oparent + 1.0.0-SNAPSHOT org.onap.msb.sdk @@ -34,30 +34,26 @@ - + org.springframework.boot spring-boot-starter - org.springframework.boot spring-boot-starter-test test - - org.springframework.boot - spring-boot-starter-web + org.springframework.boot + spring-boot-starter-web - - - org.onap.msb.sdk + + org.onap.msb.sdk msb-java-sdk 1.0.0-SNAPSHOT - - + 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 index 9f3e532..2c4cc45 100644 --- 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 @@ -1,9 +1,11 @@ /******************************************************************************* * 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 @@ -28,11 +30,11 @@ public class ContextRefreshedListener implements ApplicationListener queryEmployee(); + @GET("employee") + Call 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 index ff0dee8..bce0d96 100644 --- 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 @@ -1,9 +1,11 @@ /******************************************************************************* * 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 @@ -17,7 +19,6 @@ 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 { /** @@ -26,7 +27,7 @@ public class ExampleClient { */ 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"; + String MSB_IP="127.0.0.1"; int MSB_Port=10081; MSBServiceClient msbClient = new MSBServiceClient(MSB_IP, MSB_Port); 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 index 4a37b58..8ba925d 100644 --- 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 @@ -1,9 +1,11 @@ /******************************************************************************* * 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 @@ -16,9 +18,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringBootApp { - public static void main(String[] args) { SpringApplication.run(SpringBootApp.class, args); } -} - +} \ No newline at end of file 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 index 9c1642c..ba28cba 100644 --- 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 @@ -1,9 +1,11 @@ /******************************************************************************* * 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 @@ -38,7 +40,7 @@ public class MsbHelper { msinfo.setUrl("/api/v1"); msinfo.setProtocol("REST"); msinfo.setVisualRange("0|1"); - + Set nodes = new HashSet<>(); Node node1 = new Node(); node1.setIp(InetAddress.getLocalHost().getHostAddress()); 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 index 9223006..bed8bfa 100644 --- 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 @@ -1,9 +1,11 @@ /******************************************************************************* * 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 @@ -13,9 +15,8 @@ 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;; - +import org.onap.msb.sdk.example.springboot.model.Employee; + @RestController public class EmployeeController { @RequestMapping("/employee") 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 index 43e6d88..f0076c2 100644 --- 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 @@ -1,9 +1,11 @@ /******************************************************************************* * 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 @@ -12,25 +14,24 @@ 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; + + 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) { @@ -40,7 +41,7 @@ public class Employee implements Serializable { this.lastName = lastName; this.email = email; } - + public Integer getId() { return id; } -- cgit 1.2.3-korg