jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Willie H Armstrong <warms...@csc.com>
Subject Re: Problem with referer header.
Date Wed, 11 May 2005 19:40:50 GMT




Thanks for your reply.

I am running Tomcat 5.0.28 which is the default for the Netbeans IDE which
I am using.  I develop the classes in the IDE, launch tomcat from the IDE,
then run the test from a command prompt.

I will run your code and see if it gives me clean results.  It looks like
you have distilled the essence of the problem.

Regards,
Bill


Willie (Bill) Armstrong
Sun Certified Programmer for the Java 2 Platform 1.4



                                                                                         
                                            
                      Kazuhito SUGURI                                                    
                                            
                      <suguri.kazuhito         To:      cactus-user@jakarta.apache.org,
Willie H Armstrong/GTS/CSC@CSC                
                      @lab.ntt.co.jp>          cc:                                    
                                               
                                               Subject: Re: Problem with referer header. 
                                            
                      05/11/2005 01:22                                                   
                                            
                      PM                                                                 
                                            
                      Please respond                                                     
                                            
                      to "Cactus Users                                                   
                                            
                      List"                                                              
                                            
                                                                                         
                                            




Hi Willie,

I have tried to re-produce your problem, but my test-case does not fail.
I'm trying with tomcat-5.0.28. My test codes are appending:
              SampleServlet.java
              SampleServletTest.java

The SampleServlet is mapped to /refersample in my case.


In article
<OF1CB48276.2A1D71E4-ON86256FFE.004FBF05-86256FFE.0050195A@csc.com>,
Wed, 11 May 2005 09:34:53 -0500,
Willie H Armstrong <warmstr2@csc.com> wrote:
warmstr2> I am having a problem with the Referer header being "distorted"
by the
warmstr2> WebRequest.addHeader() method.  The header name and the header
value
warmstr2> gets changed into: "~~~~~~~" and
"~~~~:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
warmstr2> which I see when examining the Enumeration en in the debugger.
warmstr2>
warmstr2> I am attempting to set two headers in a WebRequest.
warmstr2>
warmstr2> code pieces as follows:
warmstr2>
warmstr2>
warmstr2> // the imports
warmstr2> import org.apache.cactus.ServletTestCase;
warmstr2> import org.apache.cactus.WebResponse;
warmstr2> import org.apache.cactus.WebRequest;
warmstr2>
warmstr2> // "setting up" the request
warmstr2>     public void beginProcessRequestNotReseeding(WebRequest
request) {
warmstr2>         System.out.print("beginProcessRequestNotReseeding");
warmstr2>         request.addHeader("HTTP_SM_USER", strHttpUser);
warmstr2>         request.addHeader("Referer", strRefUrl);
warmstr2>         System.out.println(".....Completed client side begin.");
warmstr2>     }

In my code, corresponds to SampleServletTest#beginReferer().

warmstr2> // sending the request
warmstr2>
warmstr2>    public void testProcessRequestNotReseeding() {
warmstr2>         System.out.println("testProcessRequestNotReseeding");
warmstr2>         assertFalse("Credential was set to true",
warmstr2> Credentialer.isReseeding());
warmstr2>         Enumeration en = request.getHeaderNames();
warmstr2>         try {
warmstr2>             servlet.processRequest(request, response);
warmstr2>         } catch (javax.servlet.ServletException jsse) {
warmstr2>             // do nothing
warmstr2>         } catch (IOException jioe) {
warmstr2>             // do nothing
warmstr2>         }
warmstr2>         Credentialer.setReseeding(false);
warmstr2>         System.out.println(".....Completed.");
warmstr2>     }

In my code, corresponds to SampleServletTest#testReferer().


warmstr2> // adding a Basic Authentication to  header then dispatching it
to
warmstr2> Sender servlet
warmstr2>
warmstr2> .... called by testProcessRequestNotReseeding() ........
warmstr2>
warmstr2>     protected void processRequest(HttpServletRequest request,
warmstr2> HttpServletResponse response)
warmstr2>     throws ServletException, IOException {
warmstr2> .......
warmstr2>             String strUser = request.getHeader("HTTP_SM_USER");
warmstr2>             String strPW = Credentialer.getPassword(strUser);
warmstr2>             // put BasicAuthurization data in request header
warmstr2>             try {
warmstr2>                 response.setHeader("Authorization", "Basic " +
warmstr2> makeAuthedString(strUser, strPW));
warmstr2>             } catch (EncoderException acnee){
warmstr2>                 acnee.printStackTrace();
warmstr2>                 // TODO make an HTML Message of failure);
warmstr2>             }
warmstr2>             // send request to Refer url
warmstr2>
request.getRequestDispatcher("/Sender").forward(request,
warmstr2> response);
warmstr2>     }

In my code, corresponds to SampleServlet#processRequest().
At this method, the request is dispatched to "/refersample",
i.e. I'm expecting SampleServlet#doGet() will be called.


warmstr2> // the Sender servlet does redirect to back to the referer.
warmstr2> ... the final servlet method called
warmstr2>
warmstr2>     protected void processRequest(HttpServletRequest request,
warmstr2> HttpServletResponse response)
warmstr2>     throws ServletException, IOException {
warmstr2>       String strRefURL = request.getHeader("Referer");
warmstr2>       response.sendRedirect(strRefURL);
warmstr2>     }

In my code, corresponds to SampleServlet#doGet(). At this point,
request.getHeader("Referer") of my code has non-null value,
"/test.jsp", and of cource, 302 response code is received at
SampleServletTest#endReferer().


warmstr2> The String strRefUrl is set to null so the sendRedirect of course
fails.

How could we re-produce the problem?

Regards,
----
Kazuhito SUGURI
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SampleServlet
    extends HttpServlet
{
    public void doGet(HttpServletRequest request,
                               HttpServletResponse response)
             throws ServletException, IOException
    {
        System.out.println("Referer: " + request.getHeader("Referer"));
        response.sendRedirect(request.getHeader("Referer"));
    }

    protected void processRequest(HttpServletRequest request,
                                  HttpServletResponse response)
             throws ServletException, IOException
    {
        response.setHeader("TEST", "testHeader");
        request.getRequestDispatcher("/refersample").forward(request,
response);
    }
}
import org.apache.cactus.ServletTestCase;
import org.apache.cactus.WebRequest;
import org.apache.cactus.WebResponse;

public class SampleServletTest
    extends ServletTestCase
{
    public SampleServletTest(String name)
    {
             super(name);
    }

    public void beginReferer(WebRequest request)
    {
             request.addHeader("Referer", "/test.jsp");
    }

    public void testReferer()
             throws Exception
    {
        assertEquals("/test.jsp", request.getHeader("Referer"));

             SampleServlet servlet = new SampleServlet();
        servlet.processRequest(request, response);
    }

    public void endReferer(WebResponse response)
        throws Exception
    {
        assertEquals(302, response.getStatusCode());
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-user-help@jakarta.apache.org


Mime
View raw message