You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Gili <co...@bbs.darktech.org> on 2005/04/26 09:28:58 UTC

WebRequest.setContentType() doesn't work

Here is my code:

   /**
    * Creates request for testProcessRequest().
    */
   public void beginTestProcessRequest(WebRequest request) throws 
IOException
   {
     Document document = DocumentHelper.createDocument();
     Element xmlRoot = document.addElement("request");
     Element subscribedTheme = xmlRoot.addElement("subscribedTheme");
     subscribedTheme.addText("1");

     PipedOutputStream out = new PipedOutputStream();
     PipedInputStream in = new PipedInputStream(out);
     BufferedWriter writer = new BufferedWriter(new 
OutputStreamWriter(out));
     OutputFormat format = OutputFormat.createPrettyPrint();
     XMLWriter xmlWriter = new XMLWriter(writer, format);
     try
     {
       xmlWriter.write(document);
     }
     finally
     {
       xmlWriter.close();
     }
     out.close();
     request.setUserData(in);
     request.setContentType("application/xml");
     Assert.assertEquals("application/xml", request.getContentType());
   }

   /**
    * Test of processRequest method, of class 
com.be.desktopbeautifier.servlet.GetNextImages.
    */
   public void testProcessRequest() throws ServletException, IOException
   {
     System.out.println("testProcessRequest");

     Assert.assertEquals("application/xml", request.getContentType());
     GetNextImages instance = new GetNextImages();
     instance.init(config);
     Session session = instance.openSession();
     instance.processRequest(request, response, session);
     instance.destroy();
   }


	It dies with on Assert.assertEquals("application/xml", 
request.getContentType()) inside of testProcessRequest() but not inside 
beginTestProcessRequest(). I don't understand how it could possibly say 
the headers were set properly in the beginXXX() method but then change 
its mind in the testXXX() method. Ideas?

Gili

Re: WebRequest.setContentType() doesn't work

Posted by Gili <co...@bbs.darktech.org>.
	Fixed by renaming beginTestProcessRequest() to beginProcessRequest(). 
Sorry for the false alarm :)

Gili

Gili wrote:
> Here is my code:
> 
>   /**
>    * Creates request for testProcessRequest().
>    */
>   public void beginTestProcessRequest(WebRequest request) throws 
> IOException
>   {
>     Document document = DocumentHelper.createDocument();
>     Element xmlRoot = document.addElement("request");
>     Element subscribedTheme = xmlRoot.addElement("subscribedTheme");
>     subscribedTheme.addText("1");
> 
>     PipedOutputStream out = new PipedOutputStream();
>     PipedInputStream in = new PipedInputStream(out);
>     BufferedWriter writer = new BufferedWriter(new 
> OutputStreamWriter(out));
>     OutputFormat format = OutputFormat.createPrettyPrint();
>     XMLWriter xmlWriter = new XMLWriter(writer, format);
>     try
>     {
>       xmlWriter.write(document);
>     }
>     finally
>     {
>       xmlWriter.close();
>     }
>     out.close();
>     request.setUserData(in);
>     request.setContentType("application/xml");
>     Assert.assertEquals("application/xml", request.getContentType());
>   }
> 
>   /**
>    * Test of processRequest method, of class 
> com.be.desktopbeautifier.servlet.GetNextImages.
>    */
>   public void testProcessRequest() throws ServletException, IOException
>   {
>     System.out.println("testProcessRequest");
> 
>     Assert.assertEquals("application/xml", request.getContentType());
>     GetNextImages instance = new GetNextImages();
>     instance.init(config);
>     Session session = instance.openSession();
>     instance.processRequest(request, response, session);
>     instance.destroy();
>   }
> 
> 
>     It dies with on Assert.assertEquals("application/xml", 
> request.getContentType()) inside of testProcessRequest() but not inside 
> beginTestProcessRequest(). I don't understand how it could possibly say 
> the headers were set properly in the beginXXX() method but then change 
> its mind in the testXXX() method. Ideas?
> 
> Gili
>