组合的 JAX-RS 和 JAX-WS

发布于 2024-10-18 05:44:42 字数 98 浏览 2 评论 0原文

是否有一种框架、库或技术可以将 JAX-RS 和 JAX-WS(或等效功能)组合成一个组合服务,其方式类似于在 WCF 中为同一服务使用两个端点(一个 SOAP 和一个 REST)?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空城之時有危險 2024-10-25 05:44:42

Apache CXF 可以完成这项工作。了解更多信息,请访问 http://cxf.apache.org/docs/frontends.html

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

生活了然无味 2024-10-25 05:44:42

使用标准的 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>

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>
魂归处 2024-10-25 05:44:42

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文