use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.
the class BufferedResponseMapper method getAndRemoveBufferedResponse.
protected BufferedWebResponse getAndRemoveBufferedResponse(Url url) {
String sessionId = getSessionId();
BufferedWebResponse response = null;
if (Strings.isEmpty(sessionId) == false) {
response = WebApplication.get().getAndRemoveBufferedResponse(sessionId, url);
}
return response;
}
use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.
the class ComponentRenderer method renderPage.
/**
* Collects the html generated by rendering a page.
*
* @param page
* supplier of the page
* @return the html rendered by the panel
*/
public CharSequence renderPage(final Supplier<? extends Page> page) {
return inThreadContext(() -> {
Request request = newRequest();
BufferedWebResponse response = new BufferedWebResponse(null);
RequestCycle cycle = application.createRequestCycle(request, response);
ThreadContext.setRequestCycle(cycle);
page.get().renderPage();
return response.getText();
});
}
use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.
the class ComponentRenderer method renderPage.
/**
* Collects the Html generated by the rendering a page.
* <p>
* Important note: Must be called on a thread bound to an application's {@link ThreadContext}!
*
* @param pageProvider
* the provider of the page class/instance and its parameters
* @return the html rendered by a page
*
* @see ThreadContext
*/
public static CharSequence renderPage(final PageProvider pageProvider) {
Application application = Application.get();
RequestCycle originalRequestCycle = RequestCycle.get();
BufferedWebResponse tempResponse = new BufferedWebResponse(null);
RequestCycle tempRequestCycle = application.createRequestCycle(originalRequestCycle.getRequest(), tempResponse);
try {
ThreadContext.setRequestCycle(tempRequestCycle);
pageProvider.getPageInstance().renderPage();
} finally {
ThreadContext.setRequestCycle(originalRequestCycle);
}
return tempResponse.getText();
}
use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.
the class ComponentRenderer method renderComponent.
/**
* Collects the Html generated by rendering a component.
* <p>
* Important notes:
* <ul>
* <li>this method is meant to render fresh component instances that are disposed after the html
* has been generate. To avoid unwanted side effects do not use it with components that are from
* an existing hierarchy.</li>
* <li>does <strong>not</strong> support rendering
* {@link org.apache.wicket.markup.html.panel.Fragment} instances</li>
* <li>must be called on a thread bound to an application's {@link ThreadContext}!</li>
* </ul>
*
* @param component
* the component to render.
* @return the html rendered by the component
*
* @see ThreadContext
*/
public static CharSequence renderComponent(final Component component) {
RequestCycle requestCycle = RequestCycle.get();
final Response originalResponse = requestCycle.getResponse();
BufferedWebResponse tempResponse = new BufferedWebResponse(null);
MarkupContainer oldParent = component.getParent();
if (oldParent != null && LOGGER.isWarnEnabled()) {
LOGGER.warn("Component '{}' with a parent '{}' is passed for standalone rendering. " + "It is recommended to render only orphan components because they are not cleaned up/detached" + " after the rendering.", component, oldParent);
}
try {
requestCycle.setResponse(tempResponse);
// add the component to a dummy page just for the rendering
RenderPage page = new RenderPage(component);
page.internalInitialize();
component.beforeRender();
component.renderPart();
} finally {
if (oldParent != null) {
// re-add the child to its old parent
oldParent.add(component);
}
requestCycle.setResponse(originalResponse);
}
return tempResponse.getText();
}
use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.
the class TestPageRenderer method renderPage.
@Override
protected BufferedWebResponse renderPage(Url targetUrl, RequestCycle requestCycle) {
BufferedWebResponse webResponse = super.renderPage(targetUrl, requestCycle);
webResponse.write("some response".getBytes());
return webResponse;
}
Aggregations