forked from apache/dubbo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add spring mvc rest demo (apache#12188)
* add spring mvc rest demo * FIX VERSION
- Loading branch information
1 parent
335733b
commit 4f86a3b
Showing
16 changed files
with
693 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...java/org/apache/dubbo/demo/rest/api/annotation/DubboServiceAnnotationServiceConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.demo.rest.api.annotation; | ||
|
||
import org.apache.dubbo.config.annotation.DubboReference; | ||
import org.apache.dubbo.demo.rest.api.DubboServiceAnnotationService; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class DubboServiceAnnotationServiceConsumer { | ||
|
||
@DubboReference(interfaceClass = DubboServiceAnnotationService.class) | ||
DubboServiceAnnotationService dubboServiceAnnotationService; | ||
|
||
public void invokeAnnotationService() { | ||
String annotation = dubboServiceAnnotationService.annotation(); | ||
System.out.println(annotation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
dubbo-demo/dubbo-demo-xml/dubbo-demo-spring-mvc-rest-consumer/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>dubbo-demo-xml</artifactId> | ||
<groupId>org.apache.dubbo</groupId> | ||
<version>${revision}</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>dubbo-demo-spring-mvc-rest-consumer</artifactId> | ||
|
||
<packaging>jar</packaging> | ||
<description>Dubbo Spring MVC Rest Consumer Demo</description> | ||
<name>${project.artifactId}</name> | ||
|
||
<properties> | ||
<skip_maven_deploy>true</skip_maven_deploy> | ||
<slf4j-log4j12.version>1.7.33</slf4j-log4j12.version> | ||
</properties> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-registry-multicast</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-registry-zookeeper</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-registry-nacos</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.alibaba.nacos</groupId> | ||
<artifactId>nacos-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-configcenter-zookeeper</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-configcenter-nacos</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-metadata-report-zookeeper</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-metadata-report-nacos</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-rpc-dubbo</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-rpc-rest</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-config-spring</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-remoting-netty4</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-serialization-hessian2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-serialization-fastjson2</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-serialization-jdk</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-log4j12</artifactId> | ||
<version>${slf4j-log4j12.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.dubbo</groupId> | ||
<artifactId>dubbo-demo-interface</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<!-- For jdk 11 above JavaEE annotation --> | ||
<profile> | ||
<id>javax.annotation</id> | ||
<activation> | ||
<jdk>[1.11,)</jdk> | ||
</activation> | ||
<dependencies> | ||
<dependency> | ||
<groupId>javax.annotation</groupId> | ||
<artifactId>javax.annotation-api</artifactId> | ||
<version>1.3.2</version> | ||
</dependency> | ||
</dependencies> | ||
</profile> | ||
</profiles> | ||
|
||
</project> | ||
|
74 changes: 74 additions & 0 deletions
74
...mvc-rest-consumer/src/main/java/org/apache/dubbo/demo/rest/api/SpringMvcRestConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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.demo.rest.api; | ||
|
||
import org.springframework.context.support.ClassPathXmlApplicationContext; | ||
import org.springframework.util.LinkedMultiValueMap; | ||
import org.springframework.util.MultiValueMap; | ||
import po.User; | ||
|
||
import java.util.Arrays; | ||
|
||
public class SpringMvcRestConsumer { | ||
|
||
public static void main(String[] args) { | ||
consumerService(); | ||
} | ||
|
||
public static void consumerService() { | ||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"spring/rest-consumer.xml"}); | ||
context.start(); | ||
System.out.println("spring mvc rest consumer start"); | ||
springMvcRestDemoServiceTest(context); | ||
System.out.println("spring mvc rest consumer test success"); | ||
} | ||
|
||
private static void springMvcRestDemoServiceTest(ClassPathXmlApplicationContext context) { | ||
SpringRestDemoService springRestDemoService = context.getBean("springRestDemoService", SpringRestDemoService.class); | ||
String hello = springRestDemoService.sayHello("hello"); | ||
assertEquals("Hello, hello", hello); | ||
Integer result = springRestDemoService.primitiveInt(1, 2); | ||
Long resultLong = springRestDemoService.primitiveLong(1, 2l); | ||
long resultByte = springRestDemoService.primitiveByte((byte) 1, 2l); | ||
long resultShort = springRestDemoService.primitiveShort((short) 1, 2l, 1); | ||
|
||
assertEquals(result, 3); | ||
assertEquals(resultShort, 3l); | ||
assertEquals(resultLong, 3l); | ||
assertEquals(resultByte, 3l); | ||
|
||
assertEquals(Long.valueOf(1l), springRestDemoService.testFormBody(1l)); | ||
|
||
MultiValueMap<String, String> forms = new LinkedMultiValueMap<>(); | ||
forms.put("form", Arrays.asList("F1")); | ||
|
||
assertEquals(Arrays.asList("F1"), springRestDemoService.testMapForm(forms)); | ||
assertEquals(User.getInstance(), springRestDemoService.testJavaBeanBody(User.getInstance())); | ||
} | ||
|
||
|
||
private static void assertEquals(Object returnStr, Object exception) { | ||
boolean equal = returnStr != null && returnStr.equals(exception); | ||
|
||
if (equal) { | ||
return; | ||
} else { | ||
throw new RuntimeException(); | ||
} | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...ng-mvc-rest-consumer/src/main/java/org/apache/dubbo/demo/rest/api/config/DubboConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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.demo.rest.api.config; | ||
|
||
import org.apache.dubbo.config.spring.context.annotation.DubboComponentScan; | ||
|
||
@DubboComponentScan("org.apache.dubbo.demo.rest") | ||
public class DubboConfig { | ||
|
||
|
||
} |
29 changes: 29 additions & 0 deletions
29
.../src/main/java/org/apache/dubbo/demo/rest/api/consumer/SpringRestDemoServiceConsumer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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.demo.rest.api.consumer; | ||
|
||
import org.apache.dubbo.config.annotation.DubboReference; | ||
import org.apache.dubbo.demo.rest.api.SpringRestDemoService; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class SpringRestDemoServiceConsumer { | ||
@DubboReference(interfaceClass = SpringRestDemoService.class ) | ||
SpringRestDemoService springRestDemoService; | ||
|
||
|
||
} |
Oops, something went wrong.