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 */
018package org.apache.oozie.servlet;
019
020import org.apache.oozie.service.Services;
021
022import javax.servlet.ServletContextListener;
023import javax.servlet.ServletContextEvent;
024
025/**
026 * Webapp context listener that initializes Oozie {@link Services}.
027 */
028public class ServicesLoader implements ServletContextListener {
029    private static Services services;
030    private static boolean sslEnabled = false;
031
032    /**
033     * Initialize Oozie services.
034     *
035     * @param event context event.
036     */
037    public void contextInitialized(ServletContextEvent event) {
038        try {
039            String ssl = event.getServletContext().getInitParameter("ssl.enabled");
040            if (ssl != null) {
041                sslEnabled = true;
042            }
043
044            services = new Services();
045            services.init();
046        }
047        catch (Throwable ex) {
048            System.out.println();
049            System.out.println("ERROR: Oozie could not be started");
050            System.out.println();
051            System.out.println("REASON: " + ex.toString());
052            System.out.println();
053            System.out.println("Stacktrace:");
054            System.out.println("-----------------------------------------------------------------");
055            ex.printStackTrace(System.out);
056            System.out.println("-----------------------------------------------------------------");
057            System.out.println();
058            System.exit(1);
059        }
060    }
061
062    /**
063     * Destroy Oozie services.
064     *
065     * @param event context event.
066     */
067    public void contextDestroyed(ServletContextEvent event) {
068        services.destroy();
069    }
070
071    public static boolean isSSLEnabled() {
072        return sslEnabled;
073    }
074}