You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Aditya Prasad <ak...@gmail.com> on 2006/09/13 03:16:19 UTC

HttpRequestBase equivalent in 5.5?

I've been using HttpRequestBase (from Tomcat 4.0) as an impl of
HttpServletRequest to construct requests for test purposes outside of
Tomcat.  I've recently switched to 5.5, and am rewriting my tests,
since that class no longer exists.

I first tried using DummyRequest, but quickly found that the setters
don't seem to do anything, because the getters return nulls.  I then
tried org.apache.catalina.connector.Request, but I get NPEs when
calling getContentType (after calling setContentType) or
setServerName.

Am I not supposed to be using either of these classes?  Is there a
well-known impl that will allow me to set arbitrary data on a request
(I know this is a tall order -- there's probably a logical order in
which the object should be constructed anyway).

Thanks,
Aditya

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: HttpRequestBase equivalent in 5.5?

Posted by Yoav Shapira <yo...@apache.org>.
Umm, what about MockObjects, HttpUnit, or any of the similar packages
that already exist that make this trivial?  Why write your own, and
worse, make it Tomcat-specific?

Yoav

On 9/12/06, Aditya Prasad <ak...@gmail.com> wrote:
> Thanks for the response.  To be more clear, I'm developing unit tests
> for code that takes ServletRequests / HttpServletRequests as input,
> but don't run inside Tomcat at all (they're essentially helpers for
> servlets).  I want to mimic what Tomcat does to create the Request
> object (but perhaps only for selected fields).
>
> Does the MemoryProtocolHandler suggestion apply here?
>
> Thanks!
> Aditya
>
> On 9/12/06, Bill Barker <wb...@wilshire.com> wrote:
> >
> > "Aditya Prasad" <ak...@gmail.com> wrote in message
> > news:6c8e56320609121816m366cc52fmbcea0bb8ba903455@mail.gmail.com...
> > > I've been using HttpRequestBase (from Tomcat 4.0) as an impl of
> > > HttpServletRequest to construct requests for test purposes outside of
> > > Tomcat.  I've recently switched to 5.5, and am rewriting my tests,
> > > since that class no longer exists.
> > >
> > > I first tried using DummyRequest, but quickly found that the setters
> > > don't seem to do anything, because the getters return nulls.  I then
> > > tried org.apache.catalina.connector.Request, but I get NPEs when
> > > calling getContentType (after calling setContentType) or
> > > setServerName.
> > >
> > > Am I not supposed to be using either of these classes?  Is there a
> > > well-known impl that will allow me to set arbitrary data on a request
> > > (I know this is a tall order -- there's probably a logical order in
> > > which the object should be constructed anyway).
> > >
> >
> > Well, you pretty much have to use o.a.c.c.Request in 5.5 ;-).  You can look
> > at CoyoteAdapter to see how to set them up.
> >
> > IMHO, it would be easier to implement your tests using something like the
> > MemoryProtocolHandler (in connectors/coyote), and let Tomcat worry about the
> > HttpRequest.
> >
> > > Thanks,
> > > Aditya
> >
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: dev-help@tomcat.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: HttpRequestBase equivalent in 5.5?

Posted by Aditya Prasad <ak...@gmail.com>.
Thanks for the response.  To be more clear, I'm developing unit tests
for code that takes ServletRequests / HttpServletRequests as input,
but don't run inside Tomcat at all (they're essentially helpers for
servlets).  I want to mimic what Tomcat does to create the Request
object (but perhaps only for selected fields).

Does the MemoryProtocolHandler suggestion apply here?

Thanks!
Aditya

On 9/12/06, Bill Barker <wb...@wilshire.com> wrote:
>
> "Aditya Prasad" <ak...@gmail.com> wrote in message
> news:6c8e56320609121816m366cc52fmbcea0bb8ba903455@mail.gmail.com...
> > I've been using HttpRequestBase (from Tomcat 4.0) as an impl of
> > HttpServletRequest to construct requests for test purposes outside of
> > Tomcat.  I've recently switched to 5.5, and am rewriting my tests,
> > since that class no longer exists.
> >
> > I first tried using DummyRequest, but quickly found that the setters
> > don't seem to do anything, because the getters return nulls.  I then
> > tried org.apache.catalina.connector.Request, but I get NPEs when
> > calling getContentType (after calling setContentType) or
> > setServerName.
> >
> > Am I not supposed to be using either of these classes?  Is there a
> > well-known impl that will allow me to set arbitrary data on a request
> > (I know this is a tall order -- there's probably a logical order in
> > which the object should be constructed anyway).
> >
>
> Well, you pretty much have to use o.a.c.c.Request in 5.5 ;-).  You can look
> at CoyoteAdapter to see how to set them up.
>
> IMHO, it would be easier to implement your tests using something like the
> MemoryProtocolHandler (in connectors/coyote), and let Tomcat worry about the
> HttpRequest.
>
> > Thanks,
> > Aditya
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: HttpRequestBase equivalent in 5.5?

Posted by Bill Barker <wb...@wilshire.com>.
"Aditya Prasad" <ak...@gmail.com> wrote in message 
news:6c8e56320609121816m366cc52fmbcea0bb8ba903455@mail.gmail.com...
> I've been using HttpRequestBase (from Tomcat 4.0) as an impl of
> HttpServletRequest to construct requests for test purposes outside of
> Tomcat.  I've recently switched to 5.5, and am rewriting my tests,
> since that class no longer exists.
>
> I first tried using DummyRequest, but quickly found that the setters
> don't seem to do anything, because the getters return nulls.  I then
> tried org.apache.catalina.connector.Request, but I get NPEs when
> calling getContentType (after calling setContentType) or
> setServerName.
>
> Am I not supposed to be using either of these classes?  Is there a
> well-known impl that will allow me to set arbitrary data on a request
> (I know this is a tall order -- there's probably a logical order in
> which the object should be constructed anyway).
>

Well, you pretty much have to use o.a.c.c.Request in 5.5 ;-).  You can look 
at CoyoteAdapter to see how to set them up.

IMHO, it would be easier to implement your tests using something like the 
MemoryProtocolHandler (in connectors/coyote), and let Tomcat worry about the 
HttpRequest.

> Thanks,
> Aditya 




---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org