使用自定义故障或用户定义异常问题

问题描述
如果 WSDL 包含引用 complexType 的 wsdl:fault,如以下代码所示:
<types xmlns:tns="http://www.bea.com/servers/wls70/samples/examples/webservices/basic/
javaclass" xmlns:wsr="http://www.openuri.org/2002/10/soap/reliability/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soap12enc="http://www.w3.org/2003/05/soap-encoding" xmlns:conv="http://www.openuri.org/2002/04/wsdl/conversation/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/">
.....
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:stns="java:examples.webservices.basic.javaclass" elementFormDefault="qualified" attributeFormDefault="qualified" targetNamespace="java:examples.webservices.basic.javaclass">
            <xsd:element type="stns:MyException" name="MyException">
   </xsd:element>
            <xsd:complexType name="MyException">
                <xsd:sequence>
                    <xsd:element type="xsd:int" name="errorId" minOccurs="1" maxOccurs="1">
     </xsd:element>
                    <xsd:element type="xsd:string" name="errorMessage" minOccurs="1" nillable="true" maxOccurs="1">
     </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
.....
    <message name="MyException">
        <part xmlns:partns="java:examples.webservices.basic.javaclass" type="partns:MyException" name="MyException">
  </part>
    </message>
.....
    <portType name="HelloWorldPort">
        <operation name="sendSOAPFault">
            <input message="tns:sendSOAPFault">
   </input>
            <output message="tns:sendSOAPFaultResponse">
   </output>
            <fault name="MyException" message="tns:MyException">
   </fault>
        </operation>
    </portType>

则在使用 WLS 7.0.x 和 WLS 8.1 从该 WSDL 生成 Web Service 时将出现下列行为:

  • 生成的服务中的方法未抛出相关异常
  • 服务器端抛出上述异常后,传输的 soap 消息中具有的是基元类型,而不是 MyException 类型
  • 通过 clientgen 生成客户端存根/代理时未生成该异常的正确实现

相反地,从抛出用户定义异常的 Java 应用程序生成 Web Service 时,也会遇到类似问题。


故障排除
请注意,并非下面所有任务都需要完成。有些问题仅通过执行几项任务就可以解决。

快速链接

为什么发生此问题?
WLS 7.0.x 和 WLS 8.1 不支持对服务特有异常进行处理。在 WLS 8.1 SP1 中,通过实现 JAX-RPC 规范的第 5.5.5 节和第 4.3.6 节增加了此项支持。有关详细信息,请参考异常处理

返回页首

异常处理
wsdl:fault(或 <fault>,如上所示)元素是 wsdl:operation(或 <operation>,如上所示)中的一个可选元素,用于指定可作为远程操作的结果输出的任何错误信息的抽象消息格式。按照 WSDL 规范,故障消息只能有一个部分。wsdl:fault 只能映射到 wsdl:operationjava.rmi.RemoteException(或其子类)、服务特有 Java 异常或 javax.xml.rpc.soap.SOAPFaultException

服务特有 Java 异常(映射自 wsdl:fault 及相应的 wsdl:message)会直接或间接地扩展 java.lang.Exception 类。

wsdl:message 中的单一消息部分(引用自 wsdl:fault 元素)可能是 xsd:complexType 或简单 XML 类型。

以下各节论述处理 SOAPFaultException处理服务特有异常

返回页首



处理 SOAPFaultException
SOAPFaultException 异常表示 SOAP 有故障。该异常是从映射自相应的 wsdl:operation 的 Java 方法抛出的。
  • SOAP 故障中的消息部分会映射到详细信息元素的内容,该内容可以通过 SOAPFaultException 上的 getDetail 方法来访问。
  • javax.xml.soap.SOAPFactory 上的 createDetail 方法可以创建 javax.xml.soap.Detail 的一个实例。
  • Faultstring 可以提供易读的 SOAP 故障说明。
  • Faultcode 元素可以提供对 SOAP 故障的算法映射。
下例为 SOAPFaultException 类的结构:

返回页首


package javax.xml.rpc.soap;
    public class SOAPFaultException extends java.lang.RuntimeException {
    public SOAPFaultException(QName faultcode,
        String faultstring,
        String faultactor,
        javax.xml.soap.Detail detail) { ... }
    public QName getFaultCode() { ... }
    public String getFaultString() { ... }
    public String getFaultActor() { ... }
    public javax.xml.soap.Detail getDetail() { ... }
    }

