Re: JSON and JAX-RS

2008-01-23 Thread Sergey Beryozkin
Hi

String is supported already, not sure if more work is needed to support 
primitive types, it would be trivial to do


Cheers, Sergey

- Original Message - 
From: Vespa, Anthony J [EMAIL PROTECTED]
To: Daniel Kulp [EMAIL PROTECTED]; cxf-user@incubator.apache.org
Sent: Wednesday, January 23, 2008 2:12 AM
Subject: RE: JSON and JAX-RS


Interesting.  Would that mean I would have to use seekAlso and list all of the 
objects that could possibly be returned - I have currently about six types of 
custom objects.  What if I was returning a type like a boolean or just a string?



From: Daniel Kulp [mailto:[EMAIL PROTECTED]
Sent: Tue 1/22/2008 5:31 PM
To: cxf-user@incubator.apache.org
Cc: Vespa, Anthony J
Subject: Re: JSON and JAX-RS




Well, looking at the code, it seems to create a new JAXBContext for each
top level type, which really sucks.   IMO, it should use our
JAXBDatabinding in some way which would allow it/you to configure things
via spring or something so one one JAXBContext is created/used that
would have all the required types in it.   Actually, checking if there
is an ObjectFactory in the package and creating the context based on
that would also go a long way to helping. 

That said,  with JAXB 2.1, you can probably add an @XmlSeeAlso annation
on the wsResponse that points to the wsMessage to make the JAXBContext
for the wsResponse be able to marshal the wsMessage as well.

Dan


On Tuesday 22 January 2008, Vespa, Anthony J wrote:
 So I spent some time playing with JAX-RS and I seem to have
 encountered an issue.

 I can return single objects from my service as JSON (standard Java
 types as well as my custom objects) but if I try to return my wrapper
 object which contains an anytype generic list, I get an exception.

 Effectively I have an object called wsResponse that, in this case, is
 returning an array of messages (wsMessage) - I have decorated both
 objects with the XMLType.  I am looking into this exception and see
 references to JAXB; is it possible to get around this?



 Jan 22, 2008 4:45:26 PM
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
 INFO: Available content types for response is: application/json,
 Jan 22, 2008 4:45:26 PM
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
 INFO: Response EntityProvider is:
 org.apache.cxf.jaxrs.provider.JSONProvider
 Jan 22, 2008 4:45:26 PM
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
 INFO: Response content type is: application/json
 javax.xml.bind.MarshalException
  - with linked exception:
 [javax.xml.bind.JAXBException: class com.cbs.bos.data.ws.wsMessage nor
 any of its super class is known to this context.]
 at
 com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:2
95 )
 at
 com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java
:1 48)
 at
 org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java:9
0) at
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAX
RS OutInterceptor.java:99)
 at
 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercepto
rC hain.java:208)
 at
 org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Outg
oi ngChainInterceptor.java:74)
 at
 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercepto
rC hain.java:208)
 at
 org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitia
ti onObserver.java:78)
 at
 org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletD
es tination.java:79)
 at
 org.apache.cxf.transport.servlet.ServletController.invokeDestination(S
er vletController.java:264)
 at
 org.apache.cxf.transport.servlet.ServletController.invoke(ServletContr
ol ler.java:123)
 at
 org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXF
Se rvlet.java:170)
 at
 org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFS
er vlet.java:152)
 at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:690) at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli
ca tionFilterChain.java:290)
 at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi
lt erChain.java:206)
 at
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVa
lv e.java:233)
 at
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextVa
lv e.java:175)
 at
 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.ja
va

 :128)

 at
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.ja
va

 :102)

 at
 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValv
e. java:109)
 at
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java
:2 63

Re: JSON and JAX-RS

2008-01-23 Thread Daniel Kulp
On Tuesday 22 January 2008, Vespa, Anthony J wrote:
 Interesting.  Would that mean I would have to use seekAlso and list
 all of the objects that could possibly be returned - I have currently
 about six types of custom objects.  What if I was returning a type
 like a boolean or just a string?

