org.cafesip.sipunit
Class SipStack

java.lang.Object
  extended by org.cafesip.sipunit.SipStack
All Implemented Interfaces:
java.util.EventListener, javax.sip.SipListener

public class SipStack
extends java.lang.Object
implements javax.sip.SipListener

This class is the starting point for a SipUnit test. Before establishing any SIP sessions, the test program must instantiate this class. Each SipStack object establishes the SIP protocol binding on the specified TCP/UDP port. This port is used to communicate with external SIP agents (a SIP proxy server, for example). A SipStack object may contain one or more SipPhone objects and each SipPhone object may contain one (or more, in future) SipCall objects and a buddy list. The getXxxFactory() methods of this class are used in conjunction with JAIN-SIP Request/Response classes for dealing with low level message, address and header content, needed when dealing at the SipSession level.


Field Summary
static int DEFAULT_PORT
           
static java.lang.String DEFAULT_PROTOCOL
           
static java.lang.String PROTOCOL_TCP
          PROTOCOL_TCP Specifies TCP/IP transport.
static java.lang.String PROTOCOL_UDP
          PROTOCOL_UDP Specifies UDP/IP transport.
 
Constructor Summary
SipStack(java.lang.String proto, int port)
          Equivalent to the other constructor without any properties specified.
SipStack(java.lang.String proto, int port, java.util.Properties props)
          A constructor for this class.
 
Method Summary
 SipPhone createSipPhone(java.lang.String me)
          This method is the equivalent to the other createSipPhone() methods but without a proxy server.
 SipPhone createSipPhone(java.lang.String host, java.lang.String me)
          This method is the equivalent to the other createSipPhone() method, but using the default transport (UDP/IP) and the default SIP port number (5060).
 SipPhone createSipPhone(java.lang.String proxyHost, java.lang.String proxyProto, int proxyPort, java.lang.String me)
          This method is used to create a SipPhone object.
 void dispose()
          This method is used to tear down the SipStack object.
static void dumpMessage(java.lang.String informationalHeader, javax.sip.message.Message msg)
          Outputs to console the provided header string followed by the message.
 javax.sip.address.AddressFactory getAddressFactory()
          This method returns the JAIN-SIP AddressFactory associated with the SipStack.
 javax.sip.header.HeaderFactory getHeaderFactory()
          This method returns the JAIN-SIP HeaderFactory associated with the SipStack.
 javax.sip.message.MessageFactory getMessageFactory()
          This method returns the JAIN-SIP MessageFactory associated with the SipStack.
 javax.sip.SipProvider getSipProvider()
          This method returns the JAIN-SIP SipProvider associated with the SipStack.
 javax.sip.SipStack getSipStack()
          This method returns the JAIN-SIP SipStack associated with this JUnit SipStack.
static boolean isTraceEnabled()
          Indicates if the SipUnit stack trace has been enabled.
 void processDialogTerminated(javax.sip.DialogTerminatedEvent arg0)
           
 void processIOException(javax.sip.IOExceptionEvent arg0)
           
 void processRequest(javax.sip.RequestEvent arg0)
          FOR INTERNAL USE ONLY.
 void processResponse(javax.sip.ResponseEvent arg0)
          FOR INTERNAL USE ONLY.
 void processTimeout(javax.sip.TimeoutEvent arg0)
          FOR INTERNAL USE ONLY.
 void processTransactionTerminated(javax.sip.TransactionTerminatedEvent arg0)
           
static void setTraceEnabled(boolean traceEnabled)
          Turn on or off the SipUnit stack tracing.
static void trace(java.lang.String msg)
          Outputs the given string to console, if SipStack.setTraceEnabled(true) has been called.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL_TCP

public static final java.lang.String PROTOCOL_TCP
PROTOCOL_TCP Specifies TCP/IP transport.

See Also:
Constant Field Values

PROTOCOL_UDP

public static final java.lang.String PROTOCOL_UDP
PROTOCOL_UDP Specifies UDP/IP transport.

See Also:
Constant Field Values

DEFAULT_PORT

public static final int DEFAULT_PORT
See Also:
Constant Field Values

DEFAULT_PROTOCOL

public static final java.lang.String DEFAULT_PROTOCOL
See Also:
Constant Field Values
Constructor Detail

SipStack

public SipStack(java.lang.String proto,
                int port,
                java.util.Properties props)
         throws java.lang.Exception
A constructor for this class. Before establishing any SIP sessions, instantiate this class. You may provide the parameters for SIP protocol binding on a specific TCP/UDP port, which will be used to communicate with external SIP agents (a SIP proxy server, for example). (TODO - update to take advantage of JAIN-SIP 1.2 architecture, multiple listening points per provider - multiple protocols.) A test program may contain one or more SipStack objects, each of which may have one or more SipPhones.

Parameters:
proto - SIP transport protocol, "tcp" or "udp" (default is "udp").
port - port on which this stack listens for messages (default is 5060).
props - properties of the SIP stack. These properties are the same as that defined for JAIN-SIP SipStack. If this parameter has a null value, we pick default values for you.
Throws:
java.lang.Exception

SipStack

public SipStack(java.lang.String proto,
                int port)
         throws java.lang.Exception
Equivalent to the other constructor without any properties specified.

Parameters:
proto - SIP transport protocol (default is UDP).
port - port on which this stack listens for messages (default is 5060).
Throws:
java.lang.Exception
Method Detail

createSipPhone

