001/**
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *      http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package org.apache.oozie.servlet;
020
021import org.apache.oozie.service.Services;
022
023import javax.servlet.ServletContextListener;
024import javax.servlet.ServletContextEvent;
025
026/**
027 * Webapp context listener that initializes Oozie {@link Services}.
028 */
029public class ServicesLoader implements ServletContextListener {
030    private static Services services;
031    private static boolean sslEnabled = false;
032
033    /**
034     * Initialize Oozie services.
035     *
036     * @param event context event.
037     */
038    public void contextInitialized(ServletContextEvent event) {
039        try {
040            String ssl = event.getServletContext().getInitParameter("ssl.enabled");
041            if (ssl != null) {
042                sslEnabled = true;
043            }
044
045            services = new Services();
046            services.init();
047        }
048        catch (Throwable ex) {
049            System.out.println();
050            System.out.println("ERROR: Oozie could not be started");
051            System.out.println();
052            System.out.println("REASON: " + ex.toString());
053            System.out.println();
054            System.out.println("Stacktrace:");
055            System.out.println("-----------------------------------------------------------------");
056            ex.printStackTrace(System.out);
057            System.out.println("-----------------------------------------------------------------");
058            System.out.println();
059            System.exit(1);
060        }
061    }
062
063    /**
064     * Destroy Oozie services.
065     *
066     * @param event context event.
067     */
068    public void contextDestroyed(ServletContextEvent event) {
069        services.destroy();
070    }
071
072    public static boolean isSSLEnabled() {
073        return sslEnabled;
074    }
075}