Package com.ericsson.ssa.sip

Source Code of com.ericsson.ssa.sip.LocalRouteManager

/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
* Copyright (c) Ericsson AB, 2004-2008. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License").  You
* may not use this file except in compliance with the License. You can obtain
* a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
* or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code.  If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year]
* [name of copyright owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license."  If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above.  However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
package com.ericsson.ssa.sip;

import com.ericsson.ssa.container.reporter.ReporterResolver;
import com.ericsson.ssa.container.reporter.Reporter;
import com.ericsson.ssa.sip.dns.TargetResolver;
import com.ericsson.ssa.sip.dns.UDPProtocol;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.jvnet.glassfish.comms.util.LogUtil;

import javax.servlet.sip.Address;
import javax.servlet.sip.SipURI;


/**
* Singleton class that manages local routes added via the
* {@link javax.servlet.sip.SipServletRequest#pushRoute(javax.servlet.sip.Address) SipServletRequest.pushRoute(Address)}
* or
* {@link javax.servlet.sip.SipServletRequest#pushRoute(javax.servlet.sip.SipURI) SipServletRequest.pushRoute(SipURI)}
* methods.
*
* This Layer checks if the top Route header on outgoing requests has the form
* sip:user@localhost;lr or sip:user@127.0.0.1;lr and in that case stops
* downwards traversal in the stack, pops the Route header and sends the request
* upwards in the stack again.
*
* @author eraknhm
*/
public class LocalRouteManager implements Layer {
    private static final LocalRouteManager singletonInstance = new LocalRouteManager();
    private Logger m_logger = LogUtil.SIP_LOGGER.getLogger();
    private Layer _nextLayer = null;
    private Reporter _reporter;

    // Enforce Singleton pattern
    private LocalRouteManager() {
        // Empty
    }

    public void setReporters(String reporters) {
        _reporter = ReporterResolver.getInstance().getReporter(reporters);
    }

    public Reporter getReporter() {
        return _reporter;
    }

    public static LocalRouteManager getInstance() {
        return singletonInstance;
    }

    /**
     * Delegate to next layer
     */
    public void next(SipServletRequestImpl req) {
        if (req.isInitial()) {
            req.pushApplicationDispatcher(this);
        }

        // Send onwards
        LayerHelper.next(req, this, _nextLayer);
    }

    /**
     * Delegate to next layer
     */
    public void next(SipServletResponseImpl resp) {
        // Send onwards
        LayerHelper.next(resp, this, _nextLayer);
    }

    public void registerNext(Layer layer) {
        _nextLayer = layer;
    }

    /**
     * Delegate to next layer
     */
    public void dispatch(SipServletRequestImpl req) {
        // Check request
        if (req.isInitial()) {
            if (req.isLocalRoute()) {
                // Let request stay in container...
                if (m_logger.isLoggable(Level.FINE)) {
                    m_logger.log(Level.FINE, "Request should stay in container.");
                }

                // Pop route header
                Address a = req.popRouteHeader();
                if (a != null) {
                    // Add this layer as dispatcher
                    req.setInitialPoppedRoute(a);
                    req.pushApplicationDispatcher(this);
                    req.setFirstInvocation(true);
                   
                    try {
                        req.setLocal(TargetResolver.getInstance().resolveReq3263_4((SipURI) a.getURI(), req.getMessageSize()).getSocketAddress());
                        //req.setLocal(new InetSocketAddress(InetAddress.getLocalHost(),port));
                    } catch (Exception e) {
                        m_logger.log(Level.SEVERE, "Cannot resolve local address. ");
                    }
                    // Send onwards
                    LayerHelper.next(req, this, _nextLayer);

                    return;
                }
            }
        }

        // Send onwards
        req.popDispatcher().dispatch(req);
    }

    /**
     * Delegate to next layer
     */
    public void dispatch(SipServletResponseImpl resp) {
        // Send onwards
        resp.popDispatcher().dispatch(resp);
    }
}
TOP

Related Classes of com.ericsson.ssa.sip.LocalRouteManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.