【问题标题】:Getting the WSDL from a CXF webservice running on Tomcat从运行在 Tomcat 上的 CXF Web 服务获取 WSDL
【发布时间】:2012-02-17 11:49:58
【问题描述】:

回答: 我知道就分辨率而言,这不是一种很好的事情,但是我摆弄了 web.xml 和 servlet.xml 文件,由于某种原因,它现在可以工作了,我可以获得服务列表和 wsdl文件现在很好。我将我的新文件与下面写的旧文件进行了比较,唯一的区别是 web.xml 的名称为 CXFServlet 而不是 LoginService,并且我现在给 cxfservlet.xml 端点一个地址。

我有一个问题,我(最后)在 Tomcat 上部署了 CXF 网络服务。或者更确切地说,它确实启动了,并且在我部署和重新部署时它不会在 tomcat 日志中产生任何警告或异常。问题是我无法检索相关服务的 WSDL。我开始认为我不像我想的那样理解 web.xml 和 cxf.xml 文件。

当我写http://localhost:8080/services/Login?wsdl 时,我希望 WSDL 会弹出,但我得到的只是 404。我做错了什么?正如我所说,我没有遇到任何异常,那么我的问题是什么?

编辑: 由于一些有用的反馈(我记得标记为有用),我意识到我可能在 web.xml 中设置了错误的上下文路径。我通过 tomcat 中的管理器应用程序将服务部署在一个名为 LoginService.war 的文件中。 这就引出了一个问题:我什至可以这样做吗? tomcat 会知道在 LoginService 库中查找 CXFServlet 类,还是会在 ROOT 中查找?我需要重新配置服务器以允许我从http://localhost:8080/LoginService 运行吗?

web.xml

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>LoginService</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:metadata/Login/cxfservlet.xml</param-value>
</context-param>
<listener>
<listener-class>
  org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>LoginService</servlet-name>
<servlet-class>
    org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginService</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>

cxfservlet.xml

 <beans xsi:schemaLocation="http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-2.0.xsd http://cxf.apache.org
 /jaxws http://cxf.apache.org/schemas/jaxws.xsd">
 <jaxws:endpoint id="LoginService"
 implementor="orgserver.services.Login" wsdlLocation="WEB-INF/LoginService.wsdl"
 address="/">
 </jaxws:endpoint>
 </beans>

【问题讨论】:

  • 你写address="/"。所以试试localhost:8080/services/?wsdl
  • 我是否至少理解正确?:我指定要在每个提供的类似于 /services/* 的 url 上运行 CXFServlet 类。那个 CXFServlet 类是什么将我在 cxfservlet.xml 文件中指定的 bean 作为端点并处理 web 服务操作?也是CXFServlet负责返回WSDL?
  • 在这个过程中的任何错误是否会记录在主 tomcat 日志之外的其他地方?

标签: web-services tomcat cxf web.xml


【解决方案1】:

您不需要设置 wsdlLocation,除非除了http://localhost:8080/services/ 之外还有其他方法可以访问您的服务。 wsdlLocation 也是一个 URL。

我假设您已将应用部署到 Tomcat 中的 ROOT.war(根上下文),因为 /services 之前没有上下文路径。

当您浏览到http://localhost:8080/services(无尾随/)时会显示什么?它应该为您提供可用服务的列表,包括 WSDL 地址。如果您将鼠标悬停在 WSDL 地址上,它将显示实际的 URL。

【讨论】:

  • 然后我导航到 localhost:8080/services 它给了我一个 404 与其他方式相同。我尝试将上下文路径更改为 /LoginService 这就是战争的名称,尝试过localhost:8080/LoginService,它仍然给我一个 404。
  • 我尝试在 LoginService 战争文件中放置一个简单的 index.html 文件,我可以使用 localhost:8080/LoginService 导航到该文件。我通过管理器 html 应用程序部署 LoginService.war。我将上下文路径更改为 /LocalHost/services/,但是当我调用 localhost:8080/LoginService/services 时仍然没有得到服务列表。我根本没有打电话给 CXFServlet 课程吗?有什么方法可以查看CXFServlet是否因为错误而失败?
  • 将我的上下文路径更改为 LoginService/services 在 tomcat 管理器中出现错误:“失败 - 上下文路径 /LoginService 处的应用程序无法启动。”除了“正在启动”消息之外,日志中没有任何内容。没有错误。
  • 我不知道为什么,但我现在可以工作了,我在原始问题中发布了答案
猜你喜欢
  • 1970-01-01
  • 2012-11-02
  • 1970-01-01
  • 2012-09-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-28
相关资源
最近更新 更多