Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Create New HttpRequest?

Thread view: 
Ernst Blofeld - 06 Feb 2006 21:40 GMT
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/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.