You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Jay Zawar <jz...@c-w.be> on 2007/10/03 10:41:50 UTC

Axis2 generation tools for services

Hi,

I noticed that the working sample generates quite some code when strting from that Bank service wsdl. 
Especially, the exceptions seem to be "manually" serialized. In the sample, the service and clients are generated from the wsdl file.

I'd like to discuss the following points:

a) the WSDL defines the fault message WSDL:FAULT with attributes: 

name: "AccountNotExistException"
message: "tns:AccountNotExistFaultMessage"

The AccountNotExistFaultMessage contains an element of type "AccountNotExistFault".


Now, let's examine the service files generated out of this wsdl with respect to this particular wsdl:fault element:
Class AccountNotExistFault (representing the element contained in the fault message): 
- implements ADBBean.
- implements a serialize method

Class AccountNotExistFaultMessageException (representing the exception to be thrown on failure of the withdraw operation):
- extends java.lang.Exception

What I want to discuss here, is the way generation would work the other way around: from java classes to WSDL, and then from WSDL to client generation. 

The problem I see here, is: to write a service for the axis2 framework, one needs to implement a hell of a lot of methods and get acquainted with many concepts. I would have expected the codegeneration tools to do exactly the work of generating serialization, correct exception handling, etc. by themselves. So that, from an ordinary java class, with operations throwing some (custom) exceptions, one could easily generate server- and client-side code. Unfortunately, this seems not to be supported. And if I had known that, I wouldn't have posted my mails treating exception handling here. I was convinced I did something wrong, but I couldn't know that "code generation" here meant not that much. 
Also, be aware of some flaws in the code generation tools: when specifying an exception extending java.lang.exception, the codegeneration tools effectively generates a wsdl in which the extension base "java.lang.)"Exception" is specified. This leads to the creation of the class "Exception" lateron, when generating the client code from the generated WSDL.

Well folks - isn't there a way to just easen these steps ? I mean, why can't the code generation wizards not just take care of serialization and all that extra stuff (isReaderMTOMaware and all those methods) by themselves ? If I have to browse the documentation to write a service this way, I can well write everything myself and it wont be of great help.

Best regards,

Jay

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


RE: AxisFault and CustomException

Posted by ROSSILLE Samuel <sa...@cgi.com>.
Hi

 

I'm not yet Axis2 guru, but i think i understand your problem :-)

 

When the java method of your service throws a method, axis translates the java exception into a soap fault. Soap fault is less structured than a java exception. It has only a soap:code and a soap:reason. Both are text elements. By default, axis sets this text to the value of the stack trace of the java exception (look at comments at the beginning of axis2.xml).

 

Then, when your client catches the soap fault, it raises an AxisFault, which is a java exception, but you have lost the structure, because of the fact that there is no equivalent in soap to the very structured java exception.

 

getDetail() just gives you soap element  which contains the code and the reason.

 

For myself, I would not use a soap fault, but encapsulate the result type of my method in a wrapper which contains an error code (one of the codes means that result ok). If the method fails, the error code gives you the exception and the wrapper object would be null:

 

package axis2test;
public class MyService {
    public MyService() {
    }
    public MyDataType addOneToPositiveValue(int value) throws CustomException {



        MyDataType result = new MyDataType();

        if(value < 1) {
            result.setErrorCode(1);

            return 0;
        }
        else {

             result.setErrorCode(0)

             return(value + 1);
        }  
    }
}



package axis2test;
public class MyDataType {
    private int data;

    private int errorCode;

 

    public getters, setters,...

 

    

}



Samuel Rossilel

________________________________

De : Pär Malmqvist [mailto:par_malmqvist@hotmail.com] 
Envoyé : jeudi 4 octobre 2007 15:20
À : axis-user@ws.apache.org
Objet : AxisFault and CustomException

 


Hello!
 
I have created a simple Axis2 service called MyService, se code below. It has one method: addOneToPositiveValue. If it is called with a negative value it throws a CustomException.
I have created a MyService.aar and deployed it on Axis2 1.3 and Tomcat 5.5.23
 
Then I created a simple client with wsdl2java and xmlbeans style.
 
Its really hard to get the CustomException in an easy way at the client side.
The AxisFault.getDetail() displays the name of the exception deep down in some kind of stacktrace. Thats all.
 
Can you Axis2 gurus have a look at it please?
If I haven't missed anything I think something has to be done to make this easier.
 
Thanks.
 
/Pär
 

package axis2test;
public class MyService {
    public MyService() {
    }
    public int addOneToPositiveValue(int value) throws CustomException {
        if(value < 1) {
            throw(new CustomException());
        }
        
        return(value + 1);
    }
}
 
package axis2test;
public class CustomException extends Exception {   
    private static final long serialVersionUID = 999999999;
    public CustomException() {
        super();
    }
    public String toString() {
        return(super.toString() + ' axis2test.CustomException');
    }
}
 
<service name='MyService' scope='application'>
    <description>
        This is a webservice for MyService
    </description>
    <messageReceivers>
        <messageReceiver mep='http://www.w3.org/2004/08/wsdl/in-out'
                         class='org.apache.axis2.rpc.receivers.RPCMessageReceiver'/>
    </messageReceivers>
    <parameter name='ServiceClass' locked='false'>axis2test.MyService</parameter>
</service>

________________________________

Get news, entertainment and everything you care about at Live.com. Check it out! <http://www.live.com/getstarted.aspx%20> 


AxisFault and CustomException

Posted by Pär Malmqvist <pa...@hotmail.com>.
Hello! I have created a simple Axis2 service called MyService, se code below. It has one method: addOneToPositiveValue. If it is called with a negative value it throws a CustomException.I have created a MyService.aar and deployed it on Axis2 1.3 and Tomcat 5.5.23 Then I created a simple client with wsdl2java and xmlbeans style. Its really hard to get the CustomException in an easy way at the client side.The AxisFault.getDetail() displays the name of the exception deep down in some kind of stacktrace. Thats all. Can you Axis2 gurus have a look at it please?If I haven't missed anything I think something has to be done to make this easier. Thanks. /Pär package axis2test;public class MyService {    public MyService() {    }    public int addOneToPositiveValue(int value) throws CustomException {        if(value < 1) {            throw(new CustomException());        }                return(value + 1);    }} package axis2test;public class CustomException extends Exception {       private static final long serialVersionUID = 999999999;    public CustomException() {        super();    }    public String toString() {        return(super.toString() + ' axis2test.CustomException');    }} <service name='MyService' scope='application'>    <description>        This is a webservice for MyService    </description>    <messageReceivers>        <messageReceiver mep='http://www.w3.org/2004/08/wsdl/in-out'                         class='org.apache.axis2.rpc.receivers.RPCMessageReceiver'/>    </messageReceivers>    <parameter name='ServiceClass' locked='false'>axis2test.MyService</parameter></service>
_________________________________________________________________
News, entertainment and everything you care about at Live.com. Get it now!
http://www.live.com/getstarted.aspx