在Tomcat上部署时SOAPFaultException但在GlassFish中工作正常

时间:2012-03-13 18:30:01

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

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

将WebService应用程序部署到Eclipse Helios中的GlassFish(Glassfish适配器和Eclipse中安装的插件)。通过SoapUI测试部署的服务,它工作正常。

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

WAR -> META-INF -> MANIFEST.MF
-> WEB-INF -> classes -> ...
-> wsdl -> .wsdl and .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只采用部署包中的那些。为什么我这么认为,因为只有在没有提供sun-jaxws.xml的情况下,Web服务才能在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服务,并且我收到带有“意外的XML标记消息......”的SOAPFaultException。

另外,添加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>

谢谢,

1 个答案:

答案 0 :(得分:0)

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

  

...预期:

     

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

     

... requestAddFund - 数据类型名称

相关问题