You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Dhaval Chauhan <dh...@hotmail.com> on 2008/07/10 02:34:53 UTC

Exception handling in store sample

Hi,

I was working on the scenarios for the JSON-RPC mentioned on the SCA

Java Web 2.0 Road map. I tried the first scenario i.e. 'Empty catalog

throws a Business Exception. Business Exception should properly

propagate and display nicely to client'



I tried simulating the exception condition by making the .get() method

of the FruitsCatalogImpl.java throw the business exception.



First I noticed that the JSON representation of the exception is not

being recognized by the browser js engine.

Currently, the Tuscany runtime is producing something like :



 "{\"id\":3,\"error\":services.ClientException: Fruits Catalog empty}"



Instead, I think it should be :

"{\"id\":3,\"error\":{\"trace\":\"services.ClientException: Fruits

Catalog empty\",\"code\":490,\"msg\":\"Fruits catalog empty\"}}"



Is it some issue related with the binding where the actual JSON error

message is formatted ?





After fixing this issue, I was still having issues with the exception

not being caught by the try/catch block, and I had to modify the

store.html client code as follow :



function init() {

            var item = new Array();

            try

            {

                item = catalog.get();

            }

            catch(e)

            {

                alert(e.message);

                return;

            }

            catalog_getResponse(item);

            shoppingCart.get("", shoppingCart_getResponse);

        }





Thanks,

Dhaval
_________________________________________________________________
The i’m Talkaton. Can 30-days of conversation change the world?
http://www.imtalkathon.com/?source=EML_WLH_Talkathon_ChangeWorld

Re: Exception handling in store sample

Posted by Luciano Resende <lu...@gmail.com>.
Please use TUSCANY-1961, that is a sub-task of TUSCANY-2394.

[1] https://issues.apache.org/jira/browse/TUSCANY-1961
[2] https://issues.apache.org/jira/browse/TUSCANY-2394

On Fri, Jul 11, 2008 at 11:05 AM, Dhaval Chauhan
<dh...@hotmail.com> wrote:
> Hi Luciano,
>
> Thanks for the comments.
>
> Yes, I can provide the patch. Let me know the JIRA number once it's created.
>
> Thanks,
> Dhaval
>
>
>
> ________________________________
>> Date: Fri, 11 Jul 2008 10:10:30 -0700
>> From: luckbr1975@gmail.com
>> To: dev@tuscany.apache.org
>> Subject: Re: Exception handling in store sample
>>
>> Hey Dhaval
>>
>> Thanks for looking into the issue. Let me try to give some comments
>> inline.
>>
>> On Wed, Jul 9, 2008 at 5:34 PM, Dhaval Chauhan
>> <dh...@hotmail.com> wrote:
>> > Hi,
>> >
>> > I was working on the scenarios for the JSON-RPC mentioned on the SCA
>> > Java Web 2.0 Road map. I tried the first scenario i.e. 'Empty catalog
>> > throws a Business Exception. Business Exception should properly
>> > propagate and display nicely to client'
>> >
>> > I tried simulating the exception condition by making the .get() method
>> > of the FruitsCatalogImpl.java throw the business exception.
>> >
>> > First I noticed that the JSON representation of the exception is not
>> > being recognized by the browser js engine.
>> > Currently, the Tuscany runtime is producing something like :
>> >
>> > "{\"id\":3,\"error\":services.ClientException: Fruits Catalog empty}"
>> >
>> > Instead, I think it should be :
>> > "{\"id\":3,\"error\":{\"trace\":\"services.ClientException: Fruits
>> > Catalog empty\",\"code\":490,\"msg\":\"Fruits catalog empty\"}}"
>> >
>> > Is it some issue related with the binding where the actual JSON error
>> > message is formatted ?
>>
>> This is because we are handling errors as regular responses in
>> JSONRPCServiceServlet. So, instead of just using the JSONResponse to
>> return errors, we should use a JSONRPCResult, that would know how to
>> properly marshal the exception in JSON format.
>>
>> I did a quick change in the servlet (handleJSONRPCMethodInvocation),
>> and the following code allows me to get the proper exception in the
>> client side.
>>
>> JSONRPCResult errorResult = new
>> JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause() );
>> return errorResult.toString().getBytes("UTF-8");
>>
>> >
>> >
>> > After fixing this issue, I was still having issues with the exception
>> > not being caught by the try/catch block, and I had to modify the
>> > store.html client code as follow :
>> >
>> > function init() {
>> > var item = new Array();
>> > try
>> > {
>> > item = catalog.get();
>> > }
>> > catch(e)
>> > {
>> > alert(e.message);
>> > return;
>> > }
>> > catalog_getResponse(item);
>> > shoppingCart.get("", shoppingCart_getResponse);
>> > }
>> >
>>
>> As for the client code, how about the following pattern for the
>> callback function :
>>
>> function shoppingTotal_getTotalResponse(total, exception) {
>> if(exception) {alert(exception.message);}
>>
>> document.getElementById('total').innerHTML = total;
>> }
>>
>> and the service call would continue with the same pattern we have been
>> using, but would need to be surrounded by try/catch
>>
>> try {
>> shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
>> //shoppingTotal_getTotalResponse(total);
>> } catch (e) {
>> alert(e);
>> }
>>
>>
>> Let me create a JIRA for this issue, and you could provide a clean
>> patch with all necessary changes if you are interested.
>> >
>> > Thanks,
>> > Dhaval
>> > ________________________________
>> > The i'm Talkaton. Can 30-days of conversation change the world? Find out
>> > now.
>>
>>
>>
>> --
>> Luciano Resende
>> Apache Tuscany Committer
>> http://people.apache.org/~lresende
>> http://lresende.blogspot.com/
>
> ________________________________
> Use video conversation to talk face-to-face with Windows Live Messenger. Get
> started.



-- 
Luciano Resende
Apache Tuscany Committer
http://people.apache.org/~lresende
http://lresende.blogspot.com/

Re: Exception handling in store sample

Posted by Luciano Resende <lu...@gmail.com>.
We are not serializing the error ourselves, so we need to identify how
the library is handling multiple JSON-RPC versions. It might be good
to check what's available on more recent releases, now that
metaparadigm library got merged to jabsorb.

On Fri, Jul 11, 2008 at 11:15 AM, Raymond Feng <en...@gmail.com> wrote:
> It seems to me there is a difference in the representation of the error in
> json-rpc 1.0 and 1.1.
>
> See: http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#ErrorObject
>
> Thanks,
> Raymond
> From: Dhaval Chauhan
> Sent: Friday, July 11, 2008 11:05 AM
> To: dev@tuscany.apache.org
> Subject: RE: Exception handling in store sample
> Hi Luciano,
>
> Thanks for the comments.
>
> Yes, I can provide the patch. Let me know the JIRA number once it's created.
>
> Thanks,
> Dhaval
>
>
>
> ________________________________
>> Date: Fri, 11 Jul 2008 10:10:30 -0700
>> From: luckbr1975@gmail.com
>> To: dev@tuscany.apache.org
>> Subject: Re: Exception handling in store sample
>>
>> Hey Dhaval
>>
>> Thanks for looking into the issue. Let me try to give some comments
>> inline.
>>
>> On Wed, Jul 9, 2008 at 5:34 PM, Dhaval Chauhan
>> <dh...@hotmail.com> wrote:
>> > Hi,
>> >
>> > I was working on the scenarios for the JSON-RPC mentioned on the SCA
>> > Java Web 2.0 Road map. I tried the first scenario i.e. 'Empty catalog
>> > throws a Business Exception. Business Exception should properly
>> > propagate and display nicely to client'
>> >
>> > I tried simulating the exception condition by making the .get() method
>> > of the FruitsCatalogImpl.java throw the business exception.
>> >
>> > First I noticed that the JSON representation of the exception is not
>> > being recognized by the browser js engine.
>> > Currently, the Tuscany runtime is producing something like :
>> >
>> > "{\"id\":3,\"error\":services.ClientException: Fruits Catalog empty}"
>> >
>> > Instead, I think it should be :
>> > "{\"id\":3,\"error\":{\"trace\":\"services.ClientException: Fruits
>> > Catalog empty\",\"code\":490,\"msg\":\"Fruits catalog empty\"}}"
>> >
>> > Is it some issue related with the binding where the actual JSON error
>> > message is formatted ?
>>
>> This is because we are handling errors as regular responses in
>> JSONRPCServiceServlet. So, instead of just using the JSONResponse to
>> return errors, we should use a JSONRPCResult, that would know how to
>> properly marshal the exception in JSON format.
>>
>> I did a quick change in the servlet (handleJSONRPCMethodInvocation),
>> and the following code allows me to get the proper exception in the
>> client side.
>>
>> JSONRPCResult errorResult = new
>> JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause() );
>> return errorResult.toString().getBytes("UTF-8");
>>
>> >
>> >
>> > After fixing this issue, I was still having issues with the exception
>> > not being caught by the try/catch block, and I had to modify the
>> > store.html client code as follow :
>> >
>> > function init() {
>> > var item = new Array();
>> > try
>> > {
>> > item = catalog.get();
>> > }
>> > catch(e)
>> > {
>> > alert(e.message);
>> > return;
>> > }
>> > catalog_getResponse(item);
>> > shoppingCart.get("", shoppingCart_getResponse);
>> > }
>> >
>>
>> As for the client code, how about the following pattern for the
>> callback function :
>>
>> function shoppingTotal_getTotalResponse(total, exception) {
>> if(exception) {alert(exception.message);}
>>
>> document.getElementById('total').innerHTML = total;
>> }
>>
>> and the service call would continue with the same pattern we have been
>> using, but would need to be surrounded by try/catch
>>
>> try {
>> shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
>> //shoppingTotal_getTotalResponse(total);
>> } catch (e) {
>> alert(e);
>> }
>>
>>
>> Let me create a JIRA for this issue, and you could provide a clean
>> patch with all necessary changes if you are interested.
>> >
>> > Thanks,
>> > Dhaval
>> > ________________________________
>> > The i'm Talkaton. Can 30-days of conversation change the world? Find out
>> > now.
>>
>>
>>
>> --
>> Luciano Resende
>> Apache Tuscany Committer
>> http://people.apache.org/~lresende
>> http://lresende.blogspot.com/
>
> ________________________________
> Use video conversation to talk face-to-face with Windows Live Messenger. Get
> started.



