+ * This method blocks until one of the following occurs: 1) A response + * message has been received. In this case, a value of true is returned. + * Call the getLastReceivedResponse() method to get the response details. 2) + * A timeout occurs. A false value is returned in this case. 3) An error + * occurs. False is returned in this case. + *
+ * Regardless of the outcome, getReturnCode() can be called after this + * method returns to get the status code: IE, the SIP response code received + * from the network (defined in SipResponse, along with the corresponding + * textual equivalent) or a SipUnit internal status/error code (defined in + * SipSession, along with the corresponding textual equivalent). SipUnit + * internal codes are in a specially designated range + * (SipSession.SIPUNIT_INTERNAL_RETURNCODE_MIN and upward). + *
+ * + * @param siptrans + * This is the object that was returned by method sendDisconnect(). + * It identifies a specific Disconnect transaction. + * @param timeout + * The maximum amount of time to wait, in milliseconds. Use a + * value of 0 to wait indefinitely. + * @return true if a response was received - in that case, call + * getReturnCode() to get the status code that was contained in the + * received response, and/or call getLastReceivedResponse() to see + * the response details. Returns false if timeout or error. + */ + public boolean waitForDisconnectResponse(SipTransaction siptrans, long timeout) + { + initErrorInfo(); + + if (siptrans == null) + { + returnCode = SipSession.INVALID_OPERATION; + errorMessage = (String) SipSession.statusCodeDescription + .get(new Integer(returnCode)) + + " - no transaction object given"; + return false; + } + + EventObject response_event = parent.waitResponse(siptrans, timeout); + + if (response_event == null) + { + setErrorMessage(parent.getErrorMessage()); + setException(parent.getException()); + setReturnCode(parent.getReturnCode()); + return false; + } + + if (response_event instanceof TimeoutEvent == true) + { + setReturnCode(SipPhone.TIMEOUT_OCCURRED); + setErrorMessage("A Timeout Event was received"); + return false; + } + + Response resp = ((ResponseEvent) response_event).getResponse(); + receivedResponses.add(new SipResponse((ResponseEvent) response_event)); + SipStack.trace("BYE response received: " + resp.toString()); + + setReturnCode(resp.getStatusCode()); + + return true; + } + /** * Gets the SIP Call ID for this incoming or outgoing call. * @@ -4292,4 +4385,4 @@ public String getCallId() return callId.getCallId(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/cafesip/sipunit/SipSession.java b/src/main/java/org/cafesip/sipunit/SipSession.java index 2f3975e2ce..fb683b79e7 100644 --- a/src/main/java/org/cafesip/sipunit/SipSession.java +++ b/src/main/java/org/cafesip/sipunit/SipSession.java @@ -448,13 +448,14 @@ public void processRequest(RequestEvent request) { SipStack .trace(" skipping 'To' check, we're not loopback (see setLoopback())"); - return; } - - // check 'To' for a match - if (to.getAddress().getURI().toString().equals(me) == false) + else { - return; + // check 'To' for a match + if (to.getAddress().getURI().toString().equals(me) == false) + { + return; + } } } @@ -2460,4 +2461,4 @@ public void processDialogTerminated(DialogTerminatedEvent arg0) // TODO Auto-generated method stub } -} \ No newline at end of file +} diff --git a/src/main/java/org/cafesip/sipunit/SipStack.java b/src/main/java/org/cafesip/sipunit/SipStack.java index 0306525da5..025f97b005 100644 --- a/src/main/java/org/cafesip/sipunit/SipStack.java +++ b/src/main/java/org/cafesip/sipunit/SipStack.java @@ -47,6 +47,8 @@ import javax.sip.header.RouteHeader; import javax.sip.message.MessageFactory; +import org.apache.log4j.Logger; + /** * This class is the starting point for a SipUnit test. Before establishing any * SIP sessions, the test program must instantiate this class. Each SipStack @@ -63,6 +65,8 @@ */ public class SipStack implements SipListener { + static Logger log = null; + private static boolean traceEnabled = false; private static SipFactory sipFactory = null; @@ -135,6 +139,16 @@ public class SipStack implements SipListener public static final String DEFAULT_PROTOCOL = PROTOCOL_UDP; + /** + * This constructor is a wrapper around the usual constructor, + * which allows an additional logging object to be passed. + */ + public SipStack(String proto, int port, Properties props, Logger log) throws Exception + { + this(proto, port, props); + SipStack.log = log; + } + /** * A constructor for this class. Before establishing any SIP sessions, * instantiate this class. You may provide the parameters for SIP protocol @@ -529,8 +543,12 @@ public synchronized static void trace(String msg) // grossly simplified { if (traceEnabled) { - System.out.println("SIPUNIT TRACE: " + System.currentTimeMillis() + if (log == null) { + System.out.println("SIPUNIT TRACE: " + System.currentTimeMillis() + " " + msg); + } else { + log.trace("SIPUNIT TRACE\t" + msg); + } } } @@ -606,4 +624,4 @@ public void processDialogTerminated(DialogTerminatedEvent arg0) public int getRetransmissions() { return retransmissions; } -} \ No newline at end of file +}