/*
(non-Javadoc)
@see javax.servlet.sip.SipServletListener#servletInitialized(javax.servlet.sip.SipServletContextEvent)
553106
public void servletInitialized(SipServletContextEvent ce) {
		String sendOnInit = ce.getServletContext().getInitParameter("send-on-init");
		String method = ce.getServletContext().getInitParameter("method");
		logger.info("Send on Init : "+ sendOnInit);
		if(sendOnInit == null || "true".equals(sendOnInit)) {
			SipFactory sipFactory = (SipFactory) getServletContext().getAttribute(SIP_FACTORY);
			SipApplicationSession sipApplicationSession = sipFactory.createApplicationSession();
			if(method.equalsIgnoreCase("INVITE")) {								
				sendMessage(sipFactory.createApplicationSession(), method);				
			} else {
				timerService.createTimer(sipApplicationSession, 10000, 20000, true, true, method);
			}
		}
	}
896067
public void init(ServletConfig config) throws ServletException
    {
        super.init(config);
        ServletTask.initServlet(this, BasicServlet.SERVLET_TYPE.PROXY);
        
        m_servletTask = this.createProxyTask();
    }
691896
protected ServletContext initServletContext(Document webXmlDoc,
			String baseDirPath, String tmpDirPath, String springConfigFiles,
			String servletAPIversion) {

		// Parse the context parameters
		MockServletContext servletContext = new MockServletContext(
				servletAPIversion, baseDirPath, tmpDirPath);
		Map<String, Object> servletContextInitParams = new HashMap<String, Object>();
		NodeList contextParamsNodes = webXmlDoc
				.getElementsByTagName(CONTEXT_TAG_NAME);
		for (int i = 0; i < contextParamsNodes.getLength(); i++) {
			Node node = contextParamsNodes.item(i);
			initializeInitParams(node, servletContextInitParams);
		}

		// Override spring config file if needed
		if (StringUtils.isNotEmpty(springConfigFiles)) {
			servletContextInitParams.put(CONFIG_LOCATION_PARAM,
					springConfigFiles.replace(" ", "%20"));
		}

		servletContext.setInitParameters(servletContextInitParams);
		return servletContext;
	}
1070896
private void requestInitialized(ServletRequest request)
    {
        ServletRequestEvent event = new ServletRequestEvent(_servletContext,request);
        for (int i=0;i<LazyList.size(_requestListeners);i++)
            ((ServletRequestListener)LazyList.get(_requestListeners,i))
                        .requestInitialized(event);
    }
612387
public void contextInitialized(ServletContextEvent servletContextEvent) {
		ServletContext servletContext = servletContextEvent.getServletContext();

		File tempWriteDir = (File) servletContext
				.getAttribute("javax.servlet.context.tempdir");
		servletContext.setAttribute("audioFilePath", FILE_PROTOCOL + tempWriteDir
				.getAbsolutePath() + File.separatorChar);
		for (int i = 0; i < AUDIO_FILES.length; i++) {
			String audioFile = AUDIO_FILES[i];
			logger.info("Writing " + audioFile + " to webapp temp dir : "
					+ tempWriteDir);			
			InputStream is = servletContext.getResourceAsStream(AUDIO_DIR + "/" + audioFile);
			copyToTempDir(is, tempWriteDir, audioFile);
		} 

		Enumeration<String> initParamNames = servletContext
				.getInitParameterNames();
		logger.info("Setting init Params into application context");
		while (initParamNames.hasMoreElements()) {
			String initParamName = (String) initParamNames.nextElement();
			servletContext.setAttribute(initParamName, servletContext
					.getInitParameter(initParamName));
			logger.info("Param key=" + initParamName + ", value = "
					+ servletContext.getInitParameter(initParamName));
		}
		// map acting as a registrar
		servletContext.setAttribute("registeredUsersMap", new HashMap<String, String>());
		
		if(servletContextEvent.getServletContext().getAttribute(MS_CONTROL_FACTORY) == null) {
			DriverImpl d = new DriverImpl();
			properties = new Properties();
			properties.setProperty(MGCP_STACK_NAME, "SipServlets");
			properties.setProperty(MGCP_PEER_IP, PEER_ADDRESS);
			properties.setProperty(MGCP_PEER_PORT, MGW_PORT);
	
			properties.setProperty(MGCP_STACK_IP, LOCAL_ADDRESS);
			properties.setProperty(MGCP_STACK_PORT, CA_PORT);
	
			try {
				// create the Media Session Factory
				final MsControlFactory msControlFactory = new DriverImpl().getFactory(properties); 
				MsControlObjects.msControlFactory = msControlFactory;
				servletContextEvent.getServletContext().setAttribute(MS_CONTROL_FACTORY, msControlFactory);
				
				MMSUtil.msControlFactory = MsControlObjects.msControlFactory;
				String pathToAudioDirectory = (String)servletContextEvent.getServletContext().getAttribute("audioFilePath");
				MMSUtil.audioFilePath = pathToAudioDirectory;
				logger.info("started MGCP Stack on " + LOCAL_ADDRESS + "and port " + CA_PORT + " obj: " + MsControlObjects.msControlFactory);
			} catch (Exception e) {
				logger.error("couldn't start the underlying MGCP Stack", e);
			}
		} else {
			logger.info("MGCP Stack already started on " + LOCAL_ADDRESS + "and port " + CA_PORT);
		}
	}
1041449
@Override
  public void onStartup(Set<Class<?>> set, ServletContext servletContext) throws ServletException {
    final ClassLoaderLeakPreventorListener classLoaderLeakPreventorListener = new ClassLoaderLeakPreventorListener();
    try {
      classLoaderLeakPreventorListener.contextInitialized(servletContext); // Initialize immediately

      servletContext.addListener(new ServletContextListener() {
        @Override
        public void contextInitialized(ServletContextEvent servletContextEvent) {
          // Do nothing, already done above
        }

        @Override
        public void contextDestroyed(ServletContextEvent servletContextEvent) {
          classLoaderLeakPreventorListener.contextDestroyed(servletContextEvent);
        }
      });
    }
    catch (Throwable t) { // (Shouldn't really be needed)
      t.printStackTrace(System.err);
    }

    for(ServletContextListener otherListener : ClassLoaderLeakPreventorListener.getDefaultOtherListeners()) {
      servletContext.addListener(otherListener);
    }
  }
1203849
@Override
	protected void initServletContext(ServletContext servletContext) {
		super.initServletContext(servletContext);
		super.setExposeRequestAttributes(true);
		
		initBaseTemplatePath(servletContext);
		initSharedFunction();
	}
108716
public void servletInitialized(SipServletContextEvent ce) {
		ServletContext servletContext = ce.getServletContext();
		SipFactory sipFactory = (SipFactory) servletContext.getAttribute(SIP_FACTORY);
		String userName = servletContext.getInitParameter("user.name");
		String domainName = servletContext.getInitParameter("domain.name");		
		
		SipApplicationSession sipApplicationSession = sipFactory.createApplicationSession();
		// for REGISTER the from and the to headers are one and the same
		SipURI fromToURI = sipFactory.createSipURI(userName, domainName);				
		SipServletRequest sipServletRequest = 
			sipFactory.createRequest(sipApplicationSession, "REGISTER", fromToURI, fromToURI);
		sipServletRequest.setHeader("Expires", "3600");		
		sipServletRequest.setHeader("User-Agent", "MobicentsSipServlets");
		SipURI requestURI = sipFactory.createSipURI(null, domainName);
		try {
			Parameterable parameterable = sipServletRequest.getParameterableHeader("Contact");
			parameterable.setParameter("expires", "0");
		} catch (ServletParseException e1) {
			logger.error("Impossible to set the expires on the contact header",e1);
		}
		try {			
			sipServletRequest.setRequestURI(requestURI);				
			sipServletRequest.send();
		} catch (IOException e) {
			logger.error("An unexpected exception occured while sending the REGISTER request",e);
		}
	}
1329040
public void initialize() throws ServletException, Throwable {
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINE))
            logger.entering(CLASS_NAME, "Initialize : app = " + config.getApplicationName() + ", initialized = " + initialized + ", destroyed = " + destroyed);
        
        if (!initialized && !destroyed) {
            synchronized (lock) {
                if (!initialized && !destroyed &&!com.ibm.ws.webcontainer.osgi.WebContainer.isServerStopping()) {
                    initialize(this.config, this.moduleConfig, this.extensionFactories);
                    started();
                    initialized = true;
                    config.setSessionCookieConfigInitilialized();
                }
            }
        }
               
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && logger.isLoggable(Level.FINE))
            logger.exiting(CLASS_NAME, "Initialize : initialized = " + initialized + ", destroyed = " + destroyed);

    }
925786
@Override
	public void init() throws ServletException {
		super.init();
		try {
			config = new Config("/config/serfj.properties");
		} catch (ConfigFileIOException e) {
			LOGGER.error("Can't load framework configuration", e);
			throw new ServletException(e);
		}
		urlInspector = new UrlInspector(config);
	}
900283
public void initialize(HttpContext context)
    {
        if (_context==null)
            _context=context;
        else if (_context!=context)
            throw new IllegalStateException("Can't initialize handler for different context");
    }
50137
@Override
    public void init(ServletConfig config) throws ServletException {
        LOGGER.info("Starting " + Config.getInstance().getApplicationName());
        super.init(config);

        final Info info = new Info()
                .title(Config.getInstance().getApplicationName() + " API")
                .version(Config.getInstance().getApplicationVersion());

        final Swagger swagger = new Swagger()
                .info(info)
                .securityDefinition("X-Api-Key", new ApiKeyAuthDefinition("X-Api-Key", In.HEADER));

        // Dynamically get the url-pattern from web.xml and use that as the 'baseUrl' for
        // the API documentation
        final ServletContext servletContext = getServletContext();
        final ServletRegistration servletRegistration = servletContext.getServletRegistration(config.getServletName());
        final Collection<String> mappings = servletRegistration.getMappings();
        if (! Collections.isEmpty(mappings)) {
            String baseUrl = mappings.iterator().next();
            if (baseUrl.charAt(0) != '/') {
                baseUrl = "/" + baseUrl;
            }
            baseUrl = baseUrl.replace("/*", "").replaceAll("\\/$", "");
            swagger.basePath(config.getServletContext().getContextPath() + baseUrl);
        }

        new SwaggerContextService().withServletConfig(config).updateSwagger(swagger).initScanner();

        // Initializes the KeyManager
        KeyManager.getInstance();

        // Log all Java System Properties
        SecurityUtil.logJavaSystemProperties();

        // Determine if Watchdog logging is enabled and if so, start interval logging
        final int interval = Config.getInstance().getPropertyAsInt(Config.AlpineKey.WATCHDOG_LOGGING_INTERVAL);
        if (interval > 0) {
            final IntervalLoggerController wd = SecurityLoggingFactory.getControllerInstance();
            wd.start(interval * 1000); // Interval is defined in seconds
        }
        LOGGER.info(Config.getInstance().getApplicationName() + " is ready");
    }
982752
public void init(ServletConfig config) throws ServletException {
        super.init(config);
        mServletConfig = config;
        
        config.getServletContext().log("Initializing TeaServlet...");
        
        String ver = System.getProperty("java.version");
        if (ver.startsWith("0.") || ver.startsWith("1.2") ||
            ver.startsWith("1.3")) {
            config.getServletContext()
                .log("The TeaServlet requires Java 1.4 or higher to run properly");
        }

        mServletContext = setServletContext(config);
        mServletName = setServletName(config);
        
        mProperties = new PropertyMap();
        mSubstitutions = SubstitutionFactory.getDefaults();
        mResourceFactory = 
            new TeaServletResourceFactory(config.getServletContext(), 
                                          mSubstitutions);
        
        Enumeration<?> e = config.getInitParameterNames();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            String value = 
                SubstitutionFactory.substitute(config.getInitParameter(key));
            
            if (key.equals("debug")) {
                mDebugEnabled = Boolean.parseBoolean(value);
                continue;
            }

            mProperties.put(key, value);
        }

        loadDefaults();
        discoverProperties();
        createListeners();
        createLog(mServletContext);
        mLog.applyProperties(mProperties.subMap("log"));
        createMemoryLog(mLog);
        
        mInstrumentationEnabled = 
            mProperties.getBoolean("instrumentation.enabled", true);
        
        Initializer initializer = new Initializer();
        if (mProperties.getBoolean("startup.background", false)) {
            mInitializer = 
                Executors.newSingleThreadExecutor().submit(initializer);
        }
        else {
            initializer.call();
        }
    }
1051781
@Override
	public void init(ServletConfig servletConfig) throws ServletException {
		final String sourceMethod = "init"; //$NON-NLS-1$
		boolean isTraceLogging = log.isLoggable(Level.FINER);
		if (isTraceLogging) {
			log.entering(AbstractAggregatorImpl.class.getName(), sourceMethod, new Object[]{servletConfig});
		}
		super.init(servletConfig);

		// Default constructor for MimetypesFileTypeMap *should* read our bundle's
		// META-INF/mime.types automatically, but some older platforms (Domino)
		// don't use the right class loader, so get the input stream ourselves
		// and pass it to the constructor.
		ClassLoader cld = AbstractAggregatorImpl.class.getClassLoader();
		InputStream is = cld.getResourceAsStream("META-INF/mime.types"); //$NON-NLS-1$

		// Initialize the type maps (see getContentType)
		fileTypeMap = new MimetypesFileTypeMap(is);
		fileNameMap = URLConnection.getFileNameMap();

		final ServletContext context = servletConfig.getServletContext();

		// Set servlet context attributes for access though the request
		context.setAttribute(IAggregator.AGGREGATOR_REQATTRNAME, this);
		try {
			webContentUri = AbstractAggregatorImpl.class.getClassLoader().getResource("WebContent").toURI(); //$NON-NLS-1$
		} catch (URISyntaxException e) {
			throw new ServletException(e);
		}

		if (isTraceLogging) {
			log.exiting(AbstractAggregatorImpl.class.getName(), sourceMethod);
		}
	}
136147
public void onServletInit (@Nonnull final Class <? extends GenericServlet> aServletClass)
  {
    if (LOGGER.isDebugEnabled ())
      LOGGER.debug ("onServletInit: " + aServletClass);
    _updateStatus (aServletClass, EServletStatus.INITED);
  }
1240544
public void initialize(HttpContext context)
    {
        SessionManager sessionManager=getSessionManager();
        

        if (_httpContext!=null&& _httpContext!=context)
            throw new IllegalStateException("Can't initialize handler for different context");
        _httpContext=context;
        
        sessionManager.initialize(this);
    }
925388
public static void init( ServletContext servletContext )
    {
        PageFlowFactoriesConfig factoriesBean = ConfigUtil.getConfig().getPageFlowFactories();
        FlowControllerFactory factory = null;

        if ( factoriesBean != null )
        {
            PageFlowFactoryConfig fcFactoryBean = factoriesBean.getPageFlowFactory();
            factory = ( FlowControllerFactory ) FactoryUtils.getFactory( servletContext, fcFactoryBean, FlowControllerFactory.class );
        }

        if ( factory == null )
            factory = new FlowControllerFactory();

        factory.reinit( servletContext );

        servletContext.setAttribute( CONTEXT_ATTR, factory );
    }