RE: Testing servlet redirects

"karthik" <[email protected]>
Newsgroups gmane.comp.jakarta.cactus.user
Message-ID <[email protected]>
Hi

  The example provided on the site is something confusing....
  If u hava a sample working test case with war file,please
  provid me the same. so i can correct my self.



with regards
Karthik


-----Original Message-----
From: Kazuhito SUGURI [mailto:[email protected]]
Sent: Tuesday, June 20, 2006 3:19 PM
To: [email protected]
Subject: Re: Testing servlet redirects


Hi Dennis,

Followings are information and recommendation from me.
These are based on short examination with default settings of Tomat-5.5.12.
But, please note that behavior of a servlet named "default" might
be different for each container and its configuration.

In article <[email protected]>,
Mon, 19 Jun 2006 23:14:40 +0200,
"Dennis Kempin" <[email protected]> wrote:
dennis> thank you for your answer. My servlet is mapped to process any
request that
dennis> is made.
dennis> Lets say we have a request on /core/test.html: My servlets checks if
it can
dennis> handle, if not it redirects to the default
dennis> servlet which should serve test.html (which does exist).
dennis> But instead of the contents of test.html i get the described 404
Error which
dennis> says that it cannot find "/core/ServletRedirector".

I think it's hard to test the forwarding by using Cactus
as long as you are using getNamedDispatcher("default").


RequestDispatcherWrapper#forward(), which is used in the test,
calls the original RequestDispatcher with the original HTTP request.
# See Cactus API JavaDoc.

A servier-side test case is invoked from a servlet,
/<context>/ ServletRedirecter. So, the request URI of the original HTTP
request is "/<context>/ServletRedirector".

When the original RequestDispatcher is the default servlet of Tomcat,
it's trying to obtain the resource from "/<context>/ServletRedirector",
that has the possiblity of causing an infinite loop.
# Fortunately, the default servlet responds 404 and stops the loop.

Please try following fragments of servlet and web.xml.
You will find similar behavior with your Cactus tests
when you access to <context>/dummy.

    public DummyServlet
        extends HttpServlet
    {
        protected void doGet(HttpServletRequest request,
                             HttpServletResponse response)
            throws ServletException, IOException
        {

getServletContext().getNamedDispatcher("default").forward(request,
response);
        }
    }

    <servlet>
      <servlet-name>dummy</servlet-name>
      <servlet-class>DummyServlet</servlet-name>
    </servlet>
    <servlet-mapping>
      <servlet-name>dummy</servlet-name>
      <url-pattern>/dummy</url-pattern>
    </servlet-mapping>


I would like to recommend you to use getRequestDispatcher(String)
instead of getNamedDispatcher("default"), it it's possible.
If you can do so, you will be able to simulate any path condition
for a testXXX() by using org.apache.cactus.WebRequest#setURL() method
in beginXXX(), and you can evaluate a forwarded responce in the
corresponding
endXXX() method.
# You should not simulate <context>/ServletRedirector,
# which is the default of Cactus, of cource :-)


Hope this helps,
----
Kazuhito SUGURI

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.