<commit_before>/**
 * Copyright 2010 Voxeo Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
 * file except in compliance with the License.
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed
 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

package com.voxeo.moho.sip;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;

import javax.media.mscontrol.MsControlFactory;
import javax.media.mscontrol.spi.Driver;
import javax.media.mscontrol.spi.DriverManager;
import javax.media.mscontrol.spi.PropertyInfo;
import javax.sdp.SdpFactory;
import javax.servlet.ServletException;
import javax.servlet.sip.SipFactory;
import javax.servlet.sip.SipServlet;
import javax.servlet.sip.SipServletRequest;
import javax.servlet.sip.SipServletResponse;

import org.apache.log4j.Logger;

import com.voxeo.moho.Application;
import com.voxeo.moho.ApplicationContext;
import com.voxeo.moho.ApplicationContextImpl;
import com.voxeo.moho.event.ApplicationEventSource;
import com.voxeo.moho.event.EventSource;
import com.voxeo.moho.util.SessionUtils;

public class SIPController extends SipServlet {

  private static final long serialVersionUID = -6039446683694940149L;

  private static final Logger log = Logger.getLogger(SIPController.class);

  protected ApplicationEventSource _app = null;

  protected SipFactory _sipFacory;

  protected SdpFactory _sdpFactory;

  protected MsControlFactory _mscFactory;

  protected String _applicationClass = null;

  @Override
  @SuppressWarnings("unchecked")
  public void init() {
    try {
      _applicationClass = getInitParameter("ApplicationClass");
      if (_applicationClass == null) {
        throw new IllegalArgumentException("Cannot found moho application class.");
      }
      Class clz = null;
      try {
        clz = this.getClass().getClassLoader().loadClass(_applicationClass);
      }
      catch (final Throwable t) {
        clz = Thread.currentThread().getContextClassLoader().loadClass(_applicationClass);
      }
      final Application app = (Application) clz.newInstance();

      _sipFacory = (SipFactory) getServletContext().getAttribute(SipServlet.SIP_FACTORY);
      _sdpFactory = (SdpFactory) getServletContext().getAttribute("javax.servlet.sdp.SdpFactory");

      if (_sdpFactory == null) {
        _sdpFactory = SdpFactory.getInstance();
      }

      final Properties p = new Properties();
      final Driver driver = DriverManager.getDrivers().next();
      for (final PropertyInfo info : driver.getFactoryPropertyInfo()) {<commit_msg>make the SdpFactory optional, because some other container don't provide a SdpFactory.<commit_after>/**
 * Copyright 2010 Voxeo Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
 * file except in compliance with the License.
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed
 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */

package com.voxeo.moho.sip;

import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;

import javax.media.mscontrol.MsControlFactory;
import javax.media.mscontrol.spi.Driver;
import javax.media.mscontrol.spi.DriverManager;
import javax.media.mscontrol.spi.PropertyInfo;
import javax.sdp.SdpFactory;
import javax.servlet.ServletException;
import javax.servlet.sip.SipFactory;
import javax.servlet.sip.SipServlet;
import javax.servlet.sip.SipServletRequest;
import javax.servlet.sip.SipServletResponse;

import org.apache.log4j.Logger;

import com.voxeo.moho.Application;
import com.voxeo.moho.ApplicationContext;
import com.voxeo.moho.ApplicationContextImpl;
import com.voxeo.moho.event.ApplicationEventSource;
import com.voxeo.moho.event.EventSource;
import com.voxeo.moho.util.SessionUtils;

public class SIPController extends SipServlet {

  private static final long serialVersionUID = -6039446683694940149L;

  private static final Logger log = Logger.getLogger(SIPController.class);

  protected ApplicationEventSource _app = null;

  protected SipFactory _sipFacory;

  protected SdpFactory _sdpFactory;

  protected MsControlFactory _mscFactory;

  protected String _applicationClass = null;

  @Override
  @SuppressWarnings("unchecked")
  public void init() {
    try {
      _applicationClass = getInitParameter("ApplicationClass");
      if (_applicationClass == null) {
        throw new IllegalArgumentException("Cannot found moho application class.");
      }
      Class clz = null;
      try {
        clz = this.getClass().getClassLoader().loadClass(_applicationClass);
      }
      catch (final Throwable t) {
        clz = Thread.currentThread().getContextClassLoader().loadClass(_applicationClass);
      }
      final Application app = (Application) clz.newInstance();

      _sipFacory = (SipFactory) getServletContext().getAttribute(SipServlet.SIP_FACTORY);
      _sdpFactory = (SdpFactory) getServletContext().getAttribute("javax.servlet.sdp.SdpFactory");

      if (_sdpFactory == null) {
        try {
          _sdpFactory = SdpFactory.getInstance();
        }
        catch (Throwable t) {
          log.warn("Unable to get SdpFactory, some function, such as call hold unhold mute unmute, is unavailable:");
        }

      }

      final Properties p = new Properties();
      final Driver driver = DriverManager.getDrivers().next();
      for (final PropertyInfo info : driver.getFactoryPropertyInfo()) {
{'fraction_non_alphanumeric': 0.0902938263453285, 'fraction_numerical': 0.00924397490921096, 'mean_word_length': 4.223275862068966, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3954619', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1696, 'n_words': 468}