Search in sources :

Example 1 with ServletContainerException

use of org.xwiki.container.servlet.ServletContainerException in project xwiki-platform by xwiki.

the class ResourceReferenceHandlerServlet method initializeContainerComponent.

private void initializeContainerComponent(HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws ServletException {
    ServletContainerInitializer containerInitializer;
    try {
        containerInitializer = this.rootComponentManager.getInstance(ServletContainerInitializer.class);
    } catch (Exception e) {
        // This shouldn't happen, raise an exception
        throw new ServletException("Failed to locate a ServletContainerInitializer component", e);
    }
    try {
        containerInitializer.initializeRequest(httpRequest);
        containerInitializer.initializeResponse(httpResponse);
        containerInitializer.initializeSession(httpRequest);
    } catch (ServletContainerException e) {
        throw new ServletException("Failed to initialize Request/Response or Session", e);
    }
}
Also used : ServletContainerInitializer(org.xwiki.container.servlet.ServletContainerInitializer) ServletException(javax.servlet.ServletException) ServletContainerException(org.xwiki.container.servlet.ServletContainerException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ResourceReferenceHandlerException(org.xwiki.resource.ResourceReferenceHandlerException) ServletContainerException(org.xwiki.container.servlet.ServletContainerException)

Example 2 with ServletContainerException

use of org.xwiki.container.servlet.ServletContainerException in project xwiki-platform by xwiki.

the class XWikiContextInitializationFilter method initializeContainerComponent.

/**
 * @param context the XWiki context
 * @throws ServletException if the container component initialization fails
 */
protected void initializeContainerComponent(XWikiContext context) throws ServletException {
    // Initialize the Container fields (request, response, session). Note that this is a bridge between the old core
    // and the component architecture. In the new component architecture we use ThreadLocal to transport the
    // request, response and session to components which require them.
    ServletContainerInitializer containerInitializer = Utils.getComponent((Type) ServletContainerInitializer.class);
    try {
        containerInitializer.initializeRequest(context.getRequest().getHttpServletRequest(), context);
        containerInitializer.initializeResponse(context.getResponse());
        containerInitializer.initializeSession(context.getRequest().getHttpServletRequest());
    } catch (ServletContainerException e) {
        throw new ServletException("Failed to initialize Request/Response or Session", e);
    }
}
Also used : ServletContainerInitializer(org.xwiki.container.servlet.ServletContainerInitializer) ServletException(javax.servlet.ServletException) ServletContainerException(org.xwiki.container.servlet.ServletContainerException)

Example 3 with ServletContainerException

use of org.xwiki.container.servlet.ServletContainerException in project xwiki-platform by xwiki.

the class XWikiAction method initializeContainerComponent.

protected void initializeContainerComponent(XWikiContext context) throws ServletException {
    // Initialize the Container fields (request, response, session).
    // Note that this is a bridge between the old core and the component architecture.
    // In the new component architecture we use ThreadLocal to transport the request,
    // response and session to components which require them.
    // In the future this Servlet will be replaced by the XWikiPlexusServlet Servlet.
    ServletContainerInitializer containerInitializer = Utils.getComponent(ServletContainerInitializer.class);
    try {
        containerInitializer.initializeRequest(context.getRequest().getHttpServletRequest(), context);
        containerInitializer.initializeResponse(context.getResponse());
        containerInitializer.initializeSession(context.getRequest().getHttpServletRequest());
    } catch (ServletContainerException e) {
        throw new ServletException("Failed to initialize Request/Response or Session", e);
    }
}
Also used : ServletContainerInitializer(org.xwiki.container.servlet.ServletContainerInitializer) ServletException(javax.servlet.ServletException) ServletContainerException(org.xwiki.container.servlet.ServletContainerException)

Example 4 with ServletContainerException

use of org.xwiki.container.servlet.ServletContainerException in project xwiki-platform by xwiki.

the class DefaultServletContainerInitializer method initializeRequest.

@Override
public void initializeRequest(HttpServletRequest httpServletRequest, Object xwikiContext) throws ServletContainerException {
    // 1) Create an empty request. From this point forward request initializers can use the
    // Container object to get any data they want from the Request.
    this.container.setRequest(new ServletRequest(httpServletRequest));
    // 2) Create an empty Execution context so that the Container initializers can put things in the
    // execution context when they execute.
    this.execution.setContext(new ExecutionContext());
    // XWikiContext object whereas new code uses the Container component.
    if (xwikiContext != null) {
        ExecutionContext ec = this.execution.getContext();
        String key = "xwikicontext";
        if (ec.hasProperty(key)) {
            ec.setProperty(key, xwikiContext);
        } else {
            ec.newProperty(key).inherited().initial(xwikiContext).declare();
        }
    }
    // 4) Call the request initializers to populate the Request further.
    try {
        RequestInitializerManager manager = this.componentManager.getInstance(RequestInitializerManager.class);
        manager.initializeRequest(this.container.getRequest());
    } catch (Exception e) {
        throw new ServletContainerException("Failed to initialize request", e);
    }
    // 5) Call Execution Context initializers to perform further Execution Context initializations
    try {
        ExecutionContextManager manager = this.componentManager.getInstance(ExecutionContextManager.class);
        manager.initialize(this.execution.getContext());
    } catch (Exception e) {
        throw new ServletContainerException("Failed to initialize Execution Context", e);
    }
}
Also used : ServletRequest(org.xwiki.container.servlet.ServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletContainerException(org.xwiki.container.servlet.ServletContainerException) ExecutionContext(org.xwiki.context.ExecutionContext) ExecutionContextManager(org.xwiki.context.ExecutionContextManager) RequestInitializerManager(org.xwiki.container.RequestInitializerManager) ServletContainerException(org.xwiki.container.servlet.ServletContainerException)

Aggregations

ServletContainerException (org.xwiki.container.servlet.ServletContainerException)4 ServletException (javax.servlet.ServletException)3 ServletContainerInitializer (org.xwiki.container.servlet.ServletContainerInitializer)3 IOException (java.io.IOException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 RequestInitializerManager (org.xwiki.container.RequestInitializerManager)1 ServletRequest (org.xwiki.container.servlet.ServletRequest)1 ExecutionContext (org.xwiki.context.ExecutionContext)1 ExecutionContextManager (org.xwiki.context.ExecutionContextManager)1 ResourceReferenceHandlerException (org.xwiki.resource.ResourceReferenceHandlerException)1