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

          People

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

            Dates

            • Created:
              Updated:

              Development