Search in sources :

Example 1 with Escape

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();
    }
}
Also used : Escape(com.github.bordertech.wcomponents.Escape) ActionEscape(com.github.bordertech.wcomponents.ActionEscape) ActionEscape(com.github.bordertech.wcomponents.ActionEscape) UIContext(com.github.bordertech.wcomponents.UIContext) Request(com.github.bordertech.wcomponents.Request)

Example 2 with Escape

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();
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) Response(com.github.bordertech.wcomponents.Response) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) Escape(com.github.bordertech.wcomponents.Escape) ActionEscape(com.github.bordertech.wcomponents.ActionEscape) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContext(com.github.bordertech.wcomponents.UIContext) WApplication(com.github.bordertech.wcomponents.WApplication) Environment(com.github.bordertech.wcomponents.Environment) PrintWriter(java.io.PrintWriter)

Example 3 with Escape

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());
}
Also used : Escape(com.github.bordertech.wcomponents.Escape) ErrorCodeEscape(com.github.bordertech.wcomponents.ErrorCodeEscape) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 4 with Escape

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());
}
Also used : Escape(com.github.bordertech.wcomponents.Escape) ErrorCodeEscape(com.github.bordertech.wcomponents.ErrorCodeEscape) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Example 5 with Escape

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());
}
Also used : Escape(com.github.bordertech.wcomponents.Escape) ErrorCodeEscape(com.github.bordertech.wcomponents.ErrorCodeEscape) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Test(org.junit.Test)

Aggregations

Escape (com.github.bordertech.wcomponents.Escape)6 Request (com.github.bordertech.wcomponents.Request)5 ErrorCodeEscape (com.github.bordertech.wcomponents.ErrorCodeEscape)4 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)4 Test (org.junit.Test)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)2 UIContext (com.github.bordertech.wcomponents.UIContext)2 Environment (com.github.bordertech.wcomponents.Environment)1 Response (com.github.bordertech.wcomponents.Response)1 WApplication (com.github.bordertech.wcomponents.WApplication)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 PrintWriter (java.io.PrintWriter)1