【发布时间】: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 可能(不是“会”)造成支持的噩梦。这是一种风险,而不是确定性。