use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.
the class WebPageRendererTest method testRedirectToBufferStatefulPageAndSameUrls.
/**
* Tests that when the page is stateful and the urls are the same then the response is written
* directly
*/
@Test
public void testRedirectToBufferStatefulPageAndSameUrls() {
final AtomicBoolean stored = new AtomicBoolean(false);
PageRenderer renderer = new TestPageRenderer(handler) {
@Override
protected boolean isRedirectToBuffer() {
return true;
}
@Override
protected void storeBufferedResponse(Url url, BufferedWebResponse response) {
stored.set(true);
}
};
when(provider.isNewPageInstance()).thenReturn(true);
Url sameUrl = Url.parse("same");
// needed for earlier checks
when(urlRenderer.getBaseUrl()).thenReturn(sameUrl);
when(requestCycle.mapUrlFor(eq(handler))).thenReturn(sameUrl);
renderer.respond(requestCycle);
verify(response).write(any(byte[].class));
verify(response, never()).sendRedirect(anyString());
Assert.assertFalse(stored.get());
}
use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.
the class WebPageRendererTest method testRedirectToBufferStatelessPageAndRedirectIsDisabled.
/**
* Tests that when the page is stateless and redirect for stateless pages is disabled then the
* page should be written without redirect
*/
@Test
public void testRedirectToBufferStatelessPageAndRedirectIsDisabled() {
final AtomicBoolean stored = new AtomicBoolean(false);
TestPageRenderer renderer = new TestPageRenderer(handler) {
@Override
protected boolean enableRedirectForStatelessPage() {
return false;
}
@Override
protected void storeBufferedResponse(Url url, BufferedWebResponse response) {
stored.set(true);
}
};
renderer.redirectToBuffer = true;
renderer.pageStateless = true;
// needed for earlier checks
when(urlRenderer.getBaseUrl()).thenReturn(Url.parse("a"));
when(requestCycle.mapUrlFor(eq(handler))).thenReturn(Url.parse("b"));
renderer.respond(requestCycle);
verify(response).write(any(byte[].class));
verify(response, never()).sendRedirect(anyString());
Assert.assertFalse(stored.get());
}
use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.
the class AbstractTransformerBehavior method afterRender.
@Override
public void afterRender(final Component component) {
final RequestCycle requestCycle = RequestCycle.get();
try {
BufferedWebResponse tempResponse = (BufferedWebResponse) requestCycle.getResponse();
if (component instanceof Page && originalResponse instanceof WebResponse) {
tempResponse.writeMetaData((WebResponse) originalResponse);
}
// Transform the data
CharSequence output = transform(component, tempResponse.getText());
originalResponse.write(output);
} catch (Exception ex) {
throw new WicketRuntimeException("Error while transforming the output of component: " + component, ex);
} finally {
// Restore the original response object
requestCycle.setResponse(originalResponse);
}
}
use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.
the class AbstractTransformerBehavior method beforeRender.
@Override
public void beforeRender(Component component) {
super.beforeRender(component);
final RequestCycle requestCycle = RequestCycle.get();
// Temporarily replace the web response with a String response
originalResponse = requestCycle.getResponse();
WebResponse origResponse = (WebResponse) ((originalResponse instanceof WebResponse) ? originalResponse : null);
BufferedWebResponse tempResponse = newResponse(origResponse);
// temporarily set StringResponse to collect the transformed output
requestCycle.setResponse(tempResponse);
}
use of org.apache.wicket.protocol.http.BufferedWebResponse in project wicket by apache.
the class BufferedResponseMapper method mapRequest.
/**
* @see org.apache.wicket.request.IRequestMapper#mapRequest(org.apache.wicket.request.Request)
*/
@Override
public IRequestHandler mapRequest(Request request) {
request = getRequest(request);
BufferedWebResponse response = getAndRemoveBufferedResponse(request.getUrl());
if (response != null) {
return new BufferedResponseRequestHandler(response);
} else {
return null;
}
}
Aggregations