REST, error handling, HTTP status codes

2008-04-14 Thread John-M Baker
Hello,

I'm looking into providing some REST based services with CXF. The examples 
are great but I can't see something demonstrating error handling. While 
error handling with REST doesn't seem to be particularly well defined, 
HTTP status codes would surfice. How easy is this to achieve with CXF? 


John Baker
-- 
Web SSO 
IT Infrastructure 
Deutsche Bank London

URL:  http://websso.cto.gt.intranet.db.com


---

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient (or have received this e-mail in error) please 
notify the sender immediately and delete this e-mail. Any unauthorized copying, 
disclosure or distribution of the material in this e-mail is strictly forbidden.

Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional 
EU corporate and regulatory disclosures.

Re: REST, error handling, HTTP status codes

2008-04-14 Thread Sergey Beryozkin
Hi


This would be fairly easy to do with JAX-RS. There's a number of ways to 
propogate HTTP errors with JAX-RS from your application code :

1. throw WenApplicationException

public void putIt(String s) {
throw new WebApplicationException()
}

By default it will cause 500.

2. You can also use a Response object, either directly or by wrapping it into a 
WebApplicationException

public void putIt(String s) {
throw new WebApplicationException(
 Response.status(406).entity(descitptionOfProblemInXml).build())
}

WebApplicationException is a RuntimeException so you can use (possibly) at any 
level in your app...

or 

just 

@ProduceMime(application/atom+entry)
@Path({id})
public Response getIt(Long id) {
   Entry e = find(id);
   if (e == null) {
   return  
Response.status(errorCode).entity(descitptionOfProblemInXml).build();
   } else {
   return Response.entity(e).build();
   }  
}

Cheers, Sergey




 Hello,
 
 I'm looking into providing some REST based services with CXF. The examples 
 are great but I can't see something demonstrating error handling. While 
 error handling with REST doesn't seem to be particularly well defined, 
 HTTP status codes would surfice. How easy is this to achieve with CXF? 
 
 
 John Baker
 -- 
 Web SSO 
 IT Infrastructure 
 Deutsche Bank London
 
 URL:  http://websso.cto.gt.intranet.db.com
 
 
 ---
 
 This e-mail may contain confidential and/or privileged information. If you 
 are not the intended recipient (or have received this e-mail in error) please 
 notify the sender immediately and delete this e-mail. Any unauthorized 
 copying, disclosure or distribution of the material in this e-mail is 
 strictly forbidden.
 
 Please refer to http://www.db.com/en/content/eu_disclosures.htm for 
 additional EU corporate and regulatory disclosures.


IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland


Re: REST, error handling, HTTP status codes

2008-04-14 Thread John-M Baker
That's great. Is this included in one of the examples, or do you have 
something you can zip up and send me? The example set with CXF is 
brilliant - running stuff that actually works (with ant) makes the product 
so much easier to comprehend.


John Baker
-- 
Web SSO 
IT Infrastructure 
Deutsche Bank London

URL:  http://websso.cto.gt.intranet.db.com




Sergey Beryozkin [EMAIL PROTECTED] 
14/04/2008 09:54
Please respond to
cxf-user@incubator.apache.org


To
cxf-user@incubator.apache.org
cc

Subject
Re: REST, error handling, HTTP status codes






Hi


This would be fairly easy to do with JAX-RS. There's a number of ways to 
propogate HTTP errors with JAX-RS from your application code :

1. throw WenApplicationException

public void putIt(String s) {
throw new WebApplicationException()
}

By default it will cause 500.

2. You can also use a Response object, either directly or by wrapping it 
into a WebApplicationException

public void putIt(String s) {
throw new WebApplicationException(
 Response.status(406).entity(descitptionOfProblemInXml).build())
}

WebApplicationException is a RuntimeException so you can use (possibly) at 
any level in your app...

or 

just 

