Create New HttpRequest?

E

Ernst Blofeld

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.
 
D

Danno

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
 
T

Tony Morris

Ernst Blofeld said:
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.
 
E

Ernst Blofeld

Tony said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top