All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mobicents.io.undertow.servlet.api.DeploymentInfoFacade Maven / Gradle / Ivy

/*
 * TeleStax, Open Source Cloud Communications
 * Copyright 2011-2015, Telestax Inc and individual contributors
 * by the @authors tag.
 *
 * This program is free software: you can redistribute it and/or modify
 * under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation; either version 3 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see 
 */
package org.mobicents.io.undertow.servlet.api;

import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.ServletInfo;
import io.undertow.servlet.api.SessionManagerFactory;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;

import javax.servlet.ServletException;
import javax.servlet.sip.SipServletRequest;

import org.apache.log4j.Logger;
import org.jboss.as.server.deployment.AttachmentKey;
import org.mobicents.servlet.sip.annotation.ConcurrencyControlMode;
import org.mobicents.servlet.sip.core.MobicentsSipServlet;
import org.mobicents.servlet.sip.core.descriptor.MobicentsSipServletMapping;
import org.mobicents.servlet.sip.core.security.MobicentsSipLoginConfig;
import org.mobicents.servlet.sip.ruby.SipRubyController;

/**
 * @author [email protected]
 *
 */
public class DeploymentInfoFacade implements Cloneable {
    public static AttachmentKey ATTACHMENT_KEY = AttachmentKey.create(DeploymentInfoFacade.class);

    private DeploymentInfo deploymentInfo;

    private static final Logger logger = Logger.getLogger(DeploymentInfoFacade.class);

    private final Map sipServlets = new HashMap<>();

    // sip-xml meta:
    protected String applicationName;
    protected String description;
    protected String smallIcon;
    protected String largeIcon;
    protected int proxyTimeout;
    protected int sipApplicationSessionTimeout;
    // Issue 1200 this is needed to be able to give a default servlet handler if we are not in main-servlet servlet
    // selection case
    // by example when creating a new sip application session from a factory from an http servlet
    private String servletHandler;
    protected boolean isMainServlet;
    private String mainServlet;
    protected transient MobicentsSipLoginConfig sipLoginConfig;
    protected transient Method sipApplicationKeyMethod;
    protected ConcurrencyControlMode concurrencyControlMode;
    protected transient List sipApplicationListeners = new CopyOnWriteArrayList();
    protected transient List sipServletMappings = new ArrayList();
    private transient SipRubyController rubyController;
    protected transient Map childrenMap;
    protected transient Map childrenMapByClassName;

    // default constructor:
    public DeploymentInfoFacade() {
    }

    public void addDeploymentInfo(DeploymentInfo info) throws ServletException {
        if (this.deploymentInfo == null) {
            if (info != null) {
                this.deploymentInfo = info;
            } else {
                throw new ServletException("Cannot set deploymentInfo to null!");
            }
        } else {
            throw new ServletException("DeploymentInfo already set!");
        }
    }

    public DeploymentInfoFacade addSipServlets(final ServletInfo... servlets) {
        for (final ServletInfo servlet : servlets) {
            sipServlets.put(servlet.getName(), servlet);
            return this;
        }
        return this;
    }

    public Map getSipServlets() {
        return Collections.unmodifiableMap(sipServlets);
    }

    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getSmallIcon() {
        return smallIcon;
    }

    public void setSmallIcon(String smallIcon) {
        this.smallIcon = smallIcon;
    }

    public String getLargeIcon() {
        return largeIcon;
    }

    public void setLargeIcon(String largeIcon) {
        this.largeIcon = largeIcon;
    }

    public int getProxyTimeout() {
        return proxyTimeout;
    }

    public void setProxyTimeout(int proxyTimeout) {
        this.proxyTimeout = proxyTimeout;
    }

    public int getSipApplicationSessionTimeout() {
        return sipApplicationSessionTimeout;
    }

    public void setSipApplicationSessionTimeout(int sipApplicationSessionTimeout) {
        this.sipApplicationSessionTimeout = sipApplicationSessionTimeout;
    }

    public String getServletHandler() {
        return servletHandler;
    }

