You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Stefan Neumann <st...@freiheit.com> on 2011/09/29 11:06:10 UTC

Redering to to file in wicket1.5

Hey guys,

 I need to render a page to a String or file. I have already read the
typical reference [1] [2] for this topic.

The difference is, that I am using wicket 1.5 and there must be some
API changes so I could not use the given examples.

Has someone an example? I tried my best to make the exampel compile
but i alwas get a NPE at
bufferedWebResponse.getText().toString()

Appreciate your help in advance,

Stefan


[1]
http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/
[2]
https://gist.github.com/1152059
[3]
 public static String renderPage(final Class<? extends Page>
pageClass, final PageParameters pageParameters)
        {
            final WebApplication application = WebApplication.get();
            final ServletContext context =
application.getServletContext();  //fake a request/response cycle
            final MockHttpSession servletSession = new MockHttpSession(context);
            servletSession.setTemporary(true);
            final MockHttpServletRequest servletRequest = new
MockHttpServletRequest(application, servletSession, context);
            final MockHttpServletResponse servletResponse = new
MockHttpServletResponse(servletRequest);  //initialize request and
response
            servletRequest.initialize();
            servletResponse.initialize();

            final ServletWebRequest webRequest = new
ServletWebRequest(servletRequest,"/");
            final WebResponse webResponse = new
ServletWebResponse(webRequest,servletResponse);
            final BufferedWebResponse bufferedWebResponse = new
BufferedWebResponse(webResponse);
            //webResponse.setAjax(true);
            final RequestCycle requestCycle = new RequestCycle(
                new RequestCycleContext(webRequest, webResponse,
application.getRootRequestMapper(,
application.getExceptionMapperProvider().get()));

            //requestCycle.setRequestTarget(new
BookmarkablePageRequestTarget(pageClass, pageParameters));
            requestCycle.setResponsePage(pageClass, pageParameters);

            try
            {
                final boolean handled = requestCycle.processRequestAndDetach();


                LOGGER.info("Response after request: " +
bufferedWebResponse.getText().toString());

                if (! handled)
                {
                    LOGGER.error(">>>>>>>>>>>>>>>>>>>>>>> NOT HANDLED");
                    //requestCycle.set(new
ErrorCodeRequestHandler(HttpServletResponse.SC_NOT_FOUND));
                }

                //requestCycle.detach();
            }
            finally
            {
                requestCycle.getResponse().close();
            }

            return bufferedWebResponse.getText().toString();
        }

-- 
Stefan Neumann
Dipl.-Ing.
freiheit.com technologies gmbh
Straßenbahnring 22 / 20251 Hamburg, Germany
fon +49 (0)40 / 890584-0
fax +49 (0)40 / 890584-20
HRB Hamburg 70814
1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof

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


Re: Redering to to file in wicket1.5

Posted by Martin Grigorov <mg...@apache.org>.
On Mon, Oct 3, 2011 at 12:39 PM, Marco <ma...@mkconsultancy.nl> wrote:
> public String renderTemplate(WebPage webPage) {
>        BufferedWebResponse bufferedWebResponse = new BufferedWebResponse(null);
>        webPage.getRequestCycle().setResponse(bufferedWebResponse);
>        webPage.render();
>
>        return bufferedWebResponse.getText().toString();
> }
>
> Martin, it's the solution we discussed earlier at
> http://apache-wicket.1842946.n4.nabble.com/Render-WebPage-to-String-in-Wicket-1-5-td3622130.html\
Yes, I'm going to create an example in wicket-examples like the one
for 1.4 at http://wicketstuff.org/wicket14/staticpages/ and another
one with TextTemplate because most of the time this email template is
actually static markup with dynamically generated urls inside.

Will be part of https://issues.apache.org/jira/browse/WICKET-4095
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Redering-to-to-file-in-wicket1-5-tp3854891p3867079.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



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

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


Re: Redering to to file in wicket1.5

Posted by Marco <ma...@mkconsultancy.nl>.
public String renderTemplate(WebPage webPage) {
	BufferedWebResponse bufferedWebResponse = new BufferedWebResponse(null);
	webPage.getRequestCycle().setResponse(bufferedWebResponse);
	webPage.render();
	
	return bufferedWebResponse.getText().toString();
}

Martin, it's the solution we discussed earlier at
http://apache-wicket.1842946.n4.nabble.com/Render-WebPage-to-String-in-Wicket-1-5-td3622130.html

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Redering-to-to-file-in-wicket1-5-tp3854891p3867079.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Redering to to file in wicket1.5

Posted by Martin Grigorov <mg...@apache.org>.
Hi Marco,

On Mon, Oct 3, 2011 at 12:22 PM, Marco <ma...@mkconsultancy.nl> wrote:
> You can also use:
>
>
>
You paste didn't make it.
> I prefer this solution. Using a class which is intended for testing
> (WicketTester) to produce results in a production environment is strange.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Redering-to-to-file-in-wicket1-5-tp3854891p3867053.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



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

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


Re: Redering to to file in wicket1.5

Posted by Marco <ma...@mkconsultancy.nl>.
You can also use:



I prefer this solution. Using a class which is intended for testing
(WicketTester) to produce results in a production environment is strange.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Redering-to-to-file-in-wicket1-5-tp3854891p3867053.html
Sent from the Users forum mailing list archive at Nabble.com.

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


Re: Redering to to file in wicket1.5

