/** * Creates a protected child context. This is especially useful for new * application attached to their parent component, to ensure their isolation * from the other applications. By default it creates a new context instance * with empty or null properties, except the client and server dispatchers * that are wrapped for isolation purpose. * * @return The child context. */ public Context createChildContext() { return new org.restlet.engine.util.ChildContext(this); }
/** * Indicates that a Restlet's context has changed. * * @param restlet * The Restlet with a changed context. * @param context * The new context. */ private static void fireContextChanged(Restlet restlet, Context context) { if (context != null) { if (context instanceof org.restlet.engine.util.ChildContext) { org.restlet.engine.util.ChildContext childContext = (org.restlet.engine.util.ChildContext) context; if (childContext.getChild() == null) { childContext.setChild(restlet); } } else if (!(restlet instanceof Component) && (context instanceof org.restlet.engine.component.ComponentContext)) { context.getLogger() .severe("For security reasons, don't pass the component context to child Restlets anymore. Use the Context#createChildContext() method instead. " + restlet.getClass()); } } }
/** * Constructor. * * @param parentContext * The parent context. */ public ChildContext(Context parentContext) { this.child = null; this.parentContext = parentContext; setClientDispatcher(new ChildClientDispatcher(this)); setServerDispatcher((parentContext != null) ? getParentContext() .getServerDispatcher() : null); setExecutorService((parentContext != null) ? ((parentContext .getExecutorService() != null) ? new WrapperScheduledExecutorService( parentContext.getExecutorService()) : null) : null); }
/** * Sets the child. * * @param child * The child. */ public void setChild(Restlet child) { this.child = child; setLogger(LogUtils.getLoggerName(this.parentContext.getLogger() .getName(), child)); }
/** * Asks to the parent component to handle the call. * * @param request * The request to handle. * @param response * The response to update. */ private void parentHandle(Request request, Response response) { if (getChildContext() != null) { if (getChildContext().getParentContext() != null) { if (getChildContext().getParentContext().getClientDispatcher() != null) { getChildContext().getParentContext().getClientDispatcher() .handle(request, response); } else { getLogger() .warning( "The parent context doesn't have a client dispatcher available. Unable to handle call."); } } else { getLogger() .warning( "Your Restlet doesn't have a parent context available."); } } else { getLogger().warning( "Your Restlet doesn't have a context available."); } }
&& (getChildContext().getChild() instanceof Application)) { Application application = (Application) getChildContext() .getChild(); request.getResourceRef().setBaseRef( request.getResourceRef().getHostIdentifier()); && (getChildContext().getChild() instanceof Application)) { Application application = (Application) getChildContext() .getChild();
@Override public Context createChildContext() { return new ChildContext(getComponentHelper().getHelped().getContext()); }