Search in sources :

Example 1 with ServletRequest

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

the class TransformXMLInterceptor method preparePaint.

/**
 * Override preparePaint in order to perform processing specific to this interceptor.
 *
 * @param request the request being responded to.
 */
@Override
public void preparePaint(final Request request) {
    if (doTransform && request instanceof ServletRequest) {
        HttpServletRequest httpServletRequest = ((ServletRequest) request).getBackingRequest();
        String userAgentString = httpServletRequest.getHeader("User-Agent");
        /* It is possible to opt out on a case by case basis by setting a flag on the ua string.
			 * This helps custom user agents that do not support HTML as well as facilitating debugging.
			 */
        if (userAgentString != null && userAgentString.contains(NO_XSLT_FLAG)) {
            doTransform = false;
        }
        String debugCookie = ServletUtil.extractCookie(httpServletRequest, DEBUG_REQUEST);
        if ("true".equals(debugCookie)) {
            debugRequested = true;
        }
    }
    super.preparePaint(request);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequest(com.github.bordertech.wcomponents.servlet.ServletRequest)

Example 2 with ServletRequest

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

the class LookupTableHelper_Test method testRegisterList.

@Test
public void testRegisterList() {
    final String key = "LookupTableHelper_Test.testRegisterList.key";
    UIContext uic = createUIContext();
    UIContextHolder.pushContext(uic);
    MockHttpSession session = new MockHttpSession();
    ServletRequest request = new ServletRequest(new MockHttpServletRequest(session));
    LookupTableHelper.registerList(key, request);
    // Use a new request to ensure that it was stored as a session attribute
    request = new ServletRequest(new MockHttpServletRequest(session));
    Assert.assertSame("Incorrect context returned", uic, LookupTableHelper.getContext(key, request));
}
Also used : ServletRequest(com.github.bordertech.wcomponents.servlet.ServletRequest) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) UIContext(com.github.bordertech.wcomponents.UIContext) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) Test(org.junit.Test)

Example 3 with ServletRequest

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

the class TransformXMLInterceptor_Test method generateOutput.

/**
 * Render the component and execute the interceptor.
 *
 * @param testUI the test component
 * @param headers Request headers to set (key/value pairs).
 * @return the response
 */
private TestResult generateOutput(final MyComponent testUI, final Map<String, String> headers) {
    InterceptorComponent interceptor = new TransformXMLInterceptor();
    interceptor.attachUI(testUI);
    MockHttpServletRequest backing = new MockHttpServletRequest();
    if (headers != null) {
        for (String headerName : headers.keySet()) {
            backing.setHeader(headerName, headers.get(headerName));
        }
    }
    ServletRequest request = new ServletRequest(backing);
    MockResponse response = new MockResponse();
    interceptor.attachResponse(response);
    StringWriter writer = new StringWriter();
    UIContext uic = createUIContext();
    uic.setLocale(new Locale("en"));
    setActiveContext(uic);
    try {
        interceptor.preparePaint(request);
        interceptor.paint(new WebXmlRenderContext(new PrintWriter(writer)));
    } finally {
        resetContext();
    }
    return new TestResult(writer.toString(), response.getContentType());
}
Also used : Locale(java.util.Locale) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) ServletRequest(com.github.bordertech.wcomponents.servlet.ServletRequest) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) StringWriter(java.io.StringWriter) UIContext(com.github.bordertech.wcomponents.UIContext) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) PrintWriter(java.io.PrintWriter)

Example 4 with ServletRequest

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

the class TemplateRenderInterceptorTest method generateOutput.

/**
 * Render the component and execute the interceptor.
 *
 * @param testUI the test component
 * @param headers Request headers to set (key/value pairs).
 * @return the response
 */
private TestResult generateOutput(final MyComponent testUI, final Map<String, String> headers) {
    InterceptorComponent interceptor = new TemplateRenderInterceptor();
    interceptor.attachUI(testUI);
    MockHttpServletRequest backing = new MockHttpServletRequest();
    if (headers != null) {
        for (String headerName : headers.keySet()) {
            backing.setHeader(headerName, headers.get(headerName));
        }
    }
    ServletRequest request = new ServletRequest(backing);
    MockResponse response = new MockResponse();
    interceptor.attachResponse(response);
    StringWriter writer = new StringWriter();
    UIContext uic = createUIContext();
    uic.setLocale(new Locale("en"));
    setActiveContext(uic);
    try {
        interceptor.preparePaint(request);
        interceptor.paint(new WebXmlRenderContext(new PrintWriter(writer)));
    } finally {
        resetContext();
    }
    return new TestResult(writer.toString(), response.getContentType());
}
Also used : Locale(java.util.Locale) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) ServletRequest(com.github.bordertech.wcomponents.servlet.ServletRequest) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockResponse(com.github.bordertech.wcomponents.util.mock.MockResponse) StringWriter(java.io.StringWriter) UIContext(com.github.bordertech.wcomponents.UIContext) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) PrintWriter(java.io.PrintWriter)

Aggregations

ServletRequest (com.github.bordertech.wcomponents.servlet.ServletRequest)4 UIContext (com.github.bordertech.wcomponents.UIContext)3 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)3 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)2 MockResponse (com.github.bordertech.wcomponents.util.mock.MockResponse)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 Locale (java.util.Locale)2 MockHttpSession (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Test (org.junit.Test)1