@ProduceMime(application/atom+entry)
@Path({id})
public Response getIt(Long id) {
   Entry e = find(id);
   if (e == null) {
   return 
Response.status(errorCode).entity(descitptionOfProblemInXml).build();
   } else {
   return Response.entity(e).build();
   } 
}

Cheers, Sergey




 Hello,
 
 I'm looking into providing some REST based services with CXF. The 
examples 
 are great but I can't see something demonstrating error handling. While 
 error handling with REST doesn't seem to be particularly well defined, 
 HTTP status codes would surfice. How easy is this to achieve with CXF? 
 
 
 John Baker
 -- 
 Web SSO 
 IT Infrastructure 
 Deutsche Bank London
 
 URL:  http://websso.cto.gt.intranet.db.com
 
 
 ---
 
 This e-mail may contain confidential and/or privileged information. If 
you are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and delete this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
 
 Please refer to http://www.db.com/en/content/eu_disclosures.htm for 
additional EU corporate and regulatory disclosures.


IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland



---

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient (or have received this e-mail in error) please 
notify the sender immediately and delete this e-mail. Any unauthorized copying, 
disclosure or distribution of the material in this e-mail is strictly forbidden.

Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional 
EU corporate and regulatory disclosures.

Re: REST, error handling, HTTP status codes

2008-04-14 Thread John-M Baker
Is jax-rs included with CXF?


John Baker
-- 
Web SSO 
IT Infrastructure 
Deutsche Bank London

URL:  http://websso.cto.gt.intranet.db.com


---

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient (or have received this e-mail in error) please 
notify the sender immediately and delete this e-mail. Any unauthorized copying, 
disclosure or distribution of the material in this e-mail is strictly forbidden.

Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional 
EU corporate and regulatory disclosures.

Re: REST, error handling, HTTP status codes

2008-04-14 Thread John-M Baker
Hiya,

I'll look at 2.1. This document is very useful:

http://cwiki.apache.org/CXF20DOC/jax-rs-jsr-311.html

It probably just needs a little work to expand on some of the topics to 
answer questions covering status codes, security, etc.


John Baker
-- 
Web SSO 
IT Infrastructure 
Deutsche Bank London

URL:  http://websso.cto.gt.intranet.db.com




Sergey Beryozkin [EMAIL PROTECTED] 
14/04/2008 10:23
Please respond to
cxf-user@incubator.apache.org


To
cxf-user@incubator.apache.org
cc

Subject
Re: REST, error handling, HTTP status codes






Hi

It's shipped with 2.1-SNAPSHOT.
Have a look please at a few JAX-RS demos available in the distribution.

I was also about to create a demo showing how one can easily do AtomPub 
with CXF and JAX-RS but I haven't had time due to time constraints. 

I've promised a number of times to document what one can do with CXF and 
JAX-RS, haven't had time to do it either, but with the 2.1 release 
approaching (according to Dan) I'll need to do it soon. 

CXF JAX-RS support 0.6 version of jsr-311 api. Jersey, RestEasy, Restlests 
are working with 0.7. CXF JAX-RS is likely to be able to support a number 
of scenarious, due its good and simple integration with Spring. 

Cheers, Sergey


 Is jax-rs included with CXF?
 
 
 John Baker
 -- 
 Web SSO 
 IT Infrastructure 
 Deutsche Bank London
 
 URL:  http://websso.cto.gt.intranet.db.com
 
 
 ---
 
 This e-mail may contain confidential and/or privileged information. If 
you are not the intended recipient (or have received this e-mail in error) 
please notify the sender immediately and delete this e-mail. Any 
unauthorized copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
 
 Please refer to http://www.db.com/en/content/eu_disclosures.htm for 
additional EU corporate and regulatory disclosures.


IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland



---

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient (or have received this e-mail in error) please 
notify the sender immediately and delete this e-mail. Any unauthorized copying, 
disclosure or distribution of the material in this e-mail is strictly forbidden.

Please refer to http://www.db.com/en/content/eu_disclosures.htm for additional 
EU corporate and regulatory disclosures.