-- 
Luciano Resende
Apache Tuscany Committer
http://people.apache.org/~lresende
http://lresende.blogspot.com/

Re: Exception handling in store sample

Posted by Raymond Feng <en...@gmail.com>.
It seems to me there is a difference in the representation of the error in json-rpc 1.0 and 1.1.

See: http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html#ErrorObject

Thanks,
Raymond


From: Dhaval Chauhan 
Sent: Friday, July 11, 2008 11:05 AM
To: dev@tuscany.apache.org 
Subject: RE: Exception handling in store sample


Hi Luciano,

Thanks for the comments.

Yes, I can provide the patch. Let me know the JIRA number once it's created.

Thanks,
Dhaval





--------------------------------------------------------------------------------
> Date: Fri, 11 Jul 2008 10:10:30 -0700
> From: luckbr1975@gmail.com
> To: dev@tuscany.apache.org
> Subject: Re: Exception handling in store sample
> 
> Hey Dhaval
> 
> Thanks for looking into the issue. Let me try to give some comments inline.
> 
> On Wed, Jul 9, 2008 at 5:34 PM, Dhaval Chauhan
> <dh...@hotmail.com> wrote:
> > Hi,
> >
> > I was working on the scenarios for the JSON-RPC mentioned on the SCA
> > Java Web 2.0 Road map. I tried the first scenario i.e. 'Empty catalog
> > throws a Business Exception. Business Exception should properly
> > propagate and display nicely to client'
> >
> > I tried simulating the exception condition by making the .get() method
> > of the FruitsCatalogImpl.java throw the business exception.
> >
> > First I noticed that the JSON representation of the exception is not
> > being recognized by the browser js engine.
> > Currently, the Tuscany runtime is producing something like :
> >
> > "{\"id\":3,\"error\":services.ClientException: Fruits Catalog empty}"
> >
> > Instead, I think it should be :
> > "{\"id\":3,\"error\":{\"trace\":\"services.ClientException: Fruits
> > Catalog empty\",\"code\":490,\"msg\":\"Fruits catalog empty\"}}"
> >
> > Is it some issue related with the binding where the actual JSON error
> > message is formatted ?
> 
> This is because we are handling errors as regular responses in
> JSONRPCServiceServlet. So, instead of just using the JSONResponse to
> return errors, we should use a JSONRPCResult, that would know how to
> properly marshal the exception in JSON format.
> 
> I did a quick change in the servlet (handleJSONRPCMethodInvocation),
> and the following code allows me to get the proper exception in the
> client side.
> 
> JSONRPCResult errorResult = new
> JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause() );
> return errorResult.toString().getBytes("UTF-8");
> 
> >
> >
> > After fixing this issue, I was still having issues with the exception
> > not being caught by the try/catch block, and I had to modify the
> > store.html client code as follow :
> >
> > function init() {
> > var item = new Array();
> > try
> > {
> > item = catalog.get();
> > }
> > catch(e)
> > {
> > alert(e.message);
> > return;
> > }
> > catalog_getResponse(item);
> > shoppingCart.get("", shoppingCart_getResponse);
> > }
> >
> 
> As for the client code, how about the following pattern for the
> callback function :
> 
> function shoppingTotal_getTotalResponse(total, exception) {
> if(exception) {alert(exception.message);}
> 
> document.getElementById('total').innerHTML = total; 
> }
> 
> and the service call would continue with the same pattern we have been
> using, but would need to be surrounded by try/catch
> 
> try { 
> shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
> //shoppingTotal_getTotalResponse(total);
> } catch (e) {
> alert(e);
> }
> 
> 
> Let me create a JIRA for this issue, and you could provide a clean
> patch with all necessary changes if you are interested.
> >
> > Thanks,
> > Dhaval
> > ________________________________
> > The i'm Talkaton. Can 30-days of conversation change the world? Find out
> > now.
> 
> 
> 
> -- 
> Luciano Resende
> Apache Tuscany Committer
> http://people.apache.org/~lresende
> http://lresende.blogspot.com/