下例说明如何处理 SOAPFaultException

服务实现
下例是 Web Service 服务器端实现的代码,其中的 sendSOAPFault() 方法抛出了 SOAPFaultException

import javax.xml.soap.SOAPFactory;
import javax.xml.soap.Detail;
import javax.xml.soap.SOAPException;

import javax.xml.namespace.QName;
import javax.xml.rpc.soap.SOAPFaultException;

public final class HelloWorld {

public void sendSOAPFault(){
    Detail detail = null;
    try{
      detail = SOAPFactory.newInstance().createDetail();
      detail.addChildElement( "MyDetails" ).addTextNode( "failed" );
    }catch( SOAPException e ){
      e.printStackTrace();
    }
    throw new SOAPFaultException(
        new QName( "http://www.bea.com/samples/ws/fault", "ServerFailed" ),
        "sendSOAPFault method failed",
        "http://foo/bar/baz/",
        detail );
  }
}



返回页首

客户端实现

下例是调用 sendSOAPFault() 操作的 Web Service 客户端实现的代码:

import javax.xml.rpc.soap.SOAPFaultException;
import java.rmi.RemoteException;

public final class Client {

  public Client() {}

  public static void main(String[] argv)
    throws Exception
  {
    // Setup the global JAXM message factory
    System.setProperty("javax.xml.soap.MessageFactory",
      "weblogic.webservice.core.soap.MessageFactoryImpl");
    // Setup the global JAX-RPC service factory
    System.setProperty( "javax.xml.rpc.ServiceFactory",
      "weblogic.webservice.core.rpc.ServiceFactoryImpl");

    HelloWorld_Impl ws = new HelloWorld_Impl(argv[0]);
    HelloWorldPort port  = ws.getHelloWorldPort();

    try {
    port.sendSOAPFault();
    } // try
    catch(SOAPFaultException ex) {
    System.out.println(ex.toString());
    ex.printStackTrace();
    }
    catch(RemoteException ex) {
    if (ex.getCause() instanceof SOAPFaultException) {
        SOAPFaultException fault = (SOAPFaultException)ex.getCause();
        System.out.println("[Client] Fault Detail : " + fault.getDetail().toString());
        System.out.println("[Client] Fault Actor : " + fault.getFaultActor());
        System.out.println("[Client] Fault String : " + fault.getFaultString());
    }
    System.out.println("[Client] Exception stack trace :");
    ex.printStackTrace();
    }

  }
}



返回页首

备注:
在 BEA WLS Web Service 客户端存根中,由于故障(因服务器抛出 SOAPFaultException 而致)映射到 java.rmi.RemoteException,基于存根的客户端 Client.java 将需要捕捉 java.rmi.RemoteException

不过,在使用动态调用接口 (Dynamic Invocation Interface, DII) 客户端时,由于该客户端使用 javax.xml.rpc.Call 接口,因此将需要捕捉 SOAPFaultException


调用 sendSOAPFault() 的 SOAP 请求/响应消息


      [java] <!-------------------- REQUEST ---------------->
     [java] URL        :  http://localhost:6151/basic_javaclass/HelloWorld
     [java] Headers    :
     [java]   SOAPAction: [""]
     [java]   Content-Type: [text/xml]

     [java] <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"xmlns:
xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://sche
mas.xmlsoap.
org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><en

v:Header/><env:Body env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><m:
sendSOAPFault xmlns:m="http://www.bea.com/servers/wls70/samples/examples/we
bservices/
basic/javaclass"/></env:Body></env:Envelope>

     [java] <!-------------------- END REQUEST ------------>
     [java] <!-------------------- RESPONSE --------------->
     [java] URL           : http://localhost:6151/basic_javaclass/HelloWorld
     [java] Response Code :500
     [java] Headers       :
     [java]   Date=Fri, 18 Jun 2004 17:20:15 GMT
     [java]   Server=WebLogic Server 8.1 SP2 Fri Dec 5 15:01:51 PST 2003 316284with
 CR182483

     [java]   Content-Length=587
     [java]   Content-Type=text/xml; charset=utf-8
     [java] Envelope   :
     [java] <?xml version="1.0" encoding="utf-8" standalone="yes"?><env:Envelopexmlns
:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.
org/2001/XMLSchema-instance"xmlns:soapenc="http://schemas.
xmlsoap.org/soap/enco
ding/"xmlns:xsd="http://www.w3.org/2001/XMLSchema"><env:Header/>
<env:Body><env:

Fault xmlns:fault="http://www.bea.com/samples/ws/fault"><faultcode>fault:ServerFailed
</faultcode><faultstring>sendSOAPFault method failed</faultstring><faultact

or>http://foo/bar/baz/</faultactor><detail><MyDetails>failed</MyDetails></detail>
</env:Fault></env:Body></env:Envelope>

     [java] <!-------------------- END RESPONSE ----------->
     [java] [Client] Fault Detail : <detail>
     [java]  <MyDetails>failed</MyDetails>
     [java] java.rmi.RemoteException: SOAP Fault:javax.xml.rpc.soap.SOAPFaultException: sendSOAPFault method failed
     [java] Detail:
     [java] <detail>
     [java] </detail>
     [java] [Client] Fault Actor : http://foo/bar/baz/
     [java] [Client] Fault String : sendSOAPFault method failed
     [java]  <MyDetails>failed</MyDetails>
     [java] </detail>; nested exception is:
     [java]     javax.xml.rpc.soap.SOAPFaultException: sendSOAPFault method failed
     [java] [Client] Exception stack trace :
     [java]     at examples.webservices.basic.javaclass.HelloWorldPort_Stub.sendSOAPFault(HelloWorldP
ort_Stub.java:29)

     [java]     at examples.webservices.basic.javaclass.Client.main(Client.java:37)
     [java] Caused by: javax.xml.rpc.soap.SOAPFaultException: sendSOAPFault method
 failed

     [java]     at weblogic.webservice.core.ClientDispatcher.receive(Client
Dispa
tcher.java:313)
     [java]     at weblogic.webservice.core.ClientDispatcher.dispatch(Client
Disp
atcher.java:144)
     [java]     at weblogic.webservice.core.DefaultOperation.invoke(Default
Opera
tion.java:457)
     [java]     at weblogic.webservice.core.DefaultOperation.invoke(Default
Opera
tion.java:443)
     [java]     at weblogic.webservice.core.rpc.StubImpl._invoke(StubImpl.java:290)
     [java]     at examples.webservices.basic.javaclass.HelloWorldPort_Stub.sendSOAPFault
(HelloWorldPort_Stub.java:25)

     [java]     ... 1 more



返回页首

处理服务特有异常

服务特有 Java 异常(映射自 wsdl:fault 及相应的 wsdl:message)会直接或间接地扩展 java.lang.Exception 类。

wsdl:messag 中的单一消息部分(引用自 wsdl:fault 元素)可能是 xsd:complexType 或简单 XML 类型。

下例所示为 wsdl:fault 到服务特有 Java 异常的映射。wsdl:message 的单一部分是 MyException 类型,而该类型是 complexType

.....
        <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:stns="java:examples.webservices.basic.javaclass" elementFormDefault="qualified" attributeFormDefault="qualified" targetNamespace="java:examples.webservices.basic.javaclass">
            <xsd:element type="stns:MyException" name="MyException">
   </xsd:element>
            <xsd:complexType name="MyException">
                <xsd:sequence>
                    <xsd:element type="xsd:int" name="errorId" minOccurs="1" maxOccurs="1">
     </xsd:element>
                    <xsd:element type="xsd:string" name="errorMessage" minOccurs="1" nillable="true" maxOccurs="1">
     </xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
.....
    <message name="MyException">
        <part xmlns:partns="java:examples.webservices.basic.javaclass" type="partns:MyException" name="MyException">
  </part>
    </message>
.....
    <portType name="HelloWorldPort">
        <operation name="sendSOAPFault">
            <input message="tns:sendSOAPFault">
   </input>
            <output message="tns:sendSOAPFaultResponse">
   </output>
            <fault name="MyException" message="tns:MyException">
   </fault>
        </operation>
    </portType>


备注:WLS 7.0.x 和 WLS 8.1 不支持对服务特有异常进行处理。在 WLS 8.1 SP1 中,通过实现 JAX-RPC 规范的第 5.5.5 节和第 4.3.6 节增加了此项支持。


下例说明了如何处理服务特有异常。

服务实现
下例是 Web Service 服务器端实现的代码,其中的 sendSOAPFault() 方法抛出了 MyException,它是一个服务特有异常:

MyException 实现

public class MyException extends Exception {
    private String errorMessage;
    private int errorId;

    //public MyException();
    public MyException(String errorMessage, int errorId) {
        this.errorMessage = errorMessage;
        this.errorId = errorId;
    }

    public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
    public String getErrorMessage() { return errorMessage; }

    public void setErrorId(int errorId) { this.errorId = errorId; }
    public int getErrorId() { return errorId; }
}


Web Service 后端组件

mport javax.xml.soap.SOAPFactory;
import javax.xml.soap.Detail;
import javax.xml.soap.SOAPException;

import javax.xml.namespace.QName;
import javax.xml.rpc.soap.SOAPFaultException;

public final class HelloWorld {
public void sendSOAPFault()throws MyException {
    throw new MyException("sendSOAPFault() call fails !", 10);
}
}

客户端实现
下例是调用 sendSOAPFault() 操作的 Web Service 客户端实现的代码。

基于存根的客户端

import javax.xml.rpc.soap.SOAPFaultException;
import java.rmi.RemoteException;

public final class Client {

  public Client() {}

  public static void main(String[] argv)
    throws Exception
  {
    // Setup the global JAXM message factory
    System.setProperty("javax.xml.soap.MessageFactory",
      "weblogic.webservice.core.soap.MessageFactoryImpl");
    // Setup the global JAX-RPC service factory
    System.setProperty( "javax.xml.rpc.ServiceFactory",
      "weblogic.webservice.core.rpc.ServiceFactoryImpl");

    HelloWorld_Impl ws = new HelloWorld_Impl(argv[0]);
    HelloWorldPort port  = ws.getHelloWorldPort();

    try {
    port.sendSOAPFault();
    } // try

    catch(MyException ex) {
    System.out.println("[Client] Exception caught is : " + ex.toString());
    System.out.println("[Client] errorMessage : " + ex.getErrorMessage());
    System.out.println("[Client] errorId : " + ex.getErrorId());

    System.out.println("[Client] Exception stack trace :");
    ex.printStackTrace();
    }
  }
}

DII 或动态客户端

import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Service;
import javax.xml.rpc.Call;
import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;

import javax.xml.rpc.soap.SOAPFaultException;
import java.rmi.RemoteException;

public class DynamicClient {
  public static void main(String[] args) throws Exception {
    //set weblogic ServiceFactory
    System.setProperty( "javax.xml.rpc.ServiceFactory",
        "weblogic.webservice.core.rpc.ServiceFactoryImpl" );

    //create service factory
    ServiceFactory factory = ServiceFactory.newInstance();
    String targetNamespace = "http://www.bea.com/servers/wls70/samples/examples/webservices/basic/javaclass";

    QName serviceName = new QName( targetNamespace,  
        "HelloWorld" );

    QName portName = new QName( targetNamespace,
        "HelloWorldPort" );

    QName operationName = new QName( targetNamespace,
        "sendSOAPFault" );

    Service service = factory.createService( serviceName );
    Call call = service.createCall();
    call.setPortTypeName( portName );
    call.setOperationName( operationName );
    call.setTargetEndpointAddress("http://localhost:6151/basic_javaclass/HelloWorld?WSDL");

    try {
    call.invoke(new Object[]{});
    } // try

    catch(SOAPFaultException ex) {
        System.out.println("[Client] Fault Detail : " + ex.getDetail().toString());
        System.out.println("[Client] Fault Actor : " + ex.getFaultActor());
        System.out.println("[Client] Fault String : " + ex.getFaultString());
         ex.printStackTrace();
    }

    catch(RemoteException ex) {
    if (ex.getCause() instanceof SOAPFaultException) {
        SOAPFaultException fault = (SOAPFaultException)ex.getCause();
        System.out.println("[Client] Fault Detail : " + fault.getDetail().toString());
        System.out.println("[Client] Fault Actor : " + fault.getFaultActor());
        System.out.println("[Client] Fault String : " + fault.getFaultString());
    }
    System.out.println("[Client] Exception stack trace :");
    ex.printStackTrace();
    }

  }
}

