From 9252e604db14785fe5382e33cedffbdd2759091d Mon Sep 17 00:00:00 2001 From: HuabingZhao Date: Fri, 18 Aug 2017 16:18:01 +0800 Subject: Modify Example code Issue-Id: MSB-23 Change-Id: I03a05b27987015725234d31ccbef2b979be40f92 Signed-off-by: HuabingZhao --- .../sdk/example/client/AnimalServiceClient.java | 33 +++++++++++ .../onap/msb/sdk/example/client/ExampleClient.java | 49 +++++++++++++++ .../org/onap/msb/sdk/example/common/Animal.java | 69 ++++++++++++++++++++++ .../org/onap/msb/sdk/example/server/Config.java | 24 ++++++++ .../onap/msb/sdk/example/server/ExampleApp.java | 54 +++++++++++++++++ .../org/onap/msb/sdk/example/server/MsbHelper.java | 62 +++++++++++++++++++ .../example/server/resources/AnimalResource.java | 38 ++++++++++++ .../sdk/httpclient/client/AnimalServiceClient.java | 34 ----------- .../msb/sdk/httpclient/client/ExampleClient.java | 47 --------------- .../org/onap/msb/sdk/httpclient/common/Animal.java | 69 ---------------------- .../org/onap/msb/sdk/httpclient/server/Config.java | 24 -------- .../onap/msb/sdk/httpclient/server/ExampleApp.java | 51 ---------------- .../onap/msb/sdk/httpclient/server/MsbHelper.java | 66 --------------------- .../server/resources/AnimalResource.java | 38 ------------ 14 files changed, 329 insertions(+), 329 deletions(-) create mode 100644 example/src/main/java/org/onap/msb/sdk/example/client/AnimalServiceClient.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/client/ExampleClient.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/common/Animal.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/server/Config.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/server/ExampleApp.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/server/MsbHelper.java create mode 100644 example/src/main/java/org/onap/msb/sdk/example/server/resources/AnimalResource.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/client/AnimalServiceClient.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/client/ExampleClient.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/common/Animal.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/server/Config.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/server/ExampleApp.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/server/MsbHelper.java delete mode 100644 example/src/main/java/org/onap/msb/sdk/httpclient/server/resources/AnimalResource.java (limited to 'example/src/main') diff --git a/example/src/main/java/org/onap/msb/sdk/example/client/AnimalServiceClient.java b/example/src/main/java/org/onap/msb/sdk/example/client/AnimalServiceClient.java new file mode 100644 index 0000000..8600241 --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/client/AnimalServiceClient.java @@ -0,0 +1,33 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. 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.client; + +import org.onap.msb.sdk.example.common.Animal; +import org.onap.msb.sdk.httpclient.annotaion.ServiceHttpEndPoint; + +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Path; + +/** + * @author hu.rui + * + */ + +@ServiceHttpEndPoint(serviceName = "animals", serviceVersion = "v1") +public interface AnimalServiceClient { + + @GET("animals/{name}") + Call queryAnimal1(@Path("name") String name); +} diff --git a/example/src/main/java/org/onap/msb/sdk/example/client/ExampleClient.java b/example/src/main/java/org/onap/msb/sdk/example/client/ExampleClient.java new file mode 100644 index 0000000..59263f1 --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/client/ExampleClient.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. 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.client; + +import java.io.IOException; + +import org.onap.msb.sdk.example.common.Animal; +import org.onap.msb.sdk.httpclient.RetrofitServiceCreater; +import org.onap.msb.sdk.httpclient.conf.HttpClientConf; +import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; + + +public class ExampleClient { + + /** + * @param args + * @throws IOException + */ + public static void main(String[] args) throws IOException { + String MSB_IP="127.0.0.1"; + int MSB_Port=10081; + + HttpClientConf globalHttpClientConf = new HttpClientConf(); + MSBServiceWrapperClient msbClient = new MSBServiceWrapperClient(MSB_IP, MSB_Port); + + RetrofitServiceCreater retrofitServiceCreater = + new RetrofitServiceCreater(globalHttpClientConf, msbClient); + + AnimalServiceClient implProxy = + retrofitServiceCreater.createRetrofitService(AnimalServiceClient.class); + Animal animal = implProxy.queryAnimal1("panda").execute().body(); + System.out.println("animal:" + animal); + } + +} diff --git a/example/src/main/java/org/onap/msb/sdk/example/common/Animal.java b/example/src/main/java/org/onap/msb/sdk/example/common/Animal.java new file mode 100644 index 0000000..03572ce --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/common/Animal.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. 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.common; + +import java.io.Serializable; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class Animal implements Serializable { + + private static final long serialVersionUID = -717235590728668809L; + + @JsonProperty + private String type; + + @JsonProperty + private String name; + + @JsonProperty + private int age; + + public Animal() {} + + public Animal(String type, String name, int age) { + this.type = type; + this.name = name; + this.age = age; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + @Override + public String toString() { + return "Animal{" + "type='" + type + '\'' + ", name='" + name + '\'' + ", age=" + age + '}'; + } +} diff --git a/example/src/main/java/org/onap/msb/sdk/example/server/Config.java b/example/src/main/java/org/onap/msb/sdk/example/server/Config.java new file mode 100644 index 0000000..446e2c1 --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/server/Config.java @@ -0,0 +1,24 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. 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.server; + +import io.dropwizard.Configuration; + +public class Config extends Configuration { + + + +} + + diff --git a/example/src/main/java/org/onap/msb/sdk/example/server/ExampleApp.java b/example/src/main/java/org/onap/msb/sdk/example/server/ExampleApp.java new file mode 100644 index 0000000..b93875f --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/server/ExampleApp.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. 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.server; + +import org.onap.msb.sdk.example.server.resources.AnimalResource; +import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; + +import io.dropwizard.Application; +import io.dropwizard.setup.Environment; + + +public class ExampleApp extends Application { + + private static final String CONFIGURATION_FILE = "example.yml"; + + public static void main(String[] args) throws Exception { + + String configFile = null; + if (args.length > 1) { + configFile = args[0]; + } else { + configFile = ExampleApp.class.getClassLoader().getResource(CONFIGURATION_FILE).getFile(); + } + args = new String[] {"server", configFile}; + new ExampleApp().run(args); + } + + @Override + public void run(Config configuration, Environment environment) throws Exception { + + String MSB_IP="127.0.0.1"; + int MSB_Port=10081; + + environment.jersey().register(new AnimalResource()); + + MSBServiceWrapperClient msbClient = new MSBServiceWrapperClient(MSB_IP, MSB_Port); + + MsbHelper helper = new MsbHelper(msbClient); + helper.registerMsb(); + + } + +} diff --git a/example/src/main/java/org/onap/msb/sdk/example/server/MsbHelper.java b/example/src/main/java/org/onap/msb/sdk/example/server/MsbHelper.java new file mode 100644 index 0000000..7b0c79d --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/server/MsbHelper.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. 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.server; + +import java.net.InetAddress; +import java.util.HashSet; +import java.util.Set; + +import org.jvnet.hk2.annotations.Service; +import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; +import org.onap.msb.sdk.discovery.entity.Node; +import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; + +/** + * @author hu.rui + * + */ +@Service +public class MsbHelper { + + private MSBServiceWrapperClient msbClient; + + + + public MsbHelper(MSBServiceWrapperClient msbClient) { + super(); + this.msbClient = msbClient; + } + + + + public void registerMsb() throws Exception { + + + MicroServiceInfo msinfo = new MicroServiceInfo(); + + msinfo.setServiceName("animals"); + msinfo.setVersion("v1"); + msinfo.setUrl("/api/rpc/v1"); + msinfo.setProtocol("REST"); + msinfo.setVisualRange("0|1"); + + Set nodes = new HashSet<>(); + Node node1 = new Node(); + node1.setIp(InetAddress.getLocalHost().getHostAddress()); + node1.setPort("9090"); + nodes.add(node1); + msinfo.setNodes(nodes); + msbClient.registerMicroServiceInfo(msinfo, false); + } +} diff --git a/example/src/main/java/org/onap/msb/sdk/example/server/resources/AnimalResource.java b/example/src/main/java/org/onap/msb/sdk/example/server/resources/AnimalResource.java new file mode 100644 index 0000000..ce7115f --- /dev/null +++ b/example/src/main/java/org/onap/msb/sdk/example/server/resources/AnimalResource.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright 2017 ZTE, Inc. 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.server.resources; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.onap.msb.sdk.example.common.Animal; + + +@Path("/animals") +public class AnimalResource { + + + @GET + @Path("/{name}") + @Produces(MediaType.APPLICATION_JSON) + public Response queryJson(@PathParam("name") String name) { + return Response.ok(new Animal("animal", name, Math.abs((int) System.currentTimeMillis() % 10))) + .build(); + } + +} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/client/AnimalServiceClient.java b/example/src/main/java/org/onap/msb/sdk/httpclient/client/AnimalServiceClient.java deleted file mode 100644 index 22101ad..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/client/AnimalServiceClient.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. 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.httpclient.client; - -import org.onap.msb.sdk.httpclient.annotaion.ServiceHttpEndPoint; -import org.onap.msb.sdk.httpclient.common.Animal; - -import retrofit2.Call; -import retrofit2.http.GET; -import retrofit2.http.Path; - -/** - * @author hu.rui - * - */ - -@ServiceHttpEndPoint(serviceName = "animals", serviceVersion = "v1", nameSpace = "javaAF") -public interface AnimalServiceClient { - - @GET("animals/{name}") - Call queryAnimal(@Path("name") String name); - -} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/client/ExampleClient.java b/example/src/main/java/org/onap/msb/sdk/httpclient/client/ExampleClient.java deleted file mode 100644 index 570078b..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/client/ExampleClient.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. 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.httpclient.client; - -import java.io.IOException; - -import org.onap.msb.sdk.httpclient.RetrofitServiceCreater; -import org.onap.msb.sdk.httpclient.common.Animal; -import org.onap.msb.sdk.httpclient.conf.HttpClientConf; -import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; - - -public class ExampleClient { - - /** - * @param args - * @throws IOException - */ - public static void main(String[] args) throws IOException { - - HttpClientConf globalHttpClientConf = new HttpClientConf(); - MSBServiceWrapperClient msbClient = new MSBServiceWrapperClient("127.0.0.1", 10081); - - RetrofitServiceCreater retrofitServiceCreater = - new RetrofitServiceCreater(globalHttpClientConf, msbClient); - - AnimalServiceClient implProxy = - retrofitServiceCreater.createRetrofitService(AnimalServiceClient.class); - Animal animal = implProxy.queryAnimal("example").execute().body(); - System.out.println("animal:" + animal); - } - -} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/common/Animal.java b/example/src/main/java/org/onap/msb/sdk/httpclient/common/Animal.java deleted file mode 100644 index 092a2f7..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/common/Animal.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. 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.httpclient.common; - -import java.io.Serializable; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Animal implements Serializable { - - private static final long serialVersionUID = -717235590728668809L; - - @JsonProperty - private String type; - - @JsonProperty - private String name; - - @JsonProperty - private int age; - - public Animal() {} - - public Animal(String type, String name, int age) { - this.type = type; - this.name = name; - this.age = age; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - @Override - public String toString() { - return "Animal{" + "type='" + type + '\'' + ", name='" + name + '\'' + ", age=" + age + '}'; - } -} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/server/Config.java b/example/src/main/java/org/onap/msb/sdk/httpclient/server/Config.java deleted file mode 100644 index 4dbb6eb..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/server/Config.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. 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.httpclient.server; - -import io.dropwizard.Configuration; - -public class Config extends Configuration { - - - -} - - diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/server/ExampleApp.java b/example/src/main/java/org/onap/msb/sdk/httpclient/server/ExampleApp.java deleted file mode 100644 index 03c052a..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/server/ExampleApp.java +++ /dev/null @@ -1,51 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. 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.httpclient.server; - -import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; -import org.onap.msb.sdk.httpclient.server.resources.AnimalResource; - -import io.dropwizard.Application; -import io.dropwizard.setup.Environment; - - -public class ExampleApp extends Application { - - private static final String CONFIGURATION_FILE = "example.yml"; - - public static void main(String[] args) throws Exception { - - String configFile = null; - if (args.length > 1) { - configFile = args[0]; - } else { - configFile = ExampleApp.class.getClassLoader().getResource(CONFIGURATION_FILE).getFile(); - } - args = new String[] {"server", configFile}; - new ExampleApp().run(args); - } - - @Override - public void run(Config configuration, Environment environment) throws Exception { - - environment.jersey().register(new AnimalResource()); - - MSBServiceWrapperClient msbClient = new MSBServiceWrapperClient("127.0.0.1", 10081); - - MsbHelper helper = new MsbHelper(msbClient); - helper.registerMsb(); - - } - -} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/server/MsbHelper.java b/example/src/main/java/org/onap/msb/sdk/httpclient/server/MsbHelper.java deleted file mode 100644 index ffaba08..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/server/MsbHelper.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. 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.httpclient.server; - -import java.net.InetAddress; -import java.util.HashSet; -import java.util.Set; - -import org.jvnet.hk2.annotations.Service; -import org.onap.msb.sdk.discovery.entity.MicroServiceInfo; -import org.onap.msb.sdk.discovery.entity.Node; -import org.onap.msb.sdk.httpclient.msb.MSBServiceWrapperClient; - -/** - * @author hu.rui - * - */ -@Service -public class MsbHelper { - - private MSBServiceWrapperClient msbClient; - - - - public MsbHelper(MSBServiceWrapperClient msbClient) { - super(); - this.msbClient = msbClient; - } - - - - public void registerMsb() throws Exception { - - - MicroServiceInfo msinfo = new MicroServiceInfo(); - - msinfo.setServiceName("animals"); - msinfo.setVersion("v1"); - msinfo.setUrl("/api/rpc/v1"); - msinfo.setProtocol("REST"); - msinfo.setVisualRange("0|1"); - - Set nodes = new HashSet<>(); - Node node1 = new Node(); - node1.setIp(InetAddress.getLocalHost().getHostAddress()); - node1.setPort("9090"); - nodes.add(node1); - msinfo.setNodes(nodes); - msbClient.registerMicroServiceInfo(msinfo, false); - - } - - - -} diff --git a/example/src/main/java/org/onap/msb/sdk/httpclient/server/resources/AnimalResource.java b/example/src/main/java/org/onap/msb/sdk/httpclient/server/resources/AnimalResource.java deleted file mode 100644 index 7a51c0f..0000000 --- a/example/src/main/java/org/onap/msb/sdk/httpclient/server/resources/AnimalResource.java +++ /dev/null @@ -1,38 +0,0 @@ -/******************************************************************************* - * Copyright 2017 ZTE, Inc. 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.httpclient.server.resources; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.onap.msb.sdk.httpclient.common.Animal; - - -@Path("/animals") -public class AnimalResource { - - - @GET - @Path("/{name}") - @Produces(MediaType.APPLICATION_JSON) - public Response query(@PathParam("name") String name) { - return Response.ok(new Animal("animal", name, (int) System.currentTimeMillis() % 10)).build(); - } - - -} -- cgit