Cactus
  1. Cactus
  2. CACTUS-131

Unable to pass both parameters and content in a POST request

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.6.1
    • Fix Version/s: None
    • Component/s: Framework
    • Labels:
      None

      Description

      I have a servlet which operates using POST, taking parameters off the URL (GET style), and the processes the body of the request (POST style).

      i.e. my users post to the URL /foo?foo=bar with a bunch of data as the body of the post.

      it seems impossible to do this using cactus (and therefore impossible to test my servlet). Note that the servlet does not rely on the parameter being in the URL, simply that the parameter is set in the received request. To demonstrate the behaviour, I have written a test case, one of which I would like to pass (or both!), so that I use the functionality provided.

      import java.io.ByteArrayInputStream;
      import java.io.IOException;

      import org.apache.cactus.ServletTestCase;
      import org.apache.cactus.WebRequest;

      public class CactusTest extends ServletTestCase
      {
      public void beginTest(WebRequest webRequest)
      {
      webRequest.addParameter("foo", "bar", "GET");
      webRequest.setUserData(new ByteArrayInputStream(new byte[]

      {'C'}

      ));
      }

      public void testTest() throws IOException

      { assertEquals("Parameter not set", "bar", request.getParameter("foo")); assertEquals("Should be able to read data", 'C', request.getInputStream().read()); }

      public void beginPostTest(WebRequest webRequest)
      {
      webRequest.addParameter("foo", "bar", "POST");
      webRequest.setUserData(new ByteArrayInputStream(new byte[]

      {1}

      ));
      }

      public void testPostTest() throws IOException

      { assertEquals("Parameter not set", "bar", request.getParameter("foo")); assertEquals("Should be able to read data", 1, request.getInputStream().read()); }

      }

        Activity

        Vincent Massol made changes -
        Field Original Value New Value
        Component/s Framework [ 10900 ]
        Hide
        Maxwell Grender-Jones added a comment -

        To clarify - both tests above fail as follows:

        [cactus] Testcase: testGetTest took 0.461 sec
        [cactus] Caused an ERROR
        [cactus] This input stream has been closed
        [cactus] java.io.IOException: This input stream has been closed
        [cactus] at org.apache.catalina.connector.http.HttpRequestStream.read(HttpRequestStream.java:197)

        and

        [cactus] Testcase: testTestTestcase: testPostTest took 0.453 sec
        [cactus] FAILED
        [cactus] Parameter not set expected:<bar> but was:<null>
        [cactus] junit.framework.ComparisonFailure: Parameter not set expected:<bar> but was:<null>
        [cactus] at com.wapmx.mmsc.web.CactusTest.testPostTest(CactusTest.java:37)

        Show
        Maxwell Grender-Jones added a comment - To clarify - both tests above fail as follows: [cactus] Testcase: testGetTest took 0.461 sec [cactus] Caused an ERROR [cactus] This input stream has been closed [cactus] java.io.IOException: This input stream has been closed [cactus] at org.apache.catalina.connector.http.HttpRequestStream.read(HttpRequestStream.java:197) and [cactus] Testcase: testTestTestcase: testPostTest took 0.453 sec [cactus] FAILED [cactus] Parameter not set expected:<bar> but was:<null> [cactus] junit.framework.ComparisonFailure: Parameter not set expected:<bar> but was:<null> [cactus] at com.wapmx.mmsc.web.CactusTest.testPostTest(CactusTest.java:37)
        Hide
        Maxwell Grender-Jones added a comment -

        I should have said before (apologies) that I'm using tomcat 4.1.30, sun java 1.4.2.01 and maven 1.0rc3

        Show
        Maxwell Grender-Jones added a comment - I should have said before (apologies) that I'm using tomcat 4.1.30, sun java 1.4.2.01 and maven 1.0rc3
        Maxwell Grender-Jones created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Maxwell Grender-Jones
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:

              Development