Combined JAX-RS and JAX-WS
Asked Answered
A

3

11

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?

Airlift answered 17/2, 2011 at 22:25 Comment(0)
K
5

Apache CXF can do the job. Read more at http://cxf.apache.org/docs/frontends.html

Kacey answered 19/2, 2011 at 21:20 Comment(0)
G
2

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>
Gastric answered 15/4, 2013 at 18:37 Comment(0)
C
1

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

Criseyde answered 4/1, 2013 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.