cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Bimschas <bimsc...@itm.uni-luebeck.de>
Subject Re: DOSGi and JSON responses
Date Fri, 05 Feb 2010 11:00:58 GMT
Sergey,

I now managed it to get it running as you suggested below, i.e. using the "org.apache.cxf.rs.provider"
key with values "org.apache.cxf.jaxrs.provider.JAXBElementProvider" and "de.uniluebeck.itm.soapraktikum.ws0910.persons.vz.rest.ExtendedJSONProvider",
the latter being an overridden JSONProvider. My provider is called and input seems fine. Here's
the debugging output of writeTo(...) that prints each argument of the method and then delegates
to the call to super.writeTo(...):

[de.uniluebeck.itm.soapraktikum.ws0910.persons.vz.rest.ExtendedJSONProvider] : ExtendedJSONProvider.writeTo
[de.uniluebeck.itm.soapraktikum.ws0910.persons.vz.rest.ExtendedJSONProvider] : obj: de.uniluebeck.itm.soapraktikum.ws0910.persons.data.Person@1f42e14b
 cls: class de.uniluebeck.itm.soapraktikum.ws0910.persons.data.Person
 genericType: class de.uniluebeck.itm.soapraktikum.ws0910.persons.data.Person
 anns: [@javax.ws.rs.GET(), @javax.ws.rs.Path(value=person.json), @javax.ws.rs.Produces(value=[application/json])]
 m: application/json
 headers: {Date=[Fri, 05 Feb 2010 10:15:31 GMT]}
 os: org.apache.cxf.transport.http.AbstractHTTPDestination$WrappedOutputStream@7f4e0ba

Setting "org.apache.cxf.rs.httpservice.context" instead of "org.apache.cxf.rs.address" gave
me the same result. Btw... to be more precise about the empty answer, this is the curl (-v)
for a JSON resource output:

> GET /verzeichnis/person.json HTTP/1.1
> User-Agent: curl/7.19.7 (i386-apple-darwin10.2.0) libcurl/7.19.7 zlib/1.2.3
> Host: localhost:8080
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Fri, 05 Feb 2010 10:31:12 GMT
< Content-Length: 0
< Server: Jetty(6.1.x)
< 

Debugging the JSONProvider implementation I found that there's an java.lang.LinkageError exception
in JAXRSOutInterceptor:249 with the message:

loader constraint violation: loader (instance of <bootloader>) previously initiated
loading for a different type with name "javax/xml/stream/XMLStreamWriter"

This is handled by JAXRSOutInterceptor.handleWriteException(). However, in line 320 excResponse
is null, i.e. JAXRSUtils.convertFaultToResponse(ex, message) didn't work as it seems. Therefore,
no response code is sent that lets one assume that an error occured.

So I guess one could improve the error handling here. Do you have an idea how I can get around
the linkage error?

Regards,
Daniel

Am 27.01.2010 um 18:53 schrieb Sergey Beryozkin:

> This is strange...Hmm... Is it only JSON responses which are empty ?  Can you try extending
 the default JSON provider and just overwrite its writeTo and delegate, just to check, before
