This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-samples.git
The following commit(s) were added to refs/heads/master by this push:
new 9a096b75d Update/dubbo tri rest jaxrs samples (#1116)
9a096b75d is described below
commit 9a096b75df8a7a440f7e39337176fe5b189e5563
Author: fanlobu <[email protected]>
AuthorDate: Mon Apr 22 16:19:29 2024 +0800
Update/dubbo tri rest jaxrs samples (#1116)
---
.../dubbo-samples-triple-rest-jaxrs/pom.xml | 39 +++-
.../org/apache/dubbo/rest/demo/DemoService.java | 27 ++-
.../rest/demo/{provider => }/DemoServiceImpl.java | 25 ++-
.../demo/complex/ComplexParamReqServiceImpl.java | 71 +++++++
.../demo/complex/ComplexParamRequestService.java | 78 +++++++
.../org/apache/dubbo/rest/demo/consumer/Task.java | 52 -----
.../exception/ExceptionMapperService.java} | 17 +-
.../exception/ExceptionMapperServiceImpl.java} | 13 +-
.../exception/ResteasyExceptionMapper.java} | 14 +-
.../filter/FilterService.java} | 17 +-
.../filter/FilterServiceImpl.java} | 13 +-
.../rest/demo/expansion/filter/TraceFilter.java | 45 +++++
.../intercept/DynamicTraceInterceptor.java | 54 +++++
.../intercept/InterceptorService.java} | 18 +-
.../intercept/InterceptorServiceImpl.java} | 13 +-
.../org/apache/dubbo/rest/demo/pojo/Person.java | 62 ++++++
.../java/org/apache/dubbo/rest/demo/pojo/User.java | 92 +++++++++
.../BasicParamRequestService.java} | 30 ++-
.../BasicParamRequestServiceImpl.java} | 31 ++-
.../demo/routine/HttpMethodRequestService.java | 69 +++++++
.../HttpMethodRequestServiceImpl.java} | 36 +++-
.../demo/routine/ParamTransferRequestService.java | 66 ++++++
.../ParamTransferRequestServiceImpl.java} | 34 +++-
.../src/main/resources/application.yml | 4 +-
.../main/resources/security/serialize.allowlist | 21 ++
.../dubbo/rest/demo/test/BasicParamRequestIT.java | 111 ++++++++++
.../rest/demo/test/ComplexParamRequestIT.java | 223 +++++++++++++++++++++
.../apache/dubbo/rest/demo/test/DemoServiceIT.java | 103 ++++++++++
.../{ConsumerIT.java => ExpansionServiceIT.java} | 41 ++--
.../dubbo/rest/demo/test/HttpMethodRequestIT.java | 151 ++++++++++++++
.../rest/demo/test/ParamTransferRequestIT.java | 133 ++++++++++++
31 files changed, 1559 insertions(+), 144 deletions(-)
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/pom.xml
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/pom.xml
index 71673bb47..b788899f6 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/pom.xml
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/pom.xml
@@ -39,7 +39,34 @@
<version>3.3.0-beta.2</version>
</dependency>
- <!-- spring web annotation support -->
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxrs</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>com.sun.xml.bind</groupId>
+ <artifactId>jaxb-impl</artifactId>
+ <version>2.3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jackson-provider</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.resteasy</groupId>
+ <artifactId>resteasy-jaxb-provider</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
@@ -71,6 +98,16 @@
<build>
<plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.1</version>
+ <configuration>
+ <compilerArgs>
+ <arg>-parameters</arg>
+ </compilerArgs>
+ </configuration>
+ </plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
index c2379472d..30a33d292 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
@@ -16,16 +16,39 @@
*/
package org.apache.dubbo.rest.demo;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
@Path("/demo")
public interface DemoService {
@GET
@Path("/hello")
- String sayHello(@QueryParam("name") String name);
+ @Produces(MediaType.TEXT_PLAIN)
+ String hello(@QueryParam("a") Integer a, @QueryParam("name") String name);
+
+ @GET
+ @Path("/findUserById")
+ int findUserById(@QueryParam("id") Integer id);
+
+
+ @POST
+ @Path("/form")
+ @Consumes({MediaType.APPLICATION_FORM_URLENCODED})
+ Long testFormBody(@FormParam("number") Long number);
+
+
+ @DELETE
+ @Path("/deleteUserById/{uid}")
+ @Produces(MediaType.TEXT_PLAIN)
+ String deleteUserById(@PathParam("uid") String uid);
- // add more methods
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoServiceImpl.java
similarity index 70%
copy from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
copy to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoServiceImpl.java
index d90361577..9f83708a5 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoServiceImpl.java
@@ -14,17 +14,32 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo.provider;
+package org.apache.dubbo.rest.demo;
import org.apache.dubbo.config.annotation.DubboService;
-import org.apache.dubbo.rest.demo.DemoService;
-@DubboService
+@DubboService()
public class DemoServiceImpl implements DemoService {
@Override
- public String sayHello(String name) {
- return "Hello " + name;
+ public String hello(Integer a, String name) {
+ return "Hello " + name + a;
+ }
+
+ @Override
+ public int findUserById(Integer id) {
+ return id;
+ }
+
+
+ @Override
+ public Long testFormBody(Long number) {
+ return number;
+ }
+
+ @Override
+ public String deleteUserById(String uid) {
+ return uid;
}
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/complex/ComplexParamReqServiceImpl.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/complex/ComplexParamReqServiceImpl.java
new file mode 100644
index 000000000..b8393be1e
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/complex/ComplexParamReqServiceImpl.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.complex;
+
+import org.apache.dubbo.config.annotation.DubboService;
+import org.apache.dubbo.rest.demo.pojo.Person;
+import org.apache.dubbo.rest.demo.pojo.User;
+
+import javax.ws.rs.core.MultivaluedMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+@DubboService
+public class ComplexParamReqServiceImpl implements ComplexParamRequestService {
+ @Override
+ public List<User> list(List<User> users) {
+ return users;
+ }
+
+ @Override
+ public Set<User> set(Set<User> users) {
+ return users;
+ }
+
+ @Override
+ public User[] array(User[] users) {
+ return users;
+ }
+
+ @Override
+ public Map<String, User> stringMap(Map<String, User> userMap) {
+ return userMap;
+ }
+
+ @Override
+ public List<String> testMapParam(Map<String, String> map) {
+ return map.values().stream().toList();
+ }
+
+ @Override
+ public String testMapHeader(String headers) {
+ return headers;
+ }
+
+ @Override
+ public List<String> testMapForm(MultivaluedMap<String, String> params) {
+ return params.values().stream().flatMap(List::stream).toList();
+ }
+
+ @Override
+ public Person testXml(Person person) {
+ return person;
+ }
+
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/complex/ComplexParamRequestService.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/complex/ComplexParamRequestService.java
new file mode 100644
index 000000000..a154f4301
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/complex/ComplexParamRequestService.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.complex;
+
+
+import org.apache.dubbo.rest.demo.pojo.Person;
+import org.apache.dubbo.rest.demo.pojo.User;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+@Path("/complex")
+public interface ComplexParamRequestService {
+ @POST
+ @Path("/list")
+ List<User> list(List<User> list);
+
+ @POST
+ @Path("/set")
+ Set<User> set(Set<User> users);
+
+ @POST
+ @Path("/array")
+ User[] array(User[] users);
+
+ @POST
+ @Path("/stringMap")
+ Map<String, User> stringMap(Map<String, User> userMap);
+
+
+ @GET
+ @Path("/testMapParam")
+ @Produces({MediaType.APPLICATION_JSON})
+ @Consumes({MediaType.APPLICATION_JSON})
+ List<String> testMapParam(@QueryParam("map") Map<String, String> map);
+
+ @GET
+ @Path("/testMapHeader")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.TEXT_PLAIN)
+ String testMapHeader(@HeaderParam("headers") String headerMap);
+
+ @POST
+ @Path("/testMapForm")
+ @Produces({MediaType.APPLICATION_JSON})
+ @Consumes({MediaType.APPLICATION_FORM_URLENCODED})
+ List<String> testMapForm(MultivaluedMap<String,String> params);
+
+ @POST
+ @Path("/xml")
+ @Consumes(MediaType.TEXT_XML)
+ @Produces(MediaType.APPLICATION_XML)
+ Person testXml(Person person);
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/consumer/Task.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/consumer/Task.java
deleted file mode 100644
index 857d23a87..000000000
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/consumer/Task.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.dubbo.rest.demo.consumer;
-
-import org.apache.dubbo.config.annotation.DubboReference;
-import org.apache.dubbo.rest.demo.DemoService;
-
-import org.springframework.boot.CommandLineRunner;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Component;
-import org.springframework.web.client.RestClient;
-
-@Component
-public class Task implements CommandLineRunner {
- @DubboReference
- private DemoService demoService;
-
- @Override
- public void run(String... args) throws Exception {
- System.out.println("Receive result ======> " + proxyHello());
- System.out.println("Receive rest result ======> " + restHello());
-
- }
-
- private String proxyHello() {
- return demoService.sayHello("world");
- }
-
- private String restHello() {
- RestClient defaultClient = RestClient.create();
- ResponseEntity<String> result = defaultClient.get()
- .uri("http://localhost:50052/demo/hello?name=world")
- .header("Content-type", "application/json")
- .retrieve()
- .toEntity(String.class);
- return result.getBody();
- }
-}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/exception/ExceptionMapperService.java
similarity index 76%
copy from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
copy to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/exception/ExceptionMapperService.java
index c2379472d..a5777cc40 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/exception/ExceptionMapperService.java
@@ -14,18 +14,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo;
+
+package org.apache.dubbo.rest.demo.expansion.exception;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
-import javax.ws.rs.QueryParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
-@Path("/demo")
-public interface DemoService {
+@Path("/ext")
+public interface ExceptionMapperService {
@GET
- @Path("/hello")
- String sayHello(@QueryParam("name") String name);
-
- // add more methods
+ @Path("/exception")
+ @Produces(MediaType.TEXT_PLAIN)
+ String testException();
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/exception/ExceptionMapperServiceImpl.java
similarity index 68%
copy from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
copy to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/exception/ExceptionMapperServiceImpl.java
index d90361577..ee21ff059 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/exception/ExceptionMapperServiceImpl.java
@@ -14,17 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo.provider;
+
+package org.apache.dubbo.rest.demo.expansion.exception;
import org.apache.dubbo.config.annotation.DubboService;
-import org.apache.dubbo.rest.demo.DemoService;
-@DubboService
-public class DemoServiceImpl implements DemoService {
+import static
org.apache.dubbo.rpc.protocol.tri.rest.RestConstants.EXTENSION_KEY;
+@DubboService(parameters =
{EXTENSION_KEY,"org.apache.dubbo.rest.demo.expansion.exception.ResteasyExceptionMapper"})
+public class ExceptionMapperServiceImpl implements ExceptionMapperService{
@Override
- public String sayHello(String name) {
- return "Hello " + name;
+ public String testException() {
+ throw new RuntimeException();
}
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/exception/ResteasyExceptionMapper.java
similarity index 70%
copy from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
copy to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/exception/ResteasyExceptionMapper.java
index d90361577..0f3571083 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/exception/ResteasyExceptionMapper.java
@@ -14,17 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo.provider;
-import org.apache.dubbo.config.annotation.DubboService;
-import org.apache.dubbo.rest.demo.DemoService;
+package org.apache.dubbo.rest.demo.expansion.exception;
-@DubboService
-public class DemoServiceImpl implements DemoService {
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+public class ResteasyExceptionMapper implements
ExceptionMapper<RuntimeException> {
@Override
- public String sayHello(String name) {
- return "Hello " + name;
+ public Response toResponse(RuntimeException exception) {
+ return Response.status(200).entity("test-exception").build();
}
-
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/filter/FilterService.java
similarity index 74%
copy from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
copy to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/filter/FilterService.java
index c2379472d..e64c1dee5 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/filter/FilterService.java
@@ -14,18 +14,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo;
+
+package org.apache.dubbo.rest.demo.expansion.filter;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
-@Path("/demo")
-public interface DemoService {
+@Path("/ext")
+public interface FilterService {
@GET
- @Path("/hello")
- String sayHello(@QueryParam("name") String name);
-
- // add more methods
+ @Path("/filter")
+ @Produces(MediaType.TEXT_PLAIN)
+ String testFilter(@QueryParam("name") String name);
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/filter/FilterServiceImpl.java
similarity index 70%
copy from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
copy to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/filter/FilterServiceImpl.java
index d90361577..09e8c7006 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/filter/FilterServiceImpl.java
@@ -14,17 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo.provider;
+
+package org.apache.dubbo.rest.demo.expansion.filter;
import org.apache.dubbo.config.annotation.DubboService;
-import org.apache.dubbo.rest.demo.DemoService;
-@DubboService
-public class DemoServiceImpl implements DemoService {
+import static
org.apache.dubbo.rpc.protocol.tri.rest.RestConstants.EXTENSION_KEY;
+@DubboService(parameters =
{EXTENSION_KEY,"org.apache.dubbo.rest.demo.expansion.filter.TraceFilter"})
+public class FilterServiceImpl implements FilterService{
@Override
- public String sayHello(String name) {
- return "Hello " + name;
+ public String testFilter(String name) {
+ return "Hello "+name;
}
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/filter/TraceFilter.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/filter/TraceFilter.java
new file mode 100644
index 000000000..88466c334
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/filter/TraceFilter.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.expansion.filter;
+
+import jakarta.annotation.Priority;
+
+import javax.ws.rs.Priorities;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import java.io.IOException;
+
+@Priority(Priorities.USER)
+public class TraceFilter implements ContainerRequestFilter,
ContainerResponseFilter {
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws
IOException {
+ System.out.println("Request filter invoked: " +
requestContext.getUriInfo().getAbsolutePath());
+ }
+
+ @Override
+ public void filter(
+ ContainerRequestContext containerRequestContext,
ContainerResponseContext containerResponseContext)
+ throws IOException {
+ String entity = (String)containerResponseContext.getEntity();
+ containerResponseContext.setEntity(entity + "response-filter");
+ System.out.println("Response filter invoked.");
+ }
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/intercept/DynamicTraceInterceptor.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/intercept/DynamicTraceInterceptor.java
new file mode 100644
index 000000000..17a674c9b
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/intercept/DynamicTraceInterceptor.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.expansion.intercept;
+
+import jakarta.annotation.Priority;
+
+import javax.ws.rs.Priorities;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.ReaderInterceptorContext;
+import javax.ws.rs.ext.WriterInterceptor;
+import javax.ws.rs.ext.WriterInterceptorContext;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
+
+@Priority(Priorities.USER)
+public class DynamicTraceInterceptor implements ReaderInterceptor,
WriterInterceptor {
+
+ public DynamicTraceInterceptor() {}
+
+ @Override
+ public Object aroundReadFrom(ReaderInterceptorContext
readerInterceptorContext)
+ throws IOException, WebApplicationException {
+ System.out.println("Dynamic reader interceptor invoked");
+ return readerInterceptorContext.proceed();
+ }
+
+ @Override
+ public void aroundWriteTo(WriterInterceptorContext
writerInterceptorContext)
+ throws IOException, WebApplicationException {
+ System.out.println("Dynamic writer interceptor invoked");
+ String entity = (String)writerInterceptorContext.getEntity();
+
writerInterceptorContext.getOutputStream().write(entity.getBytes(StandardCharsets.UTF_8));
+
writerInterceptorContext.getOutputStream().write("intercept".getBytes(StandardCharsets.UTF_8));
+ writerInterceptorContext.proceed();
+ }
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/intercept/InterceptorService.java
similarity index 72%
copy from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
copy to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/intercept/InterceptorService.java
index d90361577..390f3519c 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/intercept/InterceptorService.java
@@ -14,17 +14,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo.provider;
-import org.apache.dubbo.config.annotation.DubboService;
-import org.apache.dubbo.rest.demo.DemoService;
+package org.apache.dubbo.rest.demo.expansion.intercept;
-@DubboService
-public class DemoServiceImpl implements DemoService {
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.QueryParam;
- @Override
- public String sayHello(String name) {
- return "Hello " + name;
- }
+@Path("/ext")
+public interface InterceptorService {
+ @GET
+ @Path("/intercept")
+ String testIntercept(@QueryParam("name") String name);
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/intercept/InterceptorServiceImpl.java
similarity index 68%
copy from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
copy to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/intercept/InterceptorServiceImpl.java
index d90361577..cb0ebfe08 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/expansion/intercept/InterceptorServiceImpl.java
@@ -14,17 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo.provider;
+
+package org.apache.dubbo.rest.demo.expansion.intercept;
import org.apache.dubbo.config.annotation.DubboService;
-import org.apache.dubbo.rest.demo.DemoService;
-@DubboService
-public class DemoServiceImpl implements DemoService {
+import static
org.apache.dubbo.rpc.protocol.tri.rest.RestConstants.EXTENSION_KEY;
+@DubboService(parameters =
{EXTENSION_KEY,"org.apache.dubbo.rest.demo.expansion.intercept.DynamicTraceInterceptor"})
+public class InterceptorServiceImpl implements InterceptorService{
@Override
- public String sayHello(String name) {
- return "Hello " + name;
+ public String testIntercept(String name) {
+ return "Hello "+name;
}
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/pojo/Person.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/pojo/Person.java
new file mode 100644
index 000000000..66a863a57
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/pojo/Person.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.pojo;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+import java.util.Objects;
+
+@XmlRootElement
+public class Person implements Serializable {
+ private String name;
+
+ public Person(String name) {
+ this.name = name;
+ }
+
+ public Person() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ Person person = (Person) o;
+ return Objects.equals(name, person.name);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name);
+ }
+
+ @Override
+ public String toString() {
+ return "Person{" +
+ "name='" + name + '\'' +
+ '}';
+ }
+
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/pojo/User.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/pojo/User.java
new file mode 100644
index 000000000..2ccf1e224
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/pojo/User.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.pojo;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+
+public class User implements Serializable {
+ private Long id;
+
+ private String name;
+
+ private Integer age;
+
+ public User() {
+ }
+
+ public User(Long id, String name, Integer age) {
+ this.id = id;
+ this.name = name;
+ this.age = age;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Integer getAge() {
+ return age;
+ }
+
+ public void setAge(Integer age) {
+ this.age = age;
+ }
+
+ public static User getInstance() {
+ User user = new User();
+ user.setAge(18);
+ user.setName("dubbo");
+ user.setId(404l);
+ return user;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ User user = (User) o;
+ return Objects.equals(id, user.id) && Objects.equals(name, user.name)
&& Objects.equals(age, user.age);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, name, age);
+ }
+
+ @Override
+ public String toString() {
+ return "User{" + "id=" + id + ", name='" + name + '\'' + ", age=" +
age + '}';
+ }
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/BasicParamRequestService.java
similarity index 54%
copy from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
copy to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/BasicParamRequestService.java
index c2379472d..cc48eb107 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/DemoService.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/BasicParamRequestService.java
@@ -1,3 +1,4 @@
+
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -14,18 +15,35 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo;
+package org.apache.dubbo.rest.demo.routine;
+
import javax.ws.rs.GET;
import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
-@Path("/demo")
-public interface DemoService {
+public interface BasicParamRequestService {
+ @GET
+ @Path("/primitive")
+ int primitiveInt(@QueryParam("a") int a, @QueryParam("b") int b);
+
+ @GET
+ @Path("/primitiveLong")
+ long primitiveLong(@QueryParam("a") long a, @QueryParam("b") Long b);
@GET
- @Path("/hello")
- String sayHello(@QueryParam("name") String name);
+ @Path("/primitiveByte")
+ byte primitiveByte(@QueryParam("a") byte a, @QueryParam("b") byte b);
- // add more methods
+
+ @GET
+ @Path("/primitiveDouble")
+ double primitiveDouble(@QueryParam("a") double a,@QueryParam("b") double
b);
+
+ @GET
+ @Path("/primitiveString")
+ @Produces(MediaType.TEXT_PLAIN)
+ String primitiveString(@QueryParam("a") String a,@QueryParam("b") String
b);
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/BasicParamRequestServiceImpl.java
similarity index 60%
copy from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
copy to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/BasicParamRequestServiceImpl.java
index d90361577..ea3ceac84 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/BasicParamRequestServiceImpl.java
@@ -1,3 +1,4 @@
+
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -14,17 +15,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo.provider;
+package org.apache.dubbo.rest.demo.routine;
import org.apache.dubbo.config.annotation.DubboService;
-import org.apache.dubbo.rest.demo.DemoService;
@DubboService
-public class DemoServiceImpl implements DemoService {
+public class BasicParamRequestServiceImpl implements BasicParamRequestService{
+
+ @Override
+ public int primitiveInt(int a, int b) {
+ return a + b;
+ }
+
+ @Override
+ public long primitiveLong(long a, Long b) {
+ return a + b;
+ }
+
+ @Override
+ public byte primitiveByte(byte a, byte b) {
+ return (byte) (a + b);
+ }
+
+
+ @Override
+ public double primitiveDouble(double a, double b) {
+ return a + b;
+ }
@Override
- public String sayHello(String name) {
- return "Hello " + name;
+ public String primitiveString(String a, String b) {
+ return a + b;
}
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/HttpMethodRequestService.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/HttpMethodRequestService.java
new file mode 100644
index 000000000..3eaff8627
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/HttpMethodRequestService.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.routine;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
+import javax.ws.rs.OPTIONS;
+import javax.ws.rs.PATCH;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+
+
+
+@Path("/HttpRequestMethod")
+public interface HttpMethodRequestService {
+ @POST
+ @Path("/sayPost")
+ @Produces({javax.ws.rs.core.MediaType.TEXT_PLAIN})
+ String sayHelloPost(String hello);
+
+ @DELETE
+ @Path("/sayDelete")
+ @Produces({javax.ws.rs.core.MediaType.TEXT_PLAIN})
+ String sayHelloDelete(@QueryParam("name") String hello);
+
+ @HEAD
+ @Path("/sayHead")
+ @Produces({javax.ws.rs.core.MediaType.TEXT_PLAIN})
+ String sayHelloHead(@QueryParam("name") String hello);
+
+
+ @GET
+ @Path("/sayGet")
+ @Produces({javax.ws.rs.core.MediaType.TEXT_PLAIN})
+ String sayHelloGet(@QueryParam("name") String hello);
+
+ @PUT
+ @Path("/sayPut")
+ @Produces({javax.ws.rs.core.MediaType.TEXT_PLAIN})
+ String sayHelloPut(@QueryParam("name") String hello);
+
+ @PATCH
+ @Path("/sayPatch")
+ @Produces({javax.ws.rs.core.MediaType.TEXT_PLAIN})
+ String sayHelloPatch(@QueryParam("name") String hello);
+
+ @OPTIONS
+ @Path("/sayOptions")
+ @Produces({javax.ws.rs.core.MediaType.TEXT_PLAIN})
+ String sayHelloOptions(@QueryParam("name") String hello);
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/HttpMethodRequestServiceImpl.java
similarity index 54%
copy from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
copy to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/HttpMethodRequestServiceImpl.java
index d90361577..0ad74047b 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/HttpMethodRequestServiceImpl.java
@@ -14,17 +14,45 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo.provider;
+
+package org.apache.dubbo.rest.demo.routine;
import org.apache.dubbo.config.annotation.DubboService;
-import org.apache.dubbo.rest.demo.DemoService;
@DubboService
-public class DemoServiceImpl implements DemoService {
+public class HttpMethodRequestServiceImpl implements HttpMethodRequestService{
+ @Override
+ public String sayHelloPost(String name) {
+ return "Hello " + name;
+ }
+
+ @Override
+ public String sayHelloDelete(String name) {
+ return "Hello " + name;
+ }
+
+ @Override
+ public String sayHelloHead(String name) {
+ return "Hello " + name;
+ }
@Override
- public String sayHello(String name) {
+ public String sayHelloGet(String name) {
return "Hello " + name;
}
+ @Override
+ public String sayHelloPut(String name) {
+ return "Hello " + name;
+ }
+
+ @Override
+ public String sayHelloPatch(String name) {
+ return "Hello " + name;
+ }
+
+ @Override
+ public String sayHelloOptions(String name) {
+ return "Hello " + name;
+ }
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/ParamTransferRequestService.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/ParamTransferRequestService.java
new file mode 100644
index 000000000..9aad5a7bf
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/ParamTransferRequestService.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.routine;
+
+import org.apache.dubbo.rest.demo.pojo.Person;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.CookieParam;
+import javax.ws.rs.FormParam;
+import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.MatrixParam;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+@Path("/param")
+public interface ParamTransferRequestService {
+
+ @GET
+ @Path("/query")
+ @Produces(MediaType.TEXT_PLAIN)
+ String sayHello(@QueryParam("name") String name);
+
+ @POST
+ @Path("/form")
+ @Produces(MediaType.TEXT_PLAIN)
+ @Consumes({MediaType.APPLICATION_FORM_URLENCODED})
+ String sayForm(@FormParam("form") String name);
+
+ @GET
+ @Path("/path/{id}")
+ String sayPath(@PathParam("id") String id);
+
+ @GET
+ @Path("/header")
+ String sayHeader(@HeaderParam("name") String name);
+
+
+ @GET
+ @Path("/cookie")
+ String sayCookie(@CookieParam("cookieId") String cookieId);
+
+ @GET
+ @Path("/matrix;m={m}")
+ @Produces(MediaType.TEXT_PLAIN)
+ String sayMatrix(@MatrixParam("name") String name);
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/ParamTransferRequestServiceImpl.java
similarity index 59%
rename from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
rename to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/ParamTransferRequestServiceImpl.java
index d90361577..96a3af4b7 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/provider/DemoServiceImpl.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/java/org/apache/dubbo/rest/demo/routine/ParamTransferRequestServiceImpl.java
@@ -14,17 +14,43 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.dubbo.rest.demo.provider;
+
+package org.apache.dubbo.rest.demo.routine;
import org.apache.dubbo.config.annotation.DubboService;
-import org.apache.dubbo.rest.demo.DemoService;
+import org.apache.dubbo.rest.demo.pojo.Person;
@DubboService
-public class DemoServiceImpl implements DemoService {
-
+public class ParamTransferRequestServiceImpl implements
ParamTransferRequestService{
@Override
public String sayHello(String name) {
return "Hello " + name;
}
+ @Override
+ public String sayForm(String name) {
+ return "Hello " + name;
+ }
+
+ @Override
+ public String sayPath(String id) {
+ return "Hello " + id;
+ }
+
+ @Override
+ public String sayHeader(String name) {
+ return "Hello " + name;
+ }
+
+ @Override
+ public String sayCookie(String cookieId) {
+ return "Hello " + cookieId;
+ }
+
+ @Override
+ public String sayMatrix(String name) {
+ return "Hello " + name;
+ }
+
+
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/resources/application.yml
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/resources/application.yml
index 2bc5fa4d3..36a5dc81f 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/resources/application.yml
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/resources/application.yml
@@ -18,9 +18,11 @@ server:
dubbo:
application:
name: dubbo-springboot-triple-rest-jaxrs
- qos-port: 33333
+ qos-port: 22222
registry:
address:
nacos://${nacos.address:localhost}:8848?username=nacos&password=nacos
protocol:
name: tri
port: 50052
+# serialization: fastjson2
+# extension:
org.apache.dubbo.rest.demo.filter.TraceFilter,org.apache.dubbo.rest.demo.intercept.DynamicTraceInterceptor
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/resources/security/serialize.allowlist
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/resources/security/serialize.allowlist
new file mode 100644
index 000000000..0478cbe3d
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/main/resources/security/serialize.allowlist
@@ -0,0 +1,21 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+#
+
+javax.ws.rs.core.MultivaluedHashMap
+org.apache.dubbo.remoting.http12.ErrorResponse
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/BasicParamRequestIT.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/BasicParamRequestIT.java
new file mode 100644
index 000000000..23d64cb2d
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/BasicParamRequestIT.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.test;
+
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.apache.dubbo.rest.demo.routine.BasicParamRequestService;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.client.RestClient;
+
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class BasicParamRequestIT {
+ private static final String providerAddress =
System.getProperty("dubbo.address", "localhost");
+
+ @DubboReference
+ private BasicParamRequestService basicParamRequestService;
+
+ @Test
+ public void test() {
+ int result1 = basicParamRequestService.primitiveInt(1, 1);
+ Assert.assertEquals(2, result1);
+
+ byte result2 = basicParamRequestService.primitiveByte((byte) 1, (byte)
1);
+ Assert.assertEquals((byte) 2, result2);
+
+ long result3 = basicParamRequestService.primitiveLong(1L, 1L);
+ Assert.assertEquals(2L, result3);
+
+ double result4 = basicParamRequestService.primitiveDouble(1.1, 1.2);
+ Assert.assertEquals(2.3,result4,0.00001);
+
+ String result5 = basicParamRequestService.primitiveString("Hello ",
"world");
+ Assert.assertEquals("Hello world", result5);
+
+ }
+
+ @Test
+ public void testInt() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<Integer> result = defaultClient.get()
+ .uri("http://" + providerAddress +
":50052/primitiveByte?a={a}&b={b}", 1, 1)
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(Integer.class);
+ Assert.assertEquals(Integer.valueOf(2), result.getBody());
+ }
+
+ @Test
+ public void testByte() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<Byte> result = defaultClient.get()
+ .uri("http://" + providerAddress +
":50052/primitive?a={a}&b={b}", 1, 1)
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(Byte.class);
+ Assert.assertEquals(Byte.valueOf((byte) 2), result.getBody());
+ }
+
+ @Test
+ public void testLong() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<Long> result = defaultClient.get()
+ .uri("http://" + providerAddress +
":50052/primitiveLong?a={a}&b={b}", 1, 1)
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(Long.class);
+ Assert.assertEquals(Long.valueOf(2), result.getBody());
+ }
+
+ @Test
+ public void testDouble() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<Double> result = defaultClient.get()
+ .uri("http://" + providerAddress +
":50052/primitiveDouble?a={a}&b={b}", 1.1, 1.2)
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(Double.class);
+ Assert.assertEquals(Double.valueOf(2.3), result.getBody());
+ }
+
+ @Test
+ public void testString() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<String> result = defaultClient.get()
+ .uri("http://" + providerAddress +
":50052/primitiveString?a={a}&b={b}", "Hello ", "world")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(String.class);
+ Assert.assertEquals("Hello world", result.getBody());
+ }
+
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ComplexParamRequestIT.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ComplexParamRequestIT.java
new file mode 100644
index 000000000..c77cd1268
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ComplexParamRequestIT.java
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.test;
+
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.apache.dubbo.rest.demo.complex.ComplexParamRequestService;
+import org.apache.dubbo.rest.demo.pojo.Person;
+import org.apache.dubbo.rest.demo.pojo.User;
+import org.jboss.resteasy.specimpl.MultivaluedMapImpl;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpStatusCode;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestClient;
+import javax.ws.rs.core.MultivaluedHashMap;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import static org.springframework.http.MediaType.APPLICATION_JSON;
+
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class ComplexParamRequestIT {
+ private static final String providerAddress =
System.getProperty("dubbo.address", "localhost");
+
+ @DubboReference
+ private ComplexParamRequestService complexParamRequestService;
+
+ @Test
+ public void test(){
+ List<User> list = List.of(new User(1L, "1", 1), new User(2L, "2", 2));
+ List<User> result1 = complexParamRequestService.list(list);
+ Assert.assertEquals(list,result1);
+
+ Set<User> set = Set.of(new User(1L, "1", 1), new User(2L, "2", 2));
+ Set<User> result2 = complexParamRequestService.set(set);
+ Assert.assertEquals(set,result2);
+
+ User[] arr ={new User(1L, "1", 1), new User(2L, "2", 2)};
+ User[] result3 = complexParamRequestService.array(arr);
+ Assert.assertArrayEquals(arr,result3);
+
+ Map<String, User> map = Map.of("user1", new User(1L, "1", 1), "user2",
new User(2L, "2", 2));
+ Map<String, User> result4 = complexParamRequestService.stringMap(map);
+ Assert.assertEquals(map,result4);
+
+ MultivaluedHashMap<String,String> valueMap = new
MultivaluedHashMap<>();
+ valueMap.add("arg1","Hello");
+ valueMap.add("arg2","world");
+ List<String> result5 =
complexParamRequestService.testMapForm(valueMap);
+
Assert.assertEquals(valueMap.values().stream().flatMap(List::stream).toList(),result5);
+
+ String result6 = complexParamRequestService.testMapHeader("Head");
+ Assert.assertEquals("Head",result6);
+
+ Map<String, String> stringMap = Map.of("Hello", "World");
+ List<String> result7 =
complexParamRequestService.testMapParam(stringMap);
+ Assert.assertEquals(stringMap.values().stream().toList(),result7);
+
+ Person person = complexParamRequestService.testXml(new Person("1"));
+ Assert.assertEquals(new Person("1"),person);
+
+ }
+
+
+ @Test
+ public void testList() throws Exception {
+ ArrayList<User> list = new ArrayList<>();
+ list.add(new User(1L,"1",1));
+ list.add(new User(2L,"2",2));
+ ResponseEntity<List<User>> response = RestClient.create().post()
+ .uri("http://" + providerAddress +":50052/complex/list")
+ .contentType(APPLICATION_JSON)
+ .body(list)
+ .retrieve()
+ .toEntity(new ParameterizedTypeReference<List<User>>() {
+ });
+ Assert.assertEquals(list,response.getBody());
+ }
+
+ @Test
+ public void testSet() throws Exception {
+ Set<User> set = new HashSet<>();
+ set.add(new User(1L,"1",1));
+ set.add(new User(2L,"2",2));
+ ResponseEntity<Set<User>> response = RestClient.create().post()
+ .uri("http://" + providerAddress +":50052/complex/set")
+ .contentType(APPLICATION_JSON)
+ .body(set)
+ .retrieve()
+ .toEntity(new ParameterizedTypeReference<Set<User>>() {
+ });
+ Assert.assertEquals(set,response.getBody());
+ }
+
+ @Test
+ public void testArray() throws Exception {
+
+ User[] array = {new User(1L,"1",1),new User(2L,"2",2)};
+ ResponseEntity<User[]> response = RestClient.create().post()
+ .uri("http://" + providerAddress +":50052/complex/array")
+ .contentType(APPLICATION_JSON)
+ .body(array)
+ .retrieve()
+ .toEntity(new ParameterizedTypeReference<User[]>() {
+ });
+ Assert.assertArrayEquals(array, response.getBody());
+ }
+
+
+ @Test
+ public void testStringMap() throws Exception {
+ HashMap<String, User> map = new HashMap<>();
+ map.put("user1",new User(1L,"1",1));
+ map.put("user2",new User(2L,"2",2));
+ ResponseEntity<Map<String,User>> response = RestClient.create().post()
+ .uri("http://" + providerAddress +":50052/complex/stringMap")
+ .contentType(APPLICATION_JSON)
+ .body(map)
+ .retrieve()
+ .toEntity(new ParameterizedTypeReference<Map<String,User>>() {
+ });
+ Assert.assertEquals(map,response.getBody());
+ }
+
+ @Test
+ public void testHeader() throws Exception {
+
+ ResponseEntity<String> response = RestClient.create().get()
+ .uri("http://" + providerAddress
+":50052/complex/testMapHeader")
+ .header("Content-type", "application/json")
+ .header("headers","Head")
+ .retrieve()
+ .toEntity(new ParameterizedTypeReference<String>() {
+ });
+ Assert.assertEquals("Head",response.getBody());
+ }
+
+
+ @Test
+ public void testMapParam() throws Exception {
+ ResponseEntity<List<String>> response = RestClient.create().get()
+ .uri("http://" + providerAddress
+":50052/complex/testMapParam?arg1=World&arg2=Hello")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(new ParameterizedTypeReference<List<String>>() {
+ });
+ Assert.assertEquals(List.of("Hello","World"),response.getBody());
+ }
+
+
+ @Test
+ public void testMapForm() throws Exception {
+ MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
+ map.add("arg1","Hello");
+ map.add("arg2","world");
+ ResponseEntity<List<String>> response = RestClient.create().post()
+ .uri("http://" + providerAddress +":50052/complex/testMapForm")
+ .contentType(MediaType.APPLICATION_FORM_URLENCODED)
+ .body(map)
+ .retrieve()
+ .toEntity(new ParameterizedTypeReference<List<String>>() {
+ });
+ Assert.assertEquals(List.of("Hello","world"),response.getBody());
+ }
+
+ @Test
+ public void testXml() throws Exception {
+ // TODO xml
+ String str = "<?xml version=\"1.0\" encoding=\"UTF-8\"
standalone=\"yes\"?><person><name>1</name></person>";
+ Person person = new Person("1");
+
+ RestClient defaultClient = RestClient.create();
+ Person result = defaultClient.post()
+ .uri("http://" + providerAddress + ":50052/complex/xml")
+ .header("Content-type", "text/xml")
+ .accept(MediaType.APPLICATION_XML)
+ .body(str)
+ .exchange((request,response)->{
+
if(response.getStatusCode().isSameCodeAs(HttpStatusCode.valueOf(200))){
+ try {
+ JAXBContext jaxbContext =
JAXBContext.newInstance(Person.class);
+ Unmarshaller jaxbUnmarshaller =
jaxbContext.createUnmarshaller();
+ return (Person)
jaxbUnmarshaller.unmarshal(response.getBody());
+ } catch (JAXBException e) {
+ throw new RuntimeException(e);
+ }
+ }else {
+ throw new RuntimeException("http code erroe");
+ }
+ });
+ Assert.assertEquals(person,result);
+ }
+
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/DemoServiceIT.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/DemoServiceIT.java
new file mode 100644
index 000000000..e2bd65af4
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/DemoServiceIT.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.test;
+
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.apache.dubbo.rest.demo.DemoService;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestClient;
+
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class DemoServiceIT {
+
+ private static final String providerAddress =
System.getProperty("dubbo.address", "localhost");
+
+ @DubboReference
+ private DemoService demoService;
+
+ @Test
+ public void test() {
+ String result = demoService.hello(1, "world");
+ Assert.assertEquals("Hello world1", result);
+
+ String res = demoService.deleteUserById("1");
+ Assert.assertEquals("1", res);
+
+ int userById = demoService.findUserById(1);
+ Assert.assertEquals(1, userById);
+
+ Long formBody = demoService.testFormBody(1L);
+ Assert.assertEquals(Long.valueOf(1),formBody);
+
+ }
+
+ @Test
+ public void testRest() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<String> result = defaultClient.get()
+ .uri("http://" + providerAddress +
":50052/demo/hello?a={a}&name={name}",1,"world")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(String.class);
+ Assert.assertEquals("Hello world1", result.getBody());
+ }
+
+ @Test
+ public void testQuery(){
+ ResponseEntity<Integer> response = RestClient.create().get()
+ .uri("http://" + providerAddress +
":50052/demo/findUserById?id={id}",1)
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(Integer.class);
+ Assert.assertEquals(Integer.valueOf(1), response.getBody());
+ }
+
+ @Test
+ public void testFrom(){
+ MultiValueMap<String, Long> map = new LinkedMultiValueMap<>();
+ map.add("number",1L);
+ ResponseEntity<Long> response = RestClient.create().post()
+ .uri("http://" + providerAddress + ":50052/demo/form")
+ .contentType(MediaType.APPLICATION_FORM_URLENCODED)
+ .body(map)
+ .retrieve()
+ .toEntity(Long.class);
+ Assert.assertEquals(Long.valueOf(1), response.getBody());
+ }
+
+ @Test
+ public void testDel(){
+ ResponseEntity<String> response = RestClient.create().delete()
+ .uri("http://" + providerAddress +
":50052/demo/deleteUserById/1")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(String.class);
+ Assert.assertEquals("1", response.getBody());
+ }
+
+
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ConsumerIT.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ExpansionServiceIT.java
similarity index 57%
rename from
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ConsumerIT.java
rename to
2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ExpansionServiceIT.java
index 1dcff3c0b..a642aca54 100644
---
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ConsumerIT.java
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ExpansionServiceIT.java
@@ -16,8 +16,6 @@
*/
package org.apache.dubbo.rest.demo.test;
-import org.apache.dubbo.config.annotation.DubboReference;
-import org.apache.dubbo.rest.demo.DemoService;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,28 +26,43 @@ import org.springframework.web.client.RestClient;
@SpringBootTest
@RunWith(SpringRunner.class)
-public class ConsumerIT {
+public class ExpansionServiceIT {
private static final String providerAddress =
System.getProperty("dubbo.address", "localhost");
- @DubboReference
- private DemoService demoService;
@Test
- public void test() {
- String result = demoService.sayHello("world");
- Assert.assertEquals("Hello world", result);
+ public void testFilter(){
+ ResponseEntity<String> response = RestClient.create().get()
+ .uri("http://" + providerAddress +
":50052/ext/filter?name={name}","world ")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(String.class);
+ Assert.assertEquals("Hello world response-filter",response.getBody());
+
+ }
+
+ @Test
+ public void testIntercept(){
+ ResponseEntity<String> response = RestClient.create().get()
+ .uri("http://" + providerAddress +
":50052/ext/intercept?name={name}","world ")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(String.class);
+ Assert.assertEquals("Hello world intercept",response.getBody());
}
+
@Test
- public void testRest() {
- RestClient defaultClient = RestClient.create();
- ResponseEntity<String> result = defaultClient.get()
- .uri("http://" + providerAddress +
":50052/demo/hello?name=world")
+ public void testException(){
+ ResponseEntity<String> response = RestClient.create().get()
+ .uri("http://" + providerAddress + ":50052/ext/exception")
.header("Content-type", "application/json")
.retrieve()
.toEntity(String.class);
- // FIXME
- Assert.assertEquals("\"Hello world\"", result.getBody());
+ Assert.assertEquals("test-exception",response.getBody());
}
+
+
+
}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/HttpMethodRequestIT.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/HttpMethodRequestIT.java
new file mode 100644
index 000000000..e1e40be90
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/HttpMethodRequestIT.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.test;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.apache.dubbo.rest.demo.routine.HttpMethodRequestService;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.web.client.RestClient;
+
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class HttpMethodRequestIT {
+ private static final String providerAddress =
System.getProperty("dubbo.address", "localhost");
+
+ @DubboReference
+ private HttpMethodRequestService httpMethodRequestService;
+
+ @Test
+ public void test() {
+ String result = httpMethodRequestService.sayHelloPut("world");
+ Assert.assertEquals("Hello world", result);
+
+ result = httpMethodRequestService.sayHelloGet("world");
+ Assert.assertEquals("Hello world", result);
+
+ result = httpMethodRequestService.sayHelloPut("world");
+ Assert.assertEquals("Hello world", result);
+
+ result = httpMethodRequestService.sayHelloDelete("world");
+ Assert.assertEquals("Hello world", result);
+
+ result = httpMethodRequestService.sayHelloPatch("world");
+ Assert.assertEquals("Hello world", result);
+
+ result = httpMethodRequestService.sayHelloOptions("world");
+ Assert.assertEquals("Hello world", result);
+
+ result = httpMethodRequestService.sayHelloHead("world");
+ Assert.assertEquals("Hello world", result);
+ }
+
+ @Test
+ public void testGet() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<String> result = defaultClient.get()
+ .uri("http://" + providerAddress +
":50052/HttpRequestMethod/sayGet?name=world")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(String.class);
+
+ Assert.assertEquals("Hello world", result.getBody());
+ }
+
+ @Test
+ public void testPost() throws JsonProcessingException {
+ String value = new ObjectMapper().writeValueAsString("world");
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<String> result = defaultClient.post()
+ .uri("http://" + providerAddress +
":50052/HttpRequestMethod/sayPost")
+ .header("Content-type", "application/json")
+ .body(value)
+ .retrieve()
+ .toEntity(String.class);
+
+ Assert.assertEquals("Hello world", result.getBody());
+ }
+
+ @Test
+ public void testDel() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<String> result = defaultClient.delete()
+ .uri("http://" + providerAddress +
":50052/HttpRequestMethod/sayDelete?name=world")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(String.class);
+
+ Assert.assertEquals("Hello world", result.getBody());
+ }
+
+ @Test
+ public void testHeader() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<Void> result = defaultClient.head()
+ .uri("http://" + providerAddress +
":50052/HttpRequestMethod/sayHead?name=world")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toBodilessEntity();
+
+ Assert.assertEquals(HttpStatus.OK, result.getStatusCode());
+ }
+
+ @Test
+ public void testPatch() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<String> result = defaultClient.patch()
+ .uri("http://" + providerAddress +
":50052/HttpRequestMethod/sayPatch?name=world")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(String.class);
+
+ Assert.assertEquals("Hello world", result.getBody());
+ }
+
+ @Test
+ public void testOptions() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<String> result = defaultClient.options()
+ .uri("http://" + providerAddress +
":50052/HttpRequestMethod/sayOptions?name=world")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(String.class);
+
+ Assert.assertEquals("Hello world", result.getBody());
+ }
+
+
+ @Test
+ public void testPut() {
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<String> result = defaultClient.put()
+ .uri("http://" + providerAddress +
":50052/HttpRequestMethod/sayPut?name=world")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(String.class);
+
+ Assert.assertEquals("Hello world", result.getBody());
+ }
+
+}
diff --git
a/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ParamTransferRequestIT.java
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ParamTransferRequestIT.java
new file mode 100644
index 000000000..389d7fa23
--- /dev/null
+++
b/2-advanced/dubbo-samples-triple-rest/dubbo-samples-triple-rest-jaxrs/src/test/java/org/apache/dubbo/rest/demo/test/ParamTransferRequestIT.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.dubbo.rest.demo.test;
+
+import org.apache.dubbo.config.annotation.DubboReference;
+import org.apache.dubbo.rest.demo.routine.ParamTransferRequestService;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.http.MediaType;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestClient;
+
+@SpringBootTest
+@RunWith(SpringRunner.class)
+public class ParamTransferRequestIT {
+
+ private static final String providerAddress =
System.getProperty("dubbo.address", "localhost");
+
+
+ @DubboReference
+ private ParamTransferRequestService paramTransferRequestService;
+
+ @Test
+ public void test(){
+ String result1 = paramTransferRequestService.sayHello("world");
+ Assert.assertEquals("Hello world",result1);
+
+ String result2 = paramTransferRequestService.sayForm("world");
+ Assert.assertEquals("Hello world",result2);
+
+ String result3 = paramTransferRequestService.sayPath("1");
+ Assert.assertEquals("Hello 1",result3);
+
+ String result4 = paramTransferRequestService.sayHeader("world");
+ Assert.assertEquals("Hello world",result4);
+
+ String result5 = paramTransferRequestService.sayCookie("1");
+ Assert.assertEquals("Hello 1",result5);
+
+ String result6 = paramTransferRequestService.sayMatrix("world");
+ Assert.assertEquals("Hello world",result6);
+ }
+
+
+ @Test
+ public void testQuery(){
+ ResponseEntity<String> response = RestClient.create().get()
+ .uri("http://" + providerAddress +
":50052/param/query?name={name}","world")
+ .header( "Content-type","text/plain")
+ .retrieve()
+ .toEntity(String.class);
+ Assert.assertEquals("Hello world",response.getBody());
+ }
+
+ @Test
+ public void testPath(){
+ ResponseEntity<String> response = RestClient.create().get()
+ .uri("http://" + providerAddress + ":50052/param/path/1")
+ .header( "Content-type","text/plain")
+ .retrieve()
+ .toEntity(String.class);
+ Assert.assertEquals("Hello 1",response.getBody());
+ }
+
+ @Test
+ public void testFrom(){
+ MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
+ map.add("form","world");
+ ResponseEntity<String> response = RestClient.create().post()
+ .uri("http://" + providerAddress + ":50052/param/form")
+ .contentType(MediaType.APPLICATION_FORM_URLENCODED)
+ .body(map)
+ .retrieve()
+ .toEntity(String.class);
+ Assert.assertEquals("Hello world", response.getBody());
+
+ }
+
+ @Test
+ public void testHeader(){
+ ResponseEntity<String> response = RestClient.create().get()
+ .uri("http://" + providerAddress + ":50052/param/header")
+ .header( "Content-type","text/plain")
+ .header("name","world")
+ .retrieve()
+ .toEntity(String.class);
+ Assert.assertEquals("Hello world",response.getBody());
+ }
+
+
+ @Test
+ public void testCookie(){
+ ResponseEntity<String> response = RestClient.create().get()
+ .uri("http://" + providerAddress + ":50052/param/cookie")
+ .header( "Content-type","text/plain")
+ .header( "Cookie","cookieId=1")
+ .retrieve()
+ .toEntity(String.class);
+ System.out.println(response.getBody());
+ }
+
+ @Test
+ public void testMatrix(){
+ // TODO matrix
+ RestClient defaultClient = RestClient.create();
+ ResponseEntity<String> result = defaultClient.get()
+ .uri("http://" + providerAddress +
":50052/param/matrix;m=name=world")
+ .header("Content-type", "application/json")
+ .retrieve()
+ .toEntity(String.class);
+ Assert.assertEquals("Hello world", result.getBody());
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]