Hi
On 09/11/11 09:25, Carlsson-EXTERNAL Carl-johan wrote:
Hi,
I am trying to replace the content-type header in an incoming message with an
interceptor like this:
public void handleMessage(Message message) throws Fault {
...
String contentType = (String) message.get(Message.CONTENT_TYPE);
if (contentType != null&&
contentType.toLowerCase().indexOf("application/x-www-form-urlencoded") != -1) {
Map<String, List<String>> headers = CastUtils.cast((Map)
message.get(Message.PROTOCOL_HEADERS));
headers.put(Message.CONTENT_TYPE, Arrays.asList(MediaType.TEXT_XML));
}
should be
headers.put("Content-Type", Arrays.asList(MediaType.TEXT_XML));
But the content-type header does not seam to change:
No method match, method name : process, request path : /push, method @Path :
/push,
HTTP Method : POST, method HTTP Method : POST, ContentType :
application/x-www-form-urlencoded
message.put(Message.CONTENT_TYPE, MediaType.TEXT_XML) is the main piece
of code which is missing,
headers.put("Content-Type", Arrays.asList(MediaType.TEXT_XML));
is needed for the application code to be able to get the right values
from the injected HttpHeaders.getRequestHeaders() for example, but as
far as the matching is concerned, it is a Message.CONTENT_TYPE property
which is being checked - this property is there all the time so
it was simpler to use it instead of introspecting the headers map...
Cheers, Sergey
Am I missing something?
Regards,
Carljohan
-----Original Message-----
From: Sergey Beryozkin [mailto:[email protected]]
Sent: den 4 november 2011 16:36
To: [email protected]
Subject: Re: Consume XML POST payload with "application/x-www-form-urlencoded"
content type set
Hi
On 04/11/11 15:10, Carlsson-EXTERNAL Carl-johan wrote:
We got a REST service implemtented in Apache CXF available for our client
exposed like this:
@POST
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.TEXT_PLAIN)
@Path("/process")
public Response processBean(Bean bean);
The Bean object is annotated with @XmlRootElement and all this works great. The problem is that the
client is not setting the right content-type header (should be "application/xml" but
client sets "application/x-form-urlencoded").
Apache CXF is not regonizing the method as a valid method for the (incorrect) call since
the content-type is wrong. If I change @Consumes to "*/*" Apache CXF does not
know how to parse the POST payload (no MessageBodyReader). The client will eventually
change the header but we need a quick fix for now.
The quick fix is to register a RequestHandler filter or CXF in
interceptor which will replace Message.CONTENT_TYPE property on a
current message with "application/xml".
If adding a ?_ctype=xml property to the POST request is an option for
the client then it will do it too
HTH, Sergey
Any ideas?
Regards,
Carljohan