Re: Returning XML or HTML

2012-12-06 Thread Martin Grigorov
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 = resultentry + id +
 /entry/result;

  RequestCycle.get().**getOriginalResponse().write(**
 content);
  }


 DocumentPage.html:
 html
  head
  titleError/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(**
 

RE: Returning XML or HTML

2012-12-06 Thread McDonough, Jonathan
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 = resultentry + id +
 /entry/result;

  RequestCycle.get().**getOriginalResponse().write(**
 content);
  }


 DocumentPage.html:
 html
  head
  titleError/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

Re: Returning XML or HTML

2012-12-05 Thread Sven Meier

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 = resultentry + id + /entry/result;

 RequestCycle.get().getOriginalResponse().write(content);
 }


DocumentPage.html:
html
 head
 titleError/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