【问题标题】:SOAPFaultException when deployed on Tomcat but works fine in GlassFishSOAPFaultException 部署在 Tomcat 上但在 GlassFish 中工作正常
【发布时间】:2012-03-30 04:48:48
【问题描述】:

朋友们,我已经尝试了很多,阅读了很多论坛,但无法理解为什么会出现这个问题。
我使用契约优先方法创建了一个 Jax-WS WebService。创建了 WSDL 和 XSD,然后使用 wsimport 工具生成其余的工件,为 SEI 提供了实现。

在 Eclipse Helios 中将 WebService 应用程序部署到 GlassFish(安装在 Eclipse 中的 Glassfish 适配器和插件)。通过 SoapUI 测试了部署的服务,效果很好。

我将此 Web 服务作为 WAR 文件部署到 Tomcat7.0 中。结构为:

WAR -> META-INF -> MANIFEST.MF
-> WEB-INF -> 类 -> ...
-> wsdl -> .wsdl 和 .xsd
-> web.xml
-> sun-jaxws.xml

当我通过 SoapUI 测试 web 服务时,我得到的响应是一个异常:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <S:Fault xmlns:ns3="http://www.w3.org/2003/05/soap-envelope">
        <faultcode>S:Server</faultcode>
        <faultstring>unexpected XML tag. expected: {http://localhost/fundmanagertd}addFund but found: {http://localhost/fundmanagertd}requestAddFund</faultstring>
      </S:Fault>
   </S:Body>
</S:Envelope>

我认为它在 Glassfish 中工作,因为 Glassfish 正在动态生成所有工件,而不接受已经生成的工件。虽然 Tomcat 只采用已部署包中的那些。为什么我这么认为,因为 Web 服务仅在不提供 sun-jaxws.xml 时才在 Glassfish 中工作,但在提供时,我无法在“已部署服务”部分看到该服务。虽然 Tomcat 使用 sun-jasws.xml 并使用我提供的类但失败了。我不知道为什么会这样。非常感谢这里的任何方向。

我正在使用的 WSDL:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<definitions targetNamespace="http://localhost/fundmanagertd" name="FundManagerTDService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://localhost/fundmanagertd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://localhost/fundmanagertd" schemaLocation="FundManagerTDService_schema1.xsd"/>
    </xsd:schema>
  </types>
  <message name="addFund">
    <part name="parameters" element="tns:requestAddFund"/>
  </message>
  <message name="addFundResponse">
    <part name="parameters" element="tns:responseAddFund"/>
  </message>
  <portType name="Fund">
    <operation name="addFund">
      <input message="tns:addFund"/>
      <output message="tns:addFundResponse"/>
    </operation>
  </portType>
  <binding name="FundPortBinding" type="tns:Fund">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="addFund">
      <soap:operation soapAction="urn:Add"/>
      <input>
        <soap:body use="literal"/>
      </input>
      <output>
        <soap:body use="literal"/>
      </output>
    </operation>
  </binding>
  <service name="FundManagerTDService">
    <port name="FundPort" binding="tns:FundPortBinding">
      <soap:address location="REPLACE_WITH_ACTUAL_URL"/>
    </port>
  </service>
</definitions>

FundManagerTDService_schema1.xsd

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://localhost/fundmanagertd" xmlns:tns="http://localhost/fundmanagertd" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="requestAddFund" type="tns:requestAddFund"/>

  <xs:element name="responseAddFund" type="tns:responseAddFund"/>

  <xs:complexType name="fund">
    <xs:sequence>
      <xs:element name="annuity" type="tns:annuityType" minOccurs="0"/>
      <xs:element name="duration" type="xs:int"/>
      <xs:element name="endDate" type="xs:dateTime" minOccurs="0"/>
      <xs:element name="id" type="xs:long"/>
      <xs:element name="name" type="xs:string" minOccurs="0"/>
      <xs:element name="premium" type="xs:float"/>
      <xs:element name="startDate" type="xs:dateTime" minOccurs="0"/>
      <xs:element name="type" type="tns:investmentType" minOccurs="0"/>
      <xs:element name="value" type="xs:float"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="requestAddFund">
    <xs:sequence>
      <xs:element name="arg0" type="tns:fund" minOccurs="0"/>
      <xs:element name="arg1" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="responseAddFund">
    <xs:sequence>
      <xs:element name="return" type="xs:long"/>
    </xs:sequence>
  </xs:complexType>

  <xs:simpleType name="annuityType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="MONTHLY"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="investmentType">
    <xs:restriction base="xs:string">
      <xs:enumeration value="MF"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

SoapUI 正在自动生成请求,它是:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:fun="http://localhost/fundmanagertd">
   <soapenv:Header/>
   <soapenv:Body>
      <fun:requestAddFund>
         <!--Optional:-->
         <arg0>
            <!--Optional:-->
            <annuity>?</annuity>
            <duration>?</duration>
            <!--Optional:-->
            <endDate>?</endDate>
            <id>?</id>
            <!--Optional:-->
            <name>?</name>
            <premium>?</premium>
            <!--Optional:-->
            <startDate>?</startDate>
            <!--Optional:-->
            <type>?</type>
            <value>?</value>
         </arg0>
         <!--Optional:-->
         <arg1>?</arg1>
      </fun:requestAddFund>
   </soapenv:Body>
</soapenv:Envelope>

另外,我尝试创建一个静态客户端来访问我的 Web 服务,但我得到 SOAPFaultException 并显示“意外的 XML 标记消息...”

另外,添加 sun-jaxws.xml 以供参考:

<?xml version="1.0" encoding="UTF-8"?>
<endpoints
  xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
  version="2.0">
  <endpoint
      name="fundmanagertdservice"
      implementation="com.investment.webservice.impl.FundManagerService"
      url-pattern="/fundmanagertdsvr"
      wsdl="WEB-INF/wsdl/FundManagerTDService.wsdl"/>
</endpoints>

谢谢,

【问题讨论】:

  • 这已经是一个非常彻底的问题了,但是您能否也添加 SOAP UI 请求?此外,请求是在 SOAP UI 中自动构建的,还是您自己编写了 XML?谢谢!
  • 您好 derdc,感谢您的关注。我在上面添加了更多细节。
  • 当你在 glassfish 中测试它时,SoapUi 创建了完全相同的 xml?

标签: java eclipse jax-ws glassfish-3 tomcat7


【解决方案1】:

我认为 SOAP 请求正文中的第一个元素需要是您正在调用的操作。 这意味着需要更改自动生成的 XML。这正是错误所说的:

...预期:

...addFund - 方法名称 - 但已找到:

...requestAddFund - 数据类型名称

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-13
    • 2018-10-22
    • 1970-01-01
    • 2016-08-03
    • 2020-06-12
    • 1970-01-01
    • 2013-05-21
    相关资源
    最近更新 更多