Search in sources :

Example 6 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class SimplePicker method afterPaint.

/**
 * Override afterPaint in order to paint the UIContext serialization statistics if the profile button has been
 * pressed.
 *
 * @param renderContext the renderContext to send output to.
 */
@Override
protected void afterPaint(final RenderContext renderContext) {
    super.afterPaint(renderContext);
    if (profileBtn.isPressed()) {
        // UIC serialization stats
        UicStats stats = new UicStats(UIContextHolder.getCurrent());
        WComponent currentComp = this.getCurrentComponent();
        if (currentComp != null) {
            stats.analyseWC(currentComp);
        }
        if (renderContext instanceof WebXmlRenderContext) {
            PrintWriter writer = ((WebXmlRenderContext) renderContext).getWriter();
            writer.println("<hr />");
            writer.println("<h2>Serialization Profile of UIC</h2>");
            UicStatsAsHtml.write(writer, stats);
            if (currentComp != null) {
                writer.println("<hr />");
                writer.println("<h2>ObjectProfiler - " + currentComp + "</h2>");
                writer.println("<pre>");
                try {
                    writer.println(ObjectGraphDump.dump(currentComp).toFlatSummary());
                } catch (Exception e) {
                    LOG.error("Failed to dump component", e);
                }
                writer.println("</pre>");
            }
        }
    }
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) UicStats(com.github.bordertech.wcomponents.monitor.UicStats) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) PrintWriter(java.io.PrintWriter)

Example 7 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class ContextCleanupInterceptor_Test method testPaint.

@Test
public void testPaint() {
    MyWLabel label = new MyWLabel();
    label.setText("Hello world");
    InterceptorComponent interceptor = new ContextCleanupInterceptor();
    interceptor.setBackingComponent(label);
    StringWriter writer = new StringWriter();
    setActiveContext(createUIContext());
    interceptor.paint(new WebXmlRenderContext(new PrintWriter(writer)));
    // After the paint, the component should have been painted, and the context cleared up
    Assert.assertTrue("tidyUpUIContextForTree was not called", label.tidiedUp);
    Assert.assertTrue("Component was not painted", writer.toString().indexOf(label.getText()) != -1);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 8 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class DataListInterceptor_Test method testInterecptor.

@Test
public void testInterecptor() throws XpathException, SAXException, IOException {
    String tableKey = TestLookupTable.CACHEABLE_DAY_OF_WEEK_TABLE;
    // Create interceptor
    DataListInterceptor interceptor = new DataListInterceptor();
    interceptor.attachUI(new DefaultWComponent());
    // Action phase
    MockRequest request = new MockRequest();
    request.setParameter(WServlet.DATA_LIST_PARAM_NAME, tableKey);
    interceptor.serviceRequest(request);
    // Render phase
    MockResponse response = new MockResponse();
    interceptor.attachResponse(response);
    interceptor.paint(new WebXmlRenderContext(new PrintWriter(response.getWriter())));
    String xml = response.getWriterOutput();
    // Ensure that the data matches the test table.
    List<TestLookupTable.TableEntry> table = (List<TestLookupTable.TableEntry>) Factory.newInstance(LookupTable.class).getTable(tableKey);
    assertXpathEvaluatesTo(String.valueOf(table.size()), "count(/ui:datalist/ui:option)", xml);
    for (int i = 0; i < table.size(); i++) {
        assertXpathEvaluatesTo(table.get(i).getCode(), "/ui:datalist/ui:option[" + (i + 1) + "]/@value", xml);
        assertXpathEvaluatesTo(table.get(i).getDesc(), "/ui:datalist/ui:option[" + (i + 1) + "]/text()", xml);
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) TestLookupTable(com.github.bordertech.wcomponents.TestLookupTable) List(java.util.List) DefaultWComponent(com.github.bordertech.wcomponents.DefaultWComponent) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 9 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class DebugStructureInterceptor_Test method doRequest.

/**
 * Does a request/response cycle for a WApplication.
 *
 * @return the xml output.
 */
private String doRequest() {
    WApplication app = new WApplication();
    app.setLocked(true);
    UIContext uic = createUIContext();
    uic.setUI(app);
    setActiveContext(uic);
    // Create interceptor
    PageShellInterceptor pageInterceptor = new PageShellInterceptor();
    DebugStructureInterceptor debugInterceptor = new DebugStructureInterceptor();
    pageInterceptor.setBackingComponent(debugInterceptor);
    pageInterceptor.attachUI(app);
    // Action phase
    MockRequest request = new MockRequest();
    pageInterceptor.serviceRequest(request);
    pageInterceptor.preparePaint(request);
    // Render phase
    MockResponse response = new MockResponse();
    pageInterceptor.attachResponse(response);
    pageInterceptor.paint(new WebXmlRenderContext(response.getWriter()));
    return response.getWriterOutput();
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) WApplication(com.github.bordertech.wcomponents.WApplication) UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest)

Example 10 with WebXmlRenderContext

use of com.github.bordertech.wcomponents.servlet.WebXmlRenderContext in project wcomponents by BorderTech.

the class ResponseCacheInterceptor_Test method testOverrideDefaultNoCache.

@Test
public void testOverrideDefaultNoCache() {
    /**
     * Original config.
     */
    Configuration originalConfig;
    originalConfig = Config.getInstance();
    String override = "OVERRIDE NO CACHE";
    try {
        // Test override cache settings
        Configuration config = Config.copyConfiguration(originalConfig);
        config.setProperty(ConfigurationProperties.RESPONSE_NO_CACHE_SETTINGS, override);
        Config.setConfiguration(config);
        // Create interceptor
        ResponseCacheInterceptor interceptor = new ResponseCacheInterceptor(CacheType.CONTENT_NO_CACHE);
        interceptor.setBackingComponent(new WText());
        // Mock Response
        MockResponse response = new MockResponse();
        interceptor.attachResponse(response);
        // Render phase
        interceptor.paint(new WebXmlRenderContext(response.getWriter()));
        // Check Override
        Assert.assertEquals("Cache-Control header not overriden correctly for NO CACHE", override, response.getHeaders().get("Cache-Control"));
    } finally {
        // Remove overrides
        Config.setConfiguration(originalConfig);
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) Configuration(org.apache.commons.configuration.Configuration) WText(com.github.bordertech.wcomponents.WText) Test(org.junit.Test)

Aggregations

WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)63 PrintWriter (java.io.PrintWriter)48 StringWriter (java.io.StringWriter)27 Test (org.junit.Test)27 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)17 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)17 UIContext (com.github.bordertech.wcomponents.UIContext)15 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)7 SystemException (com.github.bordertech.wcomponents.util.SystemException)7 WText (com.github.bordertech.wcomponents.WText)6 RenderContext (com.github.bordertech.wcomponents.RenderContext)5 WComponent (com.github.bordertech.wcomponents.WComponent)5 XmlStringBuilder (com.github.bordertech.wcomponents.XmlStringBuilder)5 WServlet (com.github.bordertech.wcomponents.servlet.WServlet)5 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)4 Configuration (org.apache.commons.configuration.Configuration)4 ActionEscape (com.github.bordertech.wcomponents.ActionEscape)3 AllComponents (com.github.bordertech.wcomponents.AllComponents)3 ComponentWithContext (com.github.bordertech.wcomponents.ComponentWithContext)3 Response (com.github.bordertech.wcomponents.Response)3