Posted by Martin Grigorov <mg...@apache.org>.
On Thu, Sep 29, 2011 at 4:18 PM, Stefan Neumann
<st...@freiheit.com> wrote:
> Perfect. It works.
>
> Even though I don't need it, I just have a hint for all, who want to
> use it as well, It seems not to work in a constructor of a page.
>
> I created the issue for the wicket-examples:
> https://issues.apache.org/jira/browse/WICKET-4095
>
> You will find a working code snipplet as well.
cool. thanks !
>
> thanks a lot!
>
> Stefan
>
>
>
> 2011/9/29 Martin Grigorov <mg...@apache.org>:
>> Use org.apache.wicket.request.handler.RenderPageRequestHandler.RenderPageRequestHandler(IPageProvider,
>> RedirectPolicy)
>> with org.apache.wicket.request.handler.RenderPageRequestHandler.RedirectPolicy.NEVER_REDIRECT
>>
>> On Thu, Sep 29, 2011 at 2:01 PM, Stefan Neumann
>> <st...@freiheit.com> wrote:
>>> Hey,
>>>
>>> I tried to use a MockWebRespone:
>>>
>>>       // final StringResponse newResponse = new StringResponse();
>>>        final MockWebResponse mockWebResponse = new MockWebResponse();
>>>        requestCycle.setResponse(mockWebResponse);
>>>        pageRenderer.respond(requestCycle);
>>>        requestCycle.setResponse(oldResponse);
>>>
>>>        return mockWebResponse.getTextResponse().toString();
>>>
>>> But the getTextRespone() is null, because there is a redirect to the
>>> correct mapped url:
>>>
>>> "print/<external-id>"
>>>
>>> Can I follow this redirect?
>>>
>>>
>>>
>>> 2011/9/29 Stefan Neumann <st...@freiheit.com>:
>>>> Hey Martin,
>>>>
>>>> I get now a CastException in:
>>>>
>>>> Root cause:
>>>>
>>>> java.lang.ClassCastException:
>>>> org.apache.wicket.response.StringResponse cannot be cast to
>>>> org.apache.wicket.request.http.WebResponse
>>>>     at org.apache.wicket.request.handler.render.WebPageRenderer.redirectTo(WebPageRenderer.java:134)
>>>>     at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:214)
>>>>     at com.freiheit.tango.presentation.application.WicketUtils.renderPageNew(WicketUtils.java:54)
>>>>
>>>> the corresponing line is:
>>>>
>>>>        final WebApplication application = WebApplication.get();
>>>>
>>>>        final RenderPageRequestHandler handler = new
>>>> RenderPageRequestHandler(new PageProvider(pageClass, pageParameters));
>>>>        final PageRenderer pageRenderer =
>>>> application.getPageRendererProvider().get(handler);
>>>>
>>>>        final Response oldResponse = requestCycle.getResponse();
>>>>        final StringResponse newResponse = new StringResponse();
>>>>        requestCycle.setResponse(newResponse);
>>>>
>>>>  -->       pageRenderer.respond(requestCycle); <---
>>>>        requestCycle.setResponse(oldResponse);
>>>>
>>>>        return newResponse.toString();
>>>>
>>>> But seems to get closer ;-)
>>>>
>>>> I can add the ticket when my case is running.
>>>>
>>>> Greetings
>>>> Stefan
>>>>
>>>> 2011/9/29 Martin Grigorov <mg...@apache.org>:
>>>>> I guess I need to add an example of this in wicket-examples ...
>>>>> Please create a ticket to not forget it.
>>>>>
>>>>> Here is how it should work:
>>>>>
>>>>> IRequestHandler handler = new RenderPageRequestHandler(Page.class, parameters);
>>>>> PageReneder renderer = application.getgetPageRendererProvider().get(handler);
>>>>>
>>>>> oldResponse = requestCycle.getResponse();
>>>>> StringResponse newResponse = new StringResponse();
>>>>> requestCycle.setResponse(newResponse);
>>>>>
>>>>> renderer.respond(requestCycle);
>>>>> requestCycle.setResponse(oldResponse);
>>>>>
>>>>> pageAsText = newResponse.toString();
>>>>>
>>>>> On Thu, Sep 29, 2011 at 12:09 PM, Stefan Neumann
>>>>> <st...@freiheit.com> wrote:
>>>>>> Hey Martin,
>>>>>>
>>>>>> thanks for the quick response.  It sounds quite good, but it is not working yet.
>>>>>>
>>>>>> Since we use guice, I tried to use the WebApplication we have
>>>>>> configured already:
>>>>>>
>>>>>>        final WicketTester wicketTester = new
>>>>>> WicketTester(WebApplication.get());
>>>>>>        wicketTester.startPage(pageClass,pageParameters);
>>>>>>        return wicketTester.getLastResponseAsString();
>>>>>>
>>>>>> But I get following exception[1].
>>>>>>
>>>>>> Some more basic conditions.
>>>>>> * A request is currently running.
>>>>>> * I need to get session information into the rendering, since the data
>>>>>> loading for the page contains authorization checks on the currently
>>>>>> logged in user.
>>>>>>
>>>>>> Any suggestions?
>>>>>>
>>>>>> Stefan
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Caused by: java.lang.reflect.InvocationTargetException
>>>>>>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>>>>>>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>>>>>>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>>>>>>        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>>>>>>        at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:177)
>>>>>>        ... 37 more
>>>>>> Caused by: java.lang.IllegalStateException: Application name can only
>>>>>> be set once.
>>>>>>        at org.apache.wicket.Application.setName(Application.java:846)
>>>>>>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:291)
>>>>>>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:241)
>>>>>>        at org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:192)
>>>>>>        at com.freiheit.tango.presentation.application.WicketUtils.renderPageWithWicketTester(WicketUtils.java:43)
>>>>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:124)
>>>>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:108)
>>>>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:104)
>>>>>>        ... 42 more
>>>>>>
>>>>>>
>>>>>> 2011/9/29 Martin Grigorov <mg...@apache.org>:
>>>>>>> use WicketTester.startPage() and tester.getLastResponseAsString()
>>>>>>>
>>>>>>> On Thu, Sep 29, 2011 at 11:06 AM, Stefan Neumann
>>>>>>> <st...@freiheit.com> wrote:
>>>>>>>> Hey guys,
>>>>>>>>
>>>>>>>>  I need to render a page to a String or file. I have already read the
>>>>>>>> typical reference [1] [2] for this topic.
>>>>>>>>
>>>>>>>> The difference is, that I am using wicket 1.5 and there must be some
>>>>>>>> API changes so I could not use the given examples.
>>>>>>>>
>>>>>>>> Has someone an example? I tried my best to make the exampel compile
>>>>>>>> but i alwas get a NPE at
>>>>>>>> bufferedWebResponse.getText().toString()
>>>>>>>>
>>>>>>>> Appreciate your help in advance,
>>>>>>>>
>>>>>>>> Stefan
>>>>>>>>
>>>>>>>>
>>>>>>>> [1]
>>>>>>>> http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/
>>>>>>>> [2]
>>>>>>>> https://gist.github.com/1152059
>>>>>>>> [3]
>>>>>>>>  public static String renderPage(final Class<? extends Page>
>>>>>>>> pageClass, final PageParameters pageParameters)
>>>>>>>>        {
>>>>>>>>            final WebApplication application = WebApplication.get();
>>>>>>>>            final ServletContext context =
>>>>>>>> application.getServletContext();  //fake a request/response cycle
>>>>>>>>            final MockHttpSession servletSession = new MockHttpSession(context);
>>>>>>>>            servletSession.setTemporary(true);
>>>>>>>>            final MockHttpServletRequest servletRequest = new
>>>>>>>> MockHttpServletRequest(application, servletSession, context);
>>>>>>>>            final MockHttpServletResponse servletResponse = new
>>>>>>>> MockHttpServletResponse(servletRequest);  //initialize request and
>>>>>>>> response
>>>>>>>>            servletRequest.initialize();
>>>>>>>>            servletResponse.initialize();
>>>>>>>>
>>>>>>>>            final ServletWebRequest webRequest = new
>>>>>>>> ServletWebRequest(servletRequest,"/");
>>>>>>>>            final WebResponse webResponse = new
>>>>>>>> ServletWebResponse(webRequest,servletResponse);
>>>>>>>>            final BufferedWebResponse bufferedWebResponse = new
>>>>>>>> BufferedWebResponse(webResponse);
>>>>>>>>            //webResponse.setAjax(true);
>>>>>>>>            final RequestCycle requestCycle = new RequestCycle(
>>>>>>>>                new RequestCycleContext(webRequest, webResponse,
>>>>>>>> application.getRootRequestMapper(,
>>>>>>>> application.getExceptionMapperProvider().get()));
>>>>>>>>
>>>>>>>>            //requestCycle.setRequestTarget(new
>>>>>>>> BookmarkablePageRequestTarget(pageClass, pageParameters));
>>>>>>>>            requestCycle.setResponsePage(pageClass, pageParameters);
>>>>>>>>
>>>>>>>>            try
>>>>>>>>            {
>>>>>>>>                final boolean handled = requestCycle.processRequestAndDetach();
>>>>>>>>
>>>>>>>>
>>>>>>>>                LOGGER.info("Response after request: " +
>>>>>>>> bufferedWebResponse.getText().toString());
>>>>>>>>
>>>>>>>>                if (! handled)
>>>>>>>>                {
>>>>>>>>                    LOGGER.error(">>>>>>>>>>>>>>>>>>>>>>> NOT HANDLED");
>>>>>>>>                    //requestCycle.set(new
>>>>>>>> ErrorCodeRequestHandler(HttpServletResponse.SC_NOT_FOUND));
>>>>>>>>                }
>>>>>>>>
>>>>>>>>                //requestCycle.detach();
>>>>>>>>            }
>>>>>>>>            finally
>>>>>>>>            {
>>>>>>>>                requestCycle.getResponse().close();
>>>>>>>>            }
>>>>>>>>
>>>>>>>>            return bufferedWebResponse.getText().toString();
>>>>>>>>        }
>>>>>>>>
>>>>>>>> --
>>>>>>>> Stefan Neumann
>>>>>>>> Dipl.-Ing.
>>>>>>>> freiheit.com technologies gmbh
>>>>>>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>>>>>>> fon +49 (0)40 / 890584-0
>>>>>>>> fax +49 (0)40 / 890584-20
>>>>>>>> HRB Hamburg 70814
>>>>>>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>>>>>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>>>>>>
>>>>>>>> ---------------------------------------------------------------------
>>>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Martin Grigorov
>>>>>>> jWeekend
>>>>>>> Training, Consulting, Development
>>>>>>> http://jWeekend.com
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Stefan Neumann
>>>>>> Dipl.-Ing.
>>>>>> freiheit.com technologies gmbh
>>>>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>>>>> fon +49 (0)40 / 890584-0
>>>>>> fax +49 (0)40 / 890584-20
>>>>>> HRB Hamburg 70814
>>>>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>>>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Martin Grigorov
>>>>> jWeekend
>>>>> Training, Consulting, Development
>>>>> http://jWeekend.com
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Stefan Neumann
>>>> Dipl.-Ing.
>>>> freiheit.com technologies gmbh
>>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>>> fon +49 (0)40 / 890584-0
>>>> fax +49 (0)40 / 890584-20
>>>> HRB Hamburg 70814
>>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>>
>>>
>>>
>>>
>>> --
>>> Stefan Neumann
>>> Dipl.-Ing.
>>> freiheit.com technologies gmbh
>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>> fon +49 (0)40 / 890584-0
>>> fax +49 (0)40 / 890584-20
>>> HRB Hamburg 70814
>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Martin Grigorov
>> jWeekend
>> Training, Consulting, Development
>> http://jWeekend.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
>
> --
> Stefan Neumann
> Dipl.-Ing.
> freiheit.com technologies gmbh
> Straßenbahnring 22 / 20251 Hamburg, Germany
> fon +49 (0)40 / 890584-0
> fax +49 (0)40 / 890584-20
> HRB Hamburg 70814
> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



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

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


