📄 proxy.java
字号:
if (configuration.stopTime!=null) { try { long stopTime=Long.parseLong(configuration.stopTime); StopProxy stopProxy=new StopProxy(this); Timer timer=new Timer(); timer.schedule(stopProxy,stopTime); } catch(Exception e) { e.printStackTrace(); } } sipStack = null; SipFactory sipFactory = SipFactory.getInstance(); sipFactory.setPathName("gov.nist"); headerFactory = sipFactory.createHeaderFactory(); addressFactory = sipFactory.createAddressFactory(); messageFactory = sipFactory.createMessageFactory(); // Create SipStack object properties.setProperty("javax.sip.IP_ADDRESS", configuration.stackIPAddress); // We have to add the IP address of the proxy for the domain: configuration.domainList.addElement(configuration.stackIPAddress); ProxyDebug.println("The proxy is responsible for the domain:"+configuration.stackIPAddress); properties.setProperty("javax.sip.STACK_NAME", configuration.stackName); if (configuration.check(configuration.outboundProxy)) properties.setProperty("javax.sip.OUTBOUND_PROXY", configuration.outboundProxy); if (configuration.check(configuration.routerPath)) properties.setProperty("javax.sip.ROUTER_PATH", configuration.routerPath); if (configuration.check(configuration.extensionMethods)) properties.setProperty("javax.sip.EXTENSION_METHODS", configuration.extensionMethods); // This has to be hardcoded to true. for the proxy. properties.setProperty("javax.sip.RETRANSMISSION_FILTER", "on"); if (configuration.check(configuration.maxConnections) ) properties.setProperty("gov.nist.javax.sip.MAX_CONNECTIONS", configuration.maxConnections); if (configuration.check(configuration.maxServerTransactions) ) properties.setProperty("gov.nist.javax.sip.MAX_SERVER_TRANSACTIONS", configuration.maxServerTransactions); if (configuration.check(configuration.threadPoolSize) ) properties.setProperty("gov.nist.javax.sip.THREAD_POOL_SIZE", configuration.threadPoolSize); if (configuration.domainList!=null) for ( int j=0;j<configuration.domainList.size();j++) { String domain=(String)configuration.domainList.elementAt(j); ProxyDebug.println("Here is one domain to take care of:"+domain); } else ProxyDebug.println("No domain to take care of..."); if (configuration.accessLogViaRMI) { properties.setProperty("gov.nist.javax.sip.ACCESS_LOG_VIA_RMI", "true"); properties.setProperty("gov.nist.javax.sip.RMI_PORT", configuration.logRMIPort); if (configuration.check(configuration.logLifetime) ) properties.setProperty("gov.nist.javax.sip.LOG_LIFETIME", configuration.logLifetime); } sipStack = sipFactory.createSipStack(properties); // Authentication part: if (configuration.enableAuthentication) { authentication =new Authentication(this); try{ Class authMethodClass = Class.forName(configuration.classFile); AuthenticationMethod authMethod = (AuthenticationMethod) authMethodClass.newInstance(); authMethod.initialize(configuration.passwordsFile); authentication.setAuthenticationMethod(authMethod); } catch(Exception e) { ProxyDebug.println ("ERROR, authentication process stopped, exception raised:"); e.printStackTrace(); } } // We create the Listening points: Vector lps=configuration.getListeningPoints(); for ( int i=0;lps!=null && i<lps.size();i++) { Association a=(Association)lps.elementAt(i); try{ System.out.println("transport " + a.transport); System.out.println("port " + Integer.valueOf(a.port).intValue()); ListeningPoint lp=sipStack.createListeningPoint (Integer.valueOf(a.port).intValue(), a.transport); this.listeningPoints.add(lp); SipProvider sipProvider = sipStack.createSipProvider(lp); if (this.defaultProvider == null) this.defaultProvider = sipProvider; sipProvider.addSipListener( this ); } catch(Exception e) { e.printStackTrace(); ProxyDebug.println ("ERROR: listening point not created "); } } // Export the registry for polling by the responder. if (configuration.exportRegistry ) // initialize the registrar for RMI. this.registrar.initRMIBindings(); // Parse static configuration for registrar. if (configuration.enableRegistrations) { String value=configuration.registrationsFile; ProxyDebug.println("Parsing the XML registrations file: "+value); if (value==null || value.trim().equals("")) ProxyDebug.println("You have to set the registrations file..."); else registrar.parseXMLregistrations(value); } else ProxyDebug.println("No registrations to parse..."); // Register to proxies if any: registrar.registerToProxies(); } else { System.out.println("ERROR: the configuration file is not correct!"+ " Correct the errors first."); } } /** Stop the proxy, this method has to be called after the start method * throws Exception that which can be caught by the upper application */ public void stop() throws Exception { if (sipStack==null) return; this.presenceServer.stop(); Iterator sipProviders=sipStack.getSipProviders(); if (sipProviders!=null) { while( sipProviders.hasNext()) { SipProvider sp=(SipProvider)sipProviders.next(); sp.removeSipListener(this); sipStack.deleteSipProvider(sp); sipProviders=sipStack.getSipProviders(); System.out.println("One sip Provider removed!"); } } else { ProxyDebug.println("WARNING, STOP_PROXY, The proxy " + " has no sip Provider to remove!"); } Iterator listeningPoints=sipStack.getListeningPoints(); if (listeningPoints!=null) { while( listeningPoints.hasNext()) { ListeningPoint lp=(ListeningPoint)listeningPoints.next(); sipStack.deleteListeningPoint(lp); listeningPoints=sipStack.getListeningPoints(); System.out.println("One listening point removed!"); } } else { ProxyDebug.println("WARNING, STOP_PROXY, The proxy " + " has no listening points to remove!"); } registrar.clean(); } /** Exit the proxy, * throws Exception that which can be caught by the upper application */ public void exit() throws Exception { Iterator sipProviders=sipStack.getSipProviders(); if (sipProviders!=null) { while( sipProviders.hasNext()) { SipProvider sp=(SipProvider)sipProviders.next(); sp.removeSipListener(this); sipStack.deleteSipProvider(sp); sipProviders=sipStack.getSipProviders(); System.out.println("One sip Provider removed!"); } } else { ProxyDebug.println("WARNING, STOP_PROXY, The proxy " + " has no sip Provider to remove!"); } Iterator listeningPoints=sipStack.getListeningPoints(); if (listeningPoints!=null) { while( listeningPoints.hasNext()) { ListeningPoint lp=(ListeningPoint)listeningPoints.next(); sipStack.deleteListeningPoint(lp); listeningPoints=sipStack.getListeningPoints(); System.out.println("One listening point removed!"); } } else { ProxyDebug.println("WARNING, STOP_PROXY, The proxy " + " has no listening points to remove!"); } ProxyDebug.println("Proxy exit........................."); configuration.listeningPoints.clear(); registrar.clean(); } public ViaHeader getStackViaHeader() { 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) { e.printStackTrace(); return null; } } public ContactHeader getStackContactHeader() { try { ListeningPoint lp = (ListeningPoint)sipStack.getListeningPoints().next(); String host = sipStack.getIPAddress(); int port = lp.getPort(); String transport = lp.getTransport(); SipURI sipURI=addressFactory.createSipURI(null,host); sipURI.setPort(port); sipURI.setTransportParam(transport); Address contactAddress=addressFactory.createAddress(sipURI); return headerFactory.createContactHeader(contactAddress); } catch (Exception e) { e.printStackTrace(); return null; } } /*************************************************************************/ /************ The main method: to launch the proxy *************/ /************************************************************************/ public static void main(String args[]) { try{ // the Proxy: if (args.length == 0) { System.out.println("Config file missing!"); System.exit(0); } System.out.println("Using configuration file " + args[1]); String confFile= (String) args[1]; Proxy proxy=new Proxy(confFile); proxy.start(); ProxyDebug.println("Proxy 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 proxy can not be started, " + " exception raised:\n"); e.printStackTrace(); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -