Create New HttpRequest?

Discussion in 'Java' started by Ernst Blofeld, Feb 6, 2006.

  1. Is there a way to programmatically create a new object that implements
    the HttpServletRequest and HttpServletResponse interface in tomcat
    servlets?

    For example, the servlet container will create the HttpServletRequest
    and HttpServletResponse objects passed to the doPost() method:

    public void doPost(HttpServletRequest request, HttpServletResponse
    response)

    The two parameters passed in implement the HttpServletRequest &
    response
    interfaces. But I don't see an obvious way to create a concrete class
    that implements these interfaces.
    Ernst Blofeld, Feb 6, 2006
    #1
    1. Advertising

  2. Ernst Blofeld

    Danno Guest

    If you are thinking about using them for testing then try out easy
    mock.

    You would just do something like this:
    HttpServletRequest request = createMock(HttpServletRequest.class);
    HttpServletResponse response =
    createMock(HttpServletResponse.class);

    and those would create concrete classes and you would set up what you
    expect to get called so you can do

    expect(request.getParameter("id").andReturn(1).anyTimes();

    cool stuff

    easymock.org
    Danno, Feb 6, 2006
    #2
    1. Advertising

  3. Ernst Blofeld

    Tony Morris Guest

    "Ernst Blofeld" <> wrote in message
    news:...
    > Is there a way to programmatically create a new object that implements
    > the HttpServletRequest and HttpServletResponse interface in tomcat
    > servlets?
    >
    > For example, the servlet container will create the HttpServletRequest
    > and HttpServletResponse objects passed to the doPost() method:
    >
    > public void doPost(HttpServletRequest request, HttpServletResponse
    > response)
    >
    > The two parameters passed in implement the HttpServletRequest &
    > response
    > interfaces. But I don't see an obvious way to create a concrete class
    > that implements these interfaces.
    >


    What's the hard bit exactly? You just implement the interfaces like any
    other.
    Sounds like you're mocking up for unit testing - there are packages
    available to do that - but you can mock up yourself quite easily.

    --
    Tony Morris
    http://tmorris.net/
    Tony Morris, Feb 6, 2006
    #3
  4. Tony Morris wrote:
    > What's the hard bit exactly? You just implement the interfaces like any
    > other.
    > Sounds like you're mocking up for unit testing - there are packages
    > available to do that - but you can mock up yourself quite easily.


    Just wondering if it's done already somewhere--apparently not.
    Ernst Blofeld, Feb 6, 2006
    #4
  5. Ernst Blofeld

    Tony Morris Guest

    "Ernst Blofeld" <> wrote in message
    news:...
    >
    > Tony Morris wrote:
    > > What's the hard bit exactly? You just implement the interfaces like any
    > > other.
    > > Sounds like you're mocking up for unit testing - there are packages
    > > available to do that - but you can mock up yourself quite easily.

    >
    > Just wondering if it's done already somewhere--apparently not.
    >


    Sure it is.
    http://www.google.com/search?hl=en&q=mockhttpservletrequest
    http://www.google.com/search?hl=en&q=mock httpservletrequest

    --
    Tony Morris
    http://tmorris.net/
    Tony Morris, Feb 6, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Reevosh via .NET 247

    HTTPRequest and JAVA Servlet

    Greg Reevosh via .NET 247, Oct 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    591
    Greg Reevosh via .NET 247
    Oct 17, 2004
  2. Dino Chiesa [Microsoft]

    Re: HTTPRequest and JAVA Servlet

    Dino Chiesa [Microsoft], Oct 27, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    487
    Dino Chiesa [Microsoft]
    Oct 27, 2004
  3. Greg Reevosh via .NET 247

    HTTPRequest and JAVA Servlet

    Greg Reevosh via .NET 247, Oct 31, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    411
    Greg Reevosh via .NET 247
    Oct 31, 2004
  4. John Saunders

    Re: HTTPRequest and JAVA Servlet

    John Saunders, Nov 17, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    455
    John Saunders
    Nov 17, 2004
  5. Feroze [msft]

    Re: HTTPRequest and JAVA Servlet

    Feroze [msft], Jan 13, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    432
    Feroze [msft]
    Jan 13, 2005
Loading...

Share This Page