aboutsummaryrefslogtreecommitdiffstats
path: root/example/src/main/java/org/onap/msb/sdk/example
diff options
context:
space:
mode:
Diffstat (limited to 'example/src/main/java/org/onap/msb/sdk/example')
-rw-r--r--example/src/main/java/org/onap/msb/sdk/example/client/AnimalServiceClient.java33
-rw-r--r--example/src/main/java/org/onap/msb/sdk/example/client/ExampleClient.java49
-rw-r--r--example/src/main/java/org/onap/msb/sdk/example/common/Animal.java69
-rw-r--r--example/src/main/java/org/onap/msb/sdk/example/server/Config.java24
-rw-r--r--example/src/main/java/org/onap/msb/sdk/example/server/ExampleApp.java54
-rw-r--r--example/src/main/java/org/onap/msb/sdk/example/server/MsbHelper.java62
-rw-r--r--example/src/main/java/org/onap/msb/sdk/example/server/resources/AnimalResource.java38
7 files changed, 329 insertions, 0 deletions
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<Animal> 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<Config> {
+
+ 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<Node> 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();
+ }
+
+}