--------------------------------------------------------------------------------
Use video conversation to talk face-to-face with Windows Live Messenger. Get started. 

RE: Exception handling in store sample

Posted by Dhaval Chauhan <dh...@hotmail.com>.
Hi Luciano,

Thanks for the comments.

Yes, I can provide the patch. Let me know the JIRA number once it's created.

Thanks,
Dhaval



> Date: Fri, 11 Jul 2008 10:10:30 -0700
> From: luckbr1975@gmail.com
> To: dev@tuscany.apache.org
> Subject: Re: Exception handling in store sample
> 
> Hey Dhaval
> 
>    Thanks for looking into the issue. Let me try to give some comments inline.
> 
> On Wed, Jul 9, 2008 at 5:34 PM, Dhaval Chauhan
> <dh...@hotmail.com> wrote:
> > Hi,
> >
> > I was working on the scenarios for the JSON-RPC mentioned on the SCA
> > Java Web 2.0 Road map. I tried the first scenario i.e. 'Empty catalog
> > throws a Business Exception. Business Exception should properly
> > propagate and display nicely to client'
> >
> > I tried simulating the exception condition by making the .get() method
> > of the FruitsCatalogImpl.java throw the business exception.
> >
> > First I noticed that the JSON representation of the exception is not
> > being recognized by the browser js engine.
> > Currently, the Tuscany runtime is producing something like :
> >
> >  "{\"id\":3,\"error\":services.ClientException: Fruits Catalog empty}"
> >
> > Instead, I think it should be :
> > "{\"id\":3,\"error\":{\"trace\":\"services.ClientException: Fruits
> > Catalog empty\",\"code\":490,\"msg\":\"Fruits catalog empty\"}}"
> >
> > Is it some issue related with the binding where the actual JSON error
> > message is formatted ?
> 
> This is because we are handling errors as regular responses in
> JSONRPCServiceServlet. So, instead of just using the JSONResponse to
> return errors, we should use a JSONRPCResult, that would know how to
> properly marshal the exception in JSON format.
> 
> I did a quick change in the servlet (handleJSONRPCMethodInvocation),
> and the following code allows me to get the proper exception in the
> client side.
> 
> JSONRPCResult errorResult = new
> JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause() );
> return errorResult.toString().getBytes("UTF-8");
> 
> >
> >
> > After fixing this issue, I was still having issues with the exception
> > not being caught by the try/catch block, and I had to modify the
> > store.html client code as follow :
> >
> > function init() {
> >            var item = new Array();
> >            try
> >            {
> >                item = catalog.get();
> >            }
> >            catch(e)
> >            {
> >                alert(e.message);
> >                return;
> >            }
> >            catalog_getResponse(item);
> >            shoppingCart.get("", shoppingCart_getResponse);
> >        }
> >
> 
> As for the client code, how about the following pattern for the
> callback function :
> 
> function shoppingTotal_getTotalResponse(total, exception) {
> 		if(exception) {alert(exception.message);}
> 		
> 		document.getElementById('total').innerHTML = total;	
> 	}
> 
> and the service call would continue with the same pattern we have been
> using, but would need to be surrounded by try/catch
> 
> 	try {			
> 		shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
> 		//shoppingTotal_getTotalResponse(total);
> 	} catch (e) {
> 		alert(e);
> 	}
> 
> 
> Let me create a JIRA for this issue, and you could provide a clean
> patch with all necessary changes if you are interested.
> >
> > Thanks,
> > Dhaval
> > ________________________________
> > The i'm Talkaton. Can 30-days of conversation change the world? Find out
> > now.
> 
> 
> 
> -- 
> Luciano Resende
> Apache Tuscany Committer
> http://people.apache.org/~lresende
> http://lresende.blogspot.com/