You should be fine. (although, you probably need to wrapper them with a 
JAXBElement to get the element name)   I think all the stuff that maps 
to straight xsd schema types are always part of the created JAXBContext.   
The stuff you need to be careful of are the things that would be 
generated from the xjc. 

Dan



 

 From: Daniel Kulp [mailto:[EMAIL PROTECTED]
 Sent: Tue 1/22/2008 5:31 PM
 To: cxf-user@incubator.apache.org
 Cc: Vespa, Anthony J
 Subject: Re: JSON and JAX-RS




 Well, looking at the code, it seems to create a new JAXBContext for
 each top level type, which really sucks.   IMO, it should use our
 JAXBDatabinding in some way which would allow it/you to configure
 things via spring or something so one one JAXBContext is created/used
 that would have all the required types in it.   Actually, checking if
 there is an ObjectFactory in the package and creating the context
 based on that would also go a long way to helping.

 That said,  with JAXB 2.1, you can probably add an @XmlSeeAlso
 annation on the wsResponse that points to the wsMessage to make the
 JAXBContext for the wsResponse be able to marshal the wsMessage as
 well.

 Dan

 On Tuesday 22 January 2008, Vespa, Anthony J wrote:
  So I spent some time playing with JAX-RS and I seem to have
  encountered an issue.
 
  I can return single objects from my service as JSON (standard Java
  types as well as my custom objects) but if I try to return my
  wrapper object which contains an anytype generic list, I get an
  exception.
 
  Effectively I have an object called wsResponse that, in this case,
  is returning an array of messages (wsMessage) - I have decorated
  both objects with the XMLType.  I am looking into this exception and
  see references to JAXB; is it possible to get around this?
 
 
 
  Jan 22, 2008 4:45:26 PM
  org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
  INFO: Available content types for response is: application/json,
  Jan 22, 2008 4:45:26 PM
  org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
  INFO: Response EntityProvider is:
  org.apache.cxf.jaxrs.provider.JSONProvider
  Jan 22, 2008 4:45:26 PM
  org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
  INFO: Response content type is: application/json
  javax.xml.bind.MarshalException
   - with linked exception:
  [javax.xml.bind.JAXBException: class com.cbs.bos.data.ws.wsMessage
  nor any of its super class is known to this context.]
  at
  com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java
 :2 95 )
  at
  com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.ja
 va
 
 :1 48)
 
  at
  org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java
 :9 0) at
  org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(J
 AX RS OutInterceptor.java:99)
  at
  org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercep
 to rC hain.java:208)
  at
  org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Ou
 tg oi ngChainInterceptor.java:74)
  at
  org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercep
 to rC hain.java:208)
  at
  org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInit
 ia ti onObserver.java:78)
  at
  org.apache.cxf.transport.servlet.ServletDestination.doMessage(Servle
 tD es tination.java:79)
  at
  org.apache.cxf.transport.servlet.ServletController.invokeDestination
 (S er vletController.java:264)
  at
  org.apache.cxf.transport.servlet.ServletController.invoke(ServletCon
 tr ol ler.java:123)
  at
  org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractC
 XF Se rvlet.java:170)
  at
  org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCX
 FS er vlet.java:152)
  at
  javax.servlet.http.HttpServlet.service(HttpServlet.java:690) at
  javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at
  org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(App
 li ca tionFilterChain.java:290)
  at
  org.apache.catalina.core.ApplicationFilterChain.doFilter(Application
 Fi lt erChain.java:206)
  at
  org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapper
 Va lv e.java:233)
  at
  org.apache.catalina.core.StandardContextValve.invoke(StandardContext
 Va lv e.java:175)
  at
  org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.
 ja va
 
  :128)
 
  at
  org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.
 ja va
 
  :102

RE: JSON and JAX-RS

2008-01-23 Thread Vespa, Anthony J
Well it turned out that I had too many jaxb jars in my classpath so now
the xmlseealso works, but I get this odd exception as an invalid
namespace - I'm not quite sure why I'm getting it though, do I need to
specify another namespace somewhere?  At this point, I'm not specifying
it anywhere - my bean.xml looks like...

