My initial thoughts of the exceptions being related to the ThreadLocal nature of wicket.Application seem to hold true.

I solved this once and for all by using a subclass of WicketTester (for which I needed to add a getter for the generated source), and a new Thread to create the WicketTester within.  Of course, since I need to pass the page creation logic from the main application, I also needed to create an interface ( like ITestPageSource ) to defer the page creation until we are inside of the new Thread.



On Wed, 2006-04-19 at 01:56 -0700, Aaron Hiniker wrote:
Ok,

So I extended WicketTester, added a method to return the servlet output and I got the html mail to render correctly.  However, the normal requestCycle seems to be corrupted after I do this:

in the logs:

2006-04-19 01:47:10,500 ERROR [STDERR] java.lang.NullPointerException
2006-04-19 01:47:10,501 ERROR [STDERR]  at wicket.Component.setResponsePage(Component.java:1966)
2006-04-19 01:47:10,501 ERROR [STDERR]  at us.myblock.pages.noauth.usersignup.Step2$Step2Form.onSubmit(Step2.java:152)
2006-04-19 01:47:10,502 ERROR [STDERR]  at wicket.markup.html.form.Form.delegateSubmit(Form.java:457)
2006-04-19 01:47:10,502 ERROR [STDERR]  at wicket.markup.html.form.Form.onFormSubmitted(Form.java:284)
2006-04-19 01:47:10,502 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2006-04-19 01:47:10,502 ERROR [STDERR]  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
2006-04-19 01:47:10,502 ERROR [STDERR]  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
2006-04-19 01:47:10,502 ERROR [STDERR]  at java.lang.reflect.Method.invoke(Method.java:585)
2006-04-19 01:47:10,503 ERROR [STDERR]  at wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:163)
2006-04-19 01:47:10,503 ERROR [STDERR]  at wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:74)
2006-04-19 01:47:10,503 ERROR [STDERR]  at wicket.request.compound.DefaultEventProcessorStrategy.processEvents(DefaultEventProcessorStrategy.java:65)
2006-04-19 01:47:10,503 ERROR [STDERR]  at wicket.request.compound.AbstractCompoundRequestCycleProcessor.processEvents(AbstractCompoundRequestCycleProcessor.java:57)
2006-04-19 01:47:10,503 ERROR [STDERR]  at wicket.RequestCycle.doProcessEventsAndRespond(RequestCycle.java:822)
2006-04-19 01:47:10,504 ERROR [STDERR]  at wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:855)
2006-04-19 01:47:10,504 ERROR [STDERR]  at wicket.RequestCycle.step(RequestCycle.java:936)
2006-04-19 01:47:10,504 ERROR [STDERR]  at wicket.RequestCycle.steps(RequestCycle.java:1010)
2006-04-19 01:47:10,504 ERROR [STDERR]  at wicket.RequestCycle.request(RequestCycle.java:452)
2006-04-19 01:47:10,504 ERROR [STDERR]  at wicket.protocol.http.WicketServlet.doGet(WicketServlet.java:210)
2006-04-19 01:47:10,504 ERROR [STDERR]  at wicket.protocol.http.WicketServlet.doPost(WicketServlet.java:251)


in the browser, Tomcat reports this exception:

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)


Is this because I am creating the Page object to be rendered to WicketTester from within my main application thread?  I check the source code on the first NPE exception,

and it's because Component#setResponsePage as this line:

getRequestCycle().setResponsePage( page )  

so the NPE is present because getRequestCycle() is returning null.. what is causing that?



On Wed, 2006-04-19 at 10:28 +0200, Juergen Donnerstag wrote:
Please see WicketTester which is based on MockWebApplication and all
the junit test cases in src/test which use the same principle: create
the output as a string and compare it with the expected output which
is kept in a file.

Juergen

On 4/19/06, Aaron Hiniker <[EMAIL PROTECTED]> wrote:
> I would like to render a page to a String for sending as an HTML email.
>
> 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?





>


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to