Javier,
  Did you ever figure this out? There is a faulthandling example in the
axis2-1.1 release that generates code that looks like yours and does work. I have also been using the same wsdl/code pattern with success.

My cases all fail as soon as I engage the rampart1.1 module on the client side, giving the error

java.lang.ClassCastException: org.apache.axiom.om.impl.llom.OMElementImpl
at org.apache.axiom.soap.impl.llom.SOAPFaultImpl.getCode(SOAPFaultImpl.java:101) at org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation.java:312)
        at example.BankServiceStub.withdraw(BankServiceStub.java:173)
        at example.BankClient.main(BankClient.java:59)

Are you using rampart or getting errors without it?

Mary

---------------------------------------------------------------------
Mary R. Thompson                                <[EMAIL PROTECTED]>
Secure Grid Technologies Group                  (510) 486-7408
Lawrence Berkeley National Lab                  http://dsd.lbl.gov/~mrt
----------------------------------------------------------------------



Javier Kohen wrote:
Hi,

There is this webservice that I've written the WSDL for. I want to
handle the fault it returns as an exception on the client side. The code
generated by WSDL2Java from Axis1.1 that is supposed to convert the
AxisFault into an AuthenticationFailedMessageException (see below) seems
fishy to me, as it will never succeed. Namely it tries to map the QName
of the detail element with help of the faultExeptionNameMap (sic) when
this map only contains a reference to the faultcode class. This of
course fails, and thus the exception is never generated; the AxisFault
is re-thrown instead.

I don't understand why the detail is being used instead of the
faultcode. I believe the WSDL is correct, but please let me know if
there is something I'm doing wrong here.

When debugging the AxisFault catch block below I see that faultElt is
assigned an ElementA element, which isn't in the exception maps.
Moreover, the setFaultMessage method of
AuthenticationFailedMessageException is defined to take a
mypackage.AuthenticationFailed instance and not mypackage.ElementA, so
the code obviously expects faultElt to contain an AFME. Furthermore,
there is an explicit check for instance-of that exception at the end of
the block that is but dead code currently.

Even a hint on how to workaround the generated code manually for now
would be very appreciated. I couldn't find out how to extract the
AuthenticationFailed element from the AxisFault, which I need to pass to
fromOM, so my progress is temporarily blocked by this issue.


The generated code:
private void populateFaults(){ faultExeptionNameMap.put( new javax.xml.namespace.QName(
                 "",
                 "AuthenticationFailed"),
                 "mypackage.AuthenticationFailedMessageException"
               );
              faultExeptionClassNameMap.put(new
javax.xml.mypackage.QName(
                "",
                "AuthenticationFailed"),
                "mypackage.AuthenticationFailedMessageException");
               faultMessageMap.put( new javax.xml.mypackage.QName(
                 "",
                 "AuthenticationFailed"),
                 "mypackage.MyServiceStub$AuthenticationFailed"
               );
faultExeptionNameMap.put( new javax.xml.mypackage.QName(
                 "",
                 "AuthenticationFailed"),
                 "mypackage.AuthenticationFailedMessageException"
               );
              faultExeptionClassNameMap.put(new
javax.xml.mypackage.QName(
                "",
                "AuthenticationFailed"),
                "mypackage.AuthenticationFailedMessageException");
               faultMessageMap.put( new javax.xml.mypackage.QName(
                 "",
                 "AuthenticationFailed"),
                 "mypackage.MyServiceStub$AuthenticationFailed"
               );
faultExeptionNameMap.put( new javax.xml.mypackage.QName(
                 "",
                 "AuthenticationFailed"),
                 "mypackage.AuthenticationFailedMessageException"
               );
              faultExeptionClassNameMap.put(new
javax.xml.mypackage.QName(
                "",
                "AuthenticationFailed"),
                "mypackage.AuthenticationFailedMessageException");
               faultMessageMap.put( new javax.xml.mypackage.QName(
                 "",
                 "AuthenticationFailed"),
                 "mypackage.MyServiceStub$AuthenticationFailed"
               );
    }

                    public mypackage.MyServiceStub.MyOperationResponse
MyOperation(...
// ...
         }catch(org.apache.axis2.AxisFault f){
            org.apache.axiom.om.OMElement faultElt = f.getDetail();
            if (faultElt!=null){
                if
(faultExeptionNameMap.containsKey(faultElt.getQName())){
                    //make the fault by reflection
                    try{
                        java.lang.String exceptionClassName =
(java.lang.String)faultExeptionClassNameMap.get(faultElt.getQName());
                        java.lang.Class exceptionClass =
java.lang.Class.forName(exceptionClassName);
                        java.lang.Exception ex=
                                (java.lang.Exception)
exceptionClass.newInstance();
                        //message class
                        java.lang.String messageClassName =
(java.lang.String)faultMessageMap.get(faultElt.getQName());
                        java.lang.Class messageClass =
java.lang.Class.forName(messageClassName);
                        java.lang.Object messageObject =
fromOM(faultElt,messageClass,null);
                        java.lang.reflect.Method m =
exceptionClass.getMethod("setFaultMessage",
                                   new java.lang.Class[]{messageClass});
                        m.invoke(ex,new
java.lang.Object[]{messageObject});
if (ex instanceof
mypackage.AuthenticationFailedMessageException){
                          throw
(mypackage.AuthenticationFailedMessageException)ex;
                        }
                        throw new
java.rmi.RemoteException(ex.getMessage(), ex);


The fault message:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xmlns:xsd="http://www.w3.org/2001/XMLSchema";>
  <soap:Body>
    <soap:Fault>
      <faultcode>AuthenticationFailed</faultcode>
      <faultstring>Authentication Failed</faultstring>
      <detail>
        <ElementA xmlns="mynamespace">the content</ElementA>
      </detail>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>


Here follow the parts of the WSDL that deal with the fault:
First the XSD:
<definitions targetNamespace=""
                        xmlns:ns1="mynamespace"
        <xsd:element name="AuthenticationFailed">
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:element name="ns1:ElementA" 
type="xsd:string"/>
                        </xsd:sequence>
                </xsd:complexType>
        </xsd:element>

Then the WSDL itself:
<definitions targetNamespace="mynamespace"
                        xmlns:ns1="mynamespace"
        <message name="AuthenticationFailedMessage">
                <wsdl:part name="fault" element="AuthenticationFailed" xmlns="" 
/><!--
That's right, this element has no namespace. -->
        </message>

        <portType...
                <operation name="MyOperation">
                        <input message="ns1:OperationMessage" />
                        <output message="ns1:OperationResponseMessage" />
                        <fault message="ns1:AuthenticationFailedMessage"
name="AuthenticationFailed" />
                </operation>
        </portType>

        <binding...
                <operation name="MyOperation">
                        <soap:operation soapAction="..." style="document" />
                        <input>
                                <soap:body use="literal" />
                        </input>
                        <output>
                                <soap:body use="literal" />
                        </output>
                        <fault name="AuthenticationFailed">
                                <soap:fault use="literal" />
                        </fault>
                </operation>
        </binding>

Thanks,

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to