备注:在 BEA WLS Web Service 客户端存根中,由于故障(因服务器抛出服务特有异常而致)映射到服务特有异常,因此基于存根的客户端 Client.java 将需要捕捉服务特有异常。

不过,在使用 DII 客户端时,由于该客户端使用 javax.xml.rpc.Call 接口,因此它将需要捕捉 RemoteExceptionSOAPFaultException。服务特有异常将包装在 SOAPFaultException 中。

调用 sendSOAPFault() 的 SOAP 请求/响应消息
使用基于存根的客户端

     [java] <!-------------------- REQUEST ---------------->
     [java] URL        :  http://localhost:6151/basic_javaclass/HelloWorld
     [java] Headers    :
     [java]   SOAPAction: [""]
     [java]   Content-Type: [text/xml]

     [java] <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"xmlns
:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.
xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><env:
Header/><env:Body env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<m:sendSOAPFaultxmlns:m="http://www.bea.com/servers/wls70/samples/examples/we
bservices/basic/javaclass"/></env:Body></env:Envelope>
     [java] <!-------------------- END REQUEST ------------>
     [java] <!-------------------- RESPONSE --------------->
     [java] URL           : http://localhost:6151/basic_javaclass/HelloWorld
     [java] Response Code :500
     [java] Headers       :
     [java]   Date=Wed, 23 Jun 2004 21:39:06 GMT
     [java]   Server=WebLogic Server 8.1 SP2 Fri Dec 5 15:01:51 PST 2003 316284
with CR182483
     [java]   Content-Length=730
     [java]   Content-Type=text/xml; charset=utf-8
     [java] Envelope   :
     [java] <?xml version="1.0" encoding="utf-8" standalone="yes"?><env:Envelopexmlns
:env="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"xmlns:
xsd="http://www.w3.org/2001/XMLSchema"><env:Header/><env:Body><env:Fault><faultcode>
env:Server</faultcode><faultstring>Servicespecificexception:examples.webservices.
basic.javaclass.MyException</faultstring><detail><MyExceptionxmlns:n1="java:
examples.webservices.basic.javaclass"xsi:type="n1:MyException"><errorIdxsi:
type="xsd:int">10</errorId><errorMessage xsi:type="xsd:string">sendSOAPFault()
 call fails !</errorMessage></MyException></detail></env:Fault></env:Body>
</env:Envelope>
     [java] <!-------------------- END RESPONSE ----------->
     [java] [Client] Exception caught is : MyException{ errorId=<10> errorMessage
=<sendSOAPFault() call fails !> }
     [java] [Client] errorMessage : sendSOAPFault() call fails !
     [java] [Client] errorId : 10
     [java] [Client] Exception stack trace :
     [java] MyException{ errorId=<10> errorMessage=<sendSOAPFault() call fails !> }
     [java]     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
 Method)
     [java]     at sun.reflect.NativeConstructorAccessorImpl.newInstance
(NativeConstructorAccessorImpl.java:39)
     [java]     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance
(DelegatingConstructorAccessorImpl.java:27)
     [java]     at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
     [java]     at weblogic.xml.schema.binding.BeanExceptionCodecBase.invokeConstructor
(BeanExceptionCodecBase.java:134)
     [java]     at weblogic.xml.schema.binding.BeanExceptionCodecBase.deserialize
(BeanExceptionCodecBase.java:72)
     [java]     at weblogic.xml.schema.binding.RuntimeUtils.invoke_deserializer
(RuntimeUtils.java:428)
     [java]     at weblogic.xml.schema.binding.RuntimeUtils.invoke_deserializer
(RuntimeUtils.java:328)
     [java]     at weblogic.webservice.core.DefaultPart.toJava
(DefaultPart.java:384)
     [java]     at weblogic.webservice.core.FaultMessage.toJava
(FaultMessage.java:227)
     [java]     at weblogic.webservice.core.ClientDispatcher.deserializeFault
(ClientDispatcher.java:391)
     [java]     at weblogic.webservice.core.ClientDispatcher.receive
(ClientDispatcher.java:317)
     [java]     at weblogic.webservice.core.ClientDispatcher.dispatch
(ClientDispatcher.java:144)
     [java]     at weblogic.webservice.core.DefaultOperation.invoke
(DefaultOperation.java:457)
     [java]     at weblogic.webservice.core.DefaultOperation.invoke
