You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by ronfulkerson <ro...@gmail.com> on 2013/03/23 01:07:08 UTC

CXF JSON Binding Exception

Hello,

I am trying to produce a JSON message using JAX-RS with CXF (version
camel-cxf 2.10.3 / cxf 2.6.3).  When trying to produce some JSON messages, I
am presented the following exception:  JAXBException occurred : property
"com.sun.xml.internal.bind.namespacePrefixMapper" must be an instance of
type com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper, not
org.apache.cxf.common.jaxb.NamespaceMapper

If I choose to produce XML this message is not produced.  I am using only
@XmlRootElement and @XmlElement annotations, nothing more.

Any advice on how to prevent / fix the above exception?  Thanks in advance!



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-JSON-Binding-Exception-tp5725065.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF JSON Binding Exception

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 27/03/13 20:30, ronfulkerson wrote:
> Sergey,
>
> I have downloaded Karaf and installed the Camel/CXF components, and now have
> no issues.  It appears to have been a classpath issue specific to
> ServiceMix.  Thank you for your help!
>
OK, thanks for the update
Cheers, Sergey
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/CXF-JSON-Binding-Exception-tp5725065p5725410.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF JSON Binding Exception

Posted by ronfulkerson <ro...@gmail.com>.
Sergey,

I have downloaded Karaf and installed the Camel/CXF components, and now have
no issues.  It appears to have been a classpath issue specific to
ServiceMix.  Thank you for your help!



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-JSON-Binding-Exception-tp5725065p5725410.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF JSON Binding Exception

Posted by ronfulkerson <ro...@gmail.com>.
Hi Sergey,

Thanks for looking at this.  I will try looking at classpath issues, and I
have sent you a PM requesting the link to your Karaf distro.

Thanks again,
Ron



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-JSON-Binding-Exception-tp5725065p5725392.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF JSON Binding Exception

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 27/03/13 01:27, ronfulkerson wrote:
> Sorry... the last message had formatting and some content removed.  Please
> consider this post:
>
> So I have put together a test case using the Bookstore classes from
> systests/jaxrs. These classes are unmodified, but packaged as an OSGi bundle
> and accessed via a Camel route. I am not sure this is the exact problem I am
> encountering, but it produces the same exception so it will hopefully be a
> good place to start.
>
> Please download the test from  here
> <https://bitbucket.org/ronfulkerson/stash/downloads/cxf-camel-test.zip>   .
> I deploy using 'mvn install', then from servicemix 'install -s
> mvn:cxf-camel-test/cxf-camel-test'. I have tested with servicemix 4.5.0 and
> various JDK's (including JDK 1.7.u14).
>
> The exception for this test is thrown after the 'books/xsitype' URL is hit:
> $ curl -s -X GET http://localhost:8080/cxf/books/123
> {"Book":{"id":123,"name":"CXF in Action"}}
>
> $ curl -s -X GET http://localhost:8080/cxf/books/xsitype
> <?xml version="1.0" encoding="UTF-8"
> standalone="yes"?><Book><id>999</id><name>SuperBook</name></Book>
>
> $ curl -s -X GET http://localhost:8080/cxf/books/123
> JAXBException occurred : property
> "com.sun.xml.internal.bind.namespacePrefixMapper" must be an instance of
> type com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper, not
> org.apache.cxf.common.jaxb.NamespaceMapper.
>
> It is interesting to me that the 'books/{id}' URL initially works, but not
> after 'books/xsitype' has been accessed.
>
Thanks for creating this test project. I'm not able to reproduce.
I've built the bundle, only updated the versions to 2.10.4, and then 
deployed into our Karaf-based distro (I can link to it offline if you'd 
like to test on your own too) and the above sequence of requests works 
when the browser or curl is used.

I've spotted this:
http://www.docx4java.org/forums/docx-java-f6/grails-and-docx4j-v2-6-0-t502.html

they talk about exactly the same issue - see the tip in the end - 
perhaps that may help

Cheers, Sergey

> Again, thank you for your input!
>
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/CXF-JSON-Binding-Exception-tp5725065p5725332.html
> Sent from the cxf-user mailing list archive at Nabble.com.



Re: CXF JSON Binding Exception

Posted by ronfulkerson <ro...@gmail.com>.
Sorry... the last message had formatting and some content removed.  Please
consider this post:  

So I have put together a test case using the Bookstore classes from
systests/jaxrs. These classes are unmodified, but packaged as an OSGi bundle
and accessed via a Camel route. I am not sure this is the exact problem I am
encountering, but it produces the same exception so it will hopefully be a
good place to start. 

Please download the test from  here
<https://bitbucket.org/ronfulkerson/stash/downloads/cxf-camel-test.zip>  . 
I deploy using 'mvn install', then from servicemix 'install -s
mvn:cxf-camel-test/cxf-camel-test'. I have tested with servicemix 4.5.0 and
various JDK's (including JDK 1.7.u14). 

