📄 basereader.java
字号:
} catch (Exception ex) { if (BaseReaderDebug.debug) { BaseReaderDebug.println("BaseReader, processResponse(), internal error, "+ "exception raised:"); BaseReaderDebug.logException(ex); } } } /** JAIN Listener method. */ public void processTimeout(TimeoutEvent timeOutEvent) { BaseReaderDebug.println("TimeoutEvent received"); } /*********************** Methods for *************** * starting and stopping the base reader * ************************************************************/ /** Start the base reader. */ public void start() { try{ if (configuration!=null && configuration.isValidConfiguration()) { Properties properties=new Properties(); // LOGGING property: if (configuration.enableDebug) { BaseReaderDebug.debug=true; if (! (configuration.outputProxy==null) ) BaseReaderDebug.setProxyOutputFile(configuration.outputProxy); if (configuration.badMessageLogFile!=null) properties.setProperty("gov.nist.javax.sip.BAD_MESSAGE_LOG", configuration.badMessageLogFile); if (configuration.debugLogFile!=null) { properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", configuration.debugLogFile); } if (configuration.serverLogFile!=null) properties.setProperty("gov.nist.javax.sip.SERVER_LOG", configuration.serverLogFile); BaseReaderDebug.println("Debug files are set!"); } else { System.out.println("Debug files are not set!"); } /********************************************************************************************* SIP STACKS ****************************************************** ********************************************************************************/ SipFactory sipFactory = SipFactory.getInstance(); sipFactory.setPathName("gov.nist"); headerFactory = sipFactory.createHeaderFactory(); addressFactory = sipFactory.createAddressFactory(); messageFactory = sipFactory.createMessageFactory(); //System.out.println(stackConfiguration.stackIPAddress); properties.setProperty("javax.sip.IP_ADDRESS", 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); // This has to be hardcoded to true. for the proxy. properties.setProperty("javax.sip.RETRANSMISSION_FILTER", "on"); sipStack = sipFactory.createSipStack(properties); // We create the Listening points: Vector lps=configuration.getListeningPoints(); for ( int j=0;lps!=null && j<lps.size();j++) { Association a=(Association)lps.elementAt(j); try { BaseReaderDebug.println("BaseReader, transport:" + a.transport); BaseReaderDebug.println("BaseReader, 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 ); if (this.defaultProvider == null) this.defaultProvider = sipProvider; } catch(Exception e) { BaseReaderDebug.println ("BaseReader, ERROR: listening point not created "); BaseReaderDebug.logException(e); } } // We listen to the serial port: baseReaderThread=new BaseReaderThread(this); // We poll for the badges: baseReaderThread.start(); // We register to the presence server: RegistrationManager registrationManager=new RegistrationManager(this); registrationManager.start(); } else { System.out.println("BaseReader, ERROR: the configuration file is not correct!"+ " Correct the errors first."); } } catch (Exception e) { if (BaseReaderDebug.debug) { BaseReaderDebug.println("BaseReader, start(), internal error, "+ "exception raised:"); BaseReaderDebug.logException(e); } } } /** Stop the BaseReader, 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 { } public ContactHeader createStackContactHeader() { try { ListeningPoint lp = (ListeningPoint)sipStack.getListeningPoints().next(); String host = sipStack.getIPAddress(); int port = lp.getPort(); SipURI sipURI=addressFactory.createSipURI(configuration. baseReaderIdentifier,host); sipURI.setPort(port); Address address=addressFactory.createAddress(configuration.baseReaderLocation,sipURI); return headerFactory.createContactHeader(address); } catch (Exception e) { if (BaseReaderDebug.debug) { BaseReaderDebug.println("BaseReader, getStackContactHeader(), internal error, "+ "exception raised:"); BaseReaderDebug.logException(e); } return null; } } public FromHeader createStackFromHeader() { try { ListeningPoint lp = (ListeningPoint)sipStack.getListeningPoints().next(); String host = sipStack.getIPAddress(); int port = lp.getPort(); SipURI sipURI=addressFactory.createSipURI("base-reader",host); sipURI.setPort(port); Address fromAddress=addressFactory.createAddress("Base reader",sipURI); String fromTag=BaseReaderUtils.generateTag(); FromHeader fromHeader=headerFactory.createFromHeader(fromAddress,fromTag); return fromHeader; } catch (Exception e) { if (BaseReaderDebug.debug) { BaseReaderDebug.println("BaseReader, getStackFromHeader(), internal error, "+ "exception raised:"); BaseReaderDebug.logException(e); } return null; } } public ViaHeader createStackViaHeader() { try { ListeningPoint lp = (ListeningPoint)sipStack.getListeningPoints().next(); String host = sipStack.getIPAddress(); int port = lp.getPort(); String transport = lp.getTransport(); String branchId=BaseReaderUtils.generateBranchId(); return headerFactory.createViaHeader (host,port,transport,branchId); } catch (Exception e) { if (BaseReaderDebug.debug) { BaseReaderDebug.println("BaseReader, getStackViaHeader(), internal error, "+ "exception raised:"); BaseReaderDebug.logException(e); } return null; } } /*************************************************************************/ /************ The main method: to launch the proxy *************/ /************************************************************************/ public static void main(String args[]) { try{ // the Proxy: String confFile= (String) args[1]; BaseReader BaseReader=new BaseReader(confFile); BaseReader.start(); BaseReaderDebug.println("BaseReader 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 BaseReader can not be started, " + " exception raised:\n"); e.printStackTrace(); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -