You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jose María Zaragoza <de...@gmail.com> on 2014/02/18 13:26:43 UTC
CustomRequestHandler to modify HTTP Content-Type header
Hello:
I'm using CXF 2.7.8 + JAX-RS to deploy a REST webservice
I've defined a RequestHandler to modify HTTP Content-Type header for
incoming request
But it doesnt work
MyRequestHandler class implements
@Override
public Response handleRequest(Message message, ClassResourceInfo info)
{
message.put(Message.CONTENT_TYPE, MediaType.APPLICATION_JSON);
message.put(Message.ACCEPT_CONTENT_TYPE, MediaType.APPLICATION_JSON);
logger.info("New Content-Type {}", message.get(Message.CONTENT_TYPE));
return null;
}
And I configure
<jaxrs:providers>
<ref bean="myRequestHandler"/>
<ref bean="jsonProvider"/>
</jaxrs:providers>
When the webservice receives a request with ContentType :
application/x-www-form-urlencoded,
logs show that Content-Type header wan't modified before selecting method
13:23:23.605 [http-bio-8080-exec-138] INFO [MyRequestHandler]
[handleRequest] - New Content-Type application/json
13:23:23.605 [http-bio-8080-exec-138] DEBUG [JAXRSUtils]
[findTargetMethod] - Trying to select a resource operation on the
resource class com.ws.MyService
13:23:23.606 [http-bio-8080-exec-138] DEBUG [JAXRSUtils]
[logNoMatchMessage] - No method match, method name : notify, request
path : /notify, method @Path : /notify, HTTP Method : POST, method
HTTP Method : POST, ContentType : application/x-www-form-urlencoded,
method @Consumes : application/json,, Accept : application/json,,
method @Produces : application/json,.
What is wrong ? Do I need to do it with an interceptor ? Any example '
Thanks and regards
Re: CustomRequestHandler to modify HTTP Content-Type header
Posted by Jose María Zaragoza <de...@gmail.com>.
2014-02-18 13:40 GMT+01:00 Sergey Beryozkin <sb...@gmail.com>:
> Hi
>
> in CXF 2.7.8 you should be able to use PreMatch ContainerRequestFilter, or
> pure CXF in interceptor running before JAXRSInInterceptor
>
> CXF RequestHandler filter tries to cover all of the cases, example, some
> request filters want to know of the actual selected method, so CXF tries to
> find a method even before the filters are invoked, so effectively changing
> Content-Type inside a handler won't have the expected effect, I think
> changing Accept-Type might in CXF 2.7.8, but
> basically you'd be better of using PreMatch ContainerRequestFilter
Thanks.
I didn't see that RequestHandler/ResponseHandler are deprecated in 2.7.x
With PreMatch ContainerRequestFilter, it works fine .
Regards
Re: CustomRequestHandler to modify HTTP Content-Type header
Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi
in CXF 2.7.8 you should be able to use PreMatch ContainerRequestFilter,
or pure CXF in interceptor running before JAXRSInInterceptor
CXF RequestHandler filter tries to cover all of the cases, example, some
request filters want to know of the actual selected method, so CXF tries
to find a method even before the filters are invoked, so effectively
changing Content-Type inside a handler won't have the expected effect, I
think changing Accept-Type might in CXF 2.7.8, but
basically you'd be better of using PreMatch ContainerRequestFilter
Give it a try please
Sergey
On 18/02/14 12:26, Jose María Zaragoza wrote:
> Hello:
>
> I'm using CXF 2.7.8 + JAX-RS to deploy a REST webservice
>
> I've defined a RequestHandler to modify HTTP Content-Type header for
> incoming request
>
> But it doesnt work
>
>
> MyRequestHandler class implements
>
> @Override
> public Response handleRequest(Message message, ClassResourceInfo info)
> {
> message.put(Message.CONTENT_TYPE, MediaType.APPLICATION_JSON);
> message.put(Message.ACCEPT_CONTENT_TYPE, MediaType.APPLICATION_JSON);
> logger.info("New Content-Type {}", message.get(Message.CONTENT_TYPE));
> return null;
> }
>
> And I configure
>
> <jaxrs:providers>
> <ref bean="myRequestHandler"/>
> <ref bean="jsonProvider"/>
> </jaxrs:providers>
>
>
>
> When the webservice receives a request with ContentType :
> application/x-www-form-urlencoded,
> logs show that Content-Type header wan't modified before selecting method
>
> 13:23:23.605 [http-bio-8080-exec-138] INFO [MyRequestHandler]
> [handleRequest] - New Content-Type application/json
> 13:23:23.605 [http-bio-8080-exec-138] DEBUG [JAXRSUtils]
> [findTargetMethod] - Trying to select a resource operation on the
> resource class com.ws.MyService
> 13:23:23.606 [http-bio-8080-exec-138] DEBUG [JAXRSUtils]
> [logNoMatchMessage] - No method match, method name : notify, request
> path : /notify, method @Path : /notify, HTTP Method : POST, method
> HTTP Method : POST, ContentType : application/x-www-form-urlencoded,
> method @Consumes : application/json,, Accept : application/json,,
> method @Produces : application/json,.
>
>
>
> What is wrong ? Do I need to do it with an interceptor ? Any example '
>
> Thanks and regards
>
--
Sergey Beryozkin
Talend Community Coders
http://coders.talend.com/
Blog: http://sberyozkin.blogspot.com