use of com.github.bordertech.wcomponents.Escape in project wcomponents by BorderTech.
the class AbstractContainerHelper method processAction.
/**
* Support standard processing of the action phase of a request.
*
* @throws IOException if there is an IO error on writing a response.
*/
public void processAction() throws IOException {
if (isDisposed()) {
LOG.error("Skipping action phase. Attempt to reuse disposed ContainerHelper instance");
return;
}
try {
// Check user context has been prepared
if (getNewConversation() == null) {
throw new IllegalStateException("User context has not been prepared before the action phase");
}
prepareAction();
UIContext uic = getUIContext();
if (uic == null) {
throw new IllegalStateException("No user context set for the action phase.");
}
UIContextHolder.pushContext(uic);
// Make sure maps are cleared up
uic.clearScratchMap();
uic.clearRequestScratchMap();
prepareRequest();
Request req = getRequest();
getInterceptor().attachResponse(getResponse());
getInterceptor().serviceRequest(req);
if (req.isLogout()) {
handleLogout();
dispose();
}
} catch (ActionEscape esc) {
LOG.debug("ActionEscape performed.");
// Action escapes must be handled in the action phase and then
// do nothing if they reach the render phase (which they will in
// the servlet implementation)
handleEscape(esc);
dispose();
} catch (Escape esc) {
LOG.debug("Escape performed during action phase.");
// We can't handle the escape until the render phase.
} catch (SessionTokenException e) {
// This session token exception can occur on a page submit action phase.
// Do a warn level to create less noise in the error logs.
LOG.warn(e.getMessage());
propogateError(e);
} catch (Throwable t) {
// We try not to let any exception propagate to container.
String message = "Caught exception during action phase.";
LOG.error(message, t);
// We can't handle the error until the render phase.
propogateError(t);
} finally {
UIContextHolder.reset();
}
}
use of com.github.bordertech.wcomponents.Escape in project wcomponents by BorderTech.
the class AbstractContainerHelper method render.
/**
* Support standard processing of the render phase of a request.
*
* @throws IOException IO Exception
*/
public void render() throws IOException {
if (isDisposed()) {
LOG.debug("Skipping render phase.");
return;
}
try {
// Check user context has been prepared
if (getNewConversation() == null) {
throw new IllegalStateException("User context has not been prepared before the render phase");
}
prepareRender();
UIContext uic = getUIContext();
if (uic == null) {
throw new IllegalStateException("No user context set for the render phase.");
}
UIContextHolder.pushContext(uic);
prepareRequest();
// Handle errors from the action phase now.
if (havePropogatedError()) {
handleError(getPropogatedError());
return;
}
WComponent uiComponent = getUI();
if (uiComponent == null) {
throw new SystemException("No UI Component exists.");
}
Environment environment = uiComponent.getEnvironment();
if (environment == null) {
throw new SystemException("No WEnvironment exists.");
}
getInterceptor().attachResponse(getResponse());
getInterceptor().preparePaint(getRequest());
String contentType = getUI().getHeaders().getContentType();
Response response = getResponse();
response.setContentType(contentType);
addGenericHeaders(uic, getUI());
PrintWriter writer = getPrintWriter();
getInterceptor().paint(new WebXmlRenderContext(writer, uic.getLocale()));
// The following only matters for a Portal context
String title = uiComponent instanceof WApplication ? ((WApplication) uiComponent).getTitle() : null;
if (title != null) {
setTitle(title);
}
} catch (Escape esc) {
LOG.debug("Escape performed during render phase.");
handleEscape(esc);
} catch (Throwable t) {
// We try not to let any exception propagate to container.
String message = "Caught exception during render phase.";
LOG.error(message, t);
handleError(t);
} finally {
UIContextHolder.reset();
dispose();
}
}
use of com.github.bordertech.wcomponents.Escape in project wcomponents by BorderTech.
the class AjaxErrorInterceptor_Test method testHandleActionEscape.
@Test(expected = Escape.class)
public void testHandleActionEscape() throws IOException {
// Throw escape exception in chain
InterceptorComponent chain = new InterceptorComponent() {
@Override
public void serviceRequest(final Request request) {
throw new Escape();
}
};
// Setup interceptor
AjaxErrorInterceptor ajax = new AjaxErrorInterceptor();
ajax.setBackingComponent(chain);
// Process Action
ajax.serviceRequest(new MockRequest());
}
use of com.github.bordertech.wcomponents.Escape in project wcomponents by BorderTech.
the class TargetableErrorInterceptor_Test method testHandleActionEscape.
@Test(expected = Escape.class)
public void testHandleActionEscape() throws IOException {
// Throw escape exception in chain
InterceptorComponent chain = new InterceptorComponent() {
@Override
public void serviceRequest(final Request request) {
throw new Escape();
}
};
// Setup interceptor
TargetableErrorInterceptor interceptor = new TargetableErrorInterceptor();
interceptor.setBackingComponent(chain);
// Process Action
interceptor.serviceRequest(new MockRequest());
}
use of com.github.bordertech.wcomponents.Escape in project wcomponents by BorderTech.
the class TargetableErrorInterceptor_Test method testHandlePreparePaintEscape.
@Test(expected = Escape.class)
public void testHandlePreparePaintEscape() throws IOException {
// Throw escape exception in chain
InterceptorComponent chain = new InterceptorComponent() {
@Override
public void preparePaint(final Request request) {
throw new Escape();
}
};
// Setup interceptor
TargetableErrorInterceptor interceptor = new TargetableErrorInterceptor();
interceptor.setBackingComponent(chain);
// Prepare paint
interceptor.preparePaint(new MockRequest());
}
Aggregations