Search in sources :

Example 1 with ProxyServlet

use of org.apache.felix.http.proxy.ProxyServlet in project sling by apache.

the class SlingServletDelegate method init.

/**
     * Initializes this servlet by loading the framework configuration
     * properties, starting the OSGi framework (Apache Felix) and exposing the
     * system bundle context and the <code>Felix</code> instance as servlet
     * context attributes.
     *
     * @throws ServletException if the framework cannot be initialized.
     */
@Override
public final void init() throws ServletException {
    // temporary holders control final setup and ensure proper
    // disposal in case of setup errors
    Sling tmpSling = null;
    Servlet tmpDelegatee = null;
    try {
        log("Starting Apache Sling in " + slingHome);
        // read the default parameters
        Map<String, String> props = loadConfigProperties(slingHome);
        Logger logger = new ServletContextLogger(getServletContext());
        LaunchpadContentProvider rp = new ServletContextResourceProvider(getServletContext());
        tmpSling = SlingBridge.getSlingBridge(notifiable, logger, rp, props, getServletContext());
        // set up the OSGi HttpService proxy servlet
        tmpDelegatee = new ProxyServlet();
        tmpDelegatee.init(getServletConfig());
        // them destroyed in the finally clause.
        if (servletDestroyed) {
            log("SlingServletDelegate destroyed while starting Apache Sling, shutting Apache Sling down");
        } else {
            // set the fields now
            sling = tmpSling;
            delegatee = tmpDelegatee;
            // reset temporary holders to prevent destroyal
            tmpSling = null;
            tmpDelegatee = null;
            log("Apache Sling successfully started in " + slingHome);
        }
    } catch (BundleException be) {
        throw new ServletException("Failed to start Apache Sling in " + slingHome, be);
    } catch (ServletException se) {
        throw new ServletException("Failed to start bridge servlet for Apache Sling", se);
    } catch (Throwable t) {
        throw new ServletException("Uncaught Failure starting Apache Sling", t);
    } finally {
        // clean up temporary fields
        if (tmpDelegatee != null) {
            tmpDelegatee.destroy();
        }
        if (tmpSling != null) {
            tmpSling.destroy();
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) LaunchpadContentProvider(org.apache.sling.launchpad.api.LaunchpadContentProvider) ProxyServlet(org.apache.felix.http.proxy.ProxyServlet) ProxyServlet(org.apache.felix.http.proxy.ProxyServlet) Servlet(javax.servlet.Servlet) GenericServlet(javax.servlet.GenericServlet) BundleException(org.osgi.framework.BundleException) Logger(org.apache.felix.framework.Logger) Sling(org.apache.sling.launchpad.base.impl.Sling)

Aggregations

GenericServlet (javax.servlet.GenericServlet)1 Servlet (javax.servlet.Servlet)1 ServletException (javax.servlet.ServletException)1 Logger (org.apache.felix.framework.Logger)1 ProxyServlet (org.apache.felix.http.proxy.ProxyServlet)1 LaunchpadContentProvider (org.apache.sling.launchpad.api.LaunchpadContentProvider)1 Sling (org.apache.sling.launchpad.base.impl.Sling)1 BundleException (org.osgi.framework.BundleException)1