_________________________________________________________________
Use video conversation to talk face-to-face with Windows Live Messenger.
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_Refresh_messenger_video_072008

Re: Exception handling in store sample

Posted by Luciano Resende <lu...@gmail.com>.
Hey Dhaval

   Thanks for looking into the issue. Let me try to give some comments inline.

On Wed, Jul 9, 2008 at 5:34 PM, Dhaval Chauhan
<dh...@hotmail.com> wrote:
> Hi,
>
> I was working on the scenarios for the JSON-RPC mentioned on the SCA
> Java Web 2.0 Road map. I tried the first scenario i.e. 'Empty catalog
> throws a Business Exception. Business Exception should properly
> propagate and display nicely to client'
>
> I tried simulating the exception condition by making the .get() method
> of the FruitsCatalogImpl.java throw the business exception.
>
> First I noticed that the JSON representation of the exception is not
> being recognized by the browser js engine.
> Currently, the Tuscany runtime is producing something like :
>
>  "{\"id\":3,\"error\":services.ClientException: Fruits Catalog empty}"
>
> Instead, I think it should be :
> "{\"id\":3,\"error\":{\"trace\":\"services.ClientException: Fruits
> Catalog empty\",\"code\":490,\"msg\":\"Fruits catalog empty\"}}"
>
> Is it some issue related with the binding where the actual JSON error
> message is formatted ?

