Hello,
I tried to remove:
final Map<String, String> namespaces = new HashMap<String, String>();
namespaces.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
setNamespaceMap(namespaces);
And to add:
setWriteXsiType(false);
However, it failed... (same error than previous one)
Regards,
Anthony
-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]]
Sent: lundi 3 octobre 2011 11:43
To: [email protected]
Subject: Re: CXF 2.3.3 - JSON output - java.lang.IllegalStateException: Invalid
JSON namespace
Hi
That is great, just for your info, "writeXsiType" property, if set to
false, can probably block that xsi:null...
You may also want to experiment with Jackson which is probably is less
dependent on the way JAXB operates, as opposed to Jettison
Cheers, Sergey
On 03/10/11 10:36, Muller, Anthony wrote:
> Hey Sergey!
>
> I found a solution to my issue after many attempts and after be sure that my
> provider was called by CXF.
>
> I tuned the OSGi imported packages too.
>
> I think the problem was for interpretation of XSD Nillable value. Even if I
> set 'ignoreNamespaces' to 'true', nillable values are formatted like this in
> JSON: "@xsi.nil"
>
> Anyway, thanks for your help,
> Anthony
>
>
> @Produces({"application/json"})
> @Consumes({"application/json"})
> @Provider
> public class ExtendedJSONProvider extends JSONProvider {
>
> public ExtendedJSONProvider() {
> setIgnoreNamespaces(true);
> final Map<String, String> namespaces = new HashMap<String,
> String>();
> namespaces.put("http://www.w3.org/2001/XMLSchema-instance",
> "xsi");
> setNamespaceMap(namespaces);
> }
> }
>
>
> -----Original Message-----
> From: Sergey Beryozkin [mailto:[email protected]]
> Sent: lundi 3 octobre 2011 10:43
> To: [email protected]
> Subject: Re: CXF 2.3.3 - JSON output - java.lang.IllegalStateException:
> Invalid JSON namespace
>
> Hi,
>
> I got confused a bit, as you did say
>
> >>>>>> In the stack trace, I see that JSONProvider is still used... Not
> >>>>>> my new instance... I guess CXF takes the first provider which is
> >>>>>> able to handle application/json MIME type?
> >>>>>>
> >>>>>> Moreover, I see this warning in log:
> >>>>>>
> >>>>>> org.apache.cxf.jaxrs.utils.ResourceUtils checkMethodDispatcher
> >>>>>> ATTENTION: No resource methods have been found for resource
> >>>>>> class com.test.ExtendedJSONProvider
>
> So the problem is, that for whatever reasons, a custom provider is not
> recognized when it's registered from Application.
> Can you please try one of the following:
> - try returning com.test.ExtendedJSONProvider.class from
> Application.getClasses() but not from Application.getSingletons(); or
> the other way around. I can see that either approach is being tested on
> the trunk but I'm not 100% sure that that works in 2.3.3 properly
> - instead of using Application - try jaxrs.serviceClasses and
> jaxrs.providers init parameters - this is a temp step which may help to
> isolate the problem which may be to do with @Provider being still not
> visible.
> - finally - create a simple bundle that can help demonstrating that the
> custom provider is not picked up - and please sent to me
>
> thanks, Sergey
>
> On 30/09/11 16:15, Sergey Beryozkin wrote:
>> Hmm...
>> Sorry, can you please double-check that ExtendedJSONProvider does not
>> feature anyware in a stack trace ?
>> I'll add a test on my own a bit later on, I have few tests where
>> customized JAXB and JSON providers are used (these are effectively
>> overriding default ones),
>> Will get back to you asap - may be Monday
>> Thanks, Sergey
>>
>> On 30/09/11 15:50, Muller, Anthony wrote:
>>> Yep, classes are bundlized and deployed in an osgi environment.
>>>
>>> And yes, I imported "javax.ws.rs.ext". As I said, my provider is well
>>> instantiated but JSONProvider seems to have an higher priority.
>>>
>>> Regards,
>>> Anthony
>>>
>>>
>>> -----Original Message-----
>>> From: Sergey Beryozkin [mailto:[email protected]]
>>> Sent: vendredi 30 septembre 2011 15:58
>>> To: [email protected]
>>> Subject: Re: CXF 2.3.3 - JSON output -
>>> java.lang.IllegalStateException: Invalid JSON namespace
>>>
>>> Hi
>>>
>>> I've checked that the code in CXF 2.3.3, CXF 2.4.2 and 2.5.0 that deals
>>> with getting providers from Applications is identical and I have a test
>>> where exception mappers are registered from CXFNonSpringJaxrsServlet and
>>> Application.
>>>
>>> I'm wondering if it is an OSGI issue ? Do you have javax.ws.rs.ext
>>> imported ?
>>>
>>>
>>> On 30/09/11 11:23, Muller, Anthony wrote:
>>>> Thanks for your help Sergey. Sorry, it's configured through an
>>>> Application instance!
>>>>
>>>> Anthony
>>>>
>>>> -----Original Message-----
>>>> From: Sergey Beryozkin [mailto:[email protected]]
>>>> Sent: vendredi 30 septembre 2011 12:14
>>>> To: [email protected]
>>>> Subject: Re: CXF 2.3.3 - JSON output -
>>>> java.lang.IllegalStateException: Invalid JSON namespace
>>>>
>>>> That looks OK.
>>>> How do you register it ? From Application instance or via servlet init
>>>> params ? Give me more info please
>>>>
>>>> Cheers, Sergey
>>>>
>>>> On 30/09/11 11:10, Muller, Anthony wrote:
>>>>> Yes, it's what I did. Do you see something wrong?
>>>>>
>>>>>
>>>>> import javax.ws.rs.Consumes;
>>>>> import javax.ws.rs.Produces;
>>>>> import javax.ws.rs.ext.Provider;
>>>>>
>>>>> import org.apache.cxf.jaxrs.provider.JSONProvider;
>>>>>
>>>>> @Produces({"application/json"})
>>>>> @Consumes({"application/json"})
>>>>> @Provider
>>>>> public class ExtendedJSONProvider extends JSONProvider {
>>>>>
>>>>> public ExtendedJSONProvider() {
>>>>> setIgnoreNamespaces(true);
>>>>> }
>>>>> }
>>>>>
>>>>>
>>>>> -----Original Message-----
>>>>> From: Sergey Beryozkin [mailto:[email protected]]
>>>>> Sent: vendredi 30 septembre 2011 12:02
>>>>> To: [email protected]
>>>>> Subject: Re: CXF 2.3.3 - JSON output -
>>>>> java.lang.IllegalStateException: Invalid JSON namespace
>>>>>
>>>>> Hi, yea it does, but as I said CXF (CXFNonSpringJaxrsServlet) does not
>>>>> check superclasses for @Provider which will need to be fixed, so for
>>>>> now
>>>>> please add another @Provider to your custom provider and that will do -
>>>>>
>>>>> Cheers, Sergey
>>>>>
>>>>> On 30/09/11 10:47, Muller, Anthony wrote:
>>>>>> Hi Sergey,
>>>>>>
>>>>>> Are you sure that "org.apache.cxf.jaxrs.provider.JSONProvider"
>>>>>> doesn't have the @Provider annotation?
>>>>>>
>>>>>> I found it in "cxf-2.3.3.jar" yet :-/
>>>>>>
>>>>>> Anthony
>>>>>>
>>>>>>
>>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Sergey Beryozkin [mailto:[email protected]]
>>>>>> Sent: vendredi 30 septembre 2011 11:20
>>>>>> To: [email protected]
>>>>>> Subject: Re: CXF 2.3.3 - JSON output -
>>>>>> java.lang.IllegalStateException: Invalid JSON namespace
>>>>>>
>>>>>> Hi Anthony
>>>>>>
>>>>>> How do you register it, using jaxrs.providers parameter ?
>>>>>> A custom provider should be preferred to a default one.
>>>>>> That warning suggests that you probably use a jaxrs.serviceClasses
>>>>>> parameter ?
>>>>>>
>>>>>> Or do use register it from the Application implementation ? In that
>>>>>> case
>>>>>> this custom provider needs to have a JAX-RS @Provider annotation,
>>>>>> for it to be distinguished from other singletons. JSONProvider does
>>>>>> have
>>>>>> it - but in 2.3.3 no checks are made on superclasses - that will
>>>>>> need to
>>>>>> be improved in CXF
>>>>>>
>>>>>> Let me know please if that works
>>>>>>
>>>>>> Cheers, Sergey.
>>>>>>
>>>>>> On 30/09/11 09:38, Muller, Anthony wrote:
>>>>>>> Hey Sergey,
>>>>>>>
>>>>>>> I'm trying to follow your advice and I inherited from JSONProvider
>>>>>>> class and just set "ignoreNamespace" to true.
>>>>>>>
>>>>>>> At the beginning, I didn't inherit from JSONProvider, but only
>>>>>>> instantiated this class, set the "ignoreNamespace" property and
>>>>>>> add it as a provider: however I get an exception because this
>>>>>>> provider was already registered (by CXF itself I guess).
>>>>>>>
>>>>>>> SO, I add the provider bellow, but I still have the same exception
>>>>>>> about namespace :(
>>>>>>>
>>>>>>> In the stack trace, I see that JSONProvider is still used... Not
>>>>>>> my new instance... I guess CXF takes the first provider which is
>>>>>>> able to handle application/json MIME type?
>>>>>>>
>>>>>>> Moreover, I see this warning in log:
>>>>>>>
>>>>>>> org.apache.cxf.jaxrs.utils.ResourceUtils checkMethodDispatcher
>>>>>>> ATTENTION: No resource methods have been found for resource
>>>>>>> class com.test.ExtendedJSONProvider
>>>>>>>
>>>>>>> The code of the inherited JSONProvider.
>>>>>>>
>>>>>>> import javax.ws.rs.Consumes;
>>>>>>> import javax.ws.rs.Produces;
>>>>>>> import javax.ws.rs.ext.Provider;
>>>>>>>
>>>>>>> import org.apache.cxf.jaxrs.provider.JSONProvider;
>>>>>>>
>>>>>>> @Produces({"application/json"})
>>>>>>> @Consumes({"application/json"})
>>>>>>> @Provider
>>>>>>> public class ExtendedJSONProvider extends JSONProvider {
>>>>>>>
>>>>>>> public ExtendedJSONProvider() {
>>>>>>> setIgnoreNamespaces(true);
>>>>>>> }
>>>>>>> }
>>>>>>>
>>>>>>>
>>>>>>> Thanks for help!
>>>>>>>
>>>>>>> Cheers,
>>>>>>> Anthony
>>>>>>>
>>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: Sergey Beryozkin [mailto:[email protected]]
>>>>>>> Sent: mardi 27 septembre 2011 12:36
>>>>>>> To: [email protected]
>>>>>>> Subject: Re: CXF 2.3.3 - JSON output -
>>>>>>> java.lang.IllegalStateException: Invalid JSON namespace
>>>>>>>
>>>>>>> Hi
>>>>>>>
>>>>>>> The default Jettison provider expects a namespace-to-prefix map
>>>>>>> set up.
>>>>>>> If you don't realy need the prefixes on the receiving end then the
>>>>>>> simplest option is to configure JSONProvider with an
>>>>>>> "ignoreNamespaces"
>>>>>>> property, otherwise you'd need to provide a map, here is more info:
>>>>>>>
>>>>>>> http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-ConfiguringJSONprovider
>>>>>>>
>>>>>>>
>>>>>>> The thing is how to configure it given that you are using
>>>>>>> CXFNonSpringJAXRSServlet.
>>>>>>>
>>>>>>> One option is to extend JSONProvider and only set
>>>>>>> "ignoreNamespace" or
>>>>>>> "namespaceMap" property as needed on the superclass. And register it
>>>>>>> with the servlet using a jaxrs.providers parameter.
>>>>>>>
>>>>>>> Another option is try registering Jackson.
>>>>>>>
>>>>>>> I should probably do some enhancement for users be able to set simple
>>>>>>> properties on providers registered from web.xml...
>>>>>>>
>>>>>>> Cheers, Sergey
>>>>>>>
>>>>>>>
>>>>>>> On 27/09/11 10:41, Muller, Anthony wrote:
>>>>>>>> Hello,
>>>>>>>>
>>>>>>>> I have an issue when I try to get a JSON output, using a JAXB
>>>>>>>> object, of my REST webservice. (XML output is ok.)
>>>>>>>>
>>>>>>>> My webservice is running without using Spring.
>>>>>>>>
>>>>>>>> Can you help me? I don't know how to fix it despite browsing many
>>>>>>>> websites from Google.
>>>>>>>>
>>>>>>>> Cheers,
>>>>>>>> Anthony
>>>>>>>>
>>>>>>>>
>>>>>>>> The exception is:
>>>>>>>> javax.ws.rs.WebApplicationException:
>>>>>>>> java.lang.IllegalStateException: Invalid JSON namespace:
>>>>>>>> http://www.w3.org/2001/XMLSchema-instance
>>>>>>>> at
>>>>>>>> org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java:291)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.serializeMessage(JAXRSOutInterceptor.java:256)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.processResponse(JAXRSOutInterceptor.java:144)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor.handleMessage(JAXRSOutInterceptor.java:83)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.interceptor.OutgoingChainInterceptor.handleMessage(OutgoingChainInterceptor.java:77)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:113)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.transport.servlet.ServletDestination.invoke(ServletDestination.java:97)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:461)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:149)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sap.bip.rs.server.servlet.BIPServletController.invoke(BIPServletController.java:90)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.transport.servlet.AbstractCXFServlet.invoke(AbstractCXFServlet.java:148)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:179)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.doGet(AbstractHTTPServlet.java:108)
>>>>>>>>
>>>>>>>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
>>>>>>>> at
>>>>>>>> org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:159)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
>>>>>>>>
>>>>>>>> at java.lang.Thread.run(Thread.java:722)
>>>>>>>> Caused by: java.lang.IllegalStateException: Invalid JSON
>>>>>>>> namespace: http://www.w3.org/2001/XMLSchema-instance
>>>>>>>> at
>>>>>>>> org.codehaus.jettison.mapped.MappedNamespaceConvention.getJSONNamespace(MappedNamespaceConvention.java:248)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.codehaus.jettison.mapped.MappedNamespaceConvention.createAttributeKey(MappedNamespaceConvention.java:233)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.codehaus.jettison.mapped.MappedXMLStreamWriter.writeAttribute(MappedXMLStreamWriter.java:216)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.staxutils.DelegatingXMLStreamWriter.writeAttribute(DelegatingXMLStreamWriter.java:71)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.jaxrs.provider.JSONUtils$IgnoreContentJettisonWriter.writeAttribute(JSONUtils.java:204)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.staxutils.DelegatingXMLStreamWriter.writeAttribute(DelegatingXMLStreamWriter.java:71)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.output.XMLStreamWriterOutput.attribute(XMLStreamWriterOutput.java:122)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.attribute(XMLSerializer.java:403)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.writeXsiNilTrue(XMLSerializer.java:764)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.property.SingleElementLeafProperty.serializeBody(SingleElementLeafProperty.java:91)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:306)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:664)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.property.ArrayElementNodeProperty.serializeItem(ArrayElementNodeProperty.java:54)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:157)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:141)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:306)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsSoleContent(XMLSerializer.java:561)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:290)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:462)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:314)
>>>>>>>>
>>>>>>>> at
>>>>>>>> com.sun.xml.internal.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:161)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.jaxrs.provider.JSONProvider.marshal(JSONProvider.java:344)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.jaxrs.provider.JSONProvider.marshal(JSONProvider.java:377)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.apache.cxf.jaxrs.provider.JSONProvider.writeTo(JSONProvider.java:283)
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>