Re: Redering to to file in wicket1.5

Posted by Stefan Neumann <st...@freiheit.com>.
Perfect. It works.

Even though I don't need it, I just have a hint for all, who want to
use it as well, It seems not to work in a constructor of a page.

I created the issue for the wicket-examples:
https://issues.apache.org/jira/browse/WICKET-4095

You will find a working code snipplet as well.

thanks a lot!

Stefan



2011/9/29 Martin Grigorov <mg...@apache.org>:
> Use org.apache.wicket.request.handler.RenderPageRequestHandler.RenderPageRequestHandler(IPageProvider,
> RedirectPolicy)
> with org.apache.wicket.request.handler.RenderPageRequestHandler.RedirectPolicy.NEVER_REDIRECT
>
> On Thu, Sep 29, 2011 at 2:01 PM, Stefan Neumann
> <st...@freiheit.com> wrote:
>> Hey,
>>
>> I tried to use a MockWebRespone:
>>
>>       // final StringResponse newResponse = new StringResponse();
>>        final MockWebResponse mockWebResponse = new MockWebResponse();
>>        requestCycle.setResponse(mockWebResponse);
>>        pageRenderer.respond(requestCycle);
>>        requestCycle.setResponse(oldResponse);
>>
>>        return mockWebResponse.getTextResponse().toString();
>>
>> But the getTextRespone() is null, because there is a redirect to the
>> correct mapped url:
>>
>> "print/<external-id>"
>>
>> Can I follow this redirect?
>>
>>
>>
>> 2011/9/29 Stefan Neumann <st...@freiheit.com>:
>>> Hey Martin,
>>>
>>> I get now a CastException in:
>>>
>>> Root cause:
>>>
>>> java.lang.ClassCastException:
>>> org.apache.wicket.response.StringResponse cannot be cast to
>>> org.apache.wicket.request.http.WebResponse
>>>     at org.apache.wicket.request.handler.render.WebPageRenderer.redirectTo(WebPageRenderer.java:134)
>>>     at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:214)
>>>     at com.freiheit.tango.presentation.application.WicketUtils.renderPageNew(WicketUtils.java:54)
>>>
>>> the corresponing line is:
>>>
>>>        final WebApplication application = WebApplication.get();
>>>
>>>        final RenderPageRequestHandler handler = new
>>> RenderPageRequestHandler(new PageProvider(pageClass, pageParameters));
>>>        final PageRenderer pageRenderer =
>>> application.getPageRendererProvider().get(handler);
>>>
>>>        final Response oldResponse = requestCycle.getResponse();
>>>        final StringResponse newResponse = new StringResponse();
>>>        requestCycle.setResponse(newResponse);
>>>
>>>  -->       pageRenderer.respond(requestCycle); <---
>>>        requestCycle.setResponse(oldResponse);
>>>
>>>        return newResponse.toString();
>>>
>>> But seems to get closer ;-)
>>>
>>> I can add the ticket when my case is running.
>>>
>>> Greetings
>>> Stefan
>>>
>>> 2011/9/29 Martin Grigorov <mg...@apache.org>:
>>>> I guess I need to add an example of this in wicket-examples ...
>>>> Please create a ticket to not forget it.
>>>>
>>>> Here is how it should work:
>>>>
>>>> IRequestHandler handler = new RenderPageRequestHandler(Page.class, parameters);
>>>> PageReneder renderer = application.getgetPageRendererProvider().get(handler);
>>>>
>>>> oldResponse = requestCycle.getResponse();
>>>> StringResponse newResponse = new StringResponse();
>>>> requestCycle.setResponse(newResponse);
>>>>
>>>> renderer.respond(requestCycle);
>>>> requestCycle.setResponse(oldResponse);
>>>>
>>>> pageAsText = newResponse.toString();
>>>>
>>>> On Thu, Sep 29, 2011 at 12:09 PM, Stefan Neumann
>>>> <st...@freiheit.com> wrote:
>>>>> Hey Martin,
>>>>>
>>>>> thanks for the quick response.  It sounds quite good, but it is not working yet.
>>>>>
>>>>> Since we use guice, I tried to use the WebApplication we have
>>>>> configured already:
>>>>>
>>>>>        final WicketTester wicketTester = new
>>>>> WicketTester(WebApplication.get());
>>>>>        wicketTester.startPage(pageClass,pageParameters);
>>>>>        return wicketTester.getLastResponseAsString();
>>>>>
>>>>> But I get following exception[1].
>>>>>
>>>>> Some more basic conditions.
>>>>> * A request is currently running.
>>>>> * I need to get session information into the rendering, since the data
>>>>> loading for the page contains authorization checks on the currently
>>>>> logged in user.
>>>>>
>>>>> Any suggestions?
>>>>>
>>>>> Stefan
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Caused by: java.lang.reflect.InvocationTargetException
>>>>>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>>>>>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>>>>>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>>>>>        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>>>>>        at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:177)
>>>>>        ... 37 more
>>>>> Caused by: java.lang.IllegalStateException: Application name can only
>>>>> be set once.
>>>>>        at org.apache.wicket.Application.setName(Application.java:846)
>>>>>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:291)
>>>>>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:241)
>>>>>        at org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:192)
>>>>>        at com.freiheit.tango.presentation.application.WicketUtils.renderPageWithWicketTester(WicketUtils.java:43)
>>>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:124)
>>>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:108)
>>>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:104)
>>>>>        ... 42 more
>>>>>
>>>>>
>>>>> 2011/9/29 Martin Grigorov <mg...@apache.org>:
>>>>>> use WicketTester.startPage() and tester.getLastResponseAsString()
>>>>>>
>>>>>> On Thu, Sep 29, 2011 at 11:06 AM, Stefan Neumann
>>>>>> <st...@freiheit.com> wrote:
>>>>>>> Hey guys,
>>>>>>>
>>>>>>>  I need to render a page to a String or file. I have already read the
>>>>>>> typical reference [1] [2] for this topic.
>>>>>>>
>>>>>>> The difference is, that I am using wicket 1.5 and there must be some
>>>>>>> API changes so I could not use the given examples.
>>>>>>>
>>>>>>> Has someone an example? I tried my best to make the exampel compile
>>>>>>> but i alwas get a NPE at
>>>>>>> bufferedWebResponse.getText().toString()
>>>>>>>
>>>>>>> Appreciate your help in advance,
>>>>>>>
>>>>>>> Stefan
>>>>>>>
>>>>>>>
>>>>>>> [1]
>>>>>>> http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/
>>>>>>> [2]
>>>>>>> https://gist.github.com/1152059
>>>>>>> [3]
>>>>>>>  public static String renderPage(final Class<? extends Page>
>>>>>>> pageClass, final PageParameters pageParameters)
>>>>>>>        {
>>>>>>>            final WebApplication application = WebApplication.get();
>>>>>>>            final ServletContext context =
>>>>>>> application.getServletContext();  //fake a request/response cycle
>>>>>>>            final MockHttpSession servletSession = new MockHttpSession(context);
>>>>>>>            servletSession.setTemporary(true);
>>>>>>>            final MockHttpServletRequest servletRequest = new
>>>>>>> MockHttpServletRequest(application, servletSession, context);
>>>>>>>            final MockHttpServletResponse servletResponse = new
>>>>>>> MockHttpServletResponse(servletRequest);  //initialize request and
>>>>>>> response
>>>>>>>            servletRequest.initialize();
>>>>>>>            servletResponse.initialize();
>>>>>>>
>>>>>>>            final ServletWebRequest webRequest = new
>>>>>>> ServletWebRequest(servletRequest,"/");
>>>>>>>            final WebResponse webResponse = new
>>>>>>> ServletWebResponse(webRequest,servletResponse);
>>>>>>>            final BufferedWebResponse bufferedWebResponse = new
>>>>>>> BufferedWebResponse(webResponse);
>>>>>>>            //webResponse.setAjax(true);
>>>>>>>            final RequestCycle requestCycle = new RequestCycle(
>>>>>>>                new RequestCycleContext(webRequest, webResponse,
>>>>>>> application.getRootRequestMapper(,
>>>>>>> application.getExceptionMapperProvider().get()));
>>>>>>>
>>>>>>>            //requestCycle.setRequestTarget(new
>>>>>>> BookmarkablePageRequestTarget(pageClass, pageParameters));
>>>>>>>            requestCycle.setResponsePage(pageClass, pageParameters);
>>>>>>>
>>>>>>>            try
>>>>>>>            {
>>>>>>>                final boolean handled = requestCycle.processRequestAndDetach();
>>>>>>>
>>>>>>>
>>>>>>>                LOGGER.info("Response after request: " +
>>>>>>> bufferedWebResponse.getText().toString());
>>>>>>>
>>>>>>>                if (! handled)
>>>>>>>                {
>>>>>>>                    LOGGER.error(">>>>>>>>>>>>>>>>>>>>>>> NOT HANDLED");
>>>>>>>                    //requestCycle.set(new
>>>>>>> ErrorCodeRequestHandler(HttpServletResponse.SC_NOT_FOUND));
>>>>>>>                }
>>>>>>>
>>>>>>>                //requestCycle.detach();
>>>>>>>            }
>>>>>>>            finally
>>>>>>>            {
>>>>>>>                requestCycle.getResponse().close();
>>>>>>>            }
>>>>>>>
>>>>>>>            return bufferedWebResponse.getText().toString();
>>>>>>>        }
>>>>>>>
>>>>>>> --
>>>>>>> Stefan Neumann
>>>>>>> Dipl.-Ing.
>>>>>>> freiheit.com technologies gmbh
>>>>>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>>>>>> fon +49 (0)40 / 890584-0
>>>>>>> fax +49 (0)40 / 890584-20
>>>>>>> HRB Hamburg 70814
>>>>>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>>>>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>>>>>
>>>>>>> ---------------------------------------------------------------------
>>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Martin Grigorov
>>>>>> jWeekend
>>>>>> Training, Consulting, Development
>>>>>> http://jWeekend.com
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Stefan Neumann
>>>>> Dipl.-Ing.
>>>>> freiheit.com technologies gmbh
>>>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>>>> fon +49 (0)40 / 890584-0
>>>>> fax +49 (0)40 / 890584-20
>>>>> HRB Hamburg 70814
>>>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Martin Grigorov
>>>> jWeekend
>>>> Training, Consulting, Development
>>>> http://jWeekend.com
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Stefan Neumann
>>> Dipl.-Ing.
>>> freiheit.com technologies gmbh
>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>> fon +49 (0)40 / 890584-0
>>> fax +49 (0)40 / 890584-20
>>> HRB Hamburg 70814
>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>
>>
>>
>>
>> --
>> Stefan Neumann
>> Dipl.-Ing.
>> freiheit.com technologies gmbh
>> Straßenbahnring 22 / 20251 Hamburg, Germany
>> fon +49 (0)40 / 890584-0
>> fax +49 (0)40 / 890584-20
>> HRB Hamburg 70814
>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Stefan Neumann
Dipl.-Ing.
freiheit.com technologies gmbh
Straßenbahnring 22 / 20251 Hamburg, Germany
fon +49 (0)40 / 890584-0
fax +49 (0)40 / 890584-20
HRB Hamburg 70814
1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof

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


