jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kazuhito SUGURI <suguri.kazuh...@lab.ntt.co.jp>
Subject Re: Problem with referer header.
Date Wed, 11 May 2005 18:22:49 GMT
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

Mime
View raw message