Skip to content

Commit b60bf88

Browse files
zhengyangyongWillemJiang
authored andcommitted
SCB-434 add @get sample code and update readme
Signed-off-by: zhengyangyong <yangyong.zheng@huawei.com>
1 parent 17ad0d4 commit b60bf88

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

samples/jaxrs-sample/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ To consume a provider-service, only need to decalare a member of a service API t
6464

6565
On the consumer side, you can see the following outputs if the consumer can invoke the producer:
6666
1. *'Hello Java Chassis'* means the consumer calls sayhi by RpcReference successfully
67-
2. *'Hello person ServiceComb/Java Chassis'* means the consumer calls sayhello by RpcReference successfully
67+
2. *'Hello person ServiceComb/Java Chassis'* means the consumer calls sayhello by RpcReference successfully
68+
3. *'Bye !'* means the consumer calls saybye by RestTemplate successfully

samples/jaxrs-sample/jaxrs-consumer/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@
5050
<groupId>org.apache.servicecomb</groupId>
5151
<artifactId>provider-pojo</artifactId>
5252
</dependency>
53+
<dependency>
54+
<groupId>org.apache.servicecomb</groupId>
55+
<artifactId>provider-springmvc</artifactId>
56+
</dependency>
5357
<dependency>
5458
<groupId>org.slf4j</groupId>
5559
<artifactId>slf4j-log4j12</artifactId>

samples/jaxrs-sample/jaxrs-consumer/src/main/java/org/apache/servicecomb/samples/jaxrs/consumer/JaxrsConsumerMain.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
import org.apache.servicecomb.foundation.common.utils.BeanUtils;
2020
import org.apache.servicecomb.foundation.common.utils.Log4jUtils;
2121
import org.apache.servicecomb.provider.pojo.RpcReference;
22+
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
2223
import org.apache.servicecomb.samples.common.schema.Hello;
2324
import org.apache.servicecomb.samples.common.schema.models.Person;
2425
import org.springframework.stereotype.Component;
26+
import org.springframework.web.client.RestTemplate;
2527

2628
@Component
2729
public class JaxrsConsumerMain {
@@ -35,6 +37,10 @@ public static void main(String[] args) throws Exception {
3537
Person person = new Person();
3638
person.setName("ServiceComb/Java Chassis");
3739
System.out.println(hello.sayHello(person));
40+
41+
RestTemplate restTemplate = RestTemplateBuilder.create();
42+
String result = restTemplate.getForObject("cse://jaxrs/jaxrshello/saybye", String.class);
43+
System.out.println(result);
3844
}
3945

4046
public static void init() throws Exception {

samples/jaxrs-sample/jaxrs-provider/src/main/java/org/apache/servicecomb/samples/jaxrs/provider/JaxrsHelloImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.servicecomb.samples.jaxrs.provider;
1919

2020

21+
import javax.ws.rs.GET;
2122
import javax.ws.rs.POST;
2223
import javax.ws.rs.Path;
2324
import javax.ws.rs.Produces;
@@ -45,4 +46,11 @@ public String sayHi(String name) {
4546
public String sayHello(Person person) {
4647
return "Hello person " + person.getName();
4748
}
49+
50+
@Path("/saybye")
51+
@GET
52+
public String sayBye() {
53+
return "Bye !";
54+
}
55+
4856
}

0 commit comments

Comments
 (0)