The exception for this test is thrown after the 'books/xsitype' URL is hit: 
$ curl -s -X GET http://localhost:8080/cxf/books/123
{"Book":{"id":123,"name":"CXF in Action"}}

$ curl -s -X GET http://localhost:8080/cxf/books/xsitype
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?><Book><id>999</id><name>SuperBook</name></Book>

$ curl -s -X GET http://localhost:8080/cxf/books/123
JAXBException occurred : property
"com.sun.xml.internal.bind.namespacePrefixMapper" must be an instance of
type com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper, not
org.apache.cxf.common.jaxb.NamespaceMapper.

It is interesting to me that the 'books/{id}' URL initially works, but not
after 'books/xsitype' has been accessed. 

Again, thank you for your input!



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-JSON-Binding-Exception-tp5725065p5725332.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF JSON Binding Exception

Posted by ronfulkerson <ro...@gmail.com>.
So I have put together a test case using the Bookstore classes from
systests/jaxrs.  These classes are unmodified, but packaged as an OSGi
bundle and accessed via a Camel route.  I am not sure this is the exact
problem I am encountering, but it produces the same exception so it will
hopefully be a good place to start.Please download the test from  here
<https://bitbucket.org/ronfulkerson/stash/downloads/cxf-camel-test.zip>  . 
I deploy using 'mvn install', then from servicemix invoking 'install -s
mvn:cxf-camel-test/cxf-camel-test'.  I have tested with servicemix 4.5.0 and
various JDK's (including JDK 1.7.u14).The exception for this test is thrown
after the 'books/xsitype' URL is hit:$ curl -s -X GET
http://localhost:8080/cxf/books/123{"Book":{"id":123,"name":"CXF in
Action"}}$ curl -s -X GET http://localhost:8080/cxf/books/xsitype<?xml
version="1.0" encoding="UTF-8" standalone="yes"?>999SuperBook$ curl -s -X
GET http://localhost:8080/cxf/books/123JAXBException occurred : property
"com.sun.xml.internal.bind.namespacePrefixMapper" must be an instance of
type com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper, not
org.apache.cxf.common.jaxb.NamespaceMapper.It is interesting to me that the
'books/{id}' URL initially works, but not after 'books/xsitype' has been
accessed.Again, thank you for your input!



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-JSON-Binding-Exception-tp5725065p5725330.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF JSON Binding Exception

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 25/03/13 21:02, ronfulkerson wrote:
> Sergey, thanks for your response.  I was using the version shipped with JDK
> 1.6.u23, then noticed CXF utilizes Java 7, so switched to JAXB 2.2
> (reference implementation) using the endorsed directory.  The problem is
> exhibited with both versions.
>
> I should note that JSON is emitted for very simple documents, but a slightly
> more complex document produces the error.
>
> Thanks for any input!
>
Any chance of you creating a basic test case ? Otherwise I'm not really 
sure how this can be traced - we have the tests where JSONProvider sets 
the namespace mapper and it works OK

Thanks, Sergey
>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/CXF-JSON-Binding-Exception-tp5725065p5725178.html
> Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF JSON Binding Exception

Posted by ronfulkerson <ro...@gmail.com>.
Sergey, thanks for your response.  I was using the version shipped with JDK
1.6.u23, then noticed CXF utilizes Java 7, so switched to JAXB 2.2
(reference implementation) using the endorsed directory.  The problem is
exhibited with both versions.

I should note that JSON is emitted for very simple documents, but a slightly
more complex document produces the error.

Thanks for any input!



--
View this message in context: http://cxf.547215.n5.nabble.com/CXF-JSON-Binding-Exception-tp5725065p5725178.html
Sent from the cxf-user mailing list archive at Nabble.com.

Re: CXF JSON Binding Exception

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
On 23/03/13 03:07, ronfulkerson wrote:
> Hello,
>
> I am trying to produce a JSON message using JAX-RS with CXF (version
> camel-cxf 2.10.3 / cxf 2.6.3).  When trying to produce some JSON messages, I
> am presented the following exception:  JAXBException occurred : property
> "com.sun.xml.internal.bind.namespacePrefixMapper" must be an instance of
> type com.sun.xml.internal.bind.marshaller.NamespacePrefixMapper, not
> org.apache.cxf.common.jaxb.NamespaceMapper
>
> If I choose to produce XML this message is not produced.  I am using only
> @XmlRootElement and @XmlElement annotations, nothing more.
>
> Any advice on how to prevent / fix the above exception?  Thanks in advance!
>

Looks like you have a strict JAXB implementation loaded which enforces 
that the mapper registered with the internal 
"com.sun.xml.internal.bind.namespacePrefixMapper" property.

JSONProvider registers a mapper if its namespace map is initialized, so 
that the prefixes the runtime generates matches those provided in the 
map...

must not be a third party implementation.

What JAXB version is it ?

Dan, have you heard of this issue before ?

Thanks, Sergey

>
>
> --
> View this message in context: http://cxf.547215.n5.nabble.com/CXF-JSON-Binding-Exception-tp5725065.html
> Sent from the cxf-user mailing list archive at Nabble.com.


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com