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.
Danno - 06 Feb 2006 21:50 GMT
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
Tony Morris - 06 Feb 2006 22:21 GMT
> Is there a way to programmatically create a new object that implements
> the HttpServletRequest and HttpServletResponse interface in tomcat
[quoted text clipped - 10 lines]
> 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.

Signature
Tony Morris
http://tmorris.net/
Ernst Blofeld - 06 Feb 2006 22:51 GMT
> 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.
Tony Morris - 06 Feb 2006 23:09 GMT
> > 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

Signature
Tony Morris
http://tmorris.net/