    public void setServletHandler(String servletHandler) {
        this.servletHandler = servletHandler;
    }

    public boolean isMainServlet() {
        return isMainServlet;
    }

    public void setMainServlet(boolean isMainServlet) {
        this.isMainServlet = isMainServlet;
    }

    public String getMainServlet() {
        return mainServlet;
    }

    public void setMainServlet(String mainServlet) {
        this.mainServlet = mainServlet;
    }

    public void addSipApplicationListener(String listener) {
        sipApplicationListeners.add(listener);
        // FIXME:fireContainerEvent("addSipApplicationListener", listener);
    }

    public void removeSipApplicationListener(String listener) {
        sipApplicationListeners.remove(listener);

        // Inform interested listeners
        // FIXME:fireContainerEvent("removeSipApplicationListener", listener);
    }

    public void addSipServletMapping(MobicentsSipServletMapping sipServletMapping) {
        sipServletMappings.add(sipServletMapping);
        isMainServlet = false;
        if (servletHandler == null) {
            servletHandler = sipServletMapping.getServletName();
        }
    }

    public List findSipServletMappings() {
        return sipServletMappings;
    }

    public MobicentsSipServletMapping findSipServletMappings(SipServletRequest sipServletRequest) {
        if (logger.isDebugEnabled()) {
            logger.debug("Checking sip Servlet Mapping for following request : " + sipServletRequest);
        }
        for (MobicentsSipServletMapping sipServletMapping : sipServletMappings) {
            if (sipServletMapping.getMatchingRule().matches(sipServletRequest)) {
                return sipServletMapping;
            } else {
                logger.debug("Following mapping rule didn't match : servletName => " + sipServletMapping.getServletName()
                        + " | expression = " + sipServletMapping.getMatchingRule().getExpression());
            }
        }
        return null;
    }

    /**
     * {@inheritDoc}
     */
    public void removeSipServletMapping(MobicentsSipServletMapping sipServletMapping) {
        sipServletMappings.remove(sipServletMapping);
    }

    public String[] findSipApplicationListeners() {
        return sipApplicationListeners.toArray(new String[sipApplicationListeners.size()]);
    }

    public Method getSipApplicationKeyMethod() {
        return sipApplicationKeyMethod;
    }

    public void setSipApplicationKeyMethod(Method sipApplicationKeyMethod) {
        this.sipApplicationKeyMethod = sipApplicationKeyMethod;
    }

    public ConcurrencyControlMode getConcurrencyControlMode() {
        return concurrencyControlMode;
    }

    public void setConcurrencyControlMode(ConcurrencyControlMode concurrencyControlMode) {
        this.concurrencyControlMode = concurrencyControlMode;
    }

    public MobicentsSipLoginConfig getSipLoginConfig() {
        return sipLoginConfig;
    }

    public void setSipLoginConfig(MobicentsSipLoginConfig sipLoginConfig) {
        this.sipLoginConfig = sipLoginConfig;
    }

    public SipRubyController getRubyController() {
        return rubyController;
    }

    public void setRubyController(SipRubyController rubyController) {
        this.rubyController = rubyController;
    }

    public Map getChildrenMap() {
        return childrenMap;
    }

    public void setChildrenMap(Map childrenMap) {
        this.childrenMap = childrenMap;
    }

    public Map getChildrenMapByClassName() {
        return childrenMapByClassName;
    }

    public void setChildrenMapByClassName(Map childrenMapByClassName) {
        this.childrenMapByClassName = childrenMapByClassName;
    }

    public SessionManagerFactory getSessionManagerFactory() {
        return this.deploymentInfo.getSessionManagerFactory();
    }

    public DeploymentInfoFacade setSessionManagerFactory(final SessionManagerFactory sessionManagerFactory) {
        this.deploymentInfo.setSessionManagerFactory(sessionManagerFactory);
        return this;
    }

    public List getSipApplicationListeners() {
        return sipApplicationListeners;
    }

    public List getSipServletMappings() {
        return sipServletMappings;
    }

    public DeploymentInfo getDeploymentInfo() {
        return deploymentInfo;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy