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