Hi


Hi Sergey,

Does this mean that MessageBodyReaders are only invoked for JAXWS
annotations?

They're not used when JAXWS is involved at all, but on only on the JAXRS path 
in cases like this one :

@POST
void foo(NodeData data)

or

@POST
void foo(@PostParam("a") String a, @QueryParam("b") String b, NodeData data)

That is when a request body is available (as opposed to URI/Query ones) and 
there's only one non-JAXRS annotated parameter is there.

Mapping a JAXRS request to a method like this one :

void foo(String b, NodeData data)

is problematic - we might introduce a custom extension - but I'm not really sure it will be worth it, as having multiple parameters to be unwrapped from a request body in a web service method is problematic on its own anyway

Cheers, Sergey




Sergey Beryozkin-3 wrote:

Hi


I am trying to convert json data into one for our object types required
by a
webservice.

I have not started with the json conversion yet, I just wanted the
framework
in place and ensure that the provider class gets called. But it isn't, so
the service just has the parameter 'queryNodeData' set to null.

I can't see what I am doing wrong.

service snippet:
   @GET
   @Path("search")
   @ConsumeMime("application/json")
   @ProduceMime("application/json")
   public NodeDataMessage search(@QueryParam("querynodedata") final
NodeData queryNodeData) {
   }

MessageBodyReades are not invoked for parameters annotated with
@QueryParam or indeed with other
JAXRS annotations.

suppose you GET request looks like this :

/search?q1=a&q2=b

If you do not want to do

public NodeDataMessage search(@QueryParam("q1") String q1,
@QueryParam("q2") String q2)

then you can rely on a CXF extension (note "" as a queryparam value) :

public NodeDataMessage search((@QueryParam("") final NodeData
queryNodeData)

with NodeData having setQ1 and setQ2 methods

Another aproacj is to have UriInfo injected as a context value and access
query parameters from it

Cheers, Sergey


beans.xml snippet:
<jaxrs:server id="documentServiceRest" address="/rest">
<jaxrs:serviceBeans>
<ref bean="documentServicesFacadeBean" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="nodeDataProviderBean" />
</jaxrs:providers>
</jaxrs:server>
<bean id="nodeDataProviderBean" class="foo.bar.NodeDataProvider" />

provider class:
 package foo.bar
 import ...
 public class NodeDataProvider implements MessageBodyReader<NodeData> {
   public boolean isReadable(Class<?> type, Type genericType,
Annotation[]
annotations) {
       return NodeData.class.isAssignableFrom(type);
   }
   public NodeData readFrom(Class<NodeData> arg0, Type arg1, Annotation[]
arg2, MediaType arg3,
           MultivaluedMap<String, String> arg4, InputStream arg5) throws
IOException,
           WebApplicationException {
       return new NodeData();
   }
}

--
View this message in context:
http://www.nabble.com/MessageBodyReader-implementation-problem-tp20581190p20581190.html
Sent from the cxf-user mailing list archive at Nabble.com.






--
View this message in context: 
http://www.nabble.com/MessageBodyReader-implementation-problem-tp20581190p20582576.html
Sent from the cxf-user mailing list archive at Nabble.com.




Reply via email to