This is because we are handling errors as regular responses in
JSONRPCServiceServlet. So, instead of just using the JSONResponse to
return errors, we should use a JSONRPCResult, that would know how to
properly marshal the exception in JSON format.

I did a quick change in the servlet (handleJSONRPCMethodInvocation),
and the following code allows me to get the proper exception in the
client side.

JSONRPCResult errorResult = new
JSONRPCResult(JSONRPCResult.CODE_REMOTE_EXCEPTION, id, e.getCause() );
return errorResult.toString().getBytes("UTF-8");

>
>
> After fixing this issue, I was still having issues with the exception
> not being caught by the try/catch block, and I had to modify the
> store.html client code as follow :
>
> function init() {
>            var item = new Array();
>            try
>            {
>                item = catalog.get();
>            }
>            catch(e)
>            {
>                alert(e.message);
>                return;
>            }
>            catalog_getResponse(item);
>            shoppingCart.get("", shoppingCart_getResponse);
>        }
>

As for the client code, how about the following pattern for the
callback function :

function shoppingTotal_getTotalResponse(total, exception) {
		if(exception) {alert(exception.message);}
		
		document.getElementById('total').innerHTML = total;	
	}

and the service call would continue with the same pattern we have been
using, but would need to be surrounded by try/catch

	try {			
		shoppingTotal.getTotal(shoppingTotal_getTotalResponse);
		//shoppingTotal_getTotalResponse(total);
	} catch (e) {
		alert(e);
	}


Let me create a JIRA for this issue, and you could provide a clean
patch with all necessary changes if you are interested.
>
> Thanks,
> Dhaval
> ________________________________
> The i'm Talkaton. Can 30-days of conversation change the world? Find out
> now.



-- 
Luciano Resende
Apache Tuscany Committer
http://people.apache.org/~lresende
http://lresende.blogspot.com/

Re: Exception handling in store sample

Posted by Jean-Sebastien Delfino <js...@apache.org>.
Dhaval Chauhan wrote:
> Hi,
> 
> I was working on the scenarios for the JSON-RPC mentioned on the SCA
> Java Web 2.0 Road map. I tried the first scenario i.e. 'Empty catalog
> throws a Business Exception. Business Exception should properly
> propagate and display nicely to client'
> 
> I tried simulating the exception condition by making the .get() method
> of the FruitsCatalogImpl.java throw the business exception.
> 
> First I noticed that the JSON representation of the exception is not
> being recognized by the browser js engine.
> Currently, the Tuscany runtime is producing something like :
> 
>  "{\"id\":3,\"error\":services.ClientException: Fruits Catalog empty}"
> 
> Instead, I think it should be :
> "{\"id\":3,\"error\":{\"trace\":\"services.ClientException: Fruits
> Catalog empty\",\"code\":490,\"msg\":\"Fruits catalog empty\"}}"
> 
> Is it some issue related with the binding where the actual JSON error
> message is formatted ?
> 
> 
> After fixing this issue, I was still having issues with the exception
> not being caught by the try/catch block, and I had to modify the
> store.html client code as follow :
> 
> function init() {
>            var item = new Array();
>            try
>            {
>                item = catalog.get();
>            }
>            catch(e)
>            {
>                alert(e.message);
>                return;
>            }
>            catalog_getResponse(item);
>            shoppingCart.get("", shoppingCart_getResponse);
>        }
> 
> 
> Thanks,
> Dhaval
> 

This is a known issue, which needs to be looked at end-to-end and fixed, 
as described in JIRA https://issues.apache.org/jira/browse/TUSCANY-2394.

-- 
Jean-Sebastien