use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class UIContextDumpInterceptor method paint.
/**
* Paints the component.
*
* @param renderContext the renderContext to send the output to.
*/
@Override
public void paint(final RenderContext renderContext) {
boolean enabled = ConfigurationProperties.getDeveloperDumpUIContext();
super.paint(renderContext);
if (enabled) {
UIContext uic = UIContextHolder.getCurrent();
// We want to dump the shared WComponent tree (UIC) first, so that all the
// references from the UI context are shown as such
Object[] treeAndSession = new Object[] { uic.getUI(), uic };
try {
ObjectGraphNode root = ObjectGraphDump.dump(treeAndSession);
// We only want to dump the tree once
boolean treeDumped = "true".equalsIgnoreCase((String) uic.getFwkAttribute(UICONTEXT_TREE_DUMPED_KEY));
if (!treeDumped) {
uic.setFwkAttribute(UICONTEXT_TREE_DUMPED_KEY, "true");
// The UI will be the 1st child
LOG.info("UI dump follows:");
LOG.info(((ObjectGraphNode) root.getChildAt(0)).toXml());
}
// The UI context will be the 2nd child
LOG.info("UI Context dump follows:");
LOG.info(((ObjectGraphNode) root.getChildAt(1)).toXml());
} catch (Exception e) {
LOG.error("Failed to dump context", e);
}
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WWindowInterceptor method serviceRequest.
/**
* Temporarily replaces the environment while the request is being handled.
*
* @param request the request being responded to.
*/
@Override
public void serviceRequest(final Request request) {
// Get window id off the request
windowId = request.getParameter(WWindow.WWINDOW_REQUEST_PARAM_KEY);
if (windowId == null) {
super.serviceRequest(request);
} else {
// Get the window component
ComponentWithContext target = WebUtilities.getComponentById(windowId, true);
if (target == null) {
throw new SystemException("No window component for id " + windowId);
}
// Setup the Environment on the context
UIContext uic = UIContextHolder.getCurrentPrimaryUIContext();
Environment originalEnvironment = uic.getEnvironment();
uic.setEnvironment(new EnvironmentDelegate(originalEnvironment, windowId, target));
if (attachWindow) {
attachUI(target.getComponent());
}
UIContextHolder.pushContext(target.getContext());
try {
super.serviceRequest(request);
} finally {
uic.setEnvironment(originalEnvironment);
UIContextHolder.popContext();
}
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WrongStepAjaxInterceptor method serviceRequest.
/**
* Override to check whether the step variable in the incoming request matches what we expect.
*
* @param request the request being serviced.
*/
@Override
public void serviceRequest(final Request request) {
// Get trigger id
triggerId = request.getParameter(WServlet.AJAX_TRIGGER_PARAM_NAME);
if (triggerId == null) {
throw new SystemException("No AJAX trigger id to check step count");
}
// Get trigger and its context
ComponentWithContext trigger = AjaxHelper.getCurrentTriggerAndContext();
if (trigger == null) {
throw new IllegalStateException("No component/context available for AJAX trigger " + triggerId + ".");
}
// Get expected step count
UIContext uic = UIContextHolder.getCurrent();
int expected = uic.getEnvironment().getStep();
// Step should already be set on the session
if (expected == 0) {
throw new SystemException("Step count should already be set on the session before AJAX request.");
}
// Get step count on the request
int got = StepCountUtil.getRequestStep(request);
// Check we are on the current step
if (expected == got) {
// Process Service Request
getBackingComponent().serviceRequest(request);
} else {
// Invalid step
LOG.warn("AJAX: Wrong step detected. Expected step " + expected + " but got step " + got);
// "GET" Ajax requests are just ignored and return an error code
if ("GET".equals(request.getMethod())) {
LOG.warn("Error code will be sent in the response for AJAX GET Request.");
handleErrorCode();
// Make sure the render phase is not processed
throw new ActionEscape();
} else if (StepCountUtil.isErrorRedirect()) {
// Redirect to error page
LOG.warn("User will be redirected to an error page.");
redirectUrl = StepCountUtil.getErrorUrl();
} else {
// Warp to the future by refreshing the page
LOG.warn("Warp the user back to the future by refreshing the page.");
handleWarpToTheFuture(uic);
redirectUrl = buildApplicationUrl(uic);
}
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WrongStepContentInterceptor method serviceRequest.
/**
* Override to check whether the step variable in the incoming request matches what we expect.
*
* @param request the request being serviced.
*/
@Override
public void serviceRequest(final Request request) {
// Get expected step count
UIContext uic = UIContextHolder.getCurrent();
int expected = uic.getEnvironment().getStep();
// Step should already be set on the session
if (expected == 0) {
throw new SystemException("Step count should already be set on the session before content request.");
}
// Get step count on the request
int got = StepCountUtil.getRequestStep(request);
// Check tokens match (both must be provided)
if (expected == got) {
// Process Service Request
getBackingComponent().serviceRequest(request);
} else if (!StepCountUtil.isStepOnRequest(request) && StepCountUtil.isCachedContentRequest(request)) {
// cached content (no step on request)
// Process Service Request
getBackingComponent().serviceRequest(request);
} else {
// Invalid token
// Set an error code
LOG.warn("Wrong step detected for content request. Expected step [" + expected + "] but got step [" + got + "].");
handleError();
}
}
use of com.github.bordertech.wcomponents.UIContext in project wcomponents by BorderTech.
the class WrongStepServerInterceptor method serviceRequest.
/**
* Override to check whether the step variable in the incoming request matches what we expect.
*
* @param request the request being serviced.
*/
@Override
public void serviceRequest(final Request request) {
// Get expected step count
UIContext uic = UIContextHolder.getCurrent();
int expected = uic.getEnvironment().getStep();
// Get step count from the request
int got = StepCountUtil.getRequestStep(request);
// or no Step count and processing a GET
if (expected == got || (!StepCountUtil.isStepOnRequest(request) && "GET".equals(request.getMethod()))) {
// Process Service Request
getBackingComponent().serviceRequest(request);
} else {
// Invalid step
LOG.warn("SERVER: Wrong step detected. Expected step " + expected + " but got step " + got);
// Redirect to error page
if (StepCountUtil.isErrorRedirect()) {
String url = StepCountUtil.getErrorUrl();
LOG.warn("User will be redirected to an error page. URL: " + url);
try {
getResponse().sendRedirect(url);
} catch (IOException e) {
LOG.warn("Error trying to redirect for wrong step indicator.");
}
// Make sure the render phase is not processed
throw new ActionEscape();
} else {
// Warp to the future
// Call handle step error
WComponent application = getUI();
if (application instanceof WApplication) {
LOG.warn("The handleStepError method will be called on WApplication.");
((WApplication) application).handleStepError();
}
LOG.warn("The render phase will warp the user back to the future.");
}
}
}
Aggregations