JAXWS、Axis2和Tomcat服务URL

JAXWS、Axis2和Tomcat服务URL,tomcat,jax-ws,axis2,Tomcat,Jax Ws,Axis2,我正在开发一些必须使用JAXWS实现的web服务,这些服务必须在WebLogic10.3、WebSphere7和Tomcat5.5上运行。此外,服务的安装必须完全独立,以避免与容器中的任何其他应用程序发生冲突。WebLogic和WebSphere已经解决了,但tomcat给我带来了麻烦 通过使用jaxws-RI启用tomcat for jaxws是可行的,但是要避免在tomcat或jre中安装额外的jar(jaxws.jar、jaxb.jar) 在war中嵌入axis2来发布我的应用程序会更好,

我正在开发一些必须使用JAXWS实现的web服务,这些服务必须在WebLogic10.3、WebSphere7和Tomcat5.5上运行。此外,服务的安装必须完全独立,以避免与容器中的任何其他应用程序发生冲突。WebLogic和WebSphere已经解决了,但tomcat给我带来了麻烦

通过使用jaxws-RI启用tomcat for jaxws是可行的,但是要避免在tomcat或jre中安装额外的jar(jaxws.jar、jaxb.jar)

在war中嵌入axis2来发布我的应用程序会更好,但服务会得到有趣的URI。以这项服务为例:

使用wsimport生成的端口类型:

@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
http://localhost/MyProduct/services/AuthenticationService.AuthenticationServicePort
但是,随着axis2嵌入到war中,该服务在uri处变得可用

http://localhost/MyProduct/services/AuthenticationService
http://localhost/MyProduct/services/AuthenticationService.AuthenticationServicePort
因为这是对现有服务的升级,安装范围很广,所以此更改是不可接受的

通过services.xml配置服务已从axis2的jaxws支持中删除,因此这是一条死胡同

使用ApacheCXF而不是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>

我的网络服务
我的产品
MyProduct的JAX-WS端点
我的产品
我的产品
org.apache.axis2.transport.http.AxisServlet
我的产品
/服务/*
我还修改了axis2.xml,使其在常规类中查找带注释的类:

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

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

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

    • 我没有找到这个问题的真正解决方案,但我找到了一个解决办法

      我使用了url重写(http://www.tuckey.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>
      
      
      URL重写过滤器
      org.tuckey.web.filters.urlrewrite.UrlRewriteFilter
      对数电平
      信息
      URL重写过滤器
      /服务/*
      
      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>
      
      
      将.SomeServicePort添加到所有URL
      /服务/(*)
      /服务/$1.$1端口
      

      虽然不漂亮,但已经足够好了。

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