01: package examples.redirect;
02:
03: import java.util.Properties;
04:
05: import javax.sip.PeerUnavailableException;
06: import javax.sip.SipException;
07: import javax.sip.SipFactory;
08: import javax.sip.SipStack;
09: import javax.sip.address.AddressFactory;
10: import javax.sip.header.HeaderFactory;
11: import javax.sip.message.MessageFactory;
12:
13: /**
14: * @author M. Ranganathan
15: *
16: */
17: public class ProtocolObjects {
18: public final AddressFactory addressFactory;
19:
20: public final MessageFactory messageFactory;
21:
22: public final HeaderFactory headerFactory;
23:
24: public final SipStack sipStack;
25:
26: public final int logLevel = 32;
27:
28: public final String logFileDirectory;
29:
30: public final String transport;
31:
32: ProtocolObjects(String stackname, boolean autoDialog,
33: String transport, String logFileDirectory) {
34:
35: this .transport = transport;
36: this .logFileDirectory = logFileDirectory;
37: SipFactory sipFactory = null;
38:
39: sipFactory = SipFactory.getInstance();
40: sipFactory.setPathName("gov.nist");
41: Properties properties = new Properties();
42: // If you want to try TCP transport change the following to
43:
44: // If you want to use UDP then uncomment this.
45: properties.setProperty("javax.sip.STACK_NAME", stackname);
46:
47: // The following properties are specific to nist-sip
48: // and are not necessarily part of any other jain-sip
49: // implementation.
50: properties.setProperty("gov.nist.javax.sip.DEBUG_LOG",
51: logFileDirectory + stackname + "debug.txt");
52: properties.setProperty("gov.nist.javax.sip.SERVER_LOG",
53: logFileDirectory + stackname + "log.txt");
54:
55: properties.setProperty("javax.sip.AUTOMATIC_DIALOG_SUPPORT",
56: (autoDialog ? "on" : "off"));
57:
58: // Set to 0 in your production code for max speed.
59: // You need 16 for logging traces. 32 for debug + traces.
60: // Your code will limp at 32 but it is best for debugging.
61: properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL",
62: new Integer(logLevel).toString());
63:
64: try {
65: // Create SipStack object
66: sipStack = sipFactory.createSipStack(properties);
67:
68: System.out.println("createSipStack " + sipStack);
69: } catch (Exception e) {
70: // could not find
71: // gov.nist.jain.protocol.ip.sip.SipStackImpl
72: // in the classpath
73: e.printStackTrace();
74: System.err.println(e.getMessage());
75: throw new RuntimeException("Stack failed to initialize");
76: }
77:
78: try {
79: headerFactory = sipFactory.createHeaderFactory();
80: addressFactory = sipFactory.createAddressFactory();
81: messageFactory = sipFactory.createMessageFactory();
82: } catch (SipException ex) {
83: ex.printStackTrace();
84: throw new RuntimeException(ex);
85: }
86: }
87:
88: public void destroy() {
89: sipStack.stop();
90: }
91:
92: public void start() throws Exception {
93: sipStack.start();
94:
95: }
96: }
|