I searched the list and found a possible solution using wicket.protocol.http.MockWebApplication.. however, upon implementing that solution I am having problems. Here is the code I am using (with garbage stuff removed) which is called from my web application's Form#onSubmit().
public static void mail( Message msg, MailTemplate pageToMail ) // MailTemplate extends WebPage
{
// create a mock application
MockWebApplication app = new MockWebApplication( pageToMail.getApplication().getApplicationSettings().getContextPath() );
// set a null home page.. we will set the page later
app.setHomePage( NullHomePage.class );
// setup the request/response
app.setupRequestAndResponse();
app.processRequestCycle( pageToMail );
// get the output
String output = new String( app.getServletResponse().getBinaryContent() );
// add the template to the output
msg.getBodies().add( new TextBody( output ) );
Mailer.mail( msg );
}
generates
java.lang.NullPointerException
wicket.request.compound.DefaultExceptionResponseStrategy.onRuntimeException(DefaultExceptionResponseStrategy.java:141) wicket.request.compound.DefaultExceptionResponseStrategy.respond(DefaultExceptionResponseStrategy.java:64) wicket.request.compound.AbstractCompoundRequestCycleProcessor.respond(AbstractCompoundRequestCycleProcessor.java:76) wicket.RequestCycle.step(RequestCycle.java:976) wicket.RequestCycle.steps(RequestCycle.java:1010) wicket.RequestCycle.request(RequestCycle.java:452) wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:210) wicket.protocol.http.WicketServlet.doPost(WicketServlet.java:251) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) javax.servlet.http.HttpServlet.service(HttpServlet.java:810) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96) The mail gets sent but with empty content (no output captured) Questions.. can I just generate the output of a Page *instance*? Many of my pages have no default constructor, so I can't set them as the Mock homePage. is using MockWebApplication the best way to achieve these results?