(for this service


jaxrs:server id=boardservice address=/
jaxrs:serviceBeans
  bean class=com.cbs.bos.ws.BoardService /
/jaxrs:serviceBeans
  /jaxrs:server

And the exception


INFO: Interceptor has thrown exception, unwinding now
java.lang.IllegalStateException: Invalid JSON namespace:
http://www.w3.org/2001/XMLSchema-instance
at
org.codehaus.jettison.mapped.MappedNamespaceConvention.getJSONNamespace(
MappedNamespaceConvention.java:148)
at
org.codehaus.jettison.mapped.MappedNamespaceConvention.createAttributeKe
y(MappedNamespaceConvention.java:136)
at
org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeAttribute(Mapped
XMLStreamWriter.java:89)
at
com.sun.xml.bind.v2.runtime.output.XMLStreamWriterOutput.attribute(XMLSt
reamWriterOutput.java:133)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.attribute(XMLSerializer.java:4
31)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.j
ava:676)
at
com.sun.xml.bind.v2.runtime.property.ArrayElementNodeProperty.serializeI
tem(ArrayElementNodeProperty.java:65)
at
com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListB
ody(ArrayElementProperty.java:168)
at
com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(Array
ERProperty.java:152)
at
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInf
oImpl.java:322)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializ
er.java:589)
at
com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInf
oImpl.java:312)
at
com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java
:490)
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328
)
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:1
75)
at
org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java:90)
at
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRS
OutInterceptor.

-Original Message-
From: Daniel Kulp [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 23, 2008 10:28 AM
To: cxf-user@incubator.apache.org
Cc: Vespa, Anthony J
Subject: Re: JSON and JAX-RS

On Tuesday 22 January 2008, Vespa, Anthony J wrote:
 Interesting.  Would that mean I would have to use seekAlso and list
 all of the objects that could possibly be returned - I have currently
 about six types of custom objects.  What if I was returning a type
 like a boolean or just a string?

You should be fine. (although, you probably need to wrapper them with a 
JAXBElement to get the element name)   I think all the stuff that maps 
to straight xsd schema types are always part of the created JAXBContext.

The stuff you need to be careful of are the things that would be 
generated from the xjc. 

Dan



 

 From: Daniel Kulp [mailto:[EMAIL PROTECTED]
 Sent: Tue 1/22/2008 5:31 PM
 To: cxf-user@incubator.apache.org
 Cc: Vespa, Anthony J
 Subject: Re: JSON and JAX-RS




 Well, looking at the code, it seems to create a new JAXBContext for
 each top level type, which really sucks.   IMO, it should use our
 JAXBDatabinding in some way which would allow it/you to configure
 things via spring or something so one one JAXBContext is created/used
 that would have all the required types in it.   Actually, checking if
 there is an ObjectFactory in the package and creating the context
 based on that would also go a long way to helping.

 That said,  with JAXB 2.1, you can probably add an @XmlSeeAlso
 annation on the wsResponse that points to the wsMessage to make the
 JAXBContext for the wsResponse be able to marshal the wsMessage as
 well.

 Dan

 On Tuesday 22 January 2008, Vespa, Anthony J wrote:
  So I spent some time playing with JAX-RS and I seem to have
  encountered an issue.
 
  I can return single objects from my service as JSON (standard Java
  types as well as my custom objects) but if I try to return my
  wrapper object which contains an anytype generic list, I get an
  exception.
 
  Effectively I have an object called wsResponse that, in this case,
  is returning an array of messages (wsMessage) - I have decorated
  both objects with the XMLType.  I am looking into this exception and
  see references to JAXB; is it possible to get around this?
 
 
 
  Jan 22, 2008 4:45:26 PM
  org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
  INFO: Available content types for response is: application/json,
  Jan 22, 2008 4:45:26 PM
  org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage

JSON and JAX-RS

2008-01-22 Thread Vespa, Anthony J
So I spent some time playing with JAX-RS and I seem to have encountered
an issue.

I can return single objects from my service as JSON (standard Java types
as well as my custom objects) but if I try to return my wrapper object
which contains an anytype generic list, I get an exception.

Effectively I have an object called wsResponse that, in this case, is
returning an array of messages (wsMessage) - I have decorated both
objects with the XMLType.  I am looking into this exception and see
references to JAXB; is it possible to get around this?



Jan 22, 2008 4:45:26 PM
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
INFO: Available content types for response is: application/json,
Jan 22, 2008 4:45:26 PM
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
INFO: Response EntityProvider is:
org.apache.cxf.jaxrs.provider.JSONProvider
Jan 22, 2008 4:45:26 PM
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
INFO: Response content type is: application/json
javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class com.cbs.bos.data.ws.wsMessage nor
any of its super class is known to this context.]
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:295
)
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:1
48)
at
org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java:90)
at
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRS
OutInterceptor.java:99)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:208)
at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Outgoi
ngChainInterceptor.java:74)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:208)
at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiati
onObserver.java:78)
at
org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletDes
tination.java:79)
at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(Ser
vletController.java:264)
at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletControl
ler.java:123)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFSe
rvlet.java:170)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFSer
vlet.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:175)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:2
63)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:84
4)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
Http11Protocol.java:584)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)


RE: JSON and JAX-RS

2008-01-22 Thread Beryozkin, Sergey
Hi

org.apache.cxf.jaxrs.provider.JSONProvider checks XMLRootElement
annotations.
Would it make a difference if you annotate both wsResponse and wsMessage
classes with this annotation ?

Cheers, Sergey



-Original Message-
From: Vespa, Anthony J [mailto:[EMAIL PROTECTED] 
Sent: 22 January 2008 21:48
To: cxf-user@incubator.apache.org
Subject: JSON and JAX-RS

So I spent some time playing with JAX-RS and I seem to have encountered
an issue.

I can return single objects from my service as JSON (standard Java types
as well as my custom objects) but if I try to return my wrapper object
which contains an anytype generic list, I get an exception.

Effectively I have an object called wsResponse that, in this case, is
returning an array of messages (wsMessage) - I have decorated both
objects with the XMLType.  I am looking into this exception and see
references to JAXB; is it possible to get around this?



Jan 22, 2008 4:45:26 PM
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
INFO: Available content types for response is: application/json,
Jan 22, 2008 4:45:26 PM
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
INFO: Response EntityProvider is:
org.apache.cxf.jaxrs.provider.JSONProvider
Jan 22, 2008 4:45:26 PM
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
INFO: Response content type is: application/json
javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class com.cbs.bos.data.ws.wsMessage nor
any of its super class is known to this context.]
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:295
)
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:1
48)
at
org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java:90)
at
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRS
OutInterceptor.java:99)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:208)
at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Outgoi
ngChainInterceptor.java:74)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:208)
at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiati
onObserver.java:78)
at
org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletDes
tination.java:79)
at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(Ser
vletController.java:264)
at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletControl
ler.java:123)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFSe
rvlet.java:170)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFSer
vlet.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:175)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:2
63)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:84
4)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
Http11Protocol.java:584)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)


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


RE: JSON and JAX-RS

2008-01-22 Thread Vespa, Anthony J
I did try that, and I get the same error. 

