From ae4b66d2e236855929313c6b2b4cbfe448ee4184 Mon Sep 17 00:00:00 2001 From: virajput Date: Fri, 1 Sep 2017 00:49:58 +0530 Subject: Added license header and other review comments Issue-Id: MSB-23 Change-Id: I58ac54a53d8fb281c6284139ba5323732f3ec773 Signed-off-by: virajput --- example-spring-boot/pom.xml | 35 ++++++---- .../springboot/ContextRefreshedListener.java | 38 +++++++++++ .../example/springboot/EmployeeServiceClient.java | 24 +++++++ .../msb/sdk/example/springboot/ExampleClient.java | 44 +++++++++++++ .../msb/sdk/example/springboot/SpringBootApp.java | 24 +++++++ .../sdk/example/springboot/common/MsbHelper.java | 50 +++++++++++++++ .../springboot/controller/EmployeeController.java | 25 ++++++++ .../msb/sdk/example/springboot/model/Employee.java | 74 ++++++++++++++++++++++ 8 files changed, 302 insertions(+), 12 deletions(-) create mode 100644 example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/ContextRefreshedListener.java create mode 100644 example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/EmployeeServiceClient.java create mode 100644 example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/ExampleClient.java create mode 100644 example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/SpringBootApp.java create mode 100644 example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/common/MsbHelper.java create mode 100644 example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/controller/EmployeeController.java create mode 100644 example-spring-boot/src/main/java/org/onap/msb/sdk/example/springboot/model/Employee.java 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 @@ 4.0.0 + + + org.onap.oparent + oparent + 1.0.0-SNAPSHOT + - org.onap.boot.example - springBootService + org.onap.msb.sdk + msb-java-sdk-sprint-boot-example 0.0.1-SNAPSHOT jar - springBootService - msb skd Demo for Spring Boot - - - org.springframework.boot - spring-boot-starter-parent - 1.5.6.RELEASE - - + msb-java-sdk-sprint-boot-example + msb java skd Spring Boot example UTF-8 @@ -24,6 +23,18 @@ 1.8 + + + + org.springframework.boot + spring-boot-starter-parent + 1.5.6.RELEASE + import + pom + + + + org.springframework.boot @@ -54,9 +65,9 @@ org.springframework.boot spring-boot-maven-plugin + 1.5.6.RELEASE - 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{ + + @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 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 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 -- cgit 1.2.3-korg