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 <[email protected]> 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: [email protected] > For additional commands, e-mail: [email protected] > -- Martin Grigorov jWeekend Training, Consulting, Development http://jWeekend.com --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