(DefaultOperation.java:443)
     [java]     at weblogic.webservice.core.rpc.StubImpl._invoke(StubImpl.java:290)
     [java]     at examples.webservices.basic.javaclass.HelloWorldPort_Stub.sendSOAPFault
(HelloWorldPort_Stub.java:25)
     [java]     at examples.webservices.basic.javaclass.Client.main(Client.java:35)
     [java] Caused by: javax.xml.rpc.soap.SOAPFaultException: Service specific exception: examples.webservices.basic.javaclass.MyException
     [java]     at weblogic.webservice.core.ClientDispatcher.receive(ClientDispatcher.java:313)
     [java]     ... 6 more


使用 DII 客户端

          [java] <!-------------------- REQUEST ---------------->
     [java] URL        :  http://localhost:6151/basic_javaclass/HelloWorld?WSDL
     [java] Headers    :
     [java]   SOAPAction: [""]
     [java]   Content-Type: [text/xml]

     [java] <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"xmlns
:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.
xmlsoaporg/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><env:Header/>
<env:Body env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<m:sendSOAPFaultxmlns:m="http://www.bea.com/servers/wls70/samples/examples/webservices
/basic/javaclass"/></env:Body></env:Envelope>
     [java] <!-------------------- END REQUEST ------------>
     [java] <!-------------------- RESPONSE --------------->
     [java] URL           : http://localhost:6151/basic_javaclass/HelloWorld?WSDL
     [java] Response Code :500
     [java] Headers       :
     [java]   Date=Wed, 23 Jun 2004 21:23:15 GMT
     [java]   Server=WebLogic Server 8.1 SP2 Fri Dec 5 15:01:51 PST 2003 316284
with CR182483
     [java]   Content-Length=730
     [java]   Content-Type=text/xml; charset=utf-8
     [java] Envelope   :
     [java] <?xml version="1.0" encoding="utf-8" standalone="yes"?><env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="http://www.w3.org/
