2011-02-17 75 views
11

是否有一種框架,庫或技術將JAX-RS和JAX-WS(或等效功能)組合到一個組合服務中,類似於使用兩個端點(一個SOAP和一個REST)在WCF中的相同服務?組合JAX-RS和JAX-WS

回答

1

附加到米哈伊爾的答案,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" /> 

更新:彼得Szanto在https://github.com/ExampleDriven/cxf-example

2

有可能與標準的Tomcat配置創建一個Maven項目。只需爲服務使用單獨的URL。我決定把JAX-WS服務放在「SOAP /」後面,其他的放在小寫字母后面。如果你想在網址中使用「休息」,那就更簡單了,但對最終用戶來說並不好。別忘了添加一個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>