Re: Redering to to file in wicket1.5

Posted by Martin Grigorov <mg...@apache.org>.
Use org.apache.wicket.request.handler.RenderPageRequestHandler.RenderPageRequestHandler(IPageProvider,
RedirectPolicy)
with org.apache.wicket.request.handler.RenderPageRequestHandler.RedirectPolicy.NEVER_REDIRECT

On Thu, Sep 29, 2011 at 2:01 PM, Stefan Neumann
<st...@freiheit.com> wrote:
> Hey,
>
> I tried to use a MockWebRespone:
>
>       // final StringResponse newResponse = new StringResponse();
>        final MockWebResponse mockWebResponse = new MockWebResponse();
>        requestCycle.setResponse(mockWebResponse);
>        pageRenderer.respond(requestCycle);
>        requestCycle.setResponse(oldResponse);
>
>        return mockWebResponse.getTextResponse().toString();
>
> But the getTextRespone() is null, because there is a redirect to the
> correct mapped url:
>
> "print/<external-id>"
>
> Can I follow this redirect?
>
>
>
> 2011/9/29 Stefan Neumann <st...@freiheit.com>:
>> Hey Martin,
>>
>> I get now a CastException in:
>>
>> Root cause:
>>
>> java.lang.ClassCastException:
>> org.apache.wicket.response.StringResponse cannot be cast to
>> org.apache.wicket.request.http.WebResponse
>>     at org.apache.wicket.request.handler.render.WebPageRenderer.redirectTo(WebPageRenderer.java:134)
>>     at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:214)
>>     at com.freiheit.tango.presentation.application.WicketUtils.renderPageNew(WicketUtils.java:54)
>>
>> the corresponing line is:
>>
>>        final WebApplication application = WebApplication.get();
>>
>>        final RenderPageRequestHandler handler = new
>> RenderPageRequestHandler(new PageProvider(pageClass, pageParameters));
>>        final PageRenderer pageRenderer =
>> application.getPageRendererProvider().get(handler);
>>
>>        final Response oldResponse = requestCycle.getResponse();
>>        final StringResponse newResponse = new StringResponse();
>>        requestCycle.setResponse(newResponse);
>>
>>  -->       pageRenderer.respond(requestCycle); <---
>>        requestCycle.setResponse(oldResponse);
>>
>>        return newResponse.toString();
>>
>> But seems to get closer ;-)
>>
>> I can add the ticket when my case is running.
>>
>> Greetings
>> Stefan
>>
>> 2011/9/29 Martin Grigorov <mg...@apache.org>:
>>> I guess I need to add an example of this in wicket-examples ...
>>> Please create a ticket to not forget it.
>>>
>>> Here is how it should work:
>>>
>>> IRequestHandler handler = new RenderPageRequestHandler(Page.class, parameters);
>>> PageReneder renderer = application.getgetPageRendererProvider().get(handler);
>>>
>>> oldResponse = requestCycle.getResponse();
>>> StringResponse newResponse = new StringResponse();
>>> requestCycle.setResponse(newResponse);
>>>
>>> renderer.respond(requestCycle);
>>> requestCycle.setResponse(oldResponse);
>>>
>>> pageAsText = newResponse.toString();
>>>
>>> On Thu, Sep 29, 2011 at 12:09 PM, Stefan Neumann
>>> <st...@freiheit.com> wrote:
>>>> Hey Martin,
>>>>
>>>> thanks for the quick response.  It sounds quite good, but it is not working yet.
>>>>
>>>> Since we use guice, I tried to use the WebApplication we have
>>>> configured already:
>>>>
>>>>        final WicketTester wicketTester = new
>>>> WicketTester(WebApplication.get());
>>>>        wicketTester.startPage(pageClass,pageParameters);
>>>>        return wicketTester.getLastResponseAsString();
>>>>
>>>> But I get following exception[1].
>>>>
>>>> Some more basic conditions.
>>>> * A request is currently running.
>>>> * I need to get session information into the rendering, since the data
>>>> loading for the page contains authorization checks on the currently
>>>> logged in user.
>>>>
>>>> Any suggestions?
>>>>
>>>> Stefan
>>>>
>>>>
>>>>
>>>>
>>>> Caused by: java.lang.reflect.InvocationTargetException
>>>>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>>>>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>>>>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>>>>        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>>>>        at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:177)
>>>>        ... 37 more
>>>> Caused by: java.lang.IllegalStateException: Application name can only
>>>> be set once.
>>>>        at org.apache.wicket.Application.setName(Application.java:846)
>>>>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:291)
>>>>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:241)
>>>>        at org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:192)
>>>>        at com.freiheit.tango.presentation.application.WicketUtils.renderPageWithWicketTester(WicketUtils.java:43)
>>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:124)
>>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:108)
>>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:104)
>>>>        ... 42 more
>>>>
>>>>
>>>> 2011/9/29 Martin Grigorov <mg...@apache.org>:
>>>>> use WicketTester.startPage() and tester.getLastResponseAsString()
>>>>>
>>>>> On Thu, Sep 29, 2011 at 11:06 AM, Stefan Neumann
>>>>> <st...@freiheit.com> wrote:
>>>>>> Hey guys,
>>>>>>
>>>>>>  I need to render a page to a String or file. I have already read the
>>>>>> typical reference [1] [2] for this topic.
>>>>>>
>>>>>> The difference is, that I am using wicket 1.5 and there must be some
>>>>>> API changes so I could not use the given examples.
>>>>>>
>>>>>> Has someone an example? I tried my best to make the exampel compile
>>>>>> but i alwas get a NPE at
>>>>>> bufferedWebResponse.getText().toString()
>>>>>>
>>>>>> Appreciate your help in advance,
>>>>>>
>>>>>> Stefan
>>>>>>
>>>>>>
>>>>>> [1]
>>>>>> http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/
>>>>>> [2]
>>>>>> https://gist.github.com/1152059
>>>>>> [3]
>>>>>>  public static String renderPage(final Class<? extends Page>
>>>>>> pageClass, final PageParameters pageParameters)
>>>>>>        {
>>>>>>            final WebApplication application = WebApplication.get();
>>>>>>            final ServletContext context =
>>>>>> application.getServletContext();  //fake a request/response cycle
>>>>>>            final MockHttpSession servletSession = new MockHttpSession(context);
>>>>>>            servletSession.setTemporary(true);
>>>>>>            final MockHttpServletRequest servletRequest = new
>>>>>> MockHttpServletRequest(application, servletSession, context);
>>>>>>            final MockHttpServletResponse servletResponse = new
>>>>>> MockHttpServletResponse(servletRequest);  //initialize request and
>>>>>> response
>>>>>>            servletRequest.initialize();
>>>>>>            servletResponse.initialize();
>>>>>>
>>>>>>            final ServletWebRequest webRequest = new
>>>>>> ServletWebRequest(servletRequest,"/");
>>>>>>            final WebResponse webResponse = new
>>>>>> ServletWebResponse(webRequest,servletResponse);
>>>>>>            final BufferedWebResponse bufferedWebResponse = new
>>>>>> BufferedWebResponse(webResponse);
>>>>>>            //webResponse.setAjax(true);
>>>>>>            final RequestCycle requestCycle = new RequestCycle(
>>>>>>                new RequestCycleContext(webRequest, webResponse,
>>>>>> application.getRootRequestMapper(,
>>>>>> application.getExceptionMapperProvider().get()));
>>>>>>
>>>>>>            //requestCycle.setRequestTarget(new
>>>>>> BookmarkablePageRequestTarget(pageClass, pageParameters));
>>>>>>            requestCycle.setResponsePage(pageClass, pageParameters);
>>>>>>
>>>>>>            try
>>>>>>            {
>>>>>>                final boolean handled = requestCycle.processRequestAndDetach();
>>>>>>
>>>>>>
>>>>>>                LOGGER.info("Response after request: " +
>>>>>> bufferedWebResponse.getText().toString());
>>>>>>
>>>>>>                if (! handled)
>>>>>>                {
>>>>>>                    LOGGER.error(">>>>>>>>>>>>>>>>>>>>>>> NOT HANDLED");
>>>>>>                    //requestCycle.set(new
>>>>>> ErrorCodeRequestHandler(HttpServletResponse.SC_NOT_FOUND));
>>>>>>                }
>>>>>>
>>>>>>                //requestCycle.detach();
>>>>>>            }
>>>>>>            finally
>>>>>>            {
>>>>>>                requestCycle.getResponse().close();
>>>>>>            }
>>>>>>
>>>>>>            return bufferedWebResponse.getText().toString();
>>>>>>        }
>>>>>>
>>>>>> --
>>>>>> Stefan Neumann
>>>>>> Dipl.-Ing.
>>>>>> freiheit.com technologies gmbh
>>>>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>>>>> fon +49 (0)40 / 890584-0
>>>>>> fax +49 (0)40 / 890584-20
>>>>>> HRB Hamburg 70814
>>>>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>>>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Martin Grigorov
>>>>> jWeekend
>>>>> Training, Consulting, Development
>>>>> http://jWeekend.com
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Stefan Neumann
>>>> Dipl.-Ing.
>>>> freiheit.com technologies gmbh
>>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>>> fon +49 (0)40 / 890584-0
>>>> fax +49 (0)40 / 890584-20
>>>> HRB Hamburg 70814
>>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Martin Grigorov
>>> jWeekend
>>> Training, Consulting, Development
>>> http://jWeekend.com
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Stefan Neumann
>> Dipl.-Ing.
>> freiheit.com technologies gmbh
>> Straßenbahnring 22 / 20251 Hamburg, Germany
>> fon +49 (0)40 / 890584-0
>> fax +49 (0)40 / 890584-20
>> HRB Hamburg 70814
>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>
>
>
>
> --
> Stefan Neumann
> Dipl.-Ing.
> freiheit.com technologies gmbh
> Straßenbahnring 22 / 20251 Hamburg, Germany
> fon +49 (0)40 / 890584-0
> fax +49 (0)40 / 890584-20
> HRB Hamburg 70814
> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



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

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


