You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Julien Charon <Ju...@avitech.aero> on 2015/12/14 09:23:12 UTC

CXF 3.0.7 JAXRS POST read body

  Hi everybody,


I am currently refactoring a REST application whose implementation is based on a subclass of javax.servlet.http.HttpServlet and thus is using javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse quite extensively to use CXF and JAXRS.
The refactored version of the application extends org.apache.cxf.transport.servlet.CXFNonSpringServlet and is using a service class which defines methods using the javax.ws.rs.core.Context annotation to obtain HttpServletRequest objets, e.g.

                @POST
                public void doPost(@Context HttpServletRequest request, @Context HttpServletResponse response)  {
                               ...
                }

Now, for GET operations this works as expected. When I try to read the body of a POST request using the javax.servlet.ServletRequest.getInputStream(), the returned InputStream ist empty.
According to JAX-RS spec, I guess I could extend my method to something like

                @POST
                public void doPost(@Context HttpServletRequest request, @Context HttpServletResponse response, String body)  {
                               ...
                }

in order to get the body. However, I'd like to avoid that because I don't want to change the existing application implementation too much.
So  I have 2 questions:

1.       Why does javax.servlet.ServletRequest.getInputStream() return an InputStream that contains no data whe I using CXF? This work fine in the old style of the application.

2.       What can I do to be able to read the body that way using CXF?


Viele Grüße,
Julien

Avitech GmbH
Engineering AxL
Tel.: +49 (0)7541/282-177
Fax: +49 (0)7541/282-199
e-mail: julien.charon@avitech.aero<ma...@avitech.aero>
________________________________________________
Avitech GmbH
Principal Office: Bahnhofplatz 1 | 88045 Friedrichshafen | Germany
Court Registration: Amtsgericht Ulm | HRB 728293
Geschäftsführer/Managing Director: Antonio Maria Gonzalez Gorostiza
http://avitech.aero<http://avitech.aero/>

This message may contain confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.


AW: CXF 3.0.7 JAXRS POST read body

Posted by Julien Charon <Ju...@avitech.aero>.
  Hi,


Thanks Sergey. You're right, I should make use of the JAX-RS mechanisms. But because I already ran into some problems, I am a little bit concerned facing further more severe problems especially when it comes to chunking etc. So I'd like to be able to run both variants of our application in parallel or to be able to switch back to the old variant at any time. 


Best regards,
 
Julien 

Avitech GmbH
Engineering AxL
Tel.: +49 (0)7541/282-177
Fax: +49 (0)7541/282-199
e-mail: julien.charon@avitech.aero
________________________________________________
Avitech GmbH
Principal Office: Bahnhofplatz 1 | 88045 Friedrichshafen | Germany
Court Registration: Amtsgericht Ulm | HRB 728293
Geschäftsführer/Managing Director: Antonio Maria Gonzalez Gorostiza
http://avitech.aero

This message may contain confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.

Hi

Perhaps it is supposed to work with JAX-RS, so I've fixed it as part of
https://issues.apache.org/jira/browse/CXF-6709

I'd still recommend you to avoid dealing with Servlet request/response directly - one of the main ideas of JAX-RS was to provide a simpler/alternative mechanism.

Thanks, Sergey

On 14/12/15 08:23, Julien Charon wrote:
>    Hi everybody,
>
>
> I am currently refactoring a REST application whose implementation is based on a subclass of javax.servlet.http.HttpServlet and thus is using javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse quite extensively to use CXF and JAXRS.
> The refactored version of the application extends org.apache.cxf.transport.servlet.CXFNonSpringServlet and is using a service class which defines methods using the javax.ws.rs.core.Context annotation to obtain HttpServletRequest objets, e.g.
>
>                  @POST
>                  public void doPost(@Context HttpServletRequest request, @Context HttpServletResponse response)  {
>                                 ...
>                  }
>
> Now, for GET operations this works as expected. When I try to read the body of a POST request using the javax.servlet.ServletRequest.getInputStream(), the returned InputStream ist empty.
> According to JAX-RS spec, I guess I could extend my method to 
> something like
>
>                  @POST
>                  public void doPost(@Context HttpServletRequest request, @Context HttpServletResponse response, String body)  {
>                                 ...
>                  }
>
> in order to get the body. However, I'd like to avoid that because I don't want to change the existing application implementation too much.
> So  I have 2 questions:
>
> 1.       Why does javax.servlet.ServletRequest.getInputStream() return an InputStream that contains no data whe I using CXF? This work fine in the old style of the application.
>
> 2.       What can I do to be able to read the body that way using CXF?
>
>
> Viele Grüße,
> Julien
>
> Avitech GmbH
> Engineering AxL
> Tel.: +49 (0)7541/282-177
> Fax: +49 (0)7541/282-199
> e-mail: julien.charon@avitech.aero<ma...@avitech.aero>
> ________________________________________________
> Avitech GmbH
> Principal Office: Bahnhofplatz 1 | 88045 Friedrichshafen | Germany 
> Court Registration: Amtsgericht Ulm | HRB 728293 
> Geschäftsführer/Managing Director: Antonio Maria Gonzalez Gorostiza 
> http://avitech.aero<http://avitech.aero/>
>
> This message may contain confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.
>
>


--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Re: CXF 3.0.7 JAXRS POST read body

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

Perhaps it is supposed to work with JAX-RS, so I've fixed it as part of
https://issues.apache.org/jira/browse/CXF-6709

I'd still recommend you to avoid dealing with Servlet request/response 
directly - one of the main ideas of JAX-RS was to provide a 
simpler/alternative mechanism.

Thanks, Sergey

On 14/12/15 08:23, Julien Charon wrote:
>    Hi everybody,
>
>
> I am currently refactoring a REST application whose implementation is based on a subclass of javax.servlet.http.HttpServlet and thus is using javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse quite extensively to use CXF and JAXRS.
> The refactored version of the application extends org.apache.cxf.transport.servlet.CXFNonSpringServlet and is using a service class which defines methods using the javax.ws.rs.core.Context annotation to obtain HttpServletRequest objets, e.g.
>
>                  @POST
>                  public void doPost(@Context HttpServletRequest request, @Context HttpServletResponse response)  {
>                                 ...
>                  }
>
> Now, for GET operations this works as expected. When I try to read the body of a POST request using the javax.servlet.ServletRequest.getInputStream(), the returned InputStream ist empty.
> According to JAX-RS spec, I guess I could extend my method to something like
>
>                  @POST
>                  public void doPost(@Context HttpServletRequest request, @Context HttpServletResponse response, String body)  {
>                                 ...
>                  }
>
> in order to get the body. However, I'd like to avoid that because I don't want to change the existing application implementation too much.
> So  I have 2 questions:
>
> 1.       Why does javax.servlet.ServletRequest.getInputStream() return an InputStream that contains no data whe I using CXF? This work fine in the old style of the application.
>
> 2.       What can I do to be able to read the body that way using CXF?
>
>
> Viele Grüße,
> Julien
>
> Avitech GmbH
> Engineering AxL
> Tel.: +49 (0)7541/282-177
> Fax: +49 (0)7541/282-199
> e-mail: julien.charon@avitech.aero<ma...@avitech.aero>
> ________________________________________________
> Avitech GmbH
> Principal Office: Bahnhofplatz 1 | 88045 Friedrichshafen | Germany
> Court Registration: Amtsgericht Ulm | HRB 728293
> Geschäftsführer/Managing Director: Antonio Maria Gonzalez Gorostiza
> http://avitech.aero<http://avitech.aero/>
>
> This message may contain confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system.
>
>


-- 
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/