Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-916

PUT method does not provide form parameters

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.0.0.Beta1, 1.4.7.Final
    • 1.4.6.Final
    • Servlet
    • None
    • Hide

      To reproduce this situation I just created a eclipse maven project with empty pom.xml and added:
      pom.xml

      <dependencies>
      		<dependency>
      			<groupId>io.undertow</groupId>
      			<artifactId>undertow-core</artifactId>
      			<version>1.4.6.Final</version>
      		</dependency>
      		<dependency>
      			<groupId>io.undertow</groupId>
      			<artifactId>undertow-servlet</artifactId>
      			<version>1.4.6.Final</version>
      		</dependency>
      
      		<dependency>
      			<groupId>io.undertow</groupId>
      			<artifactId>undertow-websockets-jsr</artifactId>
      			<version>1.4.6.Final</version>
      		</dependency>
      	</dependencies>
      

      Then created a basic servlet:

      package undertow.test;
      
      import java.io.IOException;
      
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      
      @SuppressWarnings("serial")
      public class PutTest extends HttpServlet {
      	@Override
      	public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException {
      		System.out.println("Put parmameter: "+request.getParameter("test"));
      	}		
      }
      

      And deployed that code using this simple hello class:

      package undertow.test;
      
      import javax.servlet.ServletException;
      
      import io.undertow.Handlers;
      import io.undertow.Undertow;
      import io.undertow.server.HttpHandler;
      import io.undertow.server.handlers.PathHandler;
      import io.undertow.servlet.Servlets;
      import io.undertow.servlet.api.DeploymentInfo;
      import io.undertow.servlet.api.DeploymentManager;
      
      public class Deploy {
      
      	public static final String MYAPP = "/";
      
      	public static void main(final String[] args) {
      
      		try {
      
      			DeploymentInfo servletBuilder = Servlets.deployment().setClassLoader(Deploy.class.getClassLoader())
      					.setContextPath(MYAPP).setDeploymentName("test.war")
      					.addServlets(Servlets.servlet("PutTest", PutTest.class).addMapping("/test"));
      
      			DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
      			manager.deploy();
      
      			HttpHandler servletHandler = manager.start();
      			PathHandler path = Handlers.path(Handlers.redirect(MYAPP)).addPrefixPath(MYAPP, servletHandler);
      			Undertow server = Undertow.builder().addHttpListener(8080, "localhost").setHandler(path).build();
      			server.start();
      
      		} catch (ServletException e) {
      			e.printStackTrace();
      		}
      
      	}
      }
      

      After and executing a simple call using curl like this:

      curl "http://localhost:8080/test" -X "PUT" -d "test=Putting some value"
      

      Or with content-type header:

      curl "http://localhost:8080/test" -H "Content-Type: application/x-www-form-urlencoded" -X "PUT" -d "test=Putting some value"
      

      The out put is the same, no parameter founded:

      Put parmameter: null
      
      Show
      To reproduce this situation I just created a eclipse maven project with empty pom.xml and added: pom.xml <dependencies> <dependency> <groupId> io.undertow </groupId> <artifactId> undertow-core </artifactId> <version> 1.4.6.Final </version> </dependency> <dependency> <groupId> io.undertow </groupId> <artifactId> undertow-servlet </artifactId> <version> 1.4.6.Final </version> </dependency> <dependency> <groupId> io.undertow </groupId> <artifactId> undertow-websockets-jsr </artifactId> <version> 1.4.6.Final </version> </dependency> </dependencies> Then created a basic servlet : package undertow.test; import java.io.IOException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @SuppressWarnings( "serial" ) public class PutTest extends HttpServlet { @Override public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException { System .out.println( "Put parmameter: " +request.getParameter( "test" )); } } And deployed that code using this simple hello class: package undertow.test; import javax.servlet.ServletException; import io.undertow.Handlers; import io.undertow.Undertow; import io.undertow.server.HttpHandler; import io.undertow.server.handlers.PathHandler; import io.undertow.servlet.Servlets; import io.undertow.servlet.api.DeploymentInfo; import io.undertow.servlet.api.DeploymentManager; public class Deploy { public static final String MYAPP = "/" ; public static void main( final String [] args) { try { DeploymentInfo servletBuilder = Servlets.deployment().setClassLoader(Deploy. class. getClassLoader()) .setContextPath(MYAPP).setDeploymentName( "test.war" ) .addServlets(Servlets.servlet( "PutTest" , PutTest.class).addMapping( "/test" )); DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder); manager.deploy(); HttpHandler servletHandler = manager.start(); PathHandler path = Handlers.path(Handlers.redirect(MYAPP)).addPrefixPath(MYAPP, servletHandler); Undertow server = Undertow.builder().addHttpListener(8080, "localhost" ).setHandler(path).build(); server.start(); } catch (ServletException e) { e.printStackTrace(); } } } After and executing a simple call using curl like this: curl "http://localhost:8080/test" -X "PUT" -d "test=Putting some value" Or with content-type header: curl "http://localhost:8080/test" -H "Content-Type: application/x-www-form-urlencoded" -X "PUT" -d "test=Putting some value" The out put is the same, no parameter founded: Put parmameter: null

      It seems that undertow is not passing "form parameters" to servlets when PUT method is in use. It is a kind odd because you can create a resource using POST methd but you cannot update the same resource using PUT method.

      I have been using wildfly 10.x and just after migrated a code base that was in a jetty-6.1.x I faced this situation: requests using PUT method stopped to work because request "form parameters" never reach servlests endpoints.

      For example:

      This code was working on jetty-6.1.x and printing the parameter, but stopped to work on wildfly 10.1.0.Final.

      @Override
      	public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException {
      		System.out.println("Put parmameter: "+request.getParameter("test"));
      	}

              sdouglas1@redhat.com Stuart Douglas (Inactive)
              gilmatryx Gilmar P. S. Leitão (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved: