Is there a framework, library or technique that combines JAX-RS and JAX-WS (or equivalent functionality) into one combined service in a similar way to using two endpoints (one SOAP and one REST) for the same service in WCF?
Apache CXF can do the job. Read more at http://cxf.apache.org/docs/frontends.html
It's possible with a standard tomcat configuration. Just use separate URLs for the services. I decided to put the JAX-WS service behind "SOAP/" and the others behind lowercase letters. If you want to use "rest" in the URL, it's even more easy, but not looking that nice for end users. Don't forget to add a sun-jaxws.xml, too. I left the `init-params as they are useful for normalized URLs. You can drop all of them if you wish.
<?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>
Addon to Mikhail's answer, example of CXF's configuration. More info is at 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" />
Update: Peter Szanto created a maven project at https://github.com/ExampleDriven/cxf-example
© 2022 - 2024 — McMap. All rights reserved.