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