2001/XMLSchema-instance"xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/
"xmlns:xsd="http://www.w3.org/2001/XMLSchema"><env:Header/><env:Body><env:
Fault><faultcode>env:Server</faultcode><faultstring>Service specific exception:examples.webservices.basic.javaclass.MyException</faultstring><detail>
<MyExceptionxmlns:n1="java:examples.webservices.basic.javaclass"xsi:type="n1:
MyException"><errorId xsi:type="xsd:int">10</errorId><errorMessage xsi:type="xsd:string">se
ndSOAPFault() call fails !</errorMessage></MyException></detail></env:Fault></env:Body></env:Envelope>
     [java] <!-------------------- END RESPONSE ----------->
     [java] [Client] Fault Detail : <detail>
     [java]  <MyException   xmlns:n1="java:examples.webservices.basic.javaclass"

     [java]    xsi:type="n1:MyException">
     [java]   <errorId    xsi:type="xsd:int">10</errorId>
     [java] javax.xml.rpc.soap.SOAPFaultException: Service specific exception: examples.webservices.basic.javaclass.MyException
     [java]     at weblogic.webservice.core.ClientDispatcher.receive(ClientDispatcher.java:313)
     [java]   <errorMessage    xsi:type="xsd:string">sendSOAPFault() call fails!</errorMessage>
     [java]     at weblogic.webservice.core.ClientDispatcher.dispatch(ClientDispatcher.java:144)
     [java]     at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.java:457)
     [java]  </MyException>
     [java] </detail>
     [java] [Client] Fault Actor : null
     [java] [Client] Fault String : Service specific exception: examples.webservices.basic.javaclass.MyException
     [java]     at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.java:443)
     [java]     at weblogic.webservice.core.rpc.CallImpl.invoke(CallImpl.java:558)
     [java]     at weblogic.webservice.core.rpc.CallImpl.invoke(CallImpl.java:411)
     [java]     at examples.webservices.basic.javaclass.DynamicClient.main(DynamicClient.java:3



返回页首

故障排除技巧
使用 eeblogic.webservice.verbose=true

要获得线路中 SOAP 消息的跟踪,请在执行 Java 客户端时使用 weblogic.webservice.verbose=true 命令行参数。此跟踪有助于了解以请求/响应形式发送/接收的信息。例如,通过运行以下 Ant 任务:


  <target name="run">
    <java classname="examples.webservices.basic.javaclass.Client"
          fork="true">
      <arg value="http://localhost:${PORT}/basic_javaclass/HelloWorld?WSDL"
/>
      <jvmarg value="-Dweblogic.webservice.verbose=true" />

      <classpath>
        <pathelement location="${CLIENT_CLASSES}/${client_jar_file}"/>
        <pathelement path="${java.class.path}"/>
        <pathelement path="${CLIENT_CLASSES}"/>
      </classpath>
    </java>
  </target>


可以获得以下类型的 SOAP 请求/响应消息的跟踪:

       [java] <!-------------------- REQUEST ---------------->
     [java] URL        :  http://localhost:6151/basic_javaclass/HelloWorld?WSDL
     [java] Headers    :
     [java]   SOAPAction: [""]
     [java]   Content-Type: [text/xml]

     [java] <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"xmlns:
xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soapenc="http://schemas.xmlsoap
.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><env:Header/><env:Body env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><m:sendSOAPFault xmlns:
m="http://www.bea.com/servers/wls70/samples/examples/we
bservices/basic/javaclass"/></env:Body></env:Envelope>
     [java] <!-------------------- END REQUEST ------------>
     [java] <!-------------------- RESPONSE --------------->
     [java] URL           : http://localhost:6151/basic_javaclass/HelloWorld?WSDL
     [java] Response Code :500
     [java] Headers       :
     [java]   Date=Wed, 23 Jun 2004 21:23:15 GMT
     [java]   Server=WebLogic Server 8.1 SP2 Fri Dec 5 15:01:51 PST 2003 316284 with
 CR182483
     [java]   Content-Length=730
     [java]   Content-Type=text/xml; charset=utf-8
     [java] Envelope   :
     [java] <?xml version="1.0" encoding="utf-8" standalone="yes"?><env:Envelopexmlns
:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/
XMLSchema-instance"xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"xmlns:
xsd="http://www.w3.org/2001/XMLSchema"><env:Header/><env:Body><env:Fault><faultcode>
env:Server</faultcode><faultstring>Servicespecificexception:examples.webservices.
basic.javaclass.MyException</faultstring><detail><MyExceptionxmlns:n1="java:examples
.webservices.basic.javaclass" xsi:type="n1:MyException"><errorId xsi:type="xsd:int">10</errorId><errorMessage xsi:type="xsd:string">sendSOAPFault() call fails !</errorMessage></MyException></detail></env:Fault></env:Body></env:Envelope>
     [java] <!-------------------- END RESPONSE -------------------->


使用 weblogic.webservice.tools.debug.Post 实用程序
使用 weblogic.webservice.tools.debug.Post 实用程序可以将 SOAP 请求直接发送到 SOAP 服务器。

有关详细信息,请参考 http://e-docs.bea.com/wls/docs81/webserv/trouble.html#1066132 (English)。您可以使用此实用程序直接在文本编辑器中编辑 SOAP 消息,然后重新发送,以观察服务器响应中的行为变化。

返回页首



参考文献
JAX-RPC
WSDL
XML Schema Part 0 :Primer
XML Schema Part 1 :Structures
XML Schema Part 2 :Datatypes



 返回页首

需要更多帮助?
如果您已经理解这个模式,但仍需要更多帮助,您可以:

  1. http://support.bea.com/ 上查询 AskBEA(例如,使用“user-defined exceptions”),以查找其它已发布的解决办法。
  2. http://forums.bea.com 上,向 BEA 的某个新闻组提出更详细具体的问题。
如果这还不能解决您的问题,并且您拥有有效的技术支持合同,您可以通过登录以下网站来打开支持案例:http://support.bea.com/

反馈

请给我们提供您的意见,说明此支持诊断模式使用自定义故障或用户定义异常问题一文是否有所帮助、您需要的任何解释,以及对支持诊断模式的新主题的任何要求。


免责声明:

依据 BEA 与您签署的维护和支持协议条款,BEA Systems, Inc. 在本网站上提供技术技巧和补丁供您使用。虽然您可以将这些信息和代码与您获得 BEA 授权的软件一起使用,但 BEA 并不对所提供的技术技巧和补丁做任何形式的担保,无论是明确的还是隐含的。

本文档中引用的任何商标是其各自所有者的财产。有关完整的商标信息,请参考您的产品手册。