You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Salomo Petrus <sa...@gmail.com> on 2009/05/08 13:42:32 UTC

MessageBodyReader not picked up

Hi,

I am trying to map a post parameter which contains XML to an Object using a
MessageBodyReader to do the XML transformation so the web service itself is
not aware of the XML stuff. This worked fine with a MessageBodyWriter but
for some reason I cannot get the MessageBodyReader to work. :-((

I keep on getting this message:
... no constructor with single String parameter, static valueof(String) or
fromString(String) methods.

This is the implementation of the MessageBodyReader:
@Consumes("application/x-www-form-urlencoded")
@Provider
public class AgentWorkItemProvider implements
MessageBodyReader<AgentWorkItem> {

	public AgentWorkItem readFrom(Class<AgentWorkItem> type, Type genericType,
			Annotation[] annotations, MediaType mediaType,
			MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
			throws IOException, WebApplicationException {
		BosFeaturesRequest bosFeaturesRequest = XMLBinder.create(
				BosFeaturesRequest.class, entityStream);

		return bosFeaturesRequest;
	}

	public boolean isReadable(Class<?> type, Type genericType,
			Annotation[] annotations, MediaType mediaType) {
		return AgentWorkItem.class.isAssignableFrom(type);
	}

}

I registered the provider with Spring like this:
	<jaxrs:server id="agentRestWebService" address="/agent-service">
		<jaxrs:serviceBeans>
			<ref bean="receiveAgentWebService" />
		</jaxrs:serviceBeans>
		<jaxrs:providers>
			<ref bean="agentWorkItemProvider" />
		</jaxrs:providers>
	</jaxrs:server>

The service method looks like this:
@POST
@Consumes("application/x-www-form-urlencoded")
@Path("/process/")
public String process(@FormParam("item") final AgentWorkItem item) {

	if (log.isInfoEnabled()) {
		log.info("Processing.. " + item);
	}

	return "Work item processed: " + item;
}

Can somebody help me out?

Thanks in advance.

Cheers,

Salomo


-- 
View this message in context: http://www.nabble.com/MessageBodyReader-not-picked-up-tp23444478p23444478.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: MessageBodyReader not picked up

Posted by Salomo Petrus <sa...@gmail.com>.
Thanks a lot Sergey.. It works fine now :jumping:


Sergey Beryozkin-2 wrote:
> 
> Hi
> 
> Method parameters marked as JAX-RS parameters (@FormParam in this case)
> are not handled by MessageBodyReaders.
> MessageBodyReaders are checked only if a method parameter has no JAX-RS
> parameter annotations.
> For this case you might want to register a
> ParameterHandler<AgentWorkItem>, see here please for more info :
> 
> http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-DealingwithParameters
> 
> so you'll have somethig like :
> 
> AgentParameterHandler implements ParameterHandler<AgentWorkItem> {
>  public AgentWorkItem fromString(String){}
> } 
> 
> Hope it helps
> Cheers, Sergey
> 
>> 
>> Hi,
>> 
>> I am trying to map a post parameter which contains XML to an Object using
>> a
>> MessageBodyReader to do the XML transformation so the web service itself
>> is
>> not aware of the XML stuff. This worked fine with a MessageBodyWriter but
>> for some reason I cannot get the MessageBodyReader to work. :-((
>> 
>> I keep on getting this message:
>> ... no constructor with single String parameter, static valueof(String)
>> or
>> fromString(String) methods.
>> 
>> This is the implementation of the MessageBodyReader:
>> @Consumes("application/x-www-form-urlencoded")
>> @Provider
>> public class AgentWorkItemProvider implements
>> MessageBodyReader<AgentWorkItem> {
>> 
>> public AgentWorkItem readFrom(Class<AgentWorkItem> type, Type
>> genericType,
>> Annotation[] annotations, MediaType mediaType,
>> MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
>> throws IOException, WebApplicationException {
>> BosFeaturesRequest bosFeaturesRequest = XMLBinder.create(
>> BosFeaturesRequest.class, entityStream);
>> 
>> return bosFeaturesRequest;
>> }
>> 
>> public boolean isReadable(Class<?> type, Type genericType,
>> Annotation[] annotations, MediaType mediaType) {
>> return AgentWorkItem.class.isAssignableFrom(type);
>> }
>> 
>> }
>> 
>> I registered the provider with Spring like this:
>> <jaxrs:server id="agentRestWebService" address="/agent-service">
>> <jaxrs:serviceBeans>
>> <ref bean="receiveAgentWebService" />
>> </jaxrs:serviceBeans>
>> <jaxrs:providers>
>> <ref bean="agentWorkItemProvider" />
>> </jaxrs:providers>
>> </jaxrs:server>
>> 
>> The service method looks like this:
>> @POST
>> @Consumes("application/x-www-form-urlencoded")
>> @Path("/process/")
>> public String process(@FormParam("item") final AgentWorkItem item) {
>> 
>> if (log.isInfoEnabled()) {
>> log.info("Processing.. " + item);
>> }
>> 
>> return "Work item processed: " + item;
>> }
>> 
>> Can somebody help me out?
>> 
>> Thanks in advance.
>> 
>> Cheers,
>> 
>> Salomo
>> 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/MessageBodyReader-not-picked-up-tp23444478p23444478.html
>> Sent from the cxf-user mailing list archive at Nabble.com.
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/MessageBodyReader-not-picked-up-tp23444478p23446106.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: MessageBodyReader not picked up

Posted by Sergey Beryozkin <sb...@progress.com>.
Hi

Method parameters marked as JAX-RS parameters (@FormParam in this case) are not handled by MessageBodyReaders.
MessageBodyReaders are checked only if a method parameter has no JAX-RS parameter annotations.
For this case you might want to register a ParameterHandler<AgentWorkItem>, see here please for more info :

http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-DealingwithParameters

so you'll have somethig like :

AgentParameterHandler implements ParameterHandler<AgentWorkItem> {
 public AgentWorkItem fromString(String){}
} 

Hope it helps
Cheers, Sergey

> 
> Hi,
> 
> I am trying to map a post parameter which contains XML to an Object using a
> MessageBodyReader to do the XML transformation so the web service itself is
> not aware of the XML stuff. This worked fine with a MessageBodyWriter but
> for some reason I cannot get the MessageBodyReader to work. :-((
> 
> I keep on getting this message:
> ... no constructor with single String parameter, static valueof(String) or
> fromString(String) methods.
> 
> This is the implementation of the MessageBodyReader:
> @Consumes("application/x-www-form-urlencoded")
> @Provider
> public class AgentWorkItemProvider implements
> MessageBodyReader<AgentWorkItem> {
> 
> public AgentWorkItem readFrom(Class<AgentWorkItem> type, Type genericType,
> Annotation[] annotations, MediaType mediaType,
> MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
> throws IOException, WebApplicationException {
> BosFeaturesRequest bosFeaturesRequest = XMLBinder.create(
> BosFeaturesRequest.class, entityStream);
> 
> return bosFeaturesRequest;
> }
> 
> public boolean isReadable(Class<?> type, Type genericType,
> Annotation[] annotations, MediaType mediaType) {
> return AgentWorkItem.class.isAssignableFrom(type);
> }
> 
> }
> 
> I registered the provider with Spring like this:
> <jaxrs:server id="agentRestWebService" address="/agent-service">
> <jaxrs:serviceBeans>
> <ref bean="receiveAgentWebService" />
> </jaxrs:serviceBeans>
> <jaxrs:providers>
> <ref bean="agentWorkItemProvider" />
> </jaxrs:providers>
> </jaxrs:server>
> 
> The service method looks like this:
> @POST
> @Consumes("application/x-www-form-urlencoded")
> @Path("/process/")
> public String process(@FormParam("item") final AgentWorkItem item) {
> 
> if (log.isInfoEnabled()) {
> log.info("Processing.. " + item);
> }
> 
> return "Work item processed: " + item;
> }
> 
> Can somebody help me out?
> 
> Thanks in advance.
> 
> Cheers,
> 
> Salomo
> 
> 
> -- 
> View this message in context: http://www.nabble.com/MessageBodyReader-not-picked-up-tp23444478p23444478.html
> Sent from the cxf-user mailing list archive at Nabble.com.
>