Re: Redering to to file in wicket1.5

Posted by Stefan Neumann <st...@freiheit.com>.
Hey,

I tried to use a MockWebRespone:

       // final StringResponse newResponse = new StringResponse();
        final MockWebResponse mockWebResponse = new MockWebResponse();
        requestCycle.setResponse(mockWebResponse);
        pageRenderer.respond(requestCycle);
        requestCycle.setResponse(oldResponse);

        return mockWebResponse.getTextResponse().toString();

But the getTextRespone() is null, because there is a redirect to the
correct mapped url:

"print/<external-id>"

Can I follow this redirect?



2011/9/29 Stefan Neumann <st...@freiheit.com>:
> Hey Martin,
>
> I get now a CastException in:
>
> Root cause:
>
> java.lang.ClassCastException:
> org.apache.wicket.response.StringResponse cannot be cast to
> org.apache.wicket.request.http.WebResponse
>     at org.apache.wicket.request.handler.render.WebPageRenderer.redirectTo(WebPageRenderer.java:134)
>     at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:214)
>     at com.freiheit.tango.presentation.application.WicketUtils.renderPageNew(WicketUtils.java:54)
>
> the corresponing line is:
>
>        final WebApplication application = WebApplication.get();
>
>        final RenderPageRequestHandler handler = new
> RenderPageRequestHandler(new PageProvider(pageClass, pageParameters));
>        final PageRenderer pageRenderer =
> application.getPageRendererProvider().get(handler);
>
>        final Response oldResponse = requestCycle.getResponse();
>        final StringResponse newResponse = new StringResponse();
>        requestCycle.setResponse(newResponse);
>
>  -->       pageRenderer.respond(requestCycle); <---
>        requestCycle.setResponse(oldResponse);
>
>        return newResponse.toString();
>
> But seems to get closer ;-)
>
> I can add the ticket when my case is running.
>
> Greetings
> Stefan
>
> 2011/9/29 Martin Grigorov <mg...@apache.org>:
>> I guess I need to add an example of this in wicket-examples ...
>> Please create a ticket to not forget it.
>>
>> Here is how it should work:
>>
>> IRequestHandler handler = new RenderPageRequestHandler(Page.class, parameters);
>> PageReneder renderer = application.getgetPageRendererProvider().get(handler);
>>
>> oldResponse = requestCycle.getResponse();
>> StringResponse newResponse = new StringResponse();
>> requestCycle.setResponse(newResponse);
>>
>> renderer.respond(requestCycle);
>> requestCycle.setResponse(oldResponse);
>>
>> pageAsText = newResponse.toString();
>>
>> On Thu, Sep 29, 2011 at 12:09 PM, Stefan Neumann
>> <st...@freiheit.com> wrote:
>>> Hey Martin,
>>>
>>> thanks for the quick response.  It sounds quite good, but it is not working yet.
>>>
>>> Since we use guice, I tried to use the WebApplication we have
>>> configured already:
>>>
>>>        final WicketTester wicketTester = new
>>> WicketTester(WebApplication.get());
>>>        wicketTester.startPage(pageClass,pageParameters);
>>>        return wicketTester.getLastResponseAsString();
>>>
>>> But I get following exception[1].
>>>
>>> Some more basic conditions.
>>> * A request is currently running.
>>> * I need to get session information into the rendering, since the data
>>> loading for the page contains authorization checks on the currently
>>> logged in user.
>>>
>>> Any suggestions?
>>>
>>> Stefan
>>>
>>>
>>>
>>>
>>> Caused by: java.lang.reflect.InvocationTargetException
>>>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>>>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>>>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>>>        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>>>        at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:177)
>>>        ... 37 more
>>> Caused by: java.lang.IllegalStateException: Application name can only
>>> be set once.
>>>        at org.apache.wicket.Application.setName(Application.java:846)
>>>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:291)
>>>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:241)
>>>        at org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:192)
>>>        at com.freiheit.tango.presentation.application.WicketUtils.renderPageWithWicketTester(WicketUtils.java:43)
>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:124)
>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:108)
>>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:104)
>>>        ... 42 more
>>>
>>>
>>> 2011/9/29 Martin Grigorov <mg...@apache.org>:
>>>> use WicketTester.startPage() and tester.getLastResponseAsString()
>>>>
>>>> On Thu, Sep 29, 2011 at 11:06 AM, Stefan Neumann
>>>> <st...@freiheit.com> wrote:
>>>>> Hey guys,
>>>>>
>>>>>  I need to render a page to a String or file. I have already read the
>>>>> typical reference [1] [2] for this topic.
>>>>>
>>>>> The difference is, that I am using wicket 1.5 and there must be some
>>>>> API changes so I could not use the given examples.
>>>>>
>>>>> Has someone an example? I tried my best to make the exampel compile
>>>>> but i alwas get a NPE at
>>>>> bufferedWebResponse.getText().toString()
>>>>>
>>>>> Appreciate your help in advance,
>>>>>
>>>>> Stefan
>>>>>
>>>>>
>>>>> [1]
>>>>> http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/
>>>>> [2]
>>>>> https://gist.github.com/1152059
>>>>> [3]
>>>>>  public static String renderPage(final Class<? extends Page>
>>>>> pageClass, final PageParameters pageParameters)
>>>>>        {
>>>>>            final WebApplication application = WebApplication.get();
>>>>>            final ServletContext context =
>>>>> application.getServletContext();  //fake a request/response cycle
>>>>>            final MockHttpSession servletSession = new MockHttpSession(context);
>>>>>            servletSession.setTemporary(true);
>>>>>            final MockHttpServletRequest servletRequest = new
>>>>> MockHttpServletRequest(application, servletSession, context);
>>>>>            final MockHttpServletResponse servletResponse = new
>>>>> MockHttpServletResponse(servletRequest);  //initialize request and
>>>>> response
>>>>>            servletRequest.initialize();
>>>>>            servletResponse.initialize();
>>>>>
>>>>>            final ServletWebRequest webRequest = new
>>>>> ServletWebRequest(servletRequest,"/");
>>>>>            final WebResponse webResponse = new
>>>>> ServletWebResponse(webRequest,servletResponse);
>>>>>            final BufferedWebResponse bufferedWebResponse = new
>>>>> BufferedWebResponse(webResponse);
>>>>>            //webResponse.setAjax(true);
>>>>>            final RequestCycle requestCycle = new RequestCycle(
>>>>>                new RequestCycleContext(webRequest, webResponse,
>>>>> application.getRootRequestMapper(,
>>>>> application.getExceptionMapperProvider().get()));
>>>>>
>>>>>            //requestCycle.setRequestTarget(new
>>>>> BookmarkablePageRequestTarget(pageClass, pageParameters));
>>>>>            requestCycle.setResponsePage(pageClass, pageParameters);
>>>>>
>>>>>            try
>>>>>            {
>>>>>                final boolean handled = requestCycle.processRequestAndDetach();
>>>>>
>>>>>
>>>>>                LOGGER.info("Response after request: " +
>>>>> bufferedWebResponse.getText().toString());
>>>>>
>>>>>                if (! handled)
>>>>>                {
>>>>>                    LOGGER.error(">>>>>>>>>>>>>>>>>>>>>>> NOT HANDLED");
>>>>>                    //requestCycle.set(new
>>>>> ErrorCodeRequestHandler(HttpServletResponse.SC_NOT_FOUND));
>>>>>                }
>>>>>
>>>>>                //requestCycle.detach();
>>>>>            }
>>>>>            finally
>>>>>            {
>>>>>                requestCycle.getResponse().close();
>>>>>            }
>>>>>
>>>>>            return bufferedWebResponse.getText().toString();
>>>>>        }
>>>>>
>>>>> --
>>>>> Stefan Neumann
>>>>> Dipl.-Ing.
>>>>> freiheit.com technologies gmbh
>>>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>>>> fon +49 (0)40 / 890584-0
>>>>> fax +49 (0)40 / 890584-20
>>>>> HRB Hamburg 70814
>>>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Martin Grigorov
>>>> jWeekend
>>>> Training, Consulting, Development
>>>> http://jWeekend.com
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Stefan Neumann
>>> Dipl.-Ing.
>>> freiheit.com technologies gmbh
>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>> fon +49 (0)40 / 890584-0
>>> fax +49 (0)40 / 890584-20
>>> HRB Hamburg 70814
>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Martin Grigorov
>> jWeekend
>> Training, Consulting, Development
>> http://jWeekend.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
>
> --
> Stefan Neumann
> Dipl.-Ing.
> freiheit.com technologies gmbh
> Straßenbahnring 22 / 20251 Hamburg, Germany
> fon +49 (0)40 / 890584-0
> fax +49 (0)40 / 890584-20
> HRB Hamburg 70814
> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>



