dev@glassfish.java.net

Re: BUG in GF v2/v3 when reading parameters <was> Fwd: [Jersey] Tomcat Deployment Vs. Jetty Deployment -- no parameters from HttpServletRequest

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Wed, 19 Nov 2008 11:40:14 -0500

Salut,

I've filled:

https://glassfish.dev.java.net/issues/show_bug.cgi?id=6817

to track the issue. Will takes a look as soon as possible.

A+

-Jeanfrancois

Paul Sandoz wrote:
> If the InputStream of the HttpServletRequest is obtained then it is not
> possible to read URL encoded parameters sent in the request. This works
> with Jetty, but not with Tomcat to GF v2/v3.
>
> Paul.
>
> Begin forwarded message:
>
>> *From: *Paul Sandoz <Paul.Sandoz_at_Sun.COM <mailto:Paul.Sandoz_at_Sun.COM>>
>> *Date: *November 19, 2008 11:36:08 AM CEST
>> *To: *users_at_jersey.dev.java.net <mailto:users_at_jersey.dev.java.net>
>> *Subject: **Re: [Jersey] Tomcat Deployment Vs. Jetty Deployment -- no
>> parameters from HttpServletRequest*
>> *Reply-To: *users_at_jersey.dev.java.net <mailto:users_at_jersey.dev.java.net>
>>
>> Hi Davis,
>>
>> It is a bug in Tomcat and also Glassfish (i tried with v2 and v3 and
>> can reproduce the same behaviour). It is because Jersey obtains the
>> InputStream instance from the HttpServletRequest which is disabling
>> the form parsing of the parameters in the request, even though no
>> bytes have been read from the stream (at the end of the email is a
>> servlet that reproduces the same bug).
>>
>> You can do this instead:
>>
>> @POST
>> @Produces("text/html")
>> @Consumes("application/x-www-form-urlencoded")
>> public String doPost(@FormParam("x") String x, @Context
>> HttpRequestContext request) {
>> Form f = request.getFormParameters();
>> }
>>
>> But take care that there are no valves in Tomcat logging parameters
>> otherwise Tomcat will consume the request and there will be nothing
>> left for Jersey to read.
>>
>> Paul.
>>
>> public class NewServlet extends HttpServlet {
>>
>> public void service(HttpServletRequest request, HttpServletResponse
>> response)
>> throws ServletException, IOException {
>> InputStream in = request.getInputStream();
>> Map map = request.getParameterMap();
>> if(map.isEmpty()) {
>> System.out.println("request has no parameters");
>> }
>> for(Object key : map.keySet()) {
>> System.out.println("key: "+key+" value: "+map.get(key));
>> }
>> }
>> }
>>
>> On Nov 18, 2008, at 10:29 PM, Davis Ford wrote:
>>
>>> Hi I built a simple service that accepts @POST.
>>>
>>> @Path("/incoming-fax")
>>> public class EfaxServlet {
>>>
>>> @POST
>>> @Produces("text/html")
>>> @Consumes("application/x-www-form-urlencoded")
>>> public String doPost(@Context HttpServletRequest request) {
>>> etc...
>>> }
>>>
>>> I expect a parameter named "xml" to be posted that contains the full
>>> XML string contents.
>>>
>>> This is a maven project, and if I run:
>>>
>>> $ mvn jetty:run-war
>>>
>>> And then use curl to send the content like so:
>>>
>>> curl -v --data-urlencode xml_at_inbound-post-original.xml
>>> <mailto:xml_at_inbound-post-original.xml> -H
>>> "Content-Type:application/x-www-form-urlencoded"
>>> http://localhost:8080/efax/incoming-fax
>>>
>>> it works like a charm....
>>>
>>> If I switch over to Tomcat, either via mvn using "mvn tomcat:run-war"
>>> or else starting Tomcat 6 myself after dropping my .war file in there,
>>> I never receive any paramters from the HttpServletRequest.
>>>
>>> I added this snippet to the @POST method:
>>>
>>> Map<String, String> map = request.getParameterMap();
>>> if(map.isEmpty()) {
>>> LOGGER.error("request has no parameters");
>>> }
>>> for(String key : map.keySet()) {
>>> LOGGER.error("key: "+key+" value: "+map.get(key));
>>> }
>>>
>>> If I run this with Jetty, it sees "xml" parameter, but if I run the
>>> same on Tomcat, it sees no parameters at all.
>>>
>>> I'm really not seeing the problem here. Can anyone provide a clue
>>> what might be going on?? My thanks in advance.
>>>
>>> Regards,
>>> Davis
>>>
>>> My web.xml is below:
>>>
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
>>> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
>>> <servlet>
>>> <servlet-name>ServletAdaptor</servlet-name>
>>> <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
>>> <load-on-startup>1</load-on-startup>
>>> <!-- other init-param here -->
>>> </servlet>
>>> <servlet-mapping>
>>> <servlet-name>ServletAdaptor</servlet-name>
>>> <url-pattern>/*</url-pattern>
>>> </servlet-mapping>
>>> <session-config>
>>> <session-timeout>30</session-timeout>
>>> </session-config>
>>> <welcome-file-list>
>>> <welcome-file>index.jsp</welcome-file>
>>> </welcome-file-list>
>>> </web-app>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> <mailto:users-unsubscribe_at_jersey.dev.java.net>
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>> <mailto:users-help_at_jersey.dev.java.net>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> <mailto:users-unsubscribe_at_jersey.dev.java.net>
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>> <mailto:users-help_at_jersey.dev.java.net>
>>
>