You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Jan Hoeve <j....@gmail.com> on 2014/06/06 08:27:12 UTC
Why is the Content-Length header copied from request to response?
Hi all,
I encountered some strange behavior when using CXF with camel (using the
cxfrs component).
I have a route builder like:
from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer&resourceClasses=my.own.ResourceClass)
.bean(myBean, "myMethod")
Jetty is used as a transport mechanism.
When I use GET for my REST requestst, everything is fine.
However, when using POST, and supplying a (xml) body in the request, the
client does not get the expected response back, but a truncated version.
(okay, not exactly true.. the client does get all contents, but only SHOWS
a part of that content)
Say: my request looks like:
<helloWorld />
Then the response shown in the client (all clients: soapui, postman
(chrome), poster (firefox)) are like:
<?xml version=
Please note this should be a complete xml document, with some
<helloWorldResponse/> in it, but not shown at the moment.
Further investigations showed that the Content-Length header in the
response was 14, which is _exactly_ the length of the request body! The
client truncates the response to this content-length header value.
I thought that was just strange, so did some debugging.
Findings:
In org.apache.cxf.transport.http.Headers.copyFromRequest(HttpServletRequest)
all request headers (including the reqest Content-Length) are copied into
some field called 'headers'.
When creating the http servlet response
via org.apache.cxf.transport.http.Headers.copyToResponse(HttpServletResponse),
all headers present in the field 'headers' are copied onto the
HttpServletResponse.
--> there is my problem! The Content-Length header just getting copied from
request to response, forcing clients to truncate the response!
By the way: Jetty sees this, and emits a DEBUG msg saying:
org.eclipse.jetty.http.AbstractGenerator - ContentLength written==80 !=
contentLength==14
In a nutshell: I think the Content-Length headers should not be just copied
from request to response.
What do you think, is this a bug or some misunderstanding on my side?
Some info about the used jars:
camel:2.12.3
cxf:2.7.10
cxf-rt-transports-http-jetty:2.7.10
Thanks for your comments,
Jan Hoeve
Re: Why is the Content-Length header copied from request to response?
Posted by Jan Hoeve <j....@gmail.com>.
Thanks Alexey!
I just voted for that issue and posted a workaround there.
c/p to this mailinglist:
from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer&resourceClasses=my.own.ResourceClass)
.removeHeader("Content-Length") // <!-- workaround.. just remove the
incoming header so it cannot do any harm
.bean(myBean, "myMethod")
On Fri, Jun 6, 2014 at 9:19 AM, Alexey Markevich <am...@talend.com>
wrote:
> Hi Jan,
>
> https://issues.apache.org/jira/browse/CAMEL-7246
>
>
> On Fri, 06 Jun 2014 09:27:12 +0300, Jan Hoeve <j....@gmail.com> wrote:
>
> Hi all,
>>
>> I encountered some strange behavior when using CXF with camel (using the
>> cxfrs component).
>> I have a route builder like:
>>
>> from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer&
>> resourceClasses=my.own.ResourceClass)
>> .bean(myBean, "myMethod")
>> Jetty is used as a transport mechanism.
>>
>> When I use GET for my REST requestst, everything is fine.
>> However, when using POST, and supplying a (xml) body in the request, the
>> client does not get the expected response back, but a truncated version.
>> (okay, not exactly true.. the client does get all contents, but only SHOWS
>> a part of that content)
>>
>> Say: my request looks like:
>> <helloWorld />
>> Then the response shown in the client (all clients: soapui, postman
>> (chrome), poster (firefox)) are like:
>> <?xml version=
>>
>> Please note this should be a complete xml document, with some
>> <helloWorldResponse/> in it, but not shown at the moment.
>>
>> Further investigations showed that the Content-Length header in the
>> response was 14, which is _exactly_ the length of the request body! The
>> client truncates the response to this content-length header value.
>> I thought that was just strange, so did some debugging.
>>
>> Findings:
>> In org.apache.cxf.transport.http.Headers.copyFromRequest(
>> HttpServletRequest)
>> all request headers (including the reqest Content-Length) are copied into
>> some field called 'headers'.
>> When creating the http servlet response
>> via org.apache.cxf.transport.http.Headers.copyToResponse(
>> HttpServletResponse),
>> all headers present in the field 'headers' are copied onto the
>> HttpServletResponse.
>> --> there is my problem! The Content-Length header just getting copied
>> from
>> request to response, forcing clients to truncate the response!
>>
>> By the way: Jetty sees this, and emits a DEBUG msg saying:
>> org.eclipse.jetty.http.AbstractGenerator - ContentLength written==80 !=
>> contentLength==14
>>
>> In a nutshell: I think the Content-Length headers should not be just
>> copied
>> from request to response.
>> What do you think, is this a bug or some misunderstanding on my side?
>>
>> Some info about the used jars:
>> camel:2.12.3
>> cxf:2.7.10
>> cxf-rt-transports-http-jetty:2.7.10
>>
>> Thanks for your comments,
>> Jan Hoeve
>>
>
>
> --
> Regards, Alexey.
>
Re: Why is the Content-Length header copied from request to response?
Posted by Alexey Markevich <am...@talend.com>.
Hi Jan,
https://issues.apache.org/jira/browse/CAMEL-7246
On Fri, 06 Jun 2014 09:27:12 +0300, Jan Hoeve <j....@gmail.com> wrote:
> Hi all,
>
> I encountered some strange behavior when using CXF with camel (using the
> cxfrs component).
> I have a route builder like:
>
> from("cxfrs:bean:rsServer?bindingStyle=SimpleConsumer&resourceClasses=my.own.ResourceClass)
> .bean(myBean, "myMethod")
> Jetty is used as a transport mechanism.
>
> When I use GET for my REST requestst, everything is fine.
> However, when using POST, and supplying a (xml) body in the request, the
> client does not get the expected response back, but a truncated version.
> (okay, not exactly true.. the client does get all contents, but only
> SHOWS
> a part of that content)
>
> Say: my request looks like:
> <helloWorld />
> Then the response shown in the client (all clients: soapui, postman
> (chrome), poster (firefox)) are like:
> <?xml version=
>
> Please note this should be a complete xml document, with some
> <helloWorldResponse/> in it, but not shown at the moment.
>
> Further investigations showed that the Content-Length header in the
> response was 14, which is _exactly_ the length of the request body! The
> client truncates the response to this content-length header value.
> I thought that was just strange, so did some debugging.
>
> Findings:
> In
> org.apache.cxf.transport.http.Headers.copyFromRequest(HttpServletRequest)
> all request headers (including the reqest Content-Length) are copied into
> some field called 'headers'.
> When creating the http servlet response
> via
> org.apache.cxf.transport.http.Headers.copyToResponse(HttpServletResponse),
> all headers present in the field 'headers' are copied onto the
> HttpServletResponse.
> --> there is my problem! The Content-Length header just getting copied
> from
> request to response, forcing clients to truncate the response!
>
> By the way: Jetty sees this, and emits a DEBUG msg saying:
> org.eclipse.jetty.http.AbstractGenerator - ContentLength written==80 !=
> contentLength==14
>
> In a nutshell: I think the Content-Length headers should not be just
> copied
> from request to response.
> What do you think, is this a bug or some misunderstanding on my side?
>
> Some info about the used jars:
> camel:2.12.3
> cxf:2.7.10
> cxf-rt-transports-http-jetty:2.7.10
>
> Thanks for your comments,
> Jan Hoeve
--
Regards, Alexey.