// is not madatory.
super.setHostAddress(address);
}
} catch (java.net.UnknownHostException ex) {
throw new PeerUnavailableException("bad address " + address);
}
/** Retrieve the stack name */
String name = configurationProperties
.getProperty("javax.sip.STACK_NAME");
if (name == null)
throw new PeerUnavailableException("stack name is missing");
super.setStackName(name);
String stackLoggerClassName = configurationProperties
.getProperty("gov.nist.javax.sip.STACK_LOGGER");
// To log debug messages.
if (stackLoggerClassName == null)
stackLoggerClassName = "gov.nist.core.LogWriter";
try {
Class<?> stackLoggerClass = Class.forName(stackLoggerClassName);
Class<?>[] constructorArgs = new Class[0];
Constructor<?> cons = stackLoggerClass
.getConstructor(constructorArgs);
Object[] args = new Object[0];
StackLogger stackLogger = (StackLogger) cons.newInstance(args);
CommonLogger.legacyLogger = stackLogger;
stackLogger.setStackProperties(configurationProperties);
} catch (InvocationTargetException ex1) {
throw new IllegalArgumentException(
"Cound not instantiate stack logger "
+ stackLoggerClassName
+ "- check that it is present on the classpath and that there is a no-args constructor defined",
ex1);
} catch (Exception ex) {
throw new IllegalArgumentException(
"Cound not instantiate stack logger "
+ stackLoggerClassName
+ "- check that it is present on the classpath and that there is a no-args constructor defined",
ex);
}
String serverLoggerClassName = configurationProperties
.getProperty("gov.nist.javax.sip.SERVER_LOGGER");
// To log debug messages.
if (serverLoggerClassName == null)
serverLoggerClassName = "gov.nist.javax.sip.stack.ServerLog";
try {
Class<?> serverLoggerClass = Class
.forName(serverLoggerClassName);
Class<?>[] constructorArgs = new Class[0];
Constructor<?> cons = serverLoggerClass
.getConstructor(constructorArgs);
Object[] args = new Object[0];
this.serverLogger = (ServerLogger) cons.newInstance(args);
serverLogger.setSipStack(this);
serverLogger.setStackProperties(configurationProperties);
} catch (InvocationTargetException ex1) {
throw new IllegalArgumentException(
"Cound not instantiate server logger "
+ stackLoggerClassName
+ "- check that it is present on the classpath and that there is a no-args constructor defined",
ex1);
} catch (Exception ex) {
throw new IllegalArgumentException(
"Cound not instantiate server logger "
+ stackLoggerClassName
+ "- check that it is present on the classpath and that there is a no-args constructor defined",
ex);
}
super.setReliableConnectionKeepAliveTimeout(1000 * Integer.parseInt(
configurationProperties.getProperty("gov.nist.javax.sip.RELIABLE_CONNECTION_KEEP_ALIVE_TIMEOUT", "-1")));
super.setThreadPriority(Integer.parseInt(
configurationProperties.getProperty("gov.nist.javax.sip.THREAD_PRIORITY","" + Thread.MAX_PRIORITY)));
// Default router -- use this for routing SIP URIs.
// Our router does not do DNS lookups.
this.outboundProxy = configurationProperties
.getProperty("javax.sip.OUTBOUND_PROXY");
this.defaultRouter = new DefaultRouter(this, outboundProxy);
/** Retrieve the router path */
String routerPath = configurationProperties
.getProperty("javax.sip.ROUTER_PATH");
if (routerPath == null)
routerPath = "gov.nist.javax.sip.stack.DefaultRouter";
try {
Class<?> routerClass = Class.forName(routerPath);
Class<?>[] constructorArgs = new Class[2];
constructorArgs[0] = javax.sip.SipStack.class;
constructorArgs[1] = String.class;
Constructor<?> cons = routerClass.getConstructor(constructorArgs);
Object[] args = new Object[2];
args[0] = (SipStack) this;
args[1] = outboundProxy;
Router router = (Router) cons.newInstance(args);
super.setRouter(router);
} catch (InvocationTargetException ex1) {
logger
.logError(
"could not instantiate router -- invocation target problem",
(Exception) ex1.getCause());
throw new PeerUnavailableException(
"Cound not instantiate router - check constructor", ex1);
} catch (Exception ex) {
logger.logError("could not instantiate router",
(Exception) ex.getCause());
throw new PeerUnavailableException("Could not instantiate router",
ex);
}
// The flag that indicates that the default router is to be ignored.
String useRouterForAll = configurationProperties
.getProperty("javax.sip.USE_ROUTER_FOR_ALL_URIS");
this.useRouterForAll = true;
if (useRouterForAll != null) {
this.useRouterForAll = "true".equalsIgnoreCase(useRouterForAll);
}
/*
* Retrieve the EXTENSION Methods. These are used for instantiation of
* Dialogs.
*/
String extensionMethods = configurationProperties
.getProperty("javax.sip.EXTENSION_METHODS");
if (extensionMethods != null) {
java.util.StringTokenizer st = new java.util.StringTokenizer(
extensionMethods);
while (st.hasMoreTokens()) {
String em = st.nextToken(":");
if (em.equalsIgnoreCase(Request.BYE)
|| em.equalsIgnoreCase(Request.INVITE)
|| em.equalsIgnoreCase(Request.SUBSCRIBE)
|| em.equalsIgnoreCase(Request.NOTIFY)
|| em.equalsIgnoreCase(Request.ACK)
|| em.equalsIgnoreCase(Request.OPTIONS))
throw new PeerUnavailableException("Bad extension method "
+ em);
else
this.addExtensionMethod(em);
}
}
String keyStoreFile = configurationProperties
.getProperty("javax.net.ssl.keyStore");
String trustStoreFile = configurationProperties
.getProperty("javax.net.ssl.trustStore");
if (keyStoreFile != null) {
if (trustStoreFile == null) {
trustStoreFile = keyStoreFile;
}
String keyStorePassword = configurationProperties
.getProperty("javax.net.ssl.keyStorePassword");
try {
this.networkLayer = new SslNetworkLayer(trustStoreFile,
keyStoreFile,
keyStorePassword != null ?
keyStorePassword.toCharArray() : null,
configurationProperties
.getProperty("javax.net.ssl.keyStoreType"));
} catch (Exception e1) {
logger.logError(
"could not instantiate SSL networking", e1);
}
}
// Set the auto dialog support flag.
super.isAutomaticDialogSupportEnabled = configurationProperties
.getProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT", "on")
.equalsIgnoreCase("on");
super.isAutomaticDialogErrorHandlingEnabled = configurationProperties
.getProperty("gov.nist.javax.sip.AUTOMATIC_DIALOG_ERROR_HANDLING","true")
.equals(Boolean.TRUE.toString());
if ( super.isAutomaticDialogSupportEnabled ) {
super.isAutomaticDialogErrorHandlingEnabled = true;
}
if (configurationProperties
.getProperty("gov.nist.javax.sip.MAX_LISTENER_RESPONSE_TIME") != null) {
super.maxListenerResponseTime = Integer
.parseInt(configurationProperties
.getProperty("gov.nist.javax.sip.MAX_LISTENER_RESPONSE_TIME"));
if (super.maxListenerResponseTime <= 0)
throw new PeerUnavailableException(
"Bad configuration parameter gov.nist.javax.sip.MAX_LISTENER_RESPONSE_TIME : should be positive");
} else {
super.maxListenerResponseTime = -1;
}
this.setDeliverTerminatedEventForAck(configurationProperties
.getProperty(
"gov.nist.javax.sip.DELIVER_TERMINATED_EVENT_FOR_ACK",
"false").equalsIgnoreCase("true"));
super.setDeliverUnsolicitedNotify(Boolean.parseBoolean( configurationProperties.getProperty(
"gov.nist.javax.sip.DELIVER_UNSOLICITED_NOTIFY", "false")));
String forkedSubscriptions = configurationProperties
.getProperty("javax.sip.FORKABLE_EVENTS");
if (forkedSubscriptions != null) {
StringTokenizer st = new StringTokenizer(forkedSubscriptions);
while (st.hasMoreTokens()) {
String nextEvent = st.nextToken();
this.forkedEvents.add(nextEvent);
}
}
// Allow application to hook in a TLS Security Policy implementation
String tlsPolicyPath = configurationProperties.getProperty("gov.nist.javax.sip.TLS_SECURITY_POLICY");
if (tlsPolicyPath == null) {
tlsPolicyPath = "gov.nist.javax.sip.stack.DefaultTlsSecurityPolicy";
logger.logWarning("using default tls security policy");
}
try {
Class< ? > tlsPolicyClass = Class.forName(tlsPolicyPath);
Class< ? >[] constructorArgs = new Class[0];
Constructor< ? > cons = tlsPolicyClass.getConstructor(constructorArgs);
Object[] args = new Object[0];
this.tlsSecurityPolicy = (TlsSecurityPolicy) cons.newInstance(args);
} catch (InvocationTargetException ex1) {
throw new IllegalArgumentException("Cound not instantiate TLS security policy " + tlsPolicyPath
+ "- check that it is present on the classpath and that there is a no-args constructor defined",
ex1);
} catch (Exception ex) {
throw new IllegalArgumentException("Cound not instantiate TLS security policy " + tlsPolicyPath
+ "- check that it is present on the classpath and that there is a no-args constructor defined",
ex);
}
// Allow application to choose the tls client auth policy on the socket
String clientAuthType = configurationProperties.getProperty("gov.nist.javax.sip.TLS_CLIENT_AUTH_TYPE");
if (clientAuthType != null) {
super.clientAuth = ClientAuthType.valueOf(clientAuthType);
logger.logInfo("using " + clientAuthType + " tls auth policy");
}
// The following features are unique to the NIST implementation.
/*
* gets the NetworkLayer implementation, if any. Note that this is a
* NIST only feature.
*/
final String NETWORK_LAYER_KEY = "gov.nist.javax.sip.NETWORK_LAYER";
if (configurationProperties.containsKey(NETWORK_LAYER_KEY)) {
String path = configurationProperties
.getProperty(NETWORK_LAYER_KEY);
try {
Class<?> clazz = Class.forName(path);
Constructor<?> c = clazz.getConstructor(new Class[0]);
networkLayer = (NetworkLayer) c.newInstance(new Object[0]);
} catch (Exception e) {
throw new PeerUnavailableException(
"can't find or instantiate NetworkLayer implementation: "
+ path, e);
}
}
final String ADDRESS_RESOLVER_KEY = "gov.nist.javax.sip.ADDRESS_RESOLVER";
if (configurationProperties.containsKey(ADDRESS_RESOLVER_KEY)) {
String path = configurationProperties
.getProperty(ADDRESS_RESOLVER_KEY);
try {
Class<?> clazz = Class.forName(path);
Constructor<?> c = clazz.getConstructor(new Class[0]);
this.addressResolver = (AddressResolver) c
.newInstance(new Object[0]);
} catch (Exception e) {
throw new PeerUnavailableException(
"can't find or instantiate AddressResolver implementation: "
+ path, e);
}
}