Thank you very much, Johan!

I wrote my own XMLRequestTarget around your code and now it works.

Daniel

Johan Compagner schrieb:
> you can't just write to something in the constructor (thats in the
> event/request phase)
> 
> make a RequestTarget that outputs that what you want and set that
> request target as the response request target
> on the request cycle
> 
> RequestCycle.get().setRequestTarget(new IRequestTarget()
> {
>    void respond(RequestCycle requestCycle)
>    {
>         Response rep = requestCycle.getResponse();
>         rep.write(yourxml);
>    }
> });
> 
> johan
> 
> On 1/23/07, *Daniel Nüst* <[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>> wrote:
> 
>     Hi Igor!
> 
>     Igor Vaynberg schrieb:
>     > looks like you are trying to output your xml too late in the game
>     > (wicket has already written something to the request).
>     I would rather guess it seems the other way around (and I will try to
>     explain the situation a bit better):
> 
>     * If I use res.write( xmlout.outputString( doc ) );, I do not get the
>     exeption, but the response is not a xml file, but a "xml+html" document:
> 
>     <?xml version=" 1.0" encoding="UTF-8"?>
>     <newsList xlmns="http:// ... </newsList>
>     <html>
>     <head>
>     <meta http-equiv="Content-Type" content="text/html; charset=Cp1252"/>
> 
> 
>     * If I use xmlout.output(doc, res.getOutputStream() );, I have an
>     exception (whole trace):
> 
>     java.lang.IllegalStateException: getOutputStream() has already been
>     called for this response
>             at
>     org.apache.catalina.connector.Response.getWriter(Response.java:599)
>             at
>     
> org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:195)
>             at wicket.protocol.http.WebResponse.write(WebResponse.java :315)
>             at
>     
> wicket.protocol.http.BufferedWebResponse.close(BufferedWebResponse.java:75)
>             at
>     wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:229)
>             at javax.servlet.http.HttpServlet.service (HttpServlet.java:689)
>             at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>             at
>     
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
>             at
>     
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
>             at
>     
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
>             at
>     org.apache.catalina.core.StandardContextValve.invoke
>     (StandardContextValve.java:178)
>             at
>     
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
>             at
>     
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
> 
>             at
>     
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
>             at
>     
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
>             at
>     org.apache.coyote.http11.Http11Processor.process
>     (Http11Processor.java:869)
>             at
>     
> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
>             at
>     org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket
>     (PoolTcpEndpoint.java:527)
>             at
>     
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
>             at
>     
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java
>     :684)
>             at java.lang.Thread.run(Unknown Source)
> 
>     To me it looks as if I wrote my xml file and wicket wants to write the
>     html code just behind it (just as it does when i use Response.write() ),
>     but it cannot because I already called getOutputStream().
> 
>     I create the xml file on runtime and do not have a empty one in the same
>     directory as suggested in the rss examples, but I see not reason that is
>     the problem.
> 
>     > what triggers that code?
>     The constructor:
> 
>     public RequestXML() {
>             WebRequest req = (WebRequest) getRequest();
>             WebResponse res = (WebResponse) getResponse();
> 
>             parametersToResponse(req.getParameterMap(), res);
>             } catch (IOException e) {
>                     e.printStackTrace();
>             }
>     }
> 
>     I want to use that page to request data out of a Firefox extension.
>     I appreciate every idea.
> 
>     Regards
>     Daniel
> 
> 
>     >
>     > -igor
>     >
>     >
>     > On 1/22/07, *Daniel Nüst* <[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]>
>     > <mailto:[EMAIL PROTECTED]
>     <mailto:[EMAIL PROTECTED]> >> wrote:
>     >
>     >     Hi!
>     >
>     >     I want to load an XML-file from a wicket page concerning the
>     html page
>     >     parameters with javascript. The javascript part (load and
>     parse xml)
>     >     works fine and also the generated xml file is okay.
>     >
>     >     I just always get an
>     >
>     >     java.lang.IllegalStateException: getOutputStream() has already
>     been
>     >     called for this response
>     >             at
>     >     org.apache.catalina.connector.Response.getWriter
>     (Response.java:599)
>     >             at
>     >     org.apache.catalina.connector.ResponseFacade.getWriter
>     >     (ResponseFacade.java:195)
>     >             at
>     wicket.protocol.http.WebResponse.write(WebResponse.java :315)
>     >             at
>     >    
>     
> wicket.protocol.http.BufferedWebResponse.close(BufferedWebResponse.java:75)
>     >             at wicket.protocol.http.WicketServlet.doGet
>     >     (WicketServlet.java:229)
>     >     [...]
>     >
>     >
>     >     I did some research on this problem and found some workarounds
>     for jsp.
>     >     I also tried different combinations of Streams and Writers.
>     Alsways that
>     >     exception.
>     >
>     >     The code:
>     >
>     >     private void parametersToResponse(Map<String, String> params,
>     Response
>     >     res) throws IOException {
>     >                     res.setContentType("text/xml");
>     >
>     >                     logger.info("map: " + params);
>     >
>     >     //              test for illegal keys
>     >                     if ( containsIllegalKeys(params) ||
>     params.isEmpty() ) {
>     >                             logger.warn(howtoString);
>     >                             res.write(howtoString); //works!
>     >                     } else {
>     >
>     >     //                      get news from database
>     >                             Collection<News> news =
>     getNewsFromDB(params);
>     >
>     >     //                      create xml document from news
>     >                             Document doc = createXML(news);
>     >
>     >     //                      write xml file to stream
>     >                             XMLOutputter xmlout = new XMLOutputter();
>     >     //                      res.write ( xmlout.outputString( doc )
>     >     );  //does not work, res
>     >     writes xml to beginning of html page
>     >                             xmlout.output(doc,
>     res.getOutputStream() );
>     >     //somehow dublicate call
>     >     of getOutputStream !!!
>     >                     }
>     >             }
>     >
>     >     Another solution would be, not to use XMLOutputter, just
>     >     response.write("..."), but I don't get a correct XML file but
>     just my
>     >     xml put before the html:
>     >
>     >     <?xml version=" 1.0" encoding="UTF-8"?>
>     >     <newsList [...]
>     >     <html>
>     >     <head>[...]
>     >
>     >     Anybody an idea how to solve the former or the latter?
>     >
>     >     Regards,
>     >     Daniel
>     >
>     >    
>     -------------------------------------------------------------------------
>     >
>     >     Take Surveys. Earn Cash. Influence the Future of IT
>     >     Join SourceForge.net's Techsay panel and you'll get the chance to
>     >     share your
>     >     opinions on IT & business topics through brief surveys - and
>     earn cash
>     >    
>     http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>     
> <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV>
>     >    
>     <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>     
> <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV>>
>     >     _______________________________________________
>     >     Wicket-user mailing list
>     >     Wicket-user@lists.sourceforge.net
>     <mailto:Wicket-user@lists.sourceforge.net>
>     >     <mailto: Wicket-user@lists.sourceforge.net
>     <mailto:Wicket-user@lists.sourceforge.net>>
>     >     https://lists.sourceforge.net/lists/listinfo/wicket-user
>     <https://lists.sourceforge.net/lists/listinfo/wicket-user>
>     >     <https://lists.sourceforge.net/lists/listinfo/wicket-user>
>     >
>     >
> 
>     -------------------------------------------------------------------------
> 
>     Take Surveys. Earn Cash. Influence the Future of IT
>     Join SourceForge.net's Techsay panel and you'll get the chance to
>     share your
>     opinions on IT & business topics through brief surveys - and earn cash
>     http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>     
> <http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV>
>     _______________________________________________
>     Wicket-user mailing list
>     Wicket-user@lists.sourceforge.net
>     <mailto:Wicket-user@lists.sourceforge.net>
>     https://lists.sourceforge.net/lists/listinfo/wicket-user
>     <https://lists.sourceforge.net/lists/listinfo/wicket-user>
> 
> 

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to