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 / May 2005

Tip: Looking for answers? Try searching our database.

Trouble implementing an interface, strange compiler error

Thread view: 
Robert Maas, see http://tinyurl.com/uh3t - 15 May 2005 13:20 GMT
I want to set up a test rig for HttpServlet things.
The idea is that my test rig creates (from scratch,
not underneath an actual HTTP/Tomcat/J2EE session)
both HttpServletRequest and HttpServletResponse
objects, populating them with realistic data,
then calls the HttpServlet with those as args,
then upon return checks the HttpServletResponse
object to see if the HttpServlet worked correctly.

Unfortunately I haven't been able to find any
public constructor for any class that implements
HttpServletRequest (I haven't even started looking
at HttpServletResponse because I'm already stumped
here), except one which takes another already-constructed
request object as parameter to constructor thereby
begging the question how to construct one from scratch
in the first place.

So I decided to write my own dummy request class which
would implement the interface hence be acceptable as
parameter to a servlet, starting with this skeleton:

public class DummyHttpServletRequest
   implements javax.servlet.http.HttpServletRequest {
}

I tried to compile that, expecting to get a compiler
error that I'm missing one or more of the methods
needed to implement the interface. Instead I got this:

DummyHttpServletRequest.java:2: cannot resolve symbol
symbol  : class HttpServletRequest
location: package http
   implements javax.servlet.http.HttpServletRequest {
                                ^
1 error

What's wrong, and how can I fix it so I can move ahead with this project??
.
ByteCoder - 15 May 2005 13:55 GMT
> I want to set up a test rig for HttpServlet things.
> The idea is that my test rig creates (from scratch,
[quoted text clipped - 35 lines]
> What's wrong, and how can I fix it so I can move ahead with this
> project?? .

This class:
javax.servlet.http.HttpServletRequestWrapper

"Provides a convenient implementation of the HttpServletRequest
interface that can be subclassed by developers wishing to adapt the
request to a Servlet. This class implements the Wrapper or Decorator
pattern. Methods default to calling through to the wrapped request
object."

I think you are being too hard on yourself, maybe you should try an
'easy' way out and extend the HttpServletRequestWrapper.

Signature

-------------
- ByteCoder -           ...I see stupid people
-------------
                  Curiosity *Skilled* the cat

shakah - 15 May 2005 17:02 GMT
> I want to set up a test rig for HttpServlet things.
> The idea is that my test rig creates (from scratch,
[quoted text clipped - 34 lines]
>
> What's wrong, and how can I fix it so I can move ahead with this project??

Is that class in your compilation classpath? After a quick look in
Tomcat's directories, it appears to exist in
./common/lib/servlet-api.jar.
Wibble - 15 May 2005 17:47 GMT
Your looking for a 'Mock Object' servlet engine.

http://strutstestcase.sourceforge.net/api/servletunit/package-summary.html
http://java-source.net/open-source/testing-tools/mockrunner

are some examples.

Also look at htmlunit
http://htmlunit.sourceforge.net/

for testing the client side.

I rolled my own mock servlet engine, it wasnt too hard, and coupled
it with htmlunit for full testing of servlets, javascript, jsps etc.

>>I want to set up a test rig for HttpServlet things.
>>The idea is that my test rig creates (from scratch,
[quoted text clipped - 40 lines]
> Tomcat's directories, it appears to exist in
> ./common/lib/servlet-api.jar.
Ross Bamford - 15 May 2005 22:05 GMT
> I want to set up a test rig for HttpServlet things.
> The idea is that my test rig creates (from scratch,
[quoted text clipped - 4 lines]
> then upon return checks the HttpServletResponse
> object to see if the HttpServlet worked correctly.

You cannot construct one because it is implementation-specific - the
Servlet Container provides an implementation that suits it's internal
layout (usually as a facade to many other objects).

Instead try:

1) http://www.mockobjects.com/FrontPage.html

Signature

  [Ross A. Bamford]     [ross AT the.website.domain]
Roscopeco Open Tech ++ Open Source + Java + Apache + CMF
http://www.roscopec0.f9.co.uk/ + info@the.website.domain



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.