Hi Kynan
Hi Sergey,
I already had this @Produces("application/xml") annotation on the custom
exception mapper.
I'm actually not sure Exception Mappers can indicate it this way, I'll have to
ask on the jaxrs users list.
As far as I'm aware it is only resource classes/methods and message body
providers which can do it.
I presume you don't mean to annotate the actual response
class? Out of curiousity I tried this but it didn't make a difference.
No, I didn't mean it.
I was suggesting to do something like this :
return Response.status(theStatus).type("application/xml")
.entity(someEntity).build(;
Can you try it please ?
It does seem strange that for most errors this behaviour is not exhibited,
but for invalid url's it is?
I'll add a test today
thanks, Sergey
Regards,
Kynan
Sergey Beryozkin-2 wrote:
Hi Kynan,
Can you please try to set an application/xml type on your custom Response
please ?
Hopefully it will make a difference.
[2009-06-23 09:12:18,498
DEBUG][AbstractJAXBProvider][http-8080-Processor24
fw9syo1f][0:0:0:0:0:0:0:1][] Error creating a JAXBContext using
ObjectFactory : "package.name" doesnt contain ObjectFactory.class or
jaxb.index
What happens is that a provider first attempts to initialize a package
wide context and then resorts back to trying to load a
class-specific context. The message is a bit misleading. I think I can
also try to optimize given that it's already been checked
whether a given package contains ObjectFactory or not.
As a side note: I temporarily tried to marshall the response to XML
myself
in the exception mapper rather than letting the framework marshall it for
me
(but this for some reason returns application/octet-stream instead of
application/xml).
If no content-type has already been set then (per the spec) it defaults to
application/octet-stream. So please set application/xml
in your custom exception mapper and hopefully it will start working
thanks, Sergey
----- Original Message -----
From: "Kynan Fraser" <[email protected]>
To: <[email protected]>
Sent: Tuesday, June 23, 2009 12:22 AM
Subject: JAX-RS: Invalid URL handling
Hi All,
I'm working on a JAX-RS implementation and functionally things are
working
well (kudos to the team for a great framework) - cxf 2.2.2.
However, in a small part of the exception handling i'm not getting
expected
behaviour - handling invalid URL paths.
I'm using a custom Exception Mapper to handle exceptions and my
understanding is that the following happens in this scenario:
The exception mapper class is passed control after the JAXRSInInterceptor
finds 'No root resource matching request path ..." and throws a
WebApplicationException.
Then the exception mapper can just return a response (some kind of error)
as
normal. However i'm getting the following error when returning from the
exception mapper:
<XML> Parsing Error: syntax error (or parsing error)
Location: <requested URL>
Line Number 1, Column 1:
"No message body writer found for response class: Error Response"
Now in other error cases (both checked and unchecked) this exception
mapper
is returning normally. The Error Response object is XMLRootElement
annotated.
It seems that in the JAXRSOutInterceptor in certain cases its failing to
load the JAXB context/related resources. I noticed in other error cases I
get the following two lines in logs but the response comes back
correctly:
[2009-06-23 09:12:18,493
DEBUG][haseInterceptorChain][http-8080-Processor24
fw9syo1f][0:0:0:0:0:0:0:1][] Invoking handleMessage on interceptor
org.apache.cxf.jaxrs.interceptor.jaxrsoutintercep...@5a37d54
[2009-06-23 09:12:18,494
DEBUG][.JAXRSOutInterceptor][http-8080-Processor24
fw9syo1f][0:0:0:0:0:0:0:1][] Response content type is: application/xml
[2009-06-23 09:12:18,496
DEBUG][.JAXRSOutInterceptor][http-8080-Processor24
fw9syo1f][0:0:0:0:0:0:0:1][] Response EntityProvider is:
org.apache.cxf.jaxrs.provider.JAXBElementProvider
[2009-06-23 09:12:18,498
DEBUG][AbstractJAXBProvider][http-8080-Processor24
fw9syo1f][0:0:0:0:0:0:0:1][] Error creating a JAXBContext using
ObjectFactory : "package.name" doesnt contain ObjectFactory.class or
jaxb.index
[2009-06-23 09:12:18,503
DEBUG][haseInterceptorChain][http-8080-Processor24
fw9syo1f][0:0:0:0:0:0:0:1][] Invoking handleMessage on interceptor
org.apache.cxf.interceptor.messagesenderinterceptor$messagesenderendingintercep...@5e43e3ac
but in the invalid url case i get:
[2009-06-23 09:11:31,336
DEBUG][haseInterceptorChain][http-8080-Processor25
fw9sxn5s][0:0:0:0:0:0:0:1][] Invoking handleMessage on interceptor
org.apache.cxf.jaxrs.interceptor.jaxrsoutintercep...@5a37d54
[2009-06-23 09:11:31,337 WARN
][.JAXRSOutInterceptor][http-8080-Processor25
fw9sxn5s][0:0:0:0:0:0:0:1][] .No message body writer found for response
class : ErrorResponse.
[2009-06-23 09:11:31,337
DEBUG][haseInterceptorChain][http-8080-Processor25
fw9sxn5s][0:0:0:0:0:0:0:1][] Invoking handleMessage on interceptor
org.apache.cxf.interceptor.messagesenderinterceptor$messagesenderendingintercep...@5e43e3ac
I haven't really tried to debug the cxf source but it seems like in the
JAXRSOutInterceptor around line 179 the writer is not getting correctly
created possibly beacuse the annotations on the Error Response class
aren't
found? I'm not sure why in this one error case this would happen and not
in
others.
Possibly related to: http://issues.apache.org/jira/browse/CXF-1858
As a side note: I temporarily tried to marshall the response to XML
myself
in the exception mapper rather than letting the framework marshall it for
me
(but this for some reason returns application/octet-stream instead of
application/xml).
Regards,
Kynan
--
View this message in context:
http://www.nabble.com/JAX-RS%3A-Invalid-URL-handling-tp24157326p24157326.html
Sent from the cxf-user mailing list archive at Nabble.com.
--
View this message in context:
http://www.nabble.com/JAX-RS%3A-Invalid-URL-handling-tp24157326p24176239.html
Sent from the cxf-user mailing list archive at Nabble.com.