Package com.ericsson.ssa.sip

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

/*
* 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.sip.dns.TargetTuple;
import java.io.Serializable;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.sip.ServletParseException;
import javax.servlet.sip.URI;
import org.jvnet.glassfish.comms.util.LogUtil;


/**
* Outbound Interface set by the application.
*
* @author binod
*/
public class OutboundInterface implements Serializable{
   
    private InetAddress ia = null;
    private InetSocketAddress isa = null;
    private static Logger logger = LogUtil.SIP_LOGGER.getLogger();

    public OutboundInterface(InetAddress ia) {
        this.ia = ia;
    }

    public OutboundInterface(InetSocketAddress isa) {
        this.isa = isa;       
    }

    public InetAddress getInetAddress() {
        return this.ia;
    }

    public InetSocketAddress getInetSocketAddress() {
        return this.isa;
    }

    public int getPort() {
        if (this.isa != null) {
            return isa.getPort();
        }

        return 0;
    }

    public String getHost() {
        if (this.ia != null) {
            return ia.getHostAddress();
        }

        if (this.isa != null) {
            return isa.getAddress().getHostAddress();
        }

        return null;
    }

    public TargetTuple getTargetTuple() {
        TargetTuple tt = new TargetTuple();
        tt.setBindIp(getHost());
        tt.setBindPort(getPort());
        return tt;
    }

    public static void resolve(SipServletMessageImpl msg) {
        resolve(msg, PathNode.Type.Undefined);
    }

    // This method will be called when PathNode.dispatch is called.
    // Or when the resonse is created.
    public static void resolve(SipServletMessageImpl msg, PathNode.Type type) {
        SipSessionImplBase ss = (SipSessionImplBase) msg.getSession();
        if (ss != null) {          
           OutboundInterface oi = ss.getOutboundInterface();
           if (logger.isLoggable(Level.FINER)) {
               logger.log(Level.FINER, "Setting the outbound interface" + oi);
           }
          
           if (type == PathNode.Type.Proxy) {
               if (oi != null) {
                   msg.setOutboundInterface(oi);
               }
           } else {
               msg.setOutboundInterface(oi);
           }          
        }
    }

    // This method is called, when proxybranch.proxyTo is called.
    public static void resolve(SipServletMessageImpl msg, ProxyBranchImpl pb) {
        // If there is already a setting, continue using that.
        if (pb.getOutboundInterface() != null) {
            if (logger.isLoggable(Level.FINER)) {
                logger.log(Level.FINER, "Setting the outbound interface.");
            }
            msg.setOutboundInterface(pb.getOutboundInterface());
        } else {
            resolve(msg, PathNode.Type.Proxy);
        }
    }

    //Modify the contact from the Dialog Manager
    public static void modifyContact(SipServletMessageImpl msg) {
        if (msg.isContactIndicated()) {           
            modifyAddress(msg, Header.CONTACT);                       
        }
    }

       //Modify the contact from the Dialog Manager
    public static void modifyPath(SipServletMessageImpl msg) {
        modifyAddress(msg, Header.PATH);
    }

    public static void modifyRecordRoute(SipServletMessageImpl msg) {       
        modifyAddress(msg, Header.RECORD_ROUTE);
        if (logger.isLoggable(Level.FINER)) {
            logger.log(Level.FINER, "Modified record route ..." + msg);
        }
    }

    private static void modifyAddress(SipServletMessageImpl msg, String name) {
        OutboundInterface oi = msg.getOutboundInterface();
        if (oi == null) {
            if (logger.isLoggable(Level.FINER)) {
                logger.log(Level.FINER, "Not Modified");
            }
            return;
        }
        AddressImpl addr;
        try {
            addr = (AddressImpl) msg.getAddressHeaderImpl(name);
        } catch (ServletParseException ex) {
            logger.log(Level.SEVERE, null, ex);
            return;
        }       

        URI uri = (URI) addr.getURI();
        if (uri.isSipURI() && oi != null) {
            if (logger.isLoggable(Level.FINER)) {
                logger.log(Level.FINER, "Modifying ADDRESS ..." + oi.getHost());
            }
            SipURIImpl sipuri = (SipURIImpl) uri;
            if (oi.getHost() != null) {
               sipuri.__setHost(oi.getHost());
            } else {
                if (logger.isLoggable(Level.FINE)) {
                   logger.log
                   (Level.FINE, "Outbound interface is set, but host is null!!");
                }
            }
            if (oi.getPort() != 0) {
                sipuri.__setPort(oi.getPort());
            }           
        }      
    }
}
TOP

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

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.