将JAX-RS演示放入showcase中。
This commit is contained in:
@@ -1,14 +1,13 @@
|
||||
@echo off
|
||||
echo Before run this script, please save
|
||||
echo http://localhost:8080/showcase/soap/accountservice?wsdl
|
||||
echo to
|
||||
echo target/wsdl/accountservice.wsdl
|
||||
echo http://localhost:8080/showcase/soap/accountservice?wsdl to target/wsdl/accountservice.wsdl
|
||||
|
||||
cd %~dp0/../
|
||||
call mvn cxf-codegen:wsdl2java
|
||||
if errorlevel 1 goto end
|
||||
|
||||
echo [INFO] Code had generated to <target/generated-sources/cxf>
|
||||
pause
|
||||
|
||||
:end
|
||||
pause
|
||||
@@ -156,6 +156,17 @@
|
||||
<artifactId>cxf-rt-transports-http</artifactId>
|
||||
</dependency>
|
||||
<!-- SOAP end -->
|
||||
|
||||
<!-- JAX-RS begin -->
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||
</dependency>
|
||||
<!-- JAX-RS end -->
|
||||
|
||||
<!-- JMS begin -->
|
||||
<dependency>
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package org.springside.examples.showcase.webservice.jaxrs;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springside.examples.showcase.entity.User;
|
||||
import org.springside.examples.showcase.service.AccountEffectiveService;
|
||||
import org.springside.examples.showcase.webservice.rest.UserDTO;
|
||||
import org.springside.modules.mapper.BeanMapper;
|
||||
|
||||
@Path("/user")
|
||||
public class AccountRestService {
|
||||
|
||||
@Autowired
|
||||
private AccountEffectiveService accountService;
|
||||
|
||||
@GET
|
||||
@Path("/{id}.xml")
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
public UserDTO getAsXml(@PathParam("id") Long id) {
|
||||
User user = accountService.getUser(id);
|
||||
return bindDTO(user);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/{id}.json")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public UserDTO getAsJson(@PathParam("id") Long id) {
|
||||
User user = accountService.getUser(id);
|
||||
return bindDTO(user);
|
||||
}
|
||||
|
||||
private UserDTO bindDTO(User user) {
|
||||
UserDTO dto = BeanMapper.map(user, UserDTO.class);
|
||||
//补充Dozer不能自动绑定的属性
|
||||
dto.setTeamId(user.getTeam().getId());
|
||||
return dto;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -18,8 +18,9 @@ import org.springside.examples.showcase.webservice.soap.response.dto.UserDTO;
|
||||
*
|
||||
* @author calvin
|
||||
*/
|
||||
//name 指明wsdl中<wsdl:portType>元素的名称
|
||||
@WebService(name = "AccountService", targetNamespace = WsConstants.NS)
|
||||
public interface AccountWebService {
|
||||
public interface AccountSoapService {
|
||||
/**
|
||||
* 获取团队的详细信息.
|
||||
*/
|
||||
+8
-8
@@ -32,11 +32,11 @@ import org.springside.modules.utils.Exceptions;
|
||||
*
|
||||
* @author calvin
|
||||
*/
|
||||
//serviceName指明WSDL中的名称, endpointInterface属性指向Interface定义类.
|
||||
@WebService(serviceName = "AccountService", endpointInterface = "org.springside.examples.showcase.webservice.soap.AccountWebService", targetNamespace = WsConstants.NS)
|
||||
public class AccountWebServiceImpl implements AccountWebService {
|
||||
//serviceName指明WSDL中<wsdl:service>与<wsdl:binding>元素的名称, endpointInterface属性指向Interface类全称.
|
||||
@WebService(serviceName = "AccountService", endpointInterface = "org.springside.examples.showcase.webservice.soap.AccountSoapService", targetNamespace = WsConstants.NS)
|
||||
public class AccountSoapServiceImpl implements AccountSoapService {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(AccountWebServiceImpl.class);
|
||||
private static Logger logger = LoggerFactory.getLogger(AccountSoapServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private AccountEffectiveService accountService;
|
||||
@@ -45,7 +45,7 @@ public class AccountWebServiceImpl implements AccountWebService {
|
||||
private Validator validator;
|
||||
|
||||
/**
|
||||
* @see AccountWebService#getTeamDetail()
|
||||
* @see AccountSoapService#getTeamDetail()
|
||||
*/
|
||||
@Override
|
||||
public GetTeamDetailResult getTeamDetail(Long id) {
|
||||
@@ -70,7 +70,7 @@ public class AccountWebServiceImpl implements AccountWebService {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AccountWebService#getUser()
|
||||
* @see AccountSoapService#getUser()
|
||||
*/
|
||||
@Override
|
||||
public GetUserResult getUser(Long id) {
|
||||
@@ -96,7 +96,7 @@ public class AccountWebServiceImpl implements AccountWebService {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AccountWebService#searchUser()
|
||||
* @see AccountSoapService#searchUser()
|
||||
*/
|
||||
@Override
|
||||
public SearchUserResult searchUser(String loginName, String name) {
|
||||
@@ -113,7 +113,7 @@ public class AccountWebServiceImpl implements AccountWebService {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AccountWebService#createUser()
|
||||
* @see AccountSoapService#createUser()
|
||||
*/
|
||||
@Override
|
||||
public IdResult createUser(UserDTO user) {
|
||||
+2
-2
@@ -36,9 +36,9 @@ public class TeamDTO {
|
||||
this.master = master;
|
||||
}
|
||||
|
||||
//配置输出xml为<userList><User><id>1</id></User></userList>
|
||||
//配置输出xml为<userList><user><id>1</id></user></userList>
|
||||
@XmlElementWrapper(name = "userList")
|
||||
@XmlElement(name = "User")
|
||||
@XmlElement(name = "user")
|
||||
public List<UserDTO> getUserList() {
|
||||
return userList;
|
||||
}
|
||||
|
||||
@@ -16,5 +16,5 @@
|
||||
<import resource="schedule/applicationContext-quartz-timer-cluster.xml" />
|
||||
<import resource="security/applicationContext-shiro.xml" />
|
||||
<import resource="webservice/applicationContext-soap-server.xml" />
|
||||
|
||||
<import resource="webservice/applicationContext-rest-server.xml" />
|
||||
</beans>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
|
||||
xsi:schemaLocation="http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<description>Apache CXF的Restful Web Service配置</description>
|
||||
|
||||
<!-- jax-rs endpoint定义 -->
|
||||
<jaxrs:server id="serviceContainer" address="/rest">
|
||||
<jaxrs:serviceBeans>
|
||||
<ref bean="accountRestService" />
|
||||
</jaxrs:serviceBeans>
|
||||
<jaxrs:providers>
|
||||
<bean class="com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider" />
|
||||
</jaxrs:providers>
|
||||
</jaxrs:server>
|
||||
|
||||
<!-- WebService的实现Bean定义 -->
|
||||
<bean id="accountRestService" class="org.springside.examples.showcase.webservice.jaxrs.AccountRestService" />
|
||||
</beans>
|
||||
@@ -4,13 +4,13 @@
|
||||
xsi:schemaLocation="http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"
|
||||
default-lazy-init="true">
|
||||
|
||||
<description>Apache CXF的Web Service配置</description>
|
||||
|
||||
<description>Apache CXF的 SOAP Web Service配置</description>
|
||||
|
||||
<!-- jax-ws endpoint定义 -->
|
||||
<jaxws:endpoint address="/accountservice">
|
||||
<jaxws:implementor ref="accountWebService" />
|
||||
<jaxws:endpoint address="/soap/accountservice">
|
||||
<jaxws:implementor ref="accountSoapService" />
|
||||
</jaxws:endpoint>
|
||||
|
||||
<!-- WebService的实现Bean定义 -->
|
||||
<bean id="accountWebService" class="org.springside.examples.showcase.webservice.soap.AccountWebServiceImpl" />
|
||||
<bean id="accountSoapService" class="org.springside.examples.showcase.webservice.soap.AccountSoapServiceImpl" />
|
||||
</beans>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<decorators defaultdir="/WEB-INF/layouts/">
|
||||
<excludes>
|
||||
<pattern>/static/*</pattern>
|
||||
<pattern>/soap/*</pattern>
|
||||
<pattern>/cxf/*</pattern>
|
||||
<pattern>/api/*</pattern>
|
||||
</excludes>
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@
|
||||
<h1>独立演示</h1>
|
||||
<div class="submenu">
|
||||
<a id="web-tab" href="${ctx}/story/web">Web演示</a>
|
||||
<a id="webservice-tab"href="${ctx}/story/webservice">WebService演示</a>
|
||||
<a id="log-tab" href="${ctx}/log/console">日志控制演示</a>
|
||||
<a id="jmx-tab" href="${ctx}/story/jmx">JMX演示</a>
|
||||
</div>
|
||||
<h1>演示说明</h1>
|
||||
<div class="submenu">
|
||||
<a id="persistence-tab" href="${ctx}/story/persistence">持久化高级演示</a>
|
||||
<a id="webservice-tab"href="${ctx}/story/webservice">WebService演示</a>
|
||||
<a id="jms-tab" href="${ctx}/story/jms">JMS演示</a>
|
||||
<a id="cache-tab" href="${ctx}/story/cache">Cache演示</a>
|
||||
<a id="schedule-tab" href="${ctx}/story/schedule">定时任务演示</a>
|
||||
|
||||
@@ -16,18 +16,29 @@
|
||||
|
||||
<h2>传统SOAP Web Service演示</h2>
|
||||
<ul>
|
||||
<li>服务端是基于CXF的JAX-WS演示. 详见由CXF自动生成的<a href="${ctx}/soap">服务信息及wsdl文件</a>.</li>
|
||||
<li>服务端是基于CXF的JAX-WS演示. 详见由CXF自动生成的<a href="${ctx}/cxf/soap/accountservice?wsdl">wsdl文件</a>.</li>
|
||||
<li>客户端见Functional Test用例.</li>
|
||||
</ul>
|
||||
|
||||
<h2>Restful Service高级演示</h2>
|
||||
服务端:
|
||||
<ul>
|
||||
<li>集成Shiro进行HttpBasic的认证 </li>
|
||||
<li>XML与JSON两种格式的序列化</li>
|
||||
<li>演示地址:<a href="${ctx}/api/v1/user/1.xml">/api/v1/user/1.xml</a> 与 <a href="${ctx}/api/v1/user/1.xml">/api/v1/user/1.json</a></li>
|
||||
<li>用浏览器访问时需要认证admin/admin</li>
|
||||
</ul>
|
||||
客户端:
|
||||
<ul>
|
||||
<li>集成Shiro进行HttpBasic的认证</li>
|
||||
<li>XML与JSON两种格式</li>
|
||||
<li>RestTemplate设置HttpHeaders的写法,用原始的exchange()方法及用ClientHttpRequestInterceptor两种方法</li>
|
||||
<li>RestTemplate默认使用JDK HttpConnection,设置使用Apache HttpClient4作为Http Connection底层</li>
|
||||
<li>RestTemplate设置超时控制</li>
|
||||
<li>客户端同样见Functional Test用例UserRestFt.java</li>
|
||||
</ul>
|
||||
|
||||
<h2>基于JAX-RS实现的Restful演示</h2>
|
||||
<ul>
|
||||
<li>演示地址:<a href="${ctx}/cxf/rest/user/1.xml">/cxf/rest/user/1.xml</a> 与 <a href="${ctx}/cxf/rest/user/1.xml">/cxf/rest/user/1.json</a></li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
@@ -46,7 +46,7 @@
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>CXFServlet</servlet-name>
|
||||
<url-pattern>/soap/*</url-pattern>
|
||||
<url-pattern>/cxf/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- JMX JSON Agent servlet-->
|
||||
|
||||
+6
-6
@@ -12,7 +12,7 @@ import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.springside.examples.showcase.functional.BaseFunctionalTestCase;
|
||||
import org.springside.examples.showcase.webservice.soap.AccountWebService;
|
||||
import org.springside.examples.showcase.webservice.soap.AccountSoapService;
|
||||
import org.springside.examples.showcase.webservice.soap.response.GetTeamDetailResult;
|
||||
import org.springside.modules.test.category.Smoke;
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.springside.modules.test.category.Smoke;
|
||||
*/
|
||||
public class AccountWebServiceWithDynamicCreateClientFT extends BaseFunctionalTestCase {
|
||||
|
||||
public AccountWebService creatClient() {
|
||||
String address = baseUrl + "/soap/accountservice";
|
||||
public AccountSoapService creatClient() {
|
||||
String address = baseUrl + "/cxf/soap/accountservice";
|
||||
|
||||
JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
|
||||
proxyFactory.setAddress(address);
|
||||
proxyFactory.setServiceClass(AccountWebService.class);
|
||||
AccountWebService accountWebServiceProxy = (AccountWebService) proxyFactory.create();
|
||||
proxyFactory.setServiceClass(AccountSoapService.class);
|
||||
AccountSoapService accountWebServiceProxy = (AccountSoapService) proxyFactory.create();
|
||||
|
||||
//(可选)演示重新设定endpoint address.
|
||||
((BindingProvider) accountWebServiceProxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
|
||||
@@ -54,7 +54,7 @@ public class AccountWebServiceWithDynamicCreateClientFT extends BaseFunctionalTe
|
||||
@Test
|
||||
@Category(Smoke.class)
|
||||
public void getTeamDetail() {
|
||||
AccountWebService accountWebService = creatClient();
|
||||
AccountSoapService accountWebService = creatClient();
|
||||
|
||||
GetTeamDetailResult result = accountWebService.getTeamDetail(1L);
|
||||
assertEquals("Dolphin", result.getTeam().getName());
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
||||
import org.springside.examples.showcase.data.UserData;
|
||||
import org.springside.examples.showcase.entity.User;
|
||||
import org.springside.examples.showcase.functional.BaseFunctionalTestCase;
|
||||
import org.springside.examples.showcase.webservice.soap.AccountWebService;
|
||||
import org.springside.examples.showcase.webservice.soap.AccountSoapService;
|
||||
import org.springside.examples.showcase.webservice.soap.response.GetUserResult;
|
||||
import org.springside.examples.showcase.webservice.soap.response.SearchUserResult;
|
||||
import org.springside.examples.showcase.webservice.soap.response.base.IdResult;
|
||||
@@ -37,7 +37,7 @@ import org.springside.modules.test.category.Smoke;
|
||||
public class AccountWebServiceWithPredefineClientFT extends BaseFunctionalTestCase {
|
||||
|
||||
@Autowired
|
||||
private AccountWebService accountWebServiceClient;
|
||||
private AccountSoapService accountWebServiceClient;
|
||||
|
||||
/**
|
||||
* 测试获取用户.
|
||||
|
||||
@@ -12,5 +12,5 @@
|
||||
classpath*:/application.functional-local.properties" />
|
||||
|
||||
<jaxws:client id="accountWebServiceClient" serviceClass="org.springside.examples.showcase.webservice.soap.AccountWebService"
|
||||
address="${baseUrl}/soap/accountservice" />
|
||||
address="${baseUrl}/cxf/soap/accountservice" />
|
||||
</beans>
|
||||
|
||||
@@ -342,6 +342,19 @@
|
||||
</dependency>
|
||||
<!-- SOAP end -->
|
||||
|
||||
<!-- JAX-RS begin -->
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
||||
<version>${cxf.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.jaxrs</groupId>
|
||||
<artifactId>jackson-jaxrs-json-provider</artifactId>
|
||||
<version>2.0.5</version>
|
||||
</dependency>
|
||||
<!-- JAX-RS end -->
|
||||
|
||||
<!-- JMS begin -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
||||
Reference in New Issue
Block a user