You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Vincenzo Vitale <vi...@gmail.com> on 2010/03/03 17:16:57 UTC

Re: Wrong Content type set in REST web services

Email with the war sent...

BTW in the meanwhile I fixed it  (always I'm not doing something
wrong) with a responsehandler and this code:

return Response.fromResponse(response).type(MediaType.TEXT_HTML).build();


Cheers,
V.

On Fri, Jan 29, 2010 at 5:41 PM, Sergey Beryozkin <sb...@progress.com> wrote:
> Hi
>
> I'll need to have a self-contained test war to have this issue reproduced.
> Or please post the sample code here.
>
> Here is the test which works for me :
>
> @Test
>
> public void testAddBookCustomFailureStatus() throws Exception {
>
> String endpointAddress =
> "http://localhost:9080/bookstore/books/customstatus";
>
> WebClient client = WebClient.create(endpointAddress);
>
> Book book = client.type("text/xml").accept("application/xml").post(new
> Book(), Book.class);
>
> assertEquals(888L, book.getId());
>
> Response r = client.getResponse();
>
> assertEquals("CustomValue", r.getMetadata().getFirst("CustomHeader"));
>
> assertEquals(333, r.getStatus());
>
> assertEquals("application/xml", r.getMetadata().getFirst("Content-Type"));
>
> }
>
> this is the service method which sets the headers and the staus directly on
> the response but the application/xml and the book are dealt with later on...
>
> @POST
>
> @Path("/books/customstatus")
>
> @Produces("application/xml")
>
> @Consumes("text/xml")
>
> public Book addBookCustomFailure(Book book, @Context HttpServletResponse
> response) {
>
> response.setStatus(333);
>
> response.addHeader("CustomHeader", "CustomValue");
>
> book.setId(888);
>
> return book;
>
> }
>
>
>
> cheers, Sergey
>
>
>
> ----- Original Message ----- From: "Vincenzo Vitale"
> <vi...@gmail.com>
> To: "users" <us...@cxf.apache.org>
> Sent: Thursday, January 28, 2010 5:26 PM
> Subject: Re: Wrong Content type set in REST web services
>
>
>> yes, not touching the header at all doesn't change the result.
>>
>> On Thu, Jan 28, 2010 at 5:51 PM, Sergey Beryozkin
>> <sb...@progress.com>wrote:
>>
>>> Hi
>>>
>>> I'll need more info please. I belive you're writing some custom headers
>>> directly into HttpServletResponse ? Will you see text/html if you don't
>>> write directly to the HttpServletResponse ?
>>>
>>> Sergey
>>>
>>>
>>>  Hi,
>>>>
>>>> I have a service exposed like this:
>>>>
>>>>  @POST
>>>>  @Path("/login")
>>>>  @Produces( { MediaType.TEXT_HTML })
>>>>  @Consumes( { MediaType.APPLICATION_FORM_URLENCODED })
>>>>  public void login(@FormParam("username") String username,
>>>>          @FormParam("password") String password,
>>>>          @FormParam("rememberMe") boolean rememberMe,
>>>>          @FormParam("redirect") String redirect)
>>>>
>>>>
>>>> and in spring:
>>>>
>>>>    <jaxrs:server id="atomWfeAuthenticationRestWebService"
>>>> address="/wfe/authentication">
>>>> <jaxrs:serviceBeans>
>>>> <ref bean="atomWfeAuthenticationWebService" />
>>>> </jaxrs:serviceBeans>
>>>> <jaxrs:providers>
>>>> <ref bean="atomFeedProvider" />
>>>> <ref bean="cacheDisabledFilter" />
>>>> </jaxrs:providers>
>>>> </jaxrs:server>
>>>>
>>>>
>>>> the problem is that the content type set is alwasy "text/xml" instead of
>>>> the
>>>> correct one.
>>>>
>>>>
>>>> Any clue on this?
>>>>
>>>>
>>>>
>>>> Tks,
>>>> Vincenzo.
>>>>
>>>>
>>>
>>
>
>