In a legacy project I've inherited I've got a piece of code that
no longer works since the project was upgraded from Wicket 1.4 to
Wicket 6. 

It's about rendering a component (a Wicket panel) into a string
in order to return it wrapped into a webservice reply.

The webservice is based on Wicket, too. The webservice is based
on a Javascript handshake - the client calls the service using a
token connecting the user to his current session he has on the
application, the service replies are rendered into an iframe and
deliver their data through postMessage. 

Thus, when rendering a reply, I am basically rendering a Wicket
page within the context of my session. 

Now one of my API's calls requires me to render a Wicket panel
into a String, which is then wrapped into JSON as part of the
respective call's reply. 

The legacy code used to do this roughly like this (changes for
using the Wicket 6 API were applied, but this nevertheless never
worked):

- create a mock RequestCycle by creating a MockHttpSession, a
  MockHttpServletRequest and a MockHttpServletResponse, glue
  this all together to obtain a ServletWebRequest and a
  BufferedWebResponse and finaly use use Application.createRequestCycle()
  to create the RequestCycle object

- the component wrapped into a ComponentRenderingRequestHandler 

- then this code is executed:

|    try {
|        requestCycle.scheduleRequestHandlerAfterCurrent(requestHandler);
|        try {
|            if ( !requestCycle.processRequestAndDetach() ) {
|                requestCycle.scheduleRequestHandlerAfterCurrent(new 
ErrorCodeRequestHandler((HttpServletResponse.SC_NOT_FOUND));
|             }
|        } finally {
|            requestCycle.getResponse().close();
|        }
|        return requestCycle.getResponse().toString();
|    } finally {
|        requestCycle.detach();
|    }

I must admit I could not have written this myself :)

Now when running this code, I run into two different 
exceptions:

org.apache.wicket.WicketRuntimeException: Exception in rendering component: 
[Profile [Component id = profile]]
        at 
org.apache.wicket.Component.internalRenderComponent(Component.java:2576) 
[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.MarkupContainer.onRender(MarkupContainer.java:1493) 
~[wicket-core-6.9.1.jar:6.9.1]
        at org.apache.wicket.Component.internalRender(Component.java:2379) 
[wicket-core-6.9.1.jar:6.9.1]
        at org.apache.wicket.Component.render(Component.java:2307) 
[wicket-core-6.9.1.jar:6.9.1]
[...]
Caused by: java.lang.NullPointerException: null
        at 
org.apache.wicket.markup.html.internal.Enclosure.isVisible(Enclosure.java:143) 
~[wicket-core-6.9.1.jar:6.9.1]
        at org.apache.wicket.Component.determineVisibility(Component.java:4363) 
[wicket-core-6.9.1.jar:6.9.1]
        at org.apache.wicket.Component.internalBeforeRender(Component.java:916) 
[wicket-core-6.9.1.jar:6.9.1]
        at org.apache.wicket.Component.beforeRender(Component.java:991) 
[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.Component.internalPrepareForRender(Component.java:2214) 
[wicket-core-6.9.1.jar:6.9.1]
        at org.apache.wicket.Component.render(Component.java:2303) 
[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.MarkupContainer.renderNext(MarkupContainer.java:1390) 
~[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.MarkupContainer.renderAll(MarkupContainer.java:1554) 
~[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.MarkupContainer.renderComponentTagBody(MarkupContainer.java:1529)
 ~[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.MarkupContainer.onComponentTagBody(MarkupContainer.java:1484) 
~[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.markup.html.panel.DefaultMarkupSourcingStrategy.onComponentTagBody(DefaultMarkupSourcingStrategy.java:71)
 ~[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.Component.internalRenderComponent(Component.java:2549) 
[wicket-core-6.9.1.jar:6.9.1]

The enclosure's child component is null, as we see here:
|        @Override
|        public boolean isVisible()
|        {
|                return childComponent.determineVisibility() && 
super.isVisible();
|        }

Below that exception I find the markup of a stack trace page in my logs. 
Below that markup I get another stack trace:

java.lang.NullPointerException: null
        at 
org.apache.wicket.Component.internalPrepareForRender(Component.java:2224) 
~[wicket-core-6.9.1.jar:6.9.1]
        at org.apache.wicket.Page.internalPrepareForRender(Page.java:241) 
~[wicket-core-6.9.1.jar:6.9.1]
        at org.apache.wicket.Component.render(Component.java:2303) 
~[wicket-core-6.9.1.jar:6.9.1]
        at org.apache.wicket.Page.renderPage(Page.java:1010) 
~[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.request.handler.render.WebPageRenderer.renderPage(WebPageRenderer.java:121)
 ~[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.request.handler.render.WebPageRenderer.respond(WebPageRenderer.java:271)
 ~[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.core.request.handler.RenderPageRequestHandler.respond(RenderPageRequestHandler.java:165)
 ~[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.request.cycle.RequestCycle$HandlerExecutor.respond(RequestCycle.java:861)
 ~[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.request.RequestHandlerStack.execute(RequestHandlerStack.java:64)
 ~[wicket-request-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.request.cycle.RequestCycle.execute(RequestCycle.java:261) 
[wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.request.cycle.RequestCycle.processRequest(RequestCycle.java:218)
 [wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.request.cycle.RequestCycle.processRequestAndDetach(RequestCycle.java:289)
 [wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.protocol.http.WicketFilter.processRequestCycle(WicketFilter.java:259)
 [wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.protocol.http.WicketFilter.processRequest(WicketFilter.java:201)
 [wicket-core-6.9.1.jar:6.9.1]
        at 
org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:282) 
[wicket-core-6.9.1.jar:6.9.1]

Here the RequestCycle is null:
|        if (setRenderingFlag)
|        {
|                // only process feedback panel when we are about to be 
rendered.
|                // setRenderingFlag is false in case prepareForRender is 
called only to build component
|                // hierarchy (i.e. in 
BookmarkableListenerInterfaceRequestTarget).
|                // prepareForRender(true) is always called before the actual 
rendering is done so
|                // that's where feedback panels gather the messages
|
|                List<Component> feedbacks = 
getRequestCycle().getMetaData(FEEDBACK_LIST);

To me it seems like I've got two different problems here:

- the component cannot be rendered because I'm doing something
  fundamentally wrong, thus I'm not getting the expected output

- after the mock-RequestCycle's done with its work, there's no
  RequestCycle set anymore, thus I cannot render the reply


I understand that my problem may be rather specific. And since
this is webservice that is already in use, I cannot just rewrite
it completely. Thus I would greatly appreciate any hint how i could
accomplish what the old code used to do before the Wicket upgrade?

Cheers,

M'bert

-- 
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+= 
Pilot: Call me a fuel truck.
Tower: You're a fuel truck.

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

Reply via email to