Search in sources :

Example 1 with InterceptorComponent

use of com.github.bordertech.wcomponents.container.InterceptorComponent in project wcomponents by BorderTech.

the class ServletUtil method createInterceptorChain.

/**
 * Creates a new interceptor chain to handle the given request.
 *
 * @param request the request to handle
 * @return a new interceptor chain for the request.
 */
public static InterceptorComponent createInterceptorChain(final HttpServletRequest request) {
    // Allow for multi part parameters
    Map<String, String[]> parameters = getRequestParameters(request);
    InterceptorComponent[] chain;
    if (parameters.get(WServlet.DATA_LIST_PARAM_NAME) != null) {
        // Datalist
        chain = new InterceptorComponent[] { new TransformXMLInterceptor(), new DataListInterceptor() };
    } else if (parameters.get(WServlet.AJAX_TRIGGER_PARAM_NAME) != null) {
        // AJAX
        chain = new InterceptorComponent[] { new TemplateRenderInterceptor(), new TransformXMLInterceptor(), new ValidateXMLInterceptor(), new AjaxErrorInterceptor(), new SessionTokenAjaxInterceptor(), new ResponseCacheInterceptor(CacheType.NO_CACHE), new UIContextDumpInterceptor(), new AjaxSetupInterceptor(), new WWindowInterceptor(true), new WrongStepAjaxInterceptor(), new ContextCleanupInterceptor(), new WhitespaceFilterInterceptor(), new SubordinateControlInterceptor(), new AjaxPageShellInterceptor(), new AjaxDebugStructureInterceptor(), new AjaxInterceptor() };
    } else if (parameters.get(WServlet.TARGET_ID_PARAM_NAME) != null) {
        // Targetted Content
        chain = new InterceptorComponent[] { new TargetableErrorInterceptor(), new SessionTokenContentInterceptor(), new UIContextDumpInterceptor(), new TargetableInterceptor(), new WWindowInterceptor(false), new WrongStepContentInterceptor() };
    } else {
        chain = new InterceptorComponent[] { // Page submit
        new TemplateRenderInterceptor(), new TransformXMLInterceptor(), new ValidateXMLInterceptor(), new SessionTokenInterceptor(), new ResponseCacheInterceptor(CacheType.NO_CACHE), new UIContextDumpInterceptor(), new WWindowInterceptor(true), new WrongStepServerInterceptor(), new AjaxCleanupInterceptor(), new ContextCleanupInterceptor(), new WhitespaceFilterInterceptor(), new SubordinateControlInterceptor(), new PageShellInterceptor(), new FormInterceptor(), new DebugStructureInterceptor() };
    }
    // Link the interceptors together in a chain.
    for (int i = 0; i < chain.length - 1; i++) {
        chain[i].setBackingComponent(chain[i + 1]);
    }
    // Return the top of the chain.
    return chain[0];
}
Also used : AjaxCleanupInterceptor(com.github.bordertech.wcomponents.container.AjaxCleanupInterceptor) WrongStepAjaxInterceptor(com.github.bordertech.wcomponents.container.WrongStepAjaxInterceptor) AjaxPageShellInterceptor(com.github.bordertech.wcomponents.container.AjaxPageShellInterceptor) InterceptorComponent(com.github.bordertech.wcomponents.container.InterceptorComponent) AjaxErrorInterceptor(com.github.bordertech.wcomponents.container.AjaxErrorInterceptor) AjaxDebugStructureInterceptor(com.github.bordertech.wcomponents.container.AjaxDebugStructureInterceptor) WrongStepAjaxInterceptor(com.github.bordertech.wcomponents.container.WrongStepAjaxInterceptor) SessionTokenAjaxInterceptor(com.github.bordertech.wcomponents.container.SessionTokenAjaxInterceptor) AjaxInterceptor(com.github.bordertech.wcomponents.container.AjaxInterceptor) SessionTokenContentInterceptor(com.github.bordertech.wcomponents.container.SessionTokenContentInterceptor) TemplateRenderInterceptor(com.github.bordertech.wcomponents.container.TemplateRenderInterceptor) WrongStepContentInterceptor(com.github.bordertech.wcomponents.container.WrongStepContentInterceptor) AjaxSetupInterceptor(com.github.bordertech.wcomponents.container.AjaxSetupInterceptor) AjaxDebugStructureInterceptor(com.github.bordertech.wcomponents.container.AjaxDebugStructureInterceptor) DebugStructureInterceptor(com.github.bordertech.wcomponents.container.DebugStructureInterceptor) UIContextDumpInterceptor(com.github.bordertech.wcomponents.container.UIContextDumpInterceptor) TargetableErrorInterceptor(com.github.bordertech.wcomponents.container.TargetableErrorInterceptor) WhitespaceFilterInterceptor(com.github.bordertech.wcomponents.container.WhitespaceFilterInterceptor) FormInterceptor(com.github.bordertech.wcomponents.container.FormInterceptor) DataListInterceptor(com.github.bordertech.wcomponents.container.DataListInterceptor) TargetableInterceptor(com.github.bordertech.wcomponents.container.TargetableInterceptor) SessionTokenAjaxInterceptor(com.github.bordertech.wcomponents.container.SessionTokenAjaxInterceptor) ValidateXMLInterceptor(com.github.bordertech.wcomponents.container.ValidateXMLInterceptor) SessionTokenInterceptor(com.github.bordertech.wcomponents.container.SessionTokenInterceptor) WWindowInterceptor(com.github.bordertech.wcomponents.container.WWindowInterceptor) ResponseCacheInterceptor(com.github.bordertech.wcomponents.container.ResponseCacheInterceptor) TransformXMLInterceptor(com.github.bordertech.wcomponents.container.TransformXMLInterceptor) ContextCleanupInterceptor(com.github.bordertech.wcomponents.container.ContextCleanupInterceptor) SubordinateControlInterceptor(com.github.bordertech.wcomponents.container.SubordinateControlInterceptor) PageShellInterceptor(com.github.bordertech.wcomponents.container.PageShellInterceptor) AjaxPageShellInterceptor(com.github.bordertech.wcomponents.container.AjaxPageShellInterceptor) WrongStepServerInterceptor(com.github.bordertech.wcomponents.container.WrongStepServerInterceptor)

