You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by je...@apache.org on 2019/01/14 03:09:21 UTC
[incubator-dubbo-samples] branch samples-for-2.7.0-SNAPSHOT
updated: fix the rest sample problem which REST annoation should be added
to interface instead of impl
This is an automated email from the ASF dual-hosted git repository.
jefflv pushed a commit to branch samples-for-2.7.0-SNAPSHOT
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo-samples.git
The following commit(s) were added to refs/heads/samples-for-2.7.0-SNAPSHOT by this push:
new fbdcc04 fix the rest sample problem which REST annoation should be added to interface instead of impl
fbdcc04 is described below
commit fbdcc04bdbfa3350510de253040119d59d48203c
Author: kongming <ko...@taobao.com>
AuthorDate: Mon Jan 14 11:09:06 2019 +0800
fix the rest sample problem which REST annoation should be added to interface instead of impl
---
.../dubbo/samples/rest/api/facade/UserRestService.java | 16 +++++++++++++++-
.../impl/facade/AnnotationDrivenUserRestServiceImpl.java | 3 ---
.../samples/rest/impl/facade/UserRestServiceImpl.java | 8 +-------
3 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/api/facade/UserRestService.java b/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/api/facade/UserRestService.java
index dc6f777..42e34fd 100644
--- a/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/api/facade/UserRestService.java
+++ b/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/api/facade/UserRestService.java
@@ -19,7 +19,14 @@
package org.apache.dubbo.samples.rest.api.facade;
import javax.validation.constraints.Min;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.MediaType;
+import org.apache.dubbo.config.annotation.Service;
import org.apache.dubbo.samples.rest.api.User;
/**
@@ -30,12 +37,19 @@ import org.apache.dubbo.samples.rest.api.User;
* http://localhost:8888/user/1.json
* http://localhost:8888/user/1.xml
*/
+@Service(protocol = {"rest", "dubbo"}, group = "annotationConfig", validation = "true")
+@Path("customers")
+@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
public interface UserRestService {
/**
* the request object is just used to test jax-rs injection.
*/
- User getUser(@Min(value = 1L, message = "User ID must be greater than 1") Long id/*, HttpServletRequest request*/);
+ @GET
+ @Path("{id : \\d+}")
+ User getUser(@PathParam("id") @Min(value = 1L, message = "User ID must be greater than 1") Long id/*, HttpServletRequest request*/);
+ @POST
+ @Path("register")
RegistrationResult registerUser(User user);
}
diff --git a/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/impl/facade/AnnotationDrivenUserRestServiceImpl.java b/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/impl/facade/AnnotationDrivenUserRestServiceImpl.java
index d7b4e0e..9475542 100644
--- a/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/impl/facade/AnnotationDrivenUserRestServiceImpl.java
+++ b/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/impl/facade/AnnotationDrivenUserRestServiceImpl.java
@@ -35,9 +35,6 @@ import org.apache.dubbo.samples.rest.api.facade.UserRestService;
import org.springframework.beans.factory.annotation.Autowired;
-@Service(protocol = {"rest", "dubbo"}, group = "annotationConfig", validation = "true")
-@Path("customers")
-@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
@Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
public class AnnotationDrivenUserRestServiceImpl implements UserRestService {
diff --git a/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/impl/facade/UserRestServiceImpl.java b/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/impl/facade/UserRestServiceImpl.java
index 8c9a561..70b766a 100644
--- a/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/impl/facade/UserRestServiceImpl.java
+++ b/dubbo-samples-rest/src/main/java/org/apache/dubbo/samples/rest/impl/facade/UserRestServiceImpl.java
@@ -39,8 +39,6 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Service("userRestService")
-@Path("users")
-@Consumes({MediaType.APPLICATION_JSON, MediaType.TEXT_XML})
@Produces({ContentType.APPLICATION_JSON_UTF_8, ContentType.TEXT_XML_UTF_8})
public class UserRestServiceImpl implements UserRestService {
@@ -54,9 +52,7 @@ public class UserRestServiceImpl implements UserRestService {
}
@Override
- @GET
- @Path("{id : \\d+}")
- public User getUser(@PathParam("id") Long id/*, @Context HttpServletRequest request*/) {
+ public User getUser(Long id/*, @Context HttpServletRequest request*/) {
// test context injection
// System.out.println("Client address from @Context injection: " + (request != null ? request.getRemoteAddr() : ""));
System.out.println("Client address from RpcContext: " + RpcContext.getContext().getRemoteAddressString());
@@ -70,8 +66,6 @@ public class UserRestServiceImpl implements UserRestService {
}
@Override
- @POST
- @Path("register")
public RegistrationResult registerUser(User user) {
return new RegistrationResult(userService.registerUser(user));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org