-- 
Stefan Neumann
Dipl.-Ing.
freiheit.com technologies gmbh
Straßenbahnring 22 / 20251 Hamburg, Germany
fon +49 (0)40 / 890584-0
fax +49 (0)40 / 890584-20
HRB Hamburg 70814
1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof

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


Re: Redering to to file in wicket1.5

Posted by Stefan Neumann <st...@freiheit.com>.
Hey Martin,

I get now a CastException in:

Root cause:

java.lang.ClassCastException:
org.apache.wicket.response.StringResponse cannot be cast to
org.apache.wicket.request.http.WebResponse
     at org.apache.wicket.request.handler.render.WebPageRenderer.redirectTo(WebPageRenderer.java:134)
     at org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:214)
     at com.freiheit.tango.presentation.application.WicketUtils.renderPageNew(WicketUtils.java:54)

the corresponing line is:

        final WebApplication application = WebApplication.get();

        final RenderPageRequestHandler handler = new
RenderPageRequestHandler(new PageProvider(pageClass, pageParameters));
        final PageRenderer pageRenderer =
application.getPageRendererProvider().get(handler);

        final Response oldResponse = requestCycle.getResponse();
        final StringResponse newResponse = new StringResponse();
        requestCycle.setResponse(newResponse);

 -->       pageRenderer.respond(requestCycle); <---
        requestCycle.setResponse(oldResponse);

        return newResponse.toString();

But seems to get closer ;-)

I can add the ticket when my case is running.

Greetings
Stefan

2011/9/29 Martin Grigorov <mg...@apache.org>:
> I guess I need to add an example of this in wicket-examples ...
> Please create a ticket to not forget it.
>
> Here is how it should work:
>
> IRequestHandler handler = new RenderPageRequestHandler(Page.class, parameters);
> PageReneder renderer = application.getgetPageRendererProvider().get(handler);
>
> oldResponse = requestCycle.getResponse();
> StringResponse newResponse = new StringResponse();
> requestCycle.setResponse(newResponse);
>
> renderer.respond(requestCycle);
> requestCycle.setResponse(oldResponse);
>
> pageAsText = newResponse.toString();
>
> On Thu, Sep 29, 2011 at 12:09 PM, Stefan Neumann
> <st...@freiheit.com> wrote:
>> Hey Martin,
>>
>> thanks for the quick response.  It sounds quite good, but it is not working yet.
>>
>> Since we use guice, I tried to use the WebApplication we have
>> configured already:
>>
>>        final WicketTester wicketTester = new
>> WicketTester(WebApplication.get());
>>        wicketTester.startPage(pageClass,pageParameters);
>>        return wicketTester.getLastResponseAsString();
>>
>> But I get following exception[1].
>>
>> Some more basic conditions.
>> * A request is currently running.
>> * I need to get session information into the rendering, since the data
>> loading for the page contains authorization checks on the currently
>> logged in user.
>>
>> Any suggestions?
>>
>> Stefan
>>
>>
>>
>>
>> Caused by: java.lang.reflect.InvocationTargetException
>>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>>        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>>        at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:177)
>>        ... 37 more
>> Caused by: java.lang.IllegalStateException: Application name can only
>> be set once.
>>        at org.apache.wicket.Application.setName(Application.java:846)
>>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:291)
>>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:241)
>>        at org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:192)
>>        at com.freiheit.tango.presentation.application.WicketUtils.renderPageWithWicketTester(WicketUtils.java:43)
>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:124)
>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:108)
>>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:104)
>>        ... 42 more
>>
>>
>> 2011/9/29 Martin Grigorov <mg...@apache.org>:
>>> use WicketTester.startPage() and tester.getLastResponseAsString()
>>>
>>> On Thu, Sep 29, 2011 at 11:06 AM, Stefan Neumann
>>> <st...@freiheit.com> wrote:
>>>> Hey guys,
>>>>
>>>>  I need to render a page to a String or file. I have already read the
>>>> typical reference [1] [2] for this topic.
>>>>
>>>> The difference is, that I am using wicket 1.5 and there must be some
>>>> API changes so I could not use the given examples.
>>>>
>>>> Has someone an example? I tried my best to make the exampel compile
>>>> but i alwas get a NPE at
>>>> bufferedWebResponse.getText().toString()
>>>>
>>>> Appreciate your help in advance,
>>>>
>>>> Stefan
>>>>
>>>>
>>>> [1]
>>>> http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/
>>>> [2]
>>>> https://gist.github.com/1152059
>>>> [3]
>>>>  public static String renderPage(final Class<? extends Page>
>>>> pageClass, final PageParameters pageParameters)
>>>>        {
>>>>            final WebApplication application = WebApplication.get();
>>>>            final ServletContext context =
>>>> application.getServletContext();  //fake a request/response cycle
>>>>            final MockHttpSession servletSession = new MockHttpSession(context);
>>>>            servletSession.setTemporary(true);
>>>>            final MockHttpServletRequest servletRequest = new
>>>> MockHttpServletRequest(application, servletSession, context);
>>>>            final MockHttpServletResponse servletResponse = new
>>>> MockHttpServletResponse(servletRequest);  //initialize request and
>>>> response
>>>>            servletRequest.initialize();
>>>>            servletResponse.initialize();
>>>>
>>>>            final ServletWebRequest webRequest = new
>>>> ServletWebRequest(servletRequest,"/");
>>>>            final WebResponse webResponse = new
>>>> ServletWebResponse(webRequest,servletResponse);
>>>>            final BufferedWebResponse bufferedWebResponse = new
>>>> BufferedWebResponse(webResponse);
>>>>            //webResponse.setAjax(true);
>>>>            final RequestCycle requestCycle = new RequestCycle(
>>>>                new RequestCycleContext(webRequest, webResponse,
>>>> application.getRootRequestMapper(,
>>>> application.getExceptionMapperProvider().get()));
>>>>
>>>>            //requestCycle.setRequestTarget(new
>>>> BookmarkablePageRequestTarget(pageClass, pageParameters));
>>>>            requestCycle.setResponsePage(pageClass, pageParameters);
>>>>
>>>>            try
>>>>            {
>>>>                final boolean handled = requestCycle.processRequestAndDetach();
>>>>
>>>>
>>>>                LOGGER.info("Response after request: " +
>>>> bufferedWebResponse.getText().toString());
>>>>
>>>>                if (! handled)
>>>>                {
>>>>                    LOGGER.error(">>>>>>>>>>>>>>>>>>>>>>> NOT HANDLED");
>>>>                    //requestCycle.set(new
>>>> ErrorCodeRequestHandler(HttpServletResponse.SC_NOT_FOUND));
>>>>                }
>>>>
>>>>                //requestCycle.detach();
>>>>            }
>>>>            finally
>>>>            {
>>>>                requestCycle.getResponse().close();
>>>>            }
>>>>
>>>>            return bufferedWebResponse.getText().toString();
>>>>        }
>>>>
>>>> --
>>>> Stefan Neumann
>>>> Dipl.-Ing.
>>>> freiheit.com technologies gmbh
>>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>>> fon +49 (0)40 / 890584-0
>>>> fax +49 (0)40 / 890584-20
>>>> HRB Hamburg 70814
>>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Martin Grigorov
>>> jWeekend
>>> Training, Consulting, Development
>>> http://jWeekend.com
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Stefan Neumann
>> Dipl.-Ing.
>> freiheit.com technologies gmbh
>> Straßenbahnring 22 / 20251 Hamburg, Germany
>> fon +49 (0)40 / 890584-0
>> fax +49 (0)40 / 890584-20
>> HRB Hamburg 70814
>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Stefan Neumann
Dipl.-Ing.
freiheit.com technologies gmbh
Straßenbahnring 22 / 20251 Hamburg, Germany
fon +49 (0)40 / 890584-0
fax +49 (0)40 / 890584-20
HRB Hamburg 70814
1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof

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


