1

I have generated some java class files using Axis1 (axis-1.4.jar). I have a WS method call (I can see its generated java code too).

Say this method call accepts a RequestA as parameter and returns an object of type ResponseA. The problem I have now is that ResponseA extends AxisFault (I can see that in the generated java source file for ResponseA). AxisFault on its own turn extends RemoteException.

As a result of this, the ResponseA object returned is not returned to me but is thrown to/at me as it is a RemoteException.

So when I do something like this

try { 
   ResponseA x = call(y); // y is RequestA
} catch (Exception ex) {
    ex.printStackTrace();
}

in my client code, the flow of control goes to the catch block and I am actually catching what I should normally be getting in the x variable (i.e. ex is what x would normally be).

Any idea what makes Axis generate my ResponseA class as a subclass of AxisFault? Also, in general, when is a class generated by Axis, generated as subclass of AxisFault?

I think this is my current problem. I think I am in the weird situation that the response from a succesful WS method call is not returned to me but is instead thrown to/at me.

Many thanks in advance.



    package com.test.fulfillment3;

    // This is the ResponseA
    public class Actionresponse  extends org.apache.axis.AxisFault  implements java.io.Serializable {

    ...

    }


    // --------------------------------------------------------------------------------------------------------------------------------------------


    package com.test.fulfillment3;

    // This is the RequestA
    public class Actionrequest  implements java.io.Serializable {

    ...

    }


    // --------------------------------------------------------------------------------------------------------------------------------------------


    package com.test.fulfillment3;

    public class Status_ServiceBindingStub { 

    ..............


        public com.test.fulfillment3.Actionresponse status_ServiceOp(com.test.fulfillment3.Actionrequest in) throws java.rmi.RemoteException, com.test.fulfillment3.Status_ServiceFault4, com.test.fulfillment3.Status_ServiceFault2, com.test.fulfillment3.Status_ServiceFault3, com.test.fulfillment3.Actionresponse {
            if (super.cachedEndpoint == null) {
                throw new org.apache.axis.NoEndPointException();
            }
            org.apache.axis.client.Call _call = createCall();
            _call.setOperation(_operations[0]);
            _call.setUseSOAPAction(true);
            _call.setSOAPActionURI("http://soa.jboss.org/TEST/Status_ServiceOp");
            _call.setEncodingStyle(null);
            _call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
            _call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
            _call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
            _call.setOperationName(new javax.xml.namespace.QName("", "Status_ServiceOp"));

            setRequestHeaders(_call);
            setAttachments(_call);
     try {        java.lang.Object _resp = _call.invoke(new java.lang.Object[] {in});

            if (_resp instanceof java.rmi.RemoteException) {
                throw (java.rmi.RemoteException)_resp;
            }
            else {
                extractAttachments(_call);
                try {
                    return (com.test.fulfillment3.Actionresponse) _resp;
                } catch (java.lang.Exception _exception) {
                    return (com.test.fulfillment3.Actionresponse) org.apache.axis.utils.JavaUtils.convert(_resp, com.test.fulfillment3.Actionresponse.class);
                }
            }
      } catch (org.apache.axis.AxisFault axisFaultException) {
        if (axisFaultException.detail != null) {
            if (axisFaultException.detail instanceof java.rmi.RemoteException) {
                  throw (java.rmi.RemoteException) axisFaultException.detail;
             }
            if (axisFaultException.detail instanceof com.test.fulfillment3.Status_ServiceFault4) {
                  throw (com.test.fulfillment3.Status_ServiceFault4) axisFaultException.detail;
             }
            if (axisFaultException.detail instanceof com.test.fulfillment3.Status_ServiceFault2) {
                  throw (com.test.fulfillment3.Status_ServiceFault2) axisFaultException.detail;
             }
            if (axisFaultException.detail instanceof com.test.fulfillment3.Status_ServiceFault3) {
                  throw (com.test.fulfillment3.Status_ServiceFault3) axisFaultException.detail;
             }
            if (axisFaultException.detail instanceof com.test.fulfillment3.Actionresponse) {
                  throw (com.test.fulfillment3.Actionresponse) axisFaultException.detail;
             }
       }
      throw axisFaultException;
    }
        }

    }


    // --------------------------------------------------------------------------------------------------------------------------------------------


peter.petrov
  • 38,363
  • 16
  • 94
  • 159
  • can you post the code of your webservices? – Enrique San Martín Apr 19 '13 at 20:36
  • I posted some code. This part here is causing the issue that I have: if (_resp instanceof java.rmi.RemoteException) { throw (java.rmi.RemoteException)_resp; } because my response type is indeed a java.rmi.RemoteException. Hope this sample code illustrates my problem better. – peter.petrov Apr 20 '13 at 09:20

1 Answers1

1

I found the problem a few months ago. It was that the WSDL file itself defined the response type (of that method) as a fault. So the class ResponseA/Actionresponse is generated as a subclass of AxisFault by Axis.

In that case, at runtime, the client-side Axis-generated code (parts of which I pasted above) "thinks" that the server-side method does not return successfully on the server side (even though it does), and throws the return value instead of returning it.

Very weird situation but I now tend to treat this as a problem in the WSDL itself. I don't think it is normal for a return value/type to be defined as a fault at the same time (in the WSDL file). Just wanted to share this answer in case anyone else runs into the same issue.

peter.petrov
  • 38,363
  • 16
  • 94
  • 159