⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controller.java

📁 First of all, the Applet-phone is a SIP User-Agent with audio and text messaging capabilities. But
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Controller.java * * Created on September 24, 2003, 9:17 AM */package gov.nist.examples.mail;import java.util.*;import javax.sip.*;import javax.sip.message.*;import javax.sip.header.*;import javax.sip.address.*;import gov.nist.examples.mail.registrar.*;/** * * @author  DERUELLE Jean */public class Controller implements javax.sip.SipListener {    protected StackConfiguration stackConfiguration=null;    protected SipStack sipStack=null;    protected MessageFactory messageFactory;    protected HeaderFactory headerFactory;    protected AddressFactory addressFactory;            protected Registrar registrar;        protected RequestForwarding requestForwarding;    protected ResponseForwarding responseForwarding;                    protected Hashtable callerList;        /** Creates a new instance of Controller */    public Controller(String configFile) throws Exception{        if (configFile==null) {            System.out.println            ("ERROR: Set the configuration file flag: " +            "USE: -cf configuration_file_location.xml"  );        }        else {            callerList=new Hashtable();            // First, let's parse the configuration file.            ControllerConfigurationHandler handler=new ControllerConfigurationHandler(configFile);                            stackConfiguration=handler.getStackConfiguration();            //stackConfiguration=new StackConfiguration();               if (!stackConfiguration.isValidConfiguration()) {                System.out.println                ("ERROR: the configuration file is not correct!"+                " Correct the errors first.");                throw new Exception                ("ERROR: the configuration file is not correct!"+                " Correct the errors first.");            }            else {                registrar=new Registrar(this);                requestForwarding=new RequestForwarding(this);                responseForwarding=new ResponseForwarding(this);            }        }            }        public StackConfiguration getStackConfiguration() {        return stackConfiguration;    }        public RequestForwarding getRequestForwarding() {        return requestForwarding;    }        public ResponseForwarding getResponseForwarding() {        return responseForwarding;    }        public AddressFactory getAddressFactory() {        return addressFactory;    }        public MessageFactory getMessageFactory() {        return messageFactory;    }        public HeaderFactory getHeaderFactory() {        return headerFactory;    }       public ViaHeader getStackViaHeader(SipStack sipStack) {        try {            ListeningPoint lp =            (ListeningPoint)sipStack.getListeningPoints().next();            String host = sipStack.getIPAddress();            int port = lp.getPort();            String transport = lp.getTransport();            // branch id is assigned by the transaction layer.            return  headerFactory.createViaHeader            (host,port,transport,null);        }        catch (Exception e) {                            System.out.println("Proxy, getStackViaHeader(), internal error, "+                "exception raised:");                e.printStackTrace();                        return null;        }    }        public SipStack getSipStack(String toHostName) {        try {            System.out.println("getSipStack(), we try to use the "+                    " the appropriate stack for the destination:"+toHostName);                                        String stackIPAddress=sipStack.getIPAddress();                if (stackIPAddress.equals(toHostName) ) {                    System.out.println("getSipStack(), we return "+                    " the appropriate stack");                    return sipStack;                }                        System.out.println("getSipStack(), we return the default stack");            return sipStack;        }        catch(Exception e) {                            System.out.println("getSipStack(), internal error, "+                "exception raised:");                e.printStackTrace();                        return null;        }    }          public SipStack getOppositeSipStack(String stackIPAddr) {        try {            System.out.println(" getOppositeSipStack(), we try to get "+            " the opposite stack for the destination:"+stackIPAddr);                                            String stackIPAddress=sipStack.getIPAddress();                if (!stackIPAddress.equals(stackIPAddr) ) {                    System.out.println("getOppositeSipStack(), we return "+                    " the opposite stack");                    return sipStack;                }                        System.out.println("getOppositeSipStack(), we return the default stack");            return sipStack;        }        catch(Exception e) {                            System.out.println("getOppositeSipStack(), internal error, "+                "exception raised:");                e.printStackTrace();                        return null;        }    }    /** This is a listener method.     */    public void processRequest(RequestEvent requestEvent) {        Request request = requestEvent.getRequest();        SipProvider sipProvider = (SipProvider) requestEvent.getSource();        ServerTransaction serverTransaction=requestEvent.getServerTransaction();        try {                                        System.out.println                ("\n***************************************************************"+                "\n***************************************************************"+                "\nRequest " + request.getMethod() +" received:\n"+request.toString());                               if (serverTransaction==null) {                String method=request.getMethod();                                          // Methods that creates dialogs, so that can generate transactions                if ( method.equals("INVITE") ||                     method.equals("SUBSCRIBE") ||                     method.equals("MESSAGE")                 ) {                    try{                        serverTransaction=sipProvider.getNewServerTransaction(request);                    }                    catch(TransactionAlreadyExistsException e) {                                                     System.out.println("Gateway, processRequest(), this request"+                            " is a retransmission, we drop it!");                    }                }           }/*******************************  REGISTER  *************************************/                                  if (request.getMethod().equals("REGISTER")) {                //address translation                if(request.getHeader(FromHeader.NAME).toString().indexOf(stackConfiguration.serviceGuy)!=-1){                    if(!registrar.hasExpiresZero(request))                                                stackConfiguration.isRegistered=true;                    else                        stackConfiguration.isRegistered=false;                }                System.out.println("isRegistered : " +stackConfiguration.isRegistered);                 // we call the RegisterProcessing:                registrar.processRegister(request,sipProvider,serverTransaction);                               return;            } /******************************* METHODS NOT ALLOWED   **************************/                             if ( !request.getMethod().equals("INVITE") &&            !request.getMethod().equals("ACK") &&            !request.getMethod().equals("BYE") &&            !request.getMethod().equals("CANCEL")            //&&            //!request.getMethod().equals("OPTIONS")            ) {                Response response=messageFactory.createResponse                (Response.METHOD_NOT_ALLOWED,request);                if (serverTransaction!=null)                    serverTransaction.sendResponse(response);                else sipProvider.sendResponse(response);                System.out.println("Proxy, processRequest(), we drop all requests"+                " except INVITE, ACK, BYE, OPTIONS... METHOD_NOT_ALLOWED replied");                return;            }                            if ( registrar.hasRegistration(request)  ) {                Vector targetURIList=registrar.getContactsURI(request);                                    System.out.println("Proxy, processRequest(), we have the contacts"+                    ", let's forward the Request!");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -