📄 proxyconfigurationhandler.java
字号:
/* * ProxyHandler.java * Used for creating the table containing the association between the method * names and the classes processing the corresponding messages. * Created on February 3, 2003, 10:52 AM */package gov.nist.sip.proxy;import org.xml.sax.*;import org.xml.sax.helpers.DefaultHandler;import org.xml.sax.SAXException;import javax.xml.parsers.SAXParserFactory;import javax.xml.parsers.ParserConfigurationException;import javax.xml.parsers.SAXParser;import java.io.*;import java.util.*;import gov.nist.sip.proxy.registrar.*;/** * * @author deruelle */public class ProxyConfigurationHandler extends DefaultHandler { private Configuration configuration; private String element; private void configurationMessage(String message) { System.out.println(element + ":" + message); } /** Creates a new instance of ProxyHandler */ public ProxyConfigurationHandler(String confFile) { try{ SAXParserFactory saxParserFactory=SAXParserFactory.newInstance(); XMLReader saxParser = saxParserFactory.newSAXParser().getXMLReader(); saxParser.setContentHandler(this); saxParser.setFeature ("http://xml.org/sax/features/validation",true); saxParser.parse(confFile); } catch (SAXParseException spe) { spe.printStackTrace(); } catch (SAXException sxe) { sxe.printStackTrace(); } catch (IOException ioe) { // I/O error ioe.printStackTrace(); } catch (Exception pce) { // Parser with specified options can't be built pce.printStackTrace(); } } public Configuration getConfiguration() { return configuration; } //=========================================================== // SAX DocumentHandler methods //=========================================================== public void startDocument() throws SAXException { try { ProxyDebug.println("---------------------------------------"); ProxyDebug.println("Parsing the XML configuration file..."); configuration=new Configuration(); } catch (Exception e) { throw new SAXException("XMLRegistrationsParser error", e); } } public void endDocument() throws SAXException { try { ProxyDebug.println ("The XML configuration file has been successfully parsed!"); ProxyDebug.println("---------------------------------------"); } catch (Exception e) { throw new SAXException("XMLRegistrationsParser error", e); } } public void startElement(String namespaceURI, String lName, // local name String qName, // qualified name Attributes attrs) throws SAXException { String element=qName; this.element = element; if (element.compareToIgnoreCase("SIP_STACK") ==0 ) { String stackName=attrs.getValue("stack_name"); if (stackName==null || stackName.trim().equals("")) { configurationMessage("ERROR: the name of the stack is not set"); } else { configuration.stackName=stackName.trim(); configurationMessage("INFORMATION: the name of the stack is set to:"+ configuration.stackName); } String stackIPAddress=attrs.getValue("stack_IP_address"); if (stackIPAddress==null || stackIPAddress.trim().equals("")) { configurationMessage ("ERROR: the IP address of the stack is not set"); } else { configuration.stackIPAddress=stackIPAddress.trim(); configurationMessage ("INFORMATION: the stack IP address is set to:" + stackIPAddress); } String outboundProxy=attrs.getValue("outbound_proxy"); if (outboundProxy==null || outboundProxy.trim().equals("")) { configurationMessage ("INFORMATION: the outbound proxy is not set"); } else { configuration.outboundProxy=outboundProxy.trim(); configurationMessage ("INFORMATION: the outbound proxy is " + outboundProxy); } String routerPath=attrs.getValue("router_path"); if (routerPath==null || routerPath.trim().equals("")) { configurationMessage ("WARNING: the path for the router is not set using default"); } else { configuration.routerPath=routerPath.trim(); configurationMessage ("INFORMATION: the path for the router is set to: " + routerPath.trim()); } String extensionMethods=attrs.getValue("extension_methods"); if (extensionMethods==null || extensionMethods.trim().equals("") ) { configurationMessage ("INFORMATION: no extensions are supported"); } else { configuration.extensionMethods=extensionMethods.trim(); configurationMessage ("INFORMATION: extensions supported: " + extensionMethods); } String retransmissionFilter=attrs.getValue("retransmission_filter"); if (retransmissionFilter!=null && !retransmissionFilter.trim().equals("")) { configurationMessage ("INFORMATION: the retransmission filter is set to:" + retransmissionFilter); configuration.retransmissionFilter=retransmissionFilter.trim(); } else configurationMessage ("INFORMATION: no default retransmission filter"); String stopTime=attrs.getValue("stop_after"); if (stopTime!=null && !stopTime.trim().equals("")) { configurationMessage ("INFORMATION: The proxy will stop automatically after " +stopTime+" ms"); configuration.stopTime=stopTime.trim(); } String maxConnections=attrs.getValue("max_connections"); if (maxConnections!=null && !maxConnections.trim().equals("")) { configurationMessage ("INFORMATION: The proxy will authorize only " +maxConnections+" connections"); configuration.maxConnections=maxConnections.trim(); } String maxServerTransactions=attrs.getValue("max_server_transactions"); if (maxServerTransactions!=null && !maxServerTransactions.trim().equals("")) { configurationMessage ("INFORMATION: The proxy will authorize only " +maxServerTransactions+" server transactions"); configuration.maxServerTransactions=maxServerTransactions.trim(); } String threadPoolSize=attrs.getValue("thread_pool_size"); if (threadPoolSize!=null && !threadPoolSize.trim().equals("")) { configurationMessage ("INFORMATION: The thread pool size is set to " +threadPoolSize); configuration.threadPoolSize=threadPoolSize.trim(); } } if (element.compareToIgnoreCase("LISTENING_POINT") ==0 ) { String stackPort=attrs.getValue("port"); if (stackPort==null || stackPort.trim().equals("")) { configurationMessage ("ERROR: the port of the stack is not set"); } else { String stackTransport=attrs.getValue("transport"); if (stackTransport==null || stackTransport.trim().equals("")) { configurationMessage ("ERROR: the transport is not set"); } else { configurationMessage ("LISTENING_POINT port = " + stackPort); configurationMessage ("LISTENING_POINT transport = " + stackTransport); configuration.addListeningPoint(stackPort,stackTransport); } } } if (element.compareToIgnoreCase("DOMAIN") ==0 ) { String stackDomain=attrs.getValue("domain"); if (stackDomain!=null && !stackDomain.trim().equals("")) { configurationMessage ("INFORMATION: One domain to take care of is: " +stackDomain); configuration.domainList.addElement(stackDomain.trim()); } } if (element.compareToIgnoreCase("REGISTER_TO_PROXY") ==0 ) { String hostName=attrs.getValue("host_name"); Domain domain=new Domain(); if (hostName!=null && !hostName.trim().equals("")) { domain.setHostName(hostName); String hostPort=attrs.getValue("host_port"); if (hostPort!=null && !hostPort.trim().equals("")) { domain.setHostPort(hostPort); configurationMessage ("INFORMATION: One proxy to register with: " +hostName+":"+hostPort); } else configurationMessage ("INFORMATION: One proxy to register with: " +hostName); String from=attrs.getValue("from"); if (from!=null && !from.trim().equals("")) { domain.setFrom(from); } configuration.proxyToRegisterWithList.addElement(domain); } } if (element.compareToIgnoreCase("REGISTRAR") ==0 ) { String rfc2543Compatible =attrs.getValue("rfc2543_compatible"); if (rfc2543Compatible != null && "true".equalsIgnoreCase( rfc2543Compatible.trim()) ) { configuration.rfc2543Compatible = true; } String exportRegistry=attrs.getValue("export_registrations"); if (exportRegistry!=null && !exportRegistry.trim().equals("") ) { try{ Boolean b=Boolean.valueOf(exportRegistry.trim()); if ( b.booleanValue() ) { configurationMessage ("INFORMATION: the registrations will be exported"); configuration.exportRegistry=true; String registryPort=attrs.getValue("port"); if (registryPort==null) { configurationMessage ("WARNING: The registry port is not set; "+ "1099 is used by default"); configuration.registryPort="1099"; } else { configurationMessage("INFORMATION: The registry port is: "+ registryPort); configuration.registryPort=registryPort; } } else { configurationMessage ("INFORMATION: the registrations will not be exported"); configuration.exportRegistry=false; } } catch(Exception e) { configurationMessage ("INFORMATION: the registrations will not be exported"); configuration.exportRegistry=false; } } } if (element.compareToIgnoreCase("PRESENCE_SERVER") ==0 ) { String enablePresenceServerString=attrs.getValue("enable"); if (enablePresenceServerString==null) { configuration.enablePresenceServer=false; configurationMessage ("WARNING: The presence server feature is disabled"); } else { try{ Boolean b=Boolean.valueOf (enablePresenceServerString.trim()); if ( b.booleanValue() ) { configuration.enablePresenceServer=true; configurationMessage ("INFORMATION: The presence server feature is enabled"); } else { configuration.enablePresenceServer=false; configurationMessage ("WARNING: The presence server feature is disabled"); } } catch(Exception e) { configuration.enablePresenceServer=false; configurationMessage ("WARNING: The presence server feature is disabled"); } } } if (element.compareToIgnoreCase("AUTHENTICATION") ==0 ) { String enableAuthenticationString=attrs.getValue("enable"); if (enableAuthenticationString==null) { configuration.enableAuthentication=false; configurationMessage ("WARNING: Authentication support is disabled"); } else { try{ Boolean b=Boolean.valueOf (enableAuthenticationString.trim()); if ( b.booleanValue() ) { configuration.enableAuthentication=true; configurationMessage ("INFORMATION: Authentication feature is enabled"); } else { configuration.enableAuthentication=false; configurationMessage ("WARNING: The authentication feature is disabled"); } String method=attrs.getValue("method"); if (method==null) { configurationMessage ("WARNING: The Authentication method is not set"); } else { configuration.method=method.trim(); } String classFile=attrs.getValue("class_file"); if (classFile==null) { configurationMessage ("WARNING: The class_file parameter is not set"+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -