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 Justin Sands <js...@biobex.com> on 2007/08/24 01:31:50 UTC

exception handling, chicken and egg?

I am trying to do some basic exception handling with axis 2 (Using a POJO for my service).  It looks accomplishing this even in the most basic case introduces circular dependencies.  
 
Is there a clear build pattern that will avoid this?
Must I hand code my wsdl before I start?
What do people do to avoid this?
 
For example:
========================================
public class MyService {
     public boolean myOperation(String param) throws MyException;
}
 
All I want to do is generate a test client that has some code like this (as in the fault handling sample):
 
  try {
    MyServiceStub.MyOperation request = new MyServiceStub.MyOperation();
    request.setParam("13");
    stub.myOperation()
   }
   catch (MyException exception) {
     // hande my exception
   }
 
This does not work as I get an AxisFault instead of MyException
 
I've looked at the samples/faulthandling example.
Why must the MyException class be autogenerated?
Is it strictly required that the service throws the autogenerated MyException?
 
========================================
I want a nice clean feed forward build process::
 
  MyService.java -> [javac] -> MyService.class -> 
          [java2wsdl] -> MyServiceMyService.wsdl -> 
          [wsdl2java] -> MyClientStub.java
 
However, in order to compile MyService.java I need to the exception defined, compile my classes, and then
generate my wsdl.  I can certainly define a temporary MyException, but it must be deleted after the service is built, (as in the faulthandling example) or I will get duplicate classes.
 
I'm sure there is a simple way to do this.
 
 Thanks
   - Justin

Re: exception handling, chicken and egg?

Posted by Amila Suriarachchi <am...@gmail.com>.
you do not need to write the wsdl file from hand.

what you should have done was
1. deploy your pojo service
2. generate the client using wsd2java giving serviceName?wsdl as the uri
3. then access the service using the generated stub.

Can you send your generated wsdl? I'll see your issue.

Amila.

On 8/24/07, Justin Sands <js...@biobex.com> wrote:
>
> Well I tried the following since there were no POJO examples that used
> exception handling.
> The samples/faulthandling example seemed closest to what I am trying to do
> so I followed it:
>
> 1) I created a prototype POJO project with empty implementations
>
> 2) I ran wsdl2java on the prototype project to generate MyService.wsdl(i'm trying to avoid hand coding WSDL)
>
> <java2wsdl className="com.mypackage.MyService"
>                   targetNamespace=http://mypackage.com
>                   schemaTargetNamespace=http://mypackage.com/xsd>
>
>   Here, I followed some other example that puts the service classes in a
> xsd subpackage and xsd subnamespace
>
> 3) I ran java2wsdl on MyService.wsdl, this generated my ServiceSkeleton
> and data classes
>
> 4) I modified the service skeleton to add my buisness logic.
>
> At this point all i am trying to see is that when my service
> implementation throws MyException, that something other than AxisFault is
> received at the client.
>
> What I actually see is 4 seperate Exception classes being generated.
>
> com.mypackage.xsd.Exception <-- implements ADBBean
> com.mypackage.MyException <-- extends java.lang.exception
> com.mypackage.xsd.MyException <-- extends com.mypackage.xsd.Exception
> com.mypackage.xsd.MyException0 <-- implements ADBBean
>
> Then I tried doing the following to throw an exception:
>
> com.mypackage.MyException exception = new com.mypackage.MyException();
> exception.setFaultMessage(new com.mypackage.xsd.MyException0());
>
> The test client gets an AxisFault with the message text "unknown".
>
> Must I hand code my WSDL for this to work?
>
> Any Ideas?
>
> ________________________________
>
> From: Amila Suriarachchi [mailto:amilasuriarachchi@gmail.com]
> Sent: Fri 8/24/2007 12:34 AM
> To: axis-user@ws.apache.org
> Subject: Re: exception handling, chicken and egg?
>
>
> There is no relationship with the initial class exception in your service
> and the wsdl2java generated Exception.
> Let me explain you this clearly.
>
> Lets take your senario. you have this java class.
>
> public class MyService {
>      public boolean myOperation(String param) throws MyException;
> }
>
> when you deploy this class as a web service it generates you the wsdl for
> this service.
> This generated wsdl contains a fault element for the myOperation.
>
> When using wsdl2java it only concern about that fact. Only the wsdl. it
> does not know or care about the way you have implement the service. So it
> generates an Exception class for that fault message.
>
> Now as you can see these two exception classes are different
> classes(although they have the same name).
>
> If you want to use the same exception class and other classes at the
> client side you have to use the RPCServiceClient instead of wsdl2java
> codegen. But the problem with RPCServiceClient is it does not handle
> exceptions correctly.
> So if you want to have the same exception class at the client side only
> option is to use the Axis2-rmi (this is only available at nighly builds).
>
> So for your problem either you have to use two Exception classes (original
> and wsdl2java generated) at the client side and server side or have to
> switch to Axis2-rmi.
>
> Amila.
>
>
>
>
> On 8/24/07, Justin Sands <js...@biobex.com> wrote:
>
>
>         I am trying to do some basic exception handling with axis 2 (Using
> a POJO for my service).  It looks accomplishing this even in the most basic
> case introduces circular dependencies.
>
>         Is there a clear build pattern that will avoid this?
>         Must I hand code my wsdl before I start?
>         What do people do to avoid this?
>
>         For example:
>         ========================================
>         public class MyService {
>              public boolean myOperation(String param) throws MyException;
>         }
>
>         All I want to do is generate a test client that has some code like
> this (as in the fault handling sample):
>
>           try {
>             MyServiceStub.MyOperation request = new
> MyServiceStub.MyOperation();
>             request.setParam("13");
>             stub.myOperation()
>            }
>            catch (MyException exception) {
>              // hande my exception
>            }
>
>         This does not work as I get an AxisFault instead of MyException
>
>         I've looked at the samples/faulthandling example.
>         Why must the MyException class be autogenerated?
>         Is it strictly required that the service throws the autogenerated
> MyException?
>
>         ========================================
>         I want a nice clean feed forward build process::
>
>           MyService.java -> [javac] -> MyService.class ->
>                   [java2wsdl] -> MyServiceMyService.wsdl ->
>                   [wsdl2java] -> MyClientStub.java
>
>
>         However, in order to compile MyService.java I need to the
> exception defined, compile my classes, and then
>         generate my wsdl.  I can certainly define a temporary MyException,
> but it must be deleted after the service is built, (as in the faulthandling
> example) or I will get duplicate classes.
>
>         I'm sure there is a simple way to do this.
>
>          Thanks
>
>            - Justin
>
>
>
>
> --
> Amila Suriarachchi,
> WSO2 Inc.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Amila Suriarachchi,
WSO2 Inc.

RE: exception handling, chicken and egg?

Posted by Justin Sands <js...@biobex.com>.
Well I tried the following since there were no POJO examples that used exception handling.
The samples/faulthandling example seemed closest to what I am trying to do so I followed it:
 
1) I created a prototype POJO project with empty implementations 
 
2) I ran wsdl2java on the prototype project to generate MyService.wsdl (i'm trying to avoid hand coding WSDL)
 
 <java2wsdl className="com.mypackage.MyService" 
                  targetNamespace=http://mypackage.com
                  schemaTargetNamespace=http://mypackage.com/xsd>
 
  Here, I followed some other example that puts the service classes in a xsd subpackage and xsd subnamespace
 
3) I ran java2wsdl on MyService.wsdl, this generated my ServiceSkeleton and data classes
 
4) I modified the service skeleton to add my buisness logic.
 
At this point all i am trying to see is that when my service implementation throws MyException, that something other than AxisFault is received at the client.
 
What I actually see is 4 seperate Exception classes being generated.
 
com.mypackage.xsd.Exception <-- implements ADBBean
com.mypackage.MyException <-- extends java.lang.exception
com.mypackage.xsd.MyException <-- extends com.mypackage.xsd.Exception
com.mypackage.xsd.MyException0 <-- implements ADBBean
 
Then I tried doing the following to throw an exception:
 
com.mypackage.MyException exception = new com.mypackage.MyException();
exception.setFaultMessage(new com.mypackage.xsd.MyException0()); 

The test client gets an AxisFault with the message text "unknown".
 
Must I hand code my WSDL for this to work?
 
 Any Ideas?
 
________________________________

From: Amila Suriarachchi [mailto:amilasuriarachchi@gmail.com]
Sent: Fri 8/24/2007 12:34 AM
To: axis-user@ws.apache.org
Subject: Re: exception handling, chicken and egg?


There is no relationship with the initial class exception in your service and the wsdl2java generated Exception.
Let me explain you this clearly.

Lets take your senario. you have this java class.

public class MyService {
     public boolean myOperation(String param) throws MyException;
}

when you deploy this class as a web service it generates you the wsdl for this service. 
This generated wsdl contains a fault element for the myOperation. 

When using wsdl2java it only concern about that fact. Only the wsdl. it does not know or care about the way you have implement the service. So it generates an Exception class for that fault message. 

Now as you can see these two exception classes are different classes(although they have the same name).

If you want to use the same exception class and other classes at the client side you have to use the RPCServiceClient instead of wsdl2java codegen. But the problem with RPCServiceClient is it does not handle exceptions correctly. 
So if you want to have the same exception class at the client side only option is to use the Axis2-rmi (this is only available at nighly builds).

