Hi
On 17/10/12 03:18, Puro, Jeff (HBO-NS) wrote:
I have a web application that has a rest method in it that accepts a POST request and 
instead of explicitly defining the @FormParam parameters, I perform a 
request.getParametersMap() call in order to get all the passed form parameters. In a 
normal servlet, this should return all of the form parameters to my application in a Map, 
but I'm seeing strange results when running this under Weblogic versus Tomcat. In 
Weblogic, it behaves correctly, meaning I am able to see all of the parameters in the 
Map, whereas in Tomcat I consistently get 0 parameters back. Something is very fishy, but 
maybe it has to do with differences in the servlet api implmenetation and how CXF works 
with this. One thing I did notice is that when I explicitly put in a 
@FormParam("username") in the method signature, it is then able to parse out 
the username and it populates the method argument properly that way, but I'm still unable 
to access that same parameter via request.getParameter(). Has anyone ever seen this
behavior?

I am using CXF 2.2.10.

My REST method without explicit @FormParam mappings looks something like this:


   @POST

   @Path("/user/create/{token}")

   @Consumes("application/x-www-form-urlencoded")

   @Produces("text/plain")

   public int createUser(@PathParam("token") String token) {

     ...

     ..

     .


     Map<String,String>  parameters = request.getParameterMap();


     // this outputs zero

     logger.info("Request parameters size: "+parameters.size());


   }

My REST method with an explicit @FormParam looks something like this:


   @POST

   @Path("/user/create/{token}")

   @Consumes("application/x-www-form-urlencoded")

   @Produces("text/plain")

   public int createUser(@PathParam("token") String token, 
@FormParam("username") String username) {

     ...

     ..

     .


     // this outputs the value passed in the http post request correctly

     logger.info("Username: "+username);


     Map<String,String>  parameters = request.getParameterMap();


     // this is still zero

     logger.info("Request parameters size: "+parameters.size());


   }



I think it is to do with the difference in the way Servlet API is implemented on different containers. When you use @FormParam, it is CXF which deals with it but without it you do depend on how request.getParameterMap() is implemented - CXF does not intercept this method.

By the way, try using MultivaluedMap instead if you'd like to get all the parameters...Also, consider migrating to newer CXF, 2.5.x is the oldest maintained branch

Cheers, Sergey

Thanks,


Jeff



---------------------------------------------------------------------
This e-mail is intended only for the use of the addressees.  Any copying, 
forwarding, printing or other use of this e-mail by persons other than the 
addressees is not authorized.  This e-mail may contain information that is 
privileged, confidential and exempt from disclosure. If you are not the 
intended recipient, please notify us immediately by return e-mail (including 
the original message in your reply) and then delete and discard all copies of 
the e-mail.

Thank you.

---------------------------------------------------------------------




--
Sergey Beryozkin

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

Blog: http://sberyozkin.blogspot.com

Reply via email to