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