【问题标题】:JAXWS, Axis2 and Tomcat service URLsJAXWS、Axis2 和 Tomcat 服务 URL
【发布时间】:2010-11-08 14:34:53
【问题描述】:

我正在开发一些必须使用 JAXWS 实现的 Web 服务,并且必须在 WebLogic 10.3、WebSphere 7 和 Tomcat 5.5 上运行。此外,服务的安装必须完全独立,以避免与容器中的任何其他应用程序发生冲突。 WebLogic和WebSphere都解决了,但是tomcat给我带来了麻烦。

使用 JAXWS-RI 为 jaxws 启用 tomcat 是可行的,但应避免在 tomcat 或 jre 中安装额外的 jar(jaxws.jar、jaxb.jar)。

在战争中嵌入axis2的应用程序会更好,但服务会得到有趣的URI。以这个服务为例:

使用 wsimport 生成的 PortType:

@WebService(name = "AuthenticationServicePortType", targetNamespace = "http://impl.auth.webservice.my.company")
@XmlSeeAlso({
    company.my.exposed.xsd.ObjectFactory.class,
    company.my.webservice.auth.impl.ObjectFactory.class
})
public interface AuthenticationServicePortType {

实施:

@WebService(
  portName = "AuthenticationServicePort", serviceName = "AuthenticationService",
  targetNamespace = "http://impl.auth.webservice.my.company", wsdlLocation = "WEB-INF/wsdl/AuthenticationService.wsdl",
  endpointInterface = "company.my.webservice.auth.impl.AuthenticationServicePortType"
)
public class AuthenticationServiceImpl implements AuthenticationServicePortType {

在 WebSphere、WebLogic 和 tomcat+JAXWS-RI 中,此服务在 uri 中可用

http://localhost/MyProduct/services/AuthenticationService

但是,在战争中嵌入了axis2,该服务在uri中可用

http://localhost/MyProduct/services/AuthenticationService.AuthenticationServicePort

由于这是对具有广泛安装基础的现有服务的升级,因此此更改是不可接受的。

axis2 的 jaxws 支持中删除了通过 services.xml 配置服务,所以这是死路一条。

使用 Apache CXF 而不是 Axis2 不是一个好的解决方案,因为它可能会造成支持噩梦。

tomcat 版本的 web.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <description>My web service</description>
    <display-name>MyProduct</display-name>
    <servlet>
        <description>JAX-WS endpoint for MyProduct</description>
        <display-name>MyProduct</display-name>
        <servlet-name>MyProduct</servlet-name>
        <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>MyProduct</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>
</web-app>

我还修改了axis2.xml,让它在常规类中寻找带注释的类:

<deployer extension=".class" directory="classes" class="org.apache.axis2.jaxws.framework.JAXWSDeployer"/>

两种解决方案会有所帮助:

  • 一种在战争中嵌入 JAXWS-RI 的方法,因此无需在 tomcat 中安装任何内容
  • 一种让 Axis2 在常规 URI 上部署服务的方法(与其他容器相同)

【问题讨论】:

  • 出于好奇,使用 CXF 代替 Axis2 会如何造成支持噩梦?
  • 使用 CXF 可能(不是“会”)造成支持的噩梦。这是一种风险,而不是确定性。

标签: tomcat jax-ws axis2


【解决方案1】:

我没有找到真正解决这个问题的方法,但我找到了解决方法。

我使用 url 重写 (http://www.tukey.org/urlrewrite/) 在 URL 中添加额外的部分。

在 web.xml 中过滤:

<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
    <init-param>
        <param-name>logLevel</param-name>
        <param-value>INFO</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/services/*</url-pattern>
</filter-mapping>

urlrewrite.xml:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
        "http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
<urlrewrite>
    <rule>
        <note>
            Add .SomeServicePort to all urls
        </note>
        <from>/services/(.*)</from>
        <to>/services/$1.$1Port</to>
    </rule>
</urlrewrite>

不够漂亮,但足够好。

【讨论】:

    猜你喜欢
    • 2013-03-26
    • 1970-01-01
    • 2021-04-29
    • 1970-01-01
    • 1970-01-01
    • 2018-03-14
    • 1970-01-01
    • 1970-01-01
    • 2020-01-30
    相关资源
    最近更新 更多