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);
}
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));
}
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());
}
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());
}
Aggregations