Example 2 with InterceptorComponent

use of com.github.bordertech.wcomponents.container.InterceptorComponent in project wcomponents by BorderTech.

the class WServlet method serviceInt.

/**
 * Service internal. This method does the real work in servicing the http request. It integrates wcomponents into a
 * servlet environment via a servlet specific helper class.
 *
 * @param request the http servlet request.
 * @param response the http servlet response.
 * @throws IOException an IO exception
 * @throws ServletException a servlet exception
 */
protected void serviceInt(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    // Check for resource request
    boolean continueProcess = ServletUtil.checkResourceRequest(request, response);
    if (!continueProcess) {
        return;
    }
    // Create a support class to coordinate the web request.
    WServletHelper helper = createServletHelper(request, response);
    // Get the interceptors that will be used to plug in features.
    InterceptorComponent interceptorChain = createInterceptorChain(request);
    // Get the WComponent that represents the application we are serving.
    WComponent ui = getUI(request);
    ServletUtil.processRequest(helper, ui, interceptorChain);
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) InterceptorComponent(com.github.bordertech.wcomponents.container.InterceptorComponent)

Example 3 with InterceptorComponent

use of com.github.bordertech.wcomponents.container.InterceptorComponent in project wcomponents by BorderTech.

the class WebUtilities method renderWithTransformToHTML.

/**
 * Renders and transforms the given WComponent to a HTML String outside of the context of a Servlet.
 *
 * @param request the request being responded to
 * @param component the root WComponent to render
 * @param includePageShell true if include page shell
 * @return the rendered output as a String.
 */
