That worked! Thanks a lot Martin -----Original Message----- From: Martin Grigorov [mailto:mgrigo...@apache.org] Sent: Thursday, December 06, 2012 3:10 AM To: users@wicket.apache.org Subject: Re: Returning XML or HTML
A simpler solution is: if (needsXml()) { getRequestCycle().replaceAllRequestHandlers(new TextRequestHandler("text/xml", theXml)) } On Thu, Dec 6, 2012 at 7:55 AM, Sven Meier <s...@meiers.net> wrote: > You'll have to let Wicket know that you wrote the response by yourself. > > With |RestartResponseException| you can switch to another response. In > your case you could direct the request to a resource first (since your XML > doesn't seem be component-based) and switch to a page in case of missing > parameters. > > Sven > > > > On 12/06/2012 04:49 AM, McDonough, Jonathan wrote: > >> Hi all, >> I am trying to create a WebPage that returns either XML or HTML depending >> upon if a parameter is supplied. If the parameter is supplied, return a >> custom XML document. Otherwise return an HTML page with an error message. >> The code I wrote produces these results, which is great. But it is also >> throwing an exception (below) to the console. Does anyone know how to go >> about fixing this? >> >> I am using Java 6 and Wicket 6.2.0 >> >> Thanks >> Jon >> >> Here is the code for DocumentPage.java: >> public DocumentPage(final PageParameters parameters) { >> setStatelessHint(true); >> >> // Get the ID >> final org.apache.wicket.util.string.**StringValue >> idStringValue = parameters.get(0); >> if (idStringValue == null || idStringValue.isEmpty()) { >> add(new Label("errorMsg", "Please supply an >> ID")); >> return; >> } >> >> >> // Get the CTS2 XML from the database >> final String id = idStringValue.toString(); >> >> >> // Send the output >> add(new Label("errorMsg", "")); >> String content = "<result><entry>" + id + >> "</entry></result>"; >> >> RequestCycle.get().**getOriginalResponse().write(** >> content); >> } >> >> >> DocumentPage.html: >> <html> >> <head> >> <title>Error</title> >> </head> >> >> <body> >> <span wicket:id="errorMsg" /> >> </body> >> </html> >> >> >> 2012-12-05 22:36:32,976 ERROR [RequestCycle] Error during processing >> error message >> java.lang.**IllegalStateException: Header was already written to >> response! >> at org.apache.wicket.protocol.**http.** >> HeaderBufferingWebResponse.**checkHeader(**HeaderBufferingWebResponse.** >> java:64) >> at org.apache.wicket.protocol.**http.** >> HeaderBufferingWebResponse.**sendError(**HeaderBufferingWebResponse.** >> java:105) >> at org.apache.wicket.request.**http.handler.** >> ErrorCodeRequestHandler.**respond(**ErrorCodeRequestHandler.java:**77) >> at org.apache.wicket.request.**cycle.RequestCycle$** >> HandlerExecutor.respond(**RequestCycle.java:830) >> at org.apache.wicket.request.**RequestHandlerStack.execute(** >> RequestHandlerStack.java:64) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> executeExceptionRequestHandler**(RequestCycle.java:302) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> executeExceptionRequestHandler**(RequestCycle.java:311) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> executeExceptionRequestHandler**(RequestCycle.java:311) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> executeExceptionRequestHandler**(RequestCycle.java:311) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> executeExceptionRequestHandler**(RequestCycle.java:311) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> executeExceptionRequestHandler**(RequestCycle.java:311) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> executeExceptionRequestHandler**(RequestCycle.java:311) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> executeExceptionRequestHandler**(RequestCycle.java:311) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> executeExceptionRequestHandler**(RequestCycle.java:311) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> executeExceptionRequestHandler**(RequestCycle.java:311) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> executeExceptionRequestHandler**(RequestCycle.java:311) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> processRequest(RequestCycle.**java:225) >> at org.apache.wicket.request.**cycle.RequestCycle.** >> processRequestAndDetach(**RequestCycle.java:281) >> at org.apache.wicket.protocol.**http.WicketFilter.** >> processRequest(WicketFilter.**java:188) >> at org.apache.wicket.protocol.**http.WicketFilter.doFilter(** >> WicketFilter.java:245) >> at org.apache.catalina.core.**ApplicationFilterChain.** >> internalDoFilter(**ApplicationFilterChain.java:**243) >> at org.apache.catalina.core.**ApplicationFilterChain.**doFilter( >> **ApplicationFilterChain.java:**210) >> at org.apache.catalina.core.**StandardWrapperValve.invoke(** >> StandardWrapperValve.java:225) >> at org.apache.catalina.core.**StandardContextValve.invoke(** >> StandardContextValve.java:123) >> at org.apache.catalina.**authenticator.** >> AuthenticatorBase.invoke(**AuthenticatorBase.java:472) >> at org.apache.catalina.core.**StandardHostValve.invoke(** >> StandardHostValve.java:168) >> at org.apache.catalina.valves.**ErrorReportValve.invoke(** >> ErrorReportValve.java:98) >> at org.apache.catalina.valves.**AccessLogValve.invoke(** >> AccessLogValve.java:927) >> at org.apache.catalina.core.**StandardEngineValve.invoke(** >> StandardEngineValve.java:118) >> at org.apache.catalina.connector.**CoyoteAdapter.service(** >> CoyoteAdapter.java:407) >> at org.apache.coyote.http11.**AbstractHttp11Processor.**process( >> **AbstractHttp11Processor.java:**1001) >> at org.apache.coyote.**AbstractProtocol$** >> AbstractConnectionHandler.**process(AbstractProtocol.java:**579) >> at org.apache.tomcat.util.net.**JIoEndpoint$SocketProcessor.** >> run(JIoEndpoint.java:310) >> at java.util.concurrent.**ThreadPoolExecutor$Worker.** >> runTask(ThreadPoolExecutor.**java:886) >> at java.util.concurrent.**ThreadPoolExecutor$Worker.run(** >> ThreadPoolExecutor.java:908) >> at java.lang.Thread.run(Thread.**java:662) >> >> >> >> >> sdsd >> >> >> >> The information in this e-mail is intended only for the person to whom it >> is >> addressed. If you believe this e-mail was sent to you in error and the >> e-mail >> contains patient information, please contact the Partners Compliance >> HelpLine at >> http://www.partners.org/**complianceline<http://www.partners.org/complianceline>. >> If the e-mail was sent to you in error >> but does not contain patient information, please contact the sender and >> properly >> dispose of the e-mail. >> >> > > ------------------------------**------------------------------**--------- > To unsubscribe, e-mail: > users-unsubscribe@wicket.**apache.org<users-unsubscr...@wicket.apache.org> > For additional commands, e-mail: users-h...@wicket.apache.org > > -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com <http://jweekend.com/> --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org