[英]Combined JAX-RS and JAX-WS
是否存在将JAX-RS和JAX-WS(或等效功能)组合到一个组合服务中的框架,库或技术,类似于在WCF中为同一服务使用两个端点(一个SOAP和一个REST)?
Apache CXF可以完成这项工作。 更多信息,请访问http://cxf.apache.org/docs/frontends.html
使用标准的tomcat配置是可能的。 只需为服务使用单独的URL即可。 我决定将JAX-WS服务放在“SOAP /”后面,将其他服务放在小写字母后面。 如果你想在URL中使用“rest”,它会更容易,但对最终用户来说并不好看。 别忘了添加sun-jaxws.xml。 我留下了`init-params,因为它们对规范化的URL很有用。 如果您愿意,可以放弃所有这些。
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="webapp"
version="2.5">
<display-name>displayname</display-name>
<filter>
<filter-name>rest</filter-name>
<filter-class>com.sun.jersey.spi.container.servlet.ServletContainer</filter-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>thepackage</param-value>
</init-param>
<init-param>
<!-- enables processing by JSPs if not JAX-RS handler is registered -->
<param-name>com.sun.jersey.config.feature.FilterForwardOn404</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.feature.CanonicalizeURIPath</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.feature.NormalizeURI</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.feature.Redirect</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>rest</filter-name>
<url-pattern>/firstresource/</url-pattern>
<url-pattern>/secondresource/</url-pattern>
</filter-mapping>
<listener>
<listener-class>
com.sun.xml.ws.transport.http.servlet.WSServletContextListener
</listener-class>
</listener>
<servlet>
<servlet-name>soap</servlet-name>
<servlet-class>
com.sun.xml.ws.transport.http.servlet.WSServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>soap</servlet-name>
<url-pattern>/SOAP</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
</web-app>
添加到Mikhail的答案,CXF的配置示例。 更多信息请访问http://cxf.apache.org/docs/jax-rs-and-jax-ws.html#JAX-RSandJAX-WS-JAXRSandJAXWS
<!-- JAX-RS -->
<jaxrs:server id="customerService" address="/">
<jaxrs:serviceBeans>
<ref bean="customerService" />
</jaxrs:serviceBeans>
</jaxrs:server>
<!-- JAX-WS -->
<jaxws:endpoint implementor="#customerService"
address="/CustomerWorld" wsdlLocation="..."/>
<bean id="customerService" class="demo.jaxrs.server.CustomerService" />
更新:Peter Szanto在https://github.com/ExampleDriven/cxf-example创建了一个maven项目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.