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

📄 controller.java

📁 First of all, the Applet-phone is a SIP User-Agent with audio and text messaging capabilities. But
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                requestForwarding.forwardRequest(targetURIList,sipProvider,                request,serverTransaction);                            }            else{                Response response=messageFactory.createResponse                (Response.TEMPORARILY_UNAVAILABLE,request);                if (serverTransaction!=null)                    serverTransaction.sendResponse(response);                else sipProvider.sendResponse(response);                                System.out.println("processRequest(), "+                    " the receiver is not registered.\n"+                    " 480 (TEMPORARILY_UNAVAILABLE) replied:\n"+                    response.toString() );                return;            }        }        catch(Exception ex){            try{                                    System.out.println("Proxy, processRequest(), internal error, "+                    "exception raised:");                    ex.printStackTrace();                                                // This is an internal error:                // Let's return a 500 SERVER_INTERNAL_ERROR                Response response=messageFactory.createResponse                (Response.SERVER_INTERNAL_ERROR,request);                if (serverTransaction!=null)                    serverTransaction.sendResponse(response);                else sipProvider.sendResponse(response);                                                    System.out.println("Proxy, processRequest(),"+                    " 500 SERVER_INTERNAL_ERROR replied:\n"+                    response.toString());            }            catch (Exception e){                e.printStackTrace();            }        }    }        /** This is a listener method.     */    public void processResponse(ResponseEvent responseEvent) {        javax.sip.message.Response response = responseEvent.getResponse();        SipProvider sipProvider = (SipProvider) responseEvent.getSource();        ClientTransaction clientTransaction=responseEvent.getClientTransaction();                           System.out.println        ("\n***************************************************************"+        "\n***************************************************************"+        "\nResponse "+response.getStatusCode() + " "+response.getReasonPhrase()        +" received:\n"+response.toString() );        System.out.println("Processing Response in progress");        //If the response is a OK        //We stop the timer        if ( response.getStatusCode()==200){            if(response.getHeader(ToHeader.NAME).toString().indexOf(stackConfiguration.serviceGuy)!=-1){                   Timer timer=(Timer)callerList.get(response.getHeader(FromHeader.NAME).toString());                if(timer!=null){                    timer.cancel();                                    }            }        }        //If the response is a RINGING        //we start the timer, if the callee doesn't respond before timeToWait seconds        //this listener will receive a notification in the update method and send a mail        //to the callee        if ( response.getStatusCode()==180){            if(response.getHeader(ToHeader.NAME).toString().indexOf(stackConfiguration.serviceGuy)!=-1){                                                       System.out.println("Timer of "+stackConfiguration.timeToWait +" sec started !");                Timer timer=new Timer();		timer.schedule( new MyTimerTask(response), stackConfiguration.timeToWait * 1000);                String caller=response.getHeader(FromHeader.NAME).toString();                callerList.put(caller, timer);            }        }        printTransaction(clientTransaction);        //forward the response        responseForwarding.forwardResponse(sipProvider, response,clientTransaction);                    }        /** JAIN Listener method.     */    public void processTimeout(TimeoutEvent timeOutEvent) {        System.out.println("TimeoutEvent received");    }                /***********************  Methods for  **********************     *    starting and stopping the controller                  *     ************************************************************/        public static void printTransaction(Transaction transaction) {        if (transaction==null) {            System.out.println		("DEBUG TRANSACTION INFO: the transaction is null ");                return;        }                if ( transaction instanceof ServerTransaction) {            ServerTransaction serverTransaction=(ServerTransaction)transaction;            System.out.println		("DEBUG TRANSACTION INFO: here is the "+                 " server transaction: "+serverTransaction);                           System.out.println                    ("DEBUG INFO: Its dialog is: "+serverTransaction.getDialog());        }        else         if ( transaction instanceof ClientTransaction) {            ClientTransaction clientTransaction=(ClientTransaction)transaction;            System.out.println		("DEBUG TRANSACTION INFO: here is the "+                 " client transaction: "+clientTransaction);                           System.out.println                    ("DEBUG TRANSACTION INFO: Its dialog is: "+clientTransaction.getDialog());        }    }        /** Start the controller, this method has to be called after the constructor          */    public void start() throws Exception {        if (stackConfiguration!=null        && stackConfiguration.isValidConfiguration()) {            Properties properties=new Properties();            // LOGGING property:                        if (stackConfiguration.enableDebug) {                                if (stackConfiguration.badMessageLogFile!=null)                    properties.setProperty("gov.nist.javax.sip.BAD_MESSAGE_LOG",                    stackConfiguration.badMessageLogFile);                if (stackConfiguration.debugLogFile!=null) {                    properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",                    stackConfiguration.debugLogFile);                }                if (stackConfiguration.serverLogFile!=null)                    properties.setProperty("gov.nist.javax.sip.SERVER_LOG",                    stackConfiguration.serverLogFile);                            }            else {                System.out.println("DEBUG properties not set!");            }			properties.setProperty("javax.sip.ROUTER_PATH",			"gov.nist.examples.mail.router.GatewayRouter");			properties.setProperty("gov.nist.javax.sip.LOG_MESSAGE_CONTENT","false");/*********************************************************************************************  SIP STACKS ******************************************************  ********************************************************************************/                                    SipFactory sipFactory = SipFactory.getInstance();            sipFactory.setPathName("gov.nist");            headerFactory = sipFactory.createHeaderFactory();            addressFactory = sipFactory.createAddressFactory();            messageFactory = sipFactory.createMessageFactory();                                                // Create SipStack objects:                                                        properties.setProperty("javax.sip.IP_ADDRESS",                    stackConfiguration.stackIPAddress);                properties.setProperty("javax.sip.STACK_NAME",                    stackConfiguration.getStackName());                                         SipStack sipStack = sipFactory.createSipStack(properties);                                                // We create the Listening points:                Vector lps=stackConfiguration.getListeningPoints();                            for ( int j=0;lps!=null && j<lps.size();j++) {                    Association a=(Association)lps.elementAt(j);                    try {                        System.out.println("Proxy, transport:" + a.transport);                        System.out.println("Proxy, port:" +                                    Integer.valueOf(a.port).intValue());                                           ListeningPoint lp=sipStack.createListeningPoint                        (Integer.valueOf(a.port).intValue(),                        a.transport);                                            SipProvider sipProvider = sipStack.createSipProvider(lp);                        sipProvider.addSipListener( this );                    }                    catch(Exception e) {                        System.out.println                        ("Proxy, ERROR: listening point not created ");                        e.printStackTrace();                    }                }                                           }        else {            System.out.println("ERROR: the configuration file is not correct!"+            " Correct the errors first.");        }    }        public static void main(String args[]){        try{                        //String confFile= (String) args[1];                        Controller controller=new Controller(".//gov//nist//examples//mail//configuration//configuration_controller.xml");            controller.start();            System.out.println("Gateway ready to work.");        }        catch(Exception e) {            System.out.println            ("ERROR: Set the configuration file flag: " +            "USE: -cf configuration_file_location.xml"  );            System.out.println("ERROR, the gateway can not be started, " +            " exception raised:\n");            e.printStackTrace();        }    }        }

⌨️ 快捷键说明

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