JAXWS,Axis2和Tomcat服务URL

时间:2010-11-08 14:34:54

标签: tomcat jax-ws axis2

我正在开发一些必须使用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

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

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

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

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

<?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上部署服务的方法(与其他容器相同)

1 个答案:

答案 0 :(得分:0)

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

我使用网址重写(http://www.tuckey.org/urlrewrite/)在网址中添加额外部分。

在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>

不美但很好。

相关问题