Yes,  I've used code from mail example, as I said. The mail example does not  
fit into my needs because the rendering thread must be independent,  
out-of-request. ( for example into a Timer/TimerTask)

I've been looking into Wicket tester classes  
(http://wicket.apache.org/apidocs/1.5/org/apache/wicket/util/tester/BaseWicketTester.html)
and I've made changes to code.

Luckily,  I've succeed and I got a functional request-independent page 
renderer,  which only dependes on webapp and it's easy to use:

MyAppPageBuffer.java
http://pastebin.com/XJMV8N7d

If you want to see and review it, comments are welcome


    > > > Oscar Besga Arcauz  < < < 

Pd. with a little side effect, but I'll talk about it on another mail




-----Martin Grigorov <mgrigo...@apache.org> escribió: -----
Para: users@wicket.apache.org
De: Martin Grigorov <mgrigo...@apache.org>
Fecha: 08/10/2012  10:00
Asunto: Re: Wicket page HTML extractor

Hi,

Why don't use the source of MailTemplate example
(http://www.wicket-library.com/wicket-examples/mailtemplate) ?

Your code seems to be much more complex.

On Fri, Oct 5, 2012 at 8:02 PM, Oscar Besga Arcauz <obe...@isdefe.es> wrote:
>  Hi wickers !
>
> I want to generate the HTML from a wicket WebPage and store into a String; 
> out of a request - for example in a timer thread.
> I'm thinking in making a buffer (inter request) for my webapplication for 
> some pages, for this I want to extract HTML-generated content from wicket 
> pages.
>
>
>
> Here  in danwalmsley blog -> 
> http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/ <-
> and mail template (page-generated) example -> 
> http://www.wicket-library.com/wicket-examples/mailtemplate/?0 <-
> I've seen some code to build the extractor.
>
> I've walked some steps, and I think I'm on the rigth direction, but it 
> doesn't work.
>
> This is the code I've done so far, if anyone knows I'll be graceful for 
> commenting
>
>
> class WebPageExtractor
>
>     protected String renderPageToString(WebApplication webApp) {
>
>         String urlForMockRequest = "myPage"; // I've also tried 
> localhost/myPage and others
>         String filterPrefix = ""; // Doesn't know what to put here, really. 
> Wicket filter is to *
>
>         //get the servlet context
>         ServletContext context = webApp.getServletContext();
>
>         //fake a request/response cycle
>         MockHttpSession servletSession = new MockHttpSession(context);
>         servletSession.setTemporary(true);
>
>         MockHttpServletRequest mockServletRequest = new 
> MockHttpServletRequest(isdefeWebApp, servletSession, context);
>         mockServletRequest.setURL("/" + urlForMockRequest);
>         // also tried this 
> mockServletRequest.setURL(mockServletRequest.getContextPath() + 
> mockServletRequest.getServletPath() + "/");
>         MockHttpServletResponse mockServletResponse = new 
> MockHttpServletResponse(mockServletRequest);
>
>         //initialize request and response
>         mockServletRequest.initialize();
>         mockServletResponse.initialize();
>
>         // Generate wicket web request and so on..
>         Url url = new Url(Arrays.asList(urlForMockRequest), new 
> ArrayList<Url.QueryParameter>());
>
>         ServletWebRequest webRequest = new 
> ServletWebRequest(mockServletRequest, filterPrefix, url);
>         ServletWebResponse webResponse = new ServletWebResponse(webRequest, 
> mockServletResponse);
>         BufferedWebResponse bufferedWebResponse = new 
> BufferedWebResponse(webResponse);
>
>         RequestCycle requestCycle = webApp.createRequestCycle(webRequest, 
> bufferedWebResponse);
>         BookmarkablePageRequestHandler bookmarkablePageRequestHandler = new 
> BookmarkablePageRequestHandler(new PageProvider(MyPage.class, new 
> PageParameters()));
>         bookmarkablePageRequestHandler.respond(requestCycle);
>         // Also tried
>         //requestCycle.setResponsePage(MyPage.class,new PageParameters());
>         requestCycle.processRequestAndDetach();
>         requestCycle.getResponse().close();
>         CharSequence cs = bufferedWebResponse.getText(); //NULL!!!
>         if (cs != null) {
>             return cs.toString();
>         } else {
>             // CS is always null :(
>             return null;
>         }
> }
>
>
> Thanks for your help and excuse my poor english
>
>
>
>     > > > Oscar Besga Arcauz  < < <
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to