Re: Redering to to file in wicket1.5

Posted by Martin Grigorov <mg...@apache.org>.
I guess I need to add an example of this in wicket-examples ...
Please create a ticket to not forget it.

Here is how it should work:

IRequestHandler handler = new RenderPageRequestHandler(Page.class, parameters);
PageReneder renderer = application.getgetPageRendererProvider().get(handler);

oldResponse = requestCycle.getResponse();
StringResponse newResponse = new StringResponse();
requestCycle.setResponse(newResponse);

renderer.respond(requestCycle);
requestCycle.setResponse(oldResponse);

pageAsText = newResponse.toString();

On Thu, Sep 29, 2011 at 12:09 PM, Stefan Neumann
<st...@freiheit.com> wrote:
> Hey Martin,
>
> thanks for the quick response.  It sounds quite good, but it is not working yet.
>
> Since we use guice, I tried to use the WebApplication we have
> configured already:
>
>        final WicketTester wicketTester = new
> WicketTester(WebApplication.get());
>        wicketTester.startPage(pageClass,pageParameters);
>        return wicketTester.getLastResponseAsString();
>
> But I get following exception[1].
>
> Some more basic conditions.
> * A request is currently running.
> * I need to get session information into the rendering, since the data
> loading for the page contains authorization checks on the currently
> logged in user.
>
> Any suggestions?
>
> Stefan
>
>
>
>
> Caused by: java.lang.reflect.InvocationTargetException
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>        at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:177)
>        ... 37 more
> Caused by: java.lang.IllegalStateException: Application name can only
> be set once.
>        at org.apache.wicket.Application.setName(Application.java:846)
>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:291)
>        at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:241)
>        at org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:192)
>        at com.freiheit.tango.presentation.application.WicketUtils.renderPageWithWicketTester(WicketUtils.java:43)
>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:124)
>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:108)
>        at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:104)
>        ... 42 more
>
>
> 2011/9/29 Martin Grigorov <mg...@apache.org>:
>> use WicketTester.startPage() and tester.getLastResponseAsString()
>>
>> On Thu, Sep 29, 2011 at 11:06 AM, Stefan Neumann
>> <st...@freiheit.com> wrote:
>>> Hey guys,
>>>
>>>  I need to render a page to a String or file. I have already read the
>>> typical reference [1] [2] for this topic.
>>>
>>> The difference is, that I am using wicket 1.5 and there must be some
>>> API changes so I could not use the given examples.
>>>
>>> Has someone an example? I tried my best to make the exampel compile
>>> but i alwas get a NPE at
>>> bufferedWebResponse.getText().toString()
>>>
>>> Appreciate your help in advance,
>>>
>>> Stefan
>>>
>>>
>>> [1]
>>> http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/
>>> [2]
>>> https://gist.github.com/1152059
>>> [3]
>>>  public static String renderPage(final Class<? extends Page>
>>> pageClass, final PageParameters pageParameters)
>>>        {
>>>            final WebApplication application = WebApplication.get();
>>>            final ServletContext context =
>>> application.getServletContext();  //fake a request/response cycle
>>>            final MockHttpSession servletSession = new MockHttpSession(context);
>>>            servletSession.setTemporary(true);
>>>            final MockHttpServletRequest servletRequest = new
>>> MockHttpServletRequest(application, servletSession, context);
>>>            final MockHttpServletResponse servletResponse = new
>>> MockHttpServletResponse(servletRequest);  //initialize request and
>>> response
>>>            servletRequest.initialize();
>>>            servletResponse.initialize();
>>>
>>>            final ServletWebRequest webRequest = new
>>> ServletWebRequest(servletRequest,"/");
>>>            final WebResponse webResponse = new
>>> ServletWebResponse(webRequest,servletResponse);
>>>            final BufferedWebResponse bufferedWebResponse = new
>>> BufferedWebResponse(webResponse);
>>>            //webResponse.setAjax(true);
>>>            final RequestCycle requestCycle = new RequestCycle(
>>>                new RequestCycleContext(webRequest, webResponse,
>>> application.getRootRequestMapper(,
>>> application.getExceptionMapperProvider().get()));
>>>
>>>            //requestCycle.setRequestTarget(new
>>> BookmarkablePageRequestTarget(pageClass, pageParameters));
>>>            requestCycle.setResponsePage(pageClass, pageParameters);
>>>
>>>            try
>>>            {
>>>                final boolean handled = requestCycle.processRequestAndDetach();
>>>
>>>
>>>                LOGGER.info("Response after request: " +
>>> bufferedWebResponse.getText().toString());
>>>
>>>                if (! handled)
>>>                {
>>>                    LOGGER.error(">>>>>>>>>>>>>>>>>>>>>>> NOT HANDLED");
>>>                    //requestCycle.set(new
>>> ErrorCodeRequestHandler(HttpServletResponse.SC_NOT_FOUND));
>>>                }
>>>
>>>                //requestCycle.detach();
>>>            }
>>>            finally
>>>            {
>>>                requestCycle.getResponse().close();
>>>            }
>>>
>>>            return bufferedWebResponse.getText().toString();
>>>        }
>>>
>>> --
>>> Stefan Neumann
>>> Dipl.-Ing.
>>> freiheit.com technologies gmbh
>>> Straßenbahnring 22 / 20251 Hamburg, Germany
>>> fon +49 (0)40 / 890584-0
>>> fax +49 (0)40 / 890584-20
>>> HRB Hamburg 70814
>>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>>>
>>
>>
>>
>> --
>> Martin Grigorov
>> jWeekend
>> Training, Consulting, Development
>> http://jWeekend.com
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
>
> --
> Stefan Neumann
> Dipl.-Ing.
> freiheit.com technologies gmbh
> Straßenbahnring 22 / 20251 Hamburg, Germany
> fon +49 (0)40 / 890584-0
> fax +49 (0)40 / 890584-20
> HRB Hamburg 70814
> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



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

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


