[英]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.