public SipPhone createSipPhone(java.lang.String proxyHost,
                               java.lang.String proxyProto,
                               int proxyPort,
                               java.lang.String me)
                        throws javax.sip.InvalidArgumentException,
                               java.text.ParseException
This method is used to create a SipPhone object. The SipPhone class simulates a SIP User Agent. The SipPhone object is used to communicate with other SIP agents. Using a SipPhone object, the test program can make one (or more, in future) outgoing calls or (and, in future) receive one (or more, in future) incoming calls.

Parameters:
proxyHost - host name or address of the SIP proxy to use. The proxy is used for registering and outbound calling on a per-call basis. If this parameter is a null value, any registration requests will be sent to the "host" part of the "me" parameter (see below) and any attempt to make an outbound call via proxy will fail. If a host name is given here, it must resolve to a valid, reachable DNS address.
proxyProto - used to specify the protocol for communicating with the proxy server - "udp" or "tcp".
proxyPort - port number into with the proxy server listens to for SIP messages and connections.
me - "Address of Record" URI of the phone user. Each SipPhone is associated with one user. This parameter is used in the "from" header field.
Returns:
A new SipPhone object.
Throws:
javax.sip.InvalidArgumentException
java.text.ParseException

createSipPhone

public SipPhone createSipPhone(java.lang.String me)
                        throws javax.sip.InvalidArgumentException,
                               java.text.ParseException
This method is the equivalent to the other createSipPhone() methods but without a proxy server.

Parameters:
me - "Address of Record" URI of the phone user. Each SipPhone is associated with one user. This parameter is used in the "from" header field.
Returns:
A new SipPhone object.
Throws:
javax.sip.InvalidArgumentException
java.text.ParseException

createSipPhone

public SipPhone createSipPhone(java.lang.String host,
                               java.lang.String me)
                        throws javax.sip.InvalidArgumentException,
                               java.text.ParseException
This method is the equivalent to the other createSipPhone() method, but using the default transport (UDP/IP) and the default SIP port number (5060).

Parameters:
host - host name or address of the SIP proxy to use. The proxy is used for registering and outbound calling on a per-call basis. If this parameter is a null value, any registration requests will be sent to the "host" part of the "me" parameter (see below) and any attempt to make an outbound call via proxy will fail. If a host name is given here, it must resolve to a valid, reachable DNS address.
me - "Address of Record" URI of the phone user. Each SipPhone is associated with one user. This parameter is used in the "from" header field.
Returns:
A new SipPhone object.
Throws:
javax.sip.InvalidArgumentException
java.text.ParseException

dispose

public void dispose()
This method is used to tear down the SipStack object. All resources are freed up. Before calling this method, you should call the dispose() nethod on any SipPhones you've created using this sip stack.


isTraceEnabled

public static boolean isTraceEnabled()
Indicates if the SipUnit stack trace has been enabled.

Returns:
true if the stack trace is enabled.

setTraceEnabled

public static void setTraceEnabled(boolean traceEnabled)
Turn on or off the SipUnit stack tracing. After calling this method with a value of true, call SipStack.trace() to output trace messages.

Parameters:
traceEnabled - true to turn on the tracing, false to turn it off.

processRequest

public void processRequest(javax.sip.RequestEvent arg0)
FOR INTERNAL USE ONLY. Not to be used by a test program.

Specified by:
processRequest in interface javax.sip.SipListener

processResponse

public void processResponse(javax.sip.ResponseEvent arg0)
FOR INTERNAL USE ONLY. Not to be used by a test program.

Specified by:
processResponse in interface javax.sip.SipListener

processTimeout

public void processTimeout(javax.sip.TimeoutEvent arg0)
FOR INTERNAL USE ONLY. Not to be used by a test program.

Specified by:
processTimeout in interface javax.sip.SipListener

getAddressFactory

public javax.sip.address.AddressFactory getAddressFactory()
This method returns the JAIN-SIP AddressFactory associated with the SipStack.

Returns:
the address factory.

getHeaderFactory

public javax.sip.header.HeaderFactory getHeaderFactory()
This method returns the JAIN-SIP HeaderFactory associated with the SipStack.

Returns:
the header factory.

getMessageFactory

public javax.sip.message.MessageFactory getMessageFactory()
This method returns the JAIN-SIP MessageFactory associated with the SipStack.

Returns:
the message factory.

getSipProvider

public javax.sip.SipProvider getSipProvider()
This method returns the JAIN-SIP SipProvider associated with the SipStack.

Returns:
the sip provider.

getSipStack

public javax.sip.SipStack getSipStack()
This method returns the JAIN-SIP SipStack associated with this JUnit SipStack.

Returns:
the JAIN-SIP SipStack.

trace

public static void trace(java.lang.String msg)
Outputs the given string to console, if SipStack.setTraceEnabled(true) has been called.

Parameters:
msg - String to output to console.

dumpMessage

public static void dumpMessage(java.lang.String informationalHeader,
                               javax.sip.message.Message msg)
Outputs to console the provided header string followed by the message.

Parameters:
informationalHeader -
msg -

processIOException

public void processIOException(javax.sip.IOExceptionEvent arg0)
Specified by:
processIOException in interface javax.sip.SipListener

processTransactionTerminated

public void processTransactionTerminated(javax.sip.TransactionTerminatedEvent arg0)
Specified by:
processTransactionTerminated in interface javax.sip.SipListener

processDialogTerminated

public void processDialogTerminated(javax.sip.DialogTerminatedEvent arg0)
Specified by:
processDialogTerminated in interface javax.sip.SipListener


http://www.cafesip.org