So for your problem either you have to use two Exception classes (original and wsdl2java generated) at the client side and server side or have to switch to Axis2-rmi. 

Amila.




On 8/24/07, Justin Sands <js...@biobex.com> wrote: 

	
	I am trying to do some basic exception handling with axis 2 (Using a POJO for my service).  It looks accomplishing this even in the most basic case introduces circular dependencies.  
	 
	Is there a clear build pattern that will avoid this?
	Must I hand code my wsdl before I start?
	What do people do to avoid this?
	 
	For example:
	========================================
	public class MyService {
	     public boolean myOperation(String param) throws MyException;
	}
	 
	All I want to do is generate a test client that has some code like this (as in the fault handling sample):
	 
	  try {
	    MyServiceStub.MyOperation request = new MyServiceStub.MyOperation();
	    request.setParam("13");
	    stub.myOperation()
	   }
	   catch (MyException exception) {
	     // hande my exception
	   }
	 
	This does not work as I get an AxisFault instead of MyException
	 
	I've looked at the samples/faulthandling example.
	Why must the MyException class be autogenerated?
	Is it strictly required that the service throws the autogenerated MyException?
	 
	========================================
	I want a nice clean feed forward build process::
	 
	  MyService.java -> [javac] -> MyService.class -> 
	          [java2wsdl] -> MyServiceMyService.wsdl -> 
	          [wsdl2java] -> MyClientStub.java
	 
	
	However, in order to compile MyService.java I need to the exception defined, compile my classes, and then
	generate my wsdl.  I can certainly define a temporary MyException, but it must be deleted after the service is built, (as in the faulthandling example) or I will get duplicate classes.
	 
	I'm sure there is a simple way to do this.
	 
	 Thanks
	
	   - Justin




-- 
Amila Suriarachchi,
WSO2 Inc. 

Re: exception handling, chicken and egg?

Posted by Amila Suriarachchi <am...@gmail.com>.
There is no relationship with the initial class exception in your service
and the wsdl2java generated Exception.
Let me explain you this clearly.

Lets take your senario. you have this java class.
public class MyService {
     public boolean myOperation(String param) throws MyException;
}

when you deploy this class as a web service it generates you the wsdl for
this service.
This generated wsdl contains a fault element for the myOperation.

When using wsdl2java it only concern about that fact. Only the wsdl. it does
not know or care about the way you have implement the service. So it
generates an Exception class for that fault message.

Now as you can see these two exception classes are different
classes(although they have the same name).

If you want to use the same exception class and other classes at the client
side you have to use the RPCServiceClient instead of wsdl2java codegen. But
the problem with RPCServiceClient is it does not handle exceptions
correctly.
So if you want to have the same exception class at the client side only
option is to use the Axis2-rmi (this is only available at nighly builds).

So for your problem either you have to use two Exception classes (original
and wsdl2java generated) at the client side and server side or have to
switch to Axis2-rmi.

Amila.



On 8/24/07, Justin Sands <js...@biobex.com> wrote:
>
>  I am trying to do some basic exception handling with axis 2 (Using a POJO
> for my service).  It looks accomplishing this even in the most basic case
> introduces circular dependencies.
>
> Is there a clear build pattern that will avoid this?
> Must I hand code my wsdl before I start?
> What do people do to avoid this?
>
> For example:
> ========================================
> public class MyService {
>      public boolean myOperation(String param) throws MyException;
> }
>
> All I want to do is generate a test client that has some code like this
> (as in the fault handling sample):
>
>   try {
>     MyServiceStub.MyOperation request = new MyServiceStub.MyOperation();
>     request.setParam("13");
>     stub.myOperation()
>    }
>    catch (MyException exception) {
>      // hande my exception
>    }
>
> This does not work as I get an AxisFault instead of MyException
>
> I've looked at the samples/faulthandling example.
> Why must the MyException class be autogenerated?
>  Is it strictly required that the service throws the autogenerated
> MyException?
>
>  ========================================
> I want a nice clean feed forward build process::
>
>   MyService.java -> [javac] -> MyService.class ->
>           [java2wsdl] -> MyServiceMyService.wsdl ->
>           [wsdl2java] -> MyClientStub.java
>
>  However, in order to compile MyService.java I need to the exception
> defined, compile my classes, and then
> generate my wsdl.  I can certainly define a temporary MyException, but it
> must be deleted after the service is built, (as in the faulthandling
> example) or I will get duplicate classes.
>
> I'm sure there is a simple way to do this.
>
>  Thanks
>    - Justin
>



-- 
Amila Suriarachchi,
WSO2 Inc.