Re: Redering to to file in wicket1.5

Posted by Stefan Neumann <st...@freiheit.com>.
Hey Martin,

thanks for the quick response.  It sounds quite good, but it is not working yet.

Since we use guice, I tried to use the WebApplication we have
configured already:

        final WicketTester wicketTester = new
WicketTester(WebApplication.get());
        wicketTester.startPage(pageClass,pageParameters);
        return wicketTester.getLastResponseAsString();

But I get following exception[1].

Some more basic conditions.
* A request is currently running.
* I need to get session information into the rendering, since the data
loading for the page contains authorization checks on the currently
logged in user.

Any suggestions?

Stefan




Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
	at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:177)
	... 37 more
Caused by: java.lang.IllegalStateException: Application name can only
be set once.
	at org.apache.wicket.Application.setName(Application.java:846)
	at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:291)
	at org.apache.wicket.util.tester.BaseWicketTester.<init>(BaseWicketTester.java:241)
	at org.apache.wicket.util.tester.WicketTester.<init>(WicketTester.java:192)
	at com.freiheit.tango.presentation.application.WicketUtils.renderPageWithWicketTester(WicketUtils.java:43)
	at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:124)
	at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:108)
	at com.freiheit.tango.presentation.dashboard.DashboardPage.<init>(DashboardPage.java:104)
	... 42 more


2011/9/29 Martin Grigorov <mg...@apache.org>:
> use WicketTester.startPage() and tester.getLastResponseAsString()
>
> On Thu, Sep 29, 2011 at 11:06 AM, Stefan Neumann
> <st...@freiheit.com> wrote:
>> Hey guys,
>>
>>  I need to render a page to a String or file. I have already read the
>> typical reference [1] [2] for this topic.
>>
>> The difference is, that I am using wicket 1.5 and there must be some
>> API changes so I could not use the given examples.
>>
>> Has someone an example? I tried my best to make the exampel compile
>> but i alwas get a NPE at
>> bufferedWebResponse.getText().toString()
>>
>> Appreciate your help in advance,
>>
>> Stefan
>>
>>
>> [1]
>> http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/
>> [2]
>> https://gist.github.com/1152059
>> [3]
>>  public static String renderPage(final Class<? extends Page>
>> pageClass, final PageParameters pageParameters)
>>        {
>>            final WebApplication application = WebApplication.get();
>>            final ServletContext context =
>> application.getServletContext();  //fake a request/response cycle
>>            final MockHttpSession servletSession = new MockHttpSession(context);
>>            servletSession.setTemporary(true);
>>            final MockHttpServletRequest servletRequest = new
>> MockHttpServletRequest(application, servletSession, context);
>>            final MockHttpServletResponse servletResponse = new
>> MockHttpServletResponse(servletRequest);  //initialize request and
>> response
>>            servletRequest.initialize();
>>            servletResponse.initialize();
>>
>>            final ServletWebRequest webRequest = new
>> ServletWebRequest(servletRequest,"/");
>>            final WebResponse webResponse = new
>> ServletWebResponse(webRequest,servletResponse);
>>            final BufferedWebResponse bufferedWebResponse = new
>> BufferedWebResponse(webResponse);
>>            //webResponse.setAjax(true);
>>            final RequestCycle requestCycle = new RequestCycle(
>>                new RequestCycleContext(webRequest, webResponse,
>> application.getRootRequestMapper(,
>> application.getExceptionMapperProvider().get()));
>>
>>            //requestCycle.setRequestTarget(new
>> BookmarkablePageRequestTarget(pageClass, pageParameters));
>>            requestCycle.setResponsePage(pageClass, pageParameters);
>>
>>            try
>>            {
>>                final boolean handled = requestCycle.processRequestAndDetach();
>>
>>
>>                LOGGER.info("Response after request: " +
>> bufferedWebResponse.getText().toString());
>>
>>                if (! handled)
>>                {
>>                    LOGGER.error(">>>>>>>>>>>>>>>>>>>>>>> NOT HANDLED");
>>                    //requestCycle.set(new
>> ErrorCodeRequestHandler(HttpServletResponse.SC_NOT_FOUND));
>>                }
>>
>>                //requestCycle.detach();
>>            }
>>            finally
>>            {
>>                requestCycle.getResponse().close();
>>            }
>>
>>            return bufferedWebResponse.getText().toString();
>>        }
>>
>> --
>> Stefan Neumann
>> Dipl.-Ing.
>> freiheit.com technologies gmbh
>> Straßenbahnring 22 / 20251 Hamburg, Germany
>> fon +49 (0)40 / 890584-0
>> fax +49 (0)40 / 890584-20
>> HRB Hamburg 70814
>> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
>> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
>
> --
> Martin Grigorov
> jWeekend
> Training, Consulting, Development
> http://jWeekend.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



-- 
Stefan Neumann
Dipl.-Ing.
freiheit.com technologies gmbh
Straßenbahnring 22 / 20251 Hamburg, Germany
fon +49 (0)40 / 890584-0
fax +49 (0)40 / 890584-20
HRB Hamburg 70814
1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof

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


Re: Redering to to file in wicket1.5

Posted by Martin Grigorov <mg...@apache.org>.
use WicketTester.startPage() and tester.getLastResponseAsString()

On Thu, Sep 29, 2011 at 11:06 AM, Stefan Neumann
<st...@freiheit.com> wrote:
> Hey guys,
>
>  I need to render a page to a String or file. I have already read the
> typical reference [1] [2] for this topic.
>
> The difference is, that I am using wicket 1.5 and there must be some
> API changes so I could not use the given examples.
>
> Has someone an example? I tried my best to make the exampel compile
> but i alwas get a NPE at
> bufferedWebResponse.getText().toString()
>
> Appreciate your help in advance,
>
> Stefan
>
>
> [1]
> http://www.danwalmsley.com/2008/10/21/render-a-wicket-page-to-a-string-for-html-email/
> [2]
> https://gist.github.com/1152059
> [3]
>  public static String renderPage(final Class<? extends Page>
> pageClass, final PageParameters pageParameters)
>        {
>            final WebApplication application = WebApplication.get();
>            final ServletContext context =
> application.getServletContext();  //fake a request/response cycle
>            final MockHttpSession servletSession = new MockHttpSession(context);
>            servletSession.setTemporary(true);
>            final MockHttpServletRequest servletRequest = new
> MockHttpServletRequest(application, servletSession, context);
>            final MockHttpServletResponse servletResponse = new
> MockHttpServletResponse(servletRequest);  //initialize request and
> response
>            servletRequest.initialize();
>            servletResponse.initialize();
>
>            final ServletWebRequest webRequest = new
> ServletWebRequest(servletRequest,"/");
>            final WebResponse webResponse = new
> ServletWebResponse(webRequest,servletResponse);
>            final BufferedWebResponse bufferedWebResponse = new
> BufferedWebResponse(webResponse);
>            //webResponse.setAjax(true);
>            final RequestCycle requestCycle = new RequestCycle(
>                new RequestCycleContext(webRequest, webResponse,
> application.getRootRequestMapper(,
> application.getExceptionMapperProvider().get()));
>
>            //requestCycle.setRequestTarget(new
> BookmarkablePageRequestTarget(pageClass, pageParameters));
>            requestCycle.setResponsePage(pageClass, pageParameters);
>
>            try
>            {
>                final boolean handled = requestCycle.processRequestAndDetach();
>
>
>                LOGGER.info("Response after request: " +
> bufferedWebResponse.getText().toString());
>
>                if (! handled)
>                {
>                    LOGGER.error(">>>>>>>>>>>>>>>>>>>>>>> NOT HANDLED");
>                    //requestCycle.set(new
> ErrorCodeRequestHandler(HttpServletResponse.SC_NOT_FOUND));
>                }
>
>                //requestCycle.detach();
>            }
>            finally
>            {
>                requestCycle.getResponse().close();
>            }
>
>            return bufferedWebResponse.getText().toString();
>        }
>
> --
> Stefan Neumann
> Dipl.-Ing.
> freiheit.com technologies gmbh
> Straßenbahnring 22 / 20251 Hamburg, Germany
> fon +49 (0)40 / 890584-0
> fax +49 (0)40 / 890584-20
> HRB Hamburg 70814
> 1CB2 BA3C 168F 0C2B 6005 FC5E 3EBA BCE2 1BF0 21D3
> Geschäftsführer: Claudia Dietze, Stefan Richter, Jörg Kirchhof
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>



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

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