-Original Message-
From: Beryozkin, Sergey [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, January 22, 2008 5:14 PM
To: cxf-user@incubator.apache.org
Subject: RE: JSON and JAX-RS

Hi

org.apache.cxf.jaxrs.provider.JSONProvider checks XMLRootElement
annotations.
Would it make a difference if you annotate both wsResponse and wsMessage
classes with this annotation ?

Cheers, Sergey



-Original Message-
From: Vespa, Anthony J [mailto:[EMAIL PROTECTED] 
Sent: 22 January 2008 21:48
To: cxf-user@incubator.apache.org
Subject: JSON and JAX-RS

So I spent some time playing with JAX-RS and I seem to have encountered
an issue.

I can return single objects from my service as JSON (standard Java types
as well as my custom objects) but if I try to return my wrapper object
which contains an anytype generic list, I get an exception.

Effectively I have an object called wsResponse that, in this case, is
returning an array of messages (wsMessage) - I have decorated both
objects with the XMLType.  I am looking into this exception and see
references to JAXB; is it possible to get around this?



Jan 22, 2008 4:45:26 PM
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
INFO: Available content types for response is: application/json,
Jan 22, 2008 4:45:26 PM
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
INFO: Response EntityProvider is:
org.apache.cxf.jaxrs.provider.JSONProvider
Jan 22, 2008 4:45:26 PM
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
INFO: Response content type is: application/json
javax.xml.bind.MarshalException
 - with linked exception:
[javax.xml.bind.JAXBException: class com.cbs.bos.data.ws.wsMessage nor
any of its super class is known to this context.]
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:295
)
at
com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:1
48)
at
org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java:90)
at
org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRS
OutInterceptor.java:99)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:208)
at
org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Outgoi
ngChainInterceptor.java:74)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorC
hain.java:208)
at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiati
onObserver.java:78)
at
org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletDes
tination.java:79)
at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(Ser
vletController.java:264)
at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletControl
ler.java:123)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFSe
rvlet.java:170)
at
org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFSer
vlet.java:152)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:233)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:175)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:128)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:102)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:2
63)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:84
4)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
Http11Protocol.java:584)
at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)


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


Re: JSON and JAX-RS

2008-01-22 Thread Daniel Kulp

Well, looking at the code, it seems to create a new JAXBContext for each 
top level type, which really sucks.   IMO, it should use our 
JAXBDatabinding in some way which would allow it/you to configure things 
via spring or something so one one JAXBContext is created/used that 
would have all the required types in it.   Actually, checking if there 
is an ObjectFactory in the package and creating the context based on 
that would also go a long way to helping.  

That said,  with JAXB 2.1, you can probably add an @XmlSeeAlso annation 
on the wsResponse that points to the wsMessage to make the JAXBContext 
for the wsResponse be able to marshal the wsMessage as well.

Dan


On Tuesday 22 January 2008, Vespa, Anthony J wrote:
 So I spent some time playing with JAX-RS and I seem to have
 encountered an issue.

 I can return single objects from my service as JSON (standard Java
 types as well as my custom objects) but if I try to return my wrapper
 object which contains an anytype generic list, I get an exception.

 Effectively I have an object called wsResponse that, in this case, is
 returning an array of messages (wsMessage) - I have decorated both
 objects with the XMLType.  I am looking into this exception and see
 references to JAXB; is it possible to get around this?



 Jan 22, 2008 4:45:26 PM
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
 INFO: Available content types for response is: application/json,
 Jan 22, 2008 4:45:26 PM
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
 INFO: Response EntityProvider is:
 org.apache.cxf.jaxrs.provider.JSONProvider
 Jan 22, 2008 4:45:26 PM
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
 INFO: Response content type is: application/json
 javax.xml.bind.MarshalException
  - with linked exception:
 [javax.xml.bind.JAXBException: class com.cbs.bos.data.ws.wsMessage nor
 any of its super class is known to this context.]
 at
 com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:2
95 )
 at
 com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java
:1 48)
 at
 org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java:9
0) at
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAX
RS OutInterceptor.java:99)
 at
 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercepto
rC hain.java:208)
 at
 org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Outg
oi ngChainInterceptor.java:74)
 at
 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercepto
rC hain.java:208)
 at
 org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitia
ti onObserver.java:78)
 at
 org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletD
es tination.java:79)
 at
 org.apache.cxf.transport.servlet.ServletController.invokeDestination(S
er vletController.java:264)
 at
 org.apache.cxf.transport.servlet.ServletController.invoke(ServletContr
ol ler.java:123)
 at
 org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXF
Se rvlet.java:170)
 at
 org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFS
er vlet.java:152)
 at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:690) at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli
ca tionFilterChain.java:290)
 at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi
lt erChain.java:206)
 at
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVa
lv e.java:233)
 at
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextVa
lv e.java:175)
 at
 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.ja
va

 :128)

 at
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.ja
va

 :102)

 at
 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValv
e. java:109)
 at
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java
:2 63)
 at
 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
84 4)
 at
 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proces
s( Http11Protocol.java:584)
 at
 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447
)



-- 
J. Daniel Kulp
Principal Engineer, IONA
[EMAIL PROTECTED]
http://www.dankulp.com/blog


RE: JSON and JAX-RS

2008-01-22 Thread Vespa, Anthony J
Interesting.  Would that mean I would have to use seekAlso and list all of the 
objects that could possibly be returned - I have currently about six types of 
custom objects.  What if I was returning a type like a boolean or just a string?



From: Daniel Kulp [mailto:[EMAIL PROTECTED]
Sent: Tue 1/22/2008 5:31 PM
To: cxf-user@incubator.apache.org
Cc: Vespa, Anthony J
Subject: Re: JSON and JAX-RS




Well, looking at the code, it seems to create a new JAXBContext for each
top level type, which really sucks.   IMO, it should use our
JAXBDatabinding in some way which would allow it/you to configure things
via spring or something so one one JAXBContext is created/used that
would have all the required types in it.   Actually, checking if there
is an ObjectFactory in the package and creating the context based on
that would also go a long way to helping. 

That said,  with JAXB 2.1, you can probably add an @XmlSeeAlso annation
on the wsResponse that points to the wsMessage to make the JAXBContext
for the wsResponse be able to marshal the wsMessage as well.

Dan


On Tuesday 22 January 2008, Vespa, Anthony J wrote:
 So I spent some time playing with JAX-RS and I seem to have
 encountered an issue.

 I can return single objects from my service as JSON (standard Java
 types as well as my custom objects) but if I try to return my wrapper
 object which contains an anytype generic list, I get an exception.

 Effectively I have an object called wsResponse that, in this case, is
 returning an array of messages (wsMessage) - I have decorated both
 objects with the XMLType.  I am looking into this exception and see
 references to JAXB; is it possible to get around this?



 Jan 22, 2008 4:45:26 PM
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
 INFO: Available content types for response is: application/json,
 Jan 22, 2008 4:45:26 PM
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
 INFO: Response EntityProvider is:
 org.apache.cxf.jaxrs.provider.JSONProvider
 Jan 22, 2008 4:45:26 PM
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor handleMessage
 INFO: Response content type is: application/json
 javax.xml.bind.MarshalException
  - with linked exception:
 [javax.xml.bind.JAXBException: class com.cbs.bos.data.ws.wsMessage nor
 any of its super class is known to this context.]
 at
 com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:2
95 )
 at
 com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java
:1 48)
 at
 org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java:9
0) at
 org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAX
RS OutInterceptor.java:99)
 at
 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercepto
rC hain.java:208)
 at
 org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(Outg
oi ngChainInterceptor.java:74)
 at
 org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseIntercepto
rC hain.java:208)
 at
 org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitia
ti onObserver.java:78)
 at
 org.apache.cxf.transport.servlet.ServletDestination.doMessage(ServletD
es tination.java:79)
 at
 org.apache.cxf.transport.servlet.ServletController.invokeDestination(S
er vletController.java:264)
 at
 org.apache.cxf.transport.servlet.ServletController.invoke(ServletContr
ol ler.java:123)
 at
 org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXF
Se rvlet.java:170)
 at
 org.apache.cxf.transport.servlet.AbstractCXFServlet.doGet(AbstractCXFS
er vlet.java:152)
 at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:690) at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:803) at
 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appli
ca tionFilterChain.java:290)
 at
 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFi
lt erChain.java:206)
 at
 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVa
lv e.java:233)
 at
 org.apache.catalina.core.StandardContextValve.invoke(StandardContextVa
lv e.java:175)
 at
 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.ja
va

 :128)

 at
 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.ja
va

 :102)

 at
 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValv
e. java:109)
 at
 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java
:2 63)
 at
 org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:
84 4)
 at
 org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proces
s( Http11Protocol.java:584)
 at
 org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447
)



--
J. Daniel Kulp
Principal Engineer, IONA
[EMAIL PROTECTED]
http://www.dankulp.com/blog