doing the delegation, if it is actually invoked or if it has some real data passed in ? Also,
can you please try "org.apache.cxf.rs.httpservice.context" instead of "org.apache.cxf.rs.address",
say,
> 
> org.apache.cxf.rs.httpservice.context="/persons" ?
> 
> cheers, Sergey
> 
> ----- Original Message ----- From: "Daniel Bimschas" <bimschas@itm.uni-luebeck.de>
> To: <users@cxf.apache.org>
> Sent: Wednesday, January 27, 2010 3:28 PM
> Subject: Re: DOSGi and JSON responses
> 
> 
> I tried both the ServiceMix bundle and the Jettison 1.2 bundle but both still deliver
empty output. Debug output looks fine as far as I can see (it selects org.apache.cxf.jaxrs.provider.JSONProvider
for output):
> 
> ...
> 
> [btpool3-0] DEBUG org.apache.cxf.phase.PhaseInterceptorChain - Invoking handleMessage
on interceptor org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor@46cfd5ee
> [btpool3-0] DEBUG org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor - Response content
type is: application/json
> [btpool3-0] DEBUG org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor - Response EntityProvider
is: org.apache.cxf.jaxrs.provider.JSONProvider
> [btpool3-0] DEBUG org.apache.cxf.phase.PhaseInterceptorChain - Invoking handleMessage
on interceptor org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor@4d0155fb
> [btpool3-0] DEBUG org.apache.cxf.transport.http_jetty.JettyHTTPDestination - Finished
servicing http request on thread: Thread[btpool3-0,5,main]
> 
> ...
> 
> Any idea? Just to be sure my configuration is correct, here's my serviceComponents.xml:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <components xmlns:scr="http://www.osgi.org/xmlns/scr/v1.0.0">
>   <scr:component enabled="true" immediate="true" name="VzServiceRestComponent">
>       <implementation class="de.uniluebeck.itm.soapraktikum.ws0910.persons.vz.impl.PersonResource"/>
>       <service servicefactory="false">
>           <provide interface="de.uniluebeck.itm.soapraktikum.ws0910.persons.vz.impl.PersonResource"/>
>       </service>
>       <property name="service.exported.interfaces" type="String" value="*"/>
>       <property name="service.exported.configs" type="String" value="org.apache.cxf.rs"/>
>       <property name="service.exported.intents" type="String" value="HTTP"/>
>       <property name="org.apache.cxf.rs.address" type="String" value="http://localhost:9090/persons/"/>
>       <property name="org.apache.cxf.rs.databinding" type="String">
>           org.apache.cxf.jaxrs.provider.JAXBProvider
>           org.apache.cxf.jaxrs.provider.JSONProvider
>       </property>
>       <property name="service.pid" value="VzServiceRestComponent"/>
>       <reference name="vzService" interface="de.uniluebeck.itm.soapraktikum.ws0910.persons.vz.VzService"
cardinality="1..1" policy="static" bind="bindVzService" unbind="unbindVzService"/>
>   </scr:component>
> </components>
> 
> Am 27.01.2010 um 16:03 schrieb Daniel Bimschas:
> 
>> Would DOSGi RI 1.1 work with http://repo1.maven.org/maven2/org/codehaus/jettison/jettison/1.2/jettison-1.2.jar
or is there any reason it would not?
>> 
>> Am 27.01.2010 um 15:49 schrieb Sergey Beryozkin:
>> 
>>> Hi
>>> 
>>> if you use "org.apache.cxf.rs.provider" string property then it's a comma-separated
list of class names, if using declarative services then you need to have a space separated
list of class names listed on separate lines, as shown in the section I linked to.
>>> As we discussed eralier on, there's also an "org.apache.cxf.rs.databinding" property
which is of limited value to JAXRS services at the moment (can have "aegis" or "jaxb" values).
I'm thinking of adding more supported values to it so that one can say : "org.apache.cxf.rs.databinding"="jaxb,json"
instead of typing class names when setting a "org.apache.cxf.rs.provider".
>>> 
>>> Oh, I forgot...DOSGI RI does not ship Jettison (ServiceMix would install it as
part of cxf jaxrs feature), perhaps it should. So if you'd like to use a default CXF JSON
provider (which is Jettison-based) then install either Jettison 1.1 bundle [1] or Jettison
1.2, CXF 2.2.4 (which depends on Jettison 1.1) should accept it too, there's no version range
in the CXF Import-Package for jettison packages
>>> 
>>> Sergey
>>> 
>>> [1] http://repo1.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.jettison/1.0.1_2/
>>> [2] http://docs.codehaus.org/display/JETTISON/2010/01/18/Jettison+1.2+released
>>> 
>>> ----- Original Message ----- From: "Daniel Bimschas" <bimschas@itm.uni-luebeck.de>
>>> To: <users@cxf.apache.org>
>>> Sent: Wednesday, January 27, 2010 2:11 PM
>>> Subject: Re: DOSGi and JSON responses
>>> 
>>> 
>>> Sorry, accidentally sent the last before I finished writing it :)
>>> 
>>> I used maven-scr-plugin to generate the properties of the registered service,
therefore the syntax should be ok now. However, it doesn't seem to work. I keep getting empty
JSON files :( I'll now check out to do it on the greeter_rest sample, see if it works there!
>>> 
>>> Am 27.01.2010 um 10:47 schrieb Sergey Beryozkin:
>>> 
>>>> Hi Daniel
>>>> 
>>>> Please see "Registering custom JAXRS providers" in [1].
>>>> There's a couple of options. One is to to use an "org.apache.cxf.rs.provider"
property which accepts a list of class names, so you can list the provider you need, ex, "org.apache.cxf.jaxrs.provider.JSONProvider",
etc. The other option is to register an instance of say JSONProvider as an OSGI service, this
option is the only way at the moment to have a provider instance configured with some custom
properties...
>>>> 
>>>> To simplify things a bit, I'll probably need to intoduce "json", "atom",
"xbeans", etc for org.apache.cxf.rs.databinding so that users can avoid having to specify
classnames like "org.apache.cxf.jaxrs.provider.JSONProvider" directly...For more advanced
cases we will need to recognize providers configured in Spring (as an alternative to registering
them as OSGI services)...
>>>> 
>>>> cheers, Sergey
>>>> 
>>>> 
>>>> 
>>>> [1] http://cxf.apache.org/distributed-osgi-reference.html#DistributedOSGiReference-ServiceProviderpropertiesForConfiguringRESTfulJAXRSbasedendpointsandconsumers
>>>> 
>>>> ----- Original Message ----- From: "Daniel Bimschas" <bimschas@itm.uni-luebeck.de>
>>>> To: <users@cxf.apache.org>
>>>> Sent: Tuesday, January 26, 2010 9:59 PM
>>>> Subject: DOSGi and JSON responses
>>>> 
>>>> 
>>>> Hi List!
>>>> 
>>>> I've now successfully developed a project that additionally exposes its interfaces
over the DOSGi based JAX-RS implementation as RESTful service. Therefore I've used the JAXB-Binding
which worked fine. However, I couldn't find any information about how to get the JSON responses
working (they are always empty, i.e. 0 bytes of payload). Can somebody help me here and point
me to the right documentation?
>>>> 
>>>> Kind regards,
>>>> Daniel=
>>> 
>>> -- 
>>> M.Sc. Daniel Bimschas
>>> Institute of Telematics, University of Lübeck
>>> http://www.itm.uni-luebeck.de/users/bimschas
>>> Ratzeburger Allee 160, 23538 Lübeck, Germany
>>> Phone: +49 451 500 5389
>>> 
>>> 
>> 
>> -- 
>> M.Sc. Daniel Bimschas
>> Institute of Telematics, University of Lübeck
>> http://www.itm.uni-luebeck.de/users/bimschas
>> Ratzeburger Allee 160, 23538 Lübeck, Germany
>> Phone: +49 451 500 5389
>> 
> 
> -- 
> M.Sc. Daniel Bimschas
> Institute of Telematics, University of Lübeck
> http://www.itm.uni-luebeck.de/users/bimschas
> Ratzeburger Allee 160, 23538 Lübeck, Germany
> Phone: +49 451 500 5389
> 
> 

-- 
M.Sc. Daniel Bimschas
Institute of Telematics, University of Lübeck
http://www.itm.uni-luebeck.de/users/bimschas
Ratzeburger Allee 160, 23538 Lübeck, Germany
Phone: +49 451 500 5389


Mime
View raw message