public static String renderWithTransformToHTML(final Request request, final WComponent component, final boolean includePageShell) {
    // Setup a context (if needed)
    boolean needsContext = UIContextHolder.getCurrent() == null;
    if (needsContext) {
        UIContextHolder.pushContext(new UIContextImpl());
    }
    try {
        // Link Interceptors
        InterceptorComponent templateRender = new TemplateRenderInterceptor();
        InterceptorComponent transformXML = new TransformXMLInterceptor();
        templateRender.setBackingComponent(transformXML);
        if (includePageShell) {
            transformXML.setBackingComponent(new PageShellInterceptor());
        }
        // Attach Component and Mock Response
        InterceptorComponent chain = templateRender;
        chain.attachUI(component);
        chain.attachResponse(new MockResponse());
        // Render chain
        StringWriter buffer = new StringWriter();
        chain.preparePaint(request);
        try (PrintWriter writer = new PrintWriter(buffer)) {
            chain.paint(new WebXmlRenderContext(writer));
        }
        return buffer.toString();
    } finally {
        if (needsContext) {
            UIContextHolder.popContext();
        }
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) InterceptorComponent(com.github.bordertech.wcomponents.container.InterceptorComponent) StringWriter(java.io.StringWriter) TransformXMLInterceptor(com.github.bordertech.wcomponents.container.TransformXMLInterceptor) PageShellInterceptor(com.github.bordertech.wcomponents.container.PageShellInterceptor) TemplateRenderInterceptor(com.github.bordertech.wcomponents.container.TemplateRenderInterceptor) PrintWriter(java.io.PrintWriter)

Example 4 with InterceptorComponent

use of com.github.bordertech.wcomponents.container.InterceptorComponent in project wcomponents by BorderTech.

the class SerializationPerformance_Test method sendRequest.

/**
 * Invokes WComponent request processing, so that this test case can more closely match a production scenario.
 *
 * @param comp the component to invoke request processing on.
 * @param uic the user context to use.
 */
private void sendRequest(final WComponent comp, final UIContext uic) {
    PrintWriter writer = new PrintWriter(new NullWriter());
    uic.setEnvironment(new WServlet.WServletEnvironment("", "http://localhost", ""));
    uic.setUI(comp);
    InterceptorComponent root = ServletUtil.createInterceptorChain(new MockHttpServletRequest());
    root.attachUI(comp);
    Response response = new MockResponse();
    root.attachResponse(response);
    setActiveContext(uic);
    MockRequest request = new MockRequest();
    try {
        root.serviceRequest(request);
        root.preparePaint(request);
        root.paint(new WebXmlRenderContext(writer));
    } finally {
        resetContext();
    }
}
Also used : MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) InterceptorComponent(com.github.bordertech.wcomponents.container.InterceptorComponent) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) WServlet(com.github.bordertech.wcomponents.servlet.WServlet) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter)

Example 5 with InterceptorComponent

use of com.github.bordertech.wcomponents.container.InterceptorComponent in project wcomponents by BorderTech.

the class WebXmlRenderingPerformance_Test method sendRequest.

/**
 * Invokes WComponent request processing, so that this test case can more closely match a production scenario.
 *
 * @param comp the component to invoke request processing on.
 * @param uic the user context to use.
 */
private void sendRequest(final WComponent comp, final UIContext uic) {
    PrintWriter writer = new PrintWriter(new NullWriter());
    uic.setEnvironment(new WServlet.WServletEnvironment("", "http://localhost", ""));
    uic.setUI(comp);
    InterceptorComponent root = ServletUtil.createInterceptorChain(new MockHttpServletRequest());
    root.attachUI(comp);
    Response response = new MockResponse();
    root.attachResponse(response);
    setActiveContext(uic);
    MockRequest request = new MockRequest();
    try {
        root.serviceRequest(request);
        root.preparePaint(request);
        root.paint(new WebXmlRenderContext(writer));
    } finally {
        resetContext();
    }
}
Also used : Response(com.github.bordertech.wcomponents.Response) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) InterceptorComponent(com.github.bordertech.wcomponents.container.InterceptorComponent) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) WServlet(com.github.bordertech.wcomponents.servlet.WServlet) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter)

Aggregations

InterceptorComponent (com.github.bordertech.wcomponents.container.InterceptorComponent)5 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)3 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)3 PrintWriter (java.io.PrintWriter)3 PageShellInterceptor (com.github.bordertech.wcomponents.container.PageShellInterceptor)2 TemplateRenderInterceptor (com.github.bordertech.wcomponents.container.TemplateRenderInterceptor)2 TransformXMLInterceptor (com.github.bordertech.wcomponents.container.TransformXMLInterceptor)2 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)2 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)2 Response (com.github.bordertech.wcomponents.Response)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 AjaxCleanupInterceptor (com.github.bordertech.wcomponents.container.AjaxCleanupInterceptor)1 AjaxDebugStructureInterceptor (com.github.bordertech.wcomponents.container.AjaxDebugStructureInterceptor)1 AjaxErrorInterceptor (com.github.bordertech.wcomponents.container.AjaxErrorInterceptor)1 AjaxInterceptor (com.github.bordertech.wcomponents.container.AjaxInterceptor)1 AjaxPageShellInterceptor (com.github.bordertech.wcomponents.container.AjaxPageShellInterceptor)1 AjaxSetupInterceptor (com.github.bordertech.wcomponents.container.AjaxSetupInterceptor)1 ContextCleanupInterceptor (com.github.bordertech.wcomponents.container.ContextCleanupInterceptor)1