org.cafesip.sipunit
Class ReferNotifySender

java.lang.Object
  extended by org.cafesip.sipunit.PresenceNotifySender
      extended by org.cafesip.sipunit.ReferNotifySender
All Implemented Interfaces:
MessageListener, RequestListener

public class ReferNotifySender
extends PresenceNotifySender

The primary purpose of this class is as a test utility, to verify other UA's NOTIFY reception processing. When instantiated, an object of this class listens for a REFER or SUBSCRIBE message. After the calling program has sent a message to this object's uri, it can call this object's processRefer() or processSubscribe() method to receive and process the received request and send a response. After that, this object sends a NOTIFY message on that subscription each time method sendNotify() is called, with the given content body. This class can listen for and show the response to a given sent NOTIFY message. It can receive and process multiple request messages for a subscription.


Constructor Summary
ReferNotifySender(SipPhone userb)
          A constructor for this class.
 
Method Summary
 boolean processRefer()
          This method waits for up to 10 seconds to receive a REFER and if received, it sends an OK response.
 boolean processRefer(long timeout, int statusCode, java.lang.String reasonPhrase)
          This method starts a thread that waits for up to 'timeout' milliseconds to receive a REFER and if received, it sends a response with 'statusCode' and 'reasonPhrase' (if not null).
 boolean processRefer(long timeout, int statusCode, java.lang.String reasonPhrase, int duration, javax.sip.header.EventHeader overrideEvent)
          Same as the other processRefer() except allows for a couple of overrides for testing error handling by the far end outbound REFER side: (a) takes a duration for adding ExpiresHeader to the REFER response (the response shouldn't have an expires header), and (b) this method takes an EventHeader for overriding what would normally/correctly be sent back in the response (normally same as what was received in the request).
 boolean processReferSendNotifyBeforeResponse(long timeout, int statusCode, java.lang.String reasonPhrase, java.lang.String notifySubscriptionState, java.lang.String notifyTermReason, java.lang.String notifyBody, int notifyTimeLeft)
          This method starts a thread that waits for up to 'timeout' milliseconds to receive a REFER and if received, it sends NOTIFY with the given notify parms and 500ms later, it sends a response with 'statusCode' and 'reasonPhrase' (if not null).
 boolean sendNotify(java.lang.String subscriptionState, java.lang.String termReason, java.lang.String body, int timeLeft, boolean viaProxy)
          This method creates a NOTIFY message using the given parameters and sends it to the subscriber.
 boolean sendNotify(java.lang.String subscriptionState, java.lang.String termReason, java.lang.String body, int timeLeft, javax.sip.header.EventHeader eventHdr, javax.sip.header.SubscriptionStateHeader ssHdr, javax.sip.header.AcceptHeader accHdr, javax.sip.header.ContentTypeHeader ctHdr, boolean viaProxy)
          This method creates a NOTIFY message using the given parameters and sends it to the subscriber.
 
Methods inherited from class org.cafesip.sipunit.PresenceNotifySender
addNotifyHeaders, dispose, getAllReceivedRequests, getAllReceivedResponses, getDialog, getErrorMessage, getLastReceivedRequest, getLastReceivedResponse, getLastSentNotify, needAuthorization, processEvent, processSubscribe, processSubscribe, processSubscribe, register, resendWithAuthorization, sendNotify, sendStatefulNotify, setDialog, waitResponse
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReferNotifySender

public ReferNotifySender(SipPhone userb)
A constructor for this class. This object immediately starts listening for a REFER request.

Parameters:
userb - SipPhone object to use for messaging.
Throws:
java.lang.Exception - If there's a problem
Method Detail

processRefer

public boolean processRefer()
This method waits for up to 10 seconds to receive a REFER and if received, it sends an OK response.

Returns:
true if REFER is received and response sending was successful, false otherwise (call getErrorMessage() for details).

processRefer

public boolean processRefer(long timeout,
                            int statusCode,
                            java.lang.String reasonPhrase)
This method starts a thread that waits for up to 'timeout' milliseconds to receive a REFER and if received, it sends a response with 'statusCode' and 'reasonPhrase' (if not null). This method waits 500 ms before returning to allow the thread to get started and begin waiting for an incoming REFER. This method adds 500ms to the given timeout to account for this delay.

Parameters:
timeout - - number of milliseconds to wait for the request
statusCode - - use in the response to the request
reasonPhrase - - if not null, use in the response
Returns:
true if the thread got started OK.

processRefer

public boolean processRefer(long timeout,
                            int statusCode,
                            java.lang.String reasonPhrase,
                            int duration,
                            javax.sip.header.EventHeader overrideEvent)
Same as the other processRefer() except allows for a couple of overrides for testing error handling by the far end outbound REFER side: (a) takes a duration for adding ExpiresHeader to the REFER response (the response shouldn't have an expires header), and (b) this method takes an EventHeader for overriding what would normally/correctly be sent back in the response (normally same as what was received in the request).


processReferSendNotifyBeforeResponse

public boolean processReferSendNotifyBeforeResponse(long timeout,
                                                    int statusCode,
                                                    java.lang.String reasonPhrase,
                                                    java.lang.String notifySubscriptionState,
                                                    java.lang.String notifyTermReason,
                                                    java.lang.String notifyBody,
                                                    int notifyTimeLeft)
This method starts a thread that waits for up to 'timeout' milliseconds to receive a REFER and if received, it sends NOTIFY with the given notify parms and 500ms later, it sends a response with 'statusCode' and 'reasonPhrase' (if not null). This method waits 500 ms before returning to allow the thread to get started and begin waiting for an incoming REFER. This method adds 1000ms to the given timeout to account for these delays.

Parameters:
timeout - - number of milliseconds to wait for the request
statusCode - - use in the response to the request
reasonPhrase - - if not null, use in the response
notifySubscriptionState -
notifyTermReason -
notifyBody -
notifyTimeLeft -
Returns:
true if the thread got started OK.

sendNotify

public boolean sendNotify(java.lang.String subscriptionState,
                          java.lang.String termReason,
                          java.lang.String body,
                          int timeLeft,
                          boolean viaProxy)
This method creates a NOTIFY message using the given parameters and sends it to the subscriber. The request will be resent if challenged. Use this method only if you have previously called processRefer() or processSubscribe(). Use this method if you don't care about checking the response to the sent NOTIFY, otherwise use sendStatefulNotify().

Overrides:
sendNotify in class PresenceNotifySender
Parameters:
subscriptionState - - String to use as the subscription state.
termReason - - used only when subscriptionState = TERMINATED.
body - - NOTIFY body to put in the message
timeLeft - - expiry in seconds to put in the NOTIFY message (used only when subscriptionState = ACTIVE or PENDING).
viaProxy - If true, send the message to the proxy. In this case a Route header will be added. Else send the message as is.
Returns:
true if successful, false otherwise (call getErrorMessage() for details).

sendNotify

public boolean sendNotify(java.lang.String subscriptionState,
                          java.lang.String termReason,
                          java.lang.String body,
                          int timeLeft,
                          javax.sip.header.EventHeader eventHdr,
                          javax.sip.header.SubscriptionStateHeader ssHdr,
                          javax.sip.header.AcceptHeader accHdr,
                          javax.sip.header.ContentTypeHeader ctHdr,
                          boolean viaProxy)
This method creates a NOTIFY message using the given parameters and sends it to the subscriber. Knowledge of JAIN-SIP API headers is required. The request will be resent if challenged. Use this method only if you have previously called processRefer() or processSubscribe(). Use this method if you don't care about checking the response to the sent NOTIFY, otherwise use sendStatefulNotify().

Overrides:
sendNotify in class PresenceNotifySender
Parameters:
subscriptionState - - String to use as the subscription state. Overridden by sshdr.
termReason - - used only when subscriptionState = TERMINATED. Overridden by sshdr.
body - - NOTIFY body to put in the message
timeLeft - - expiry in seconds to put in the NOTIFY message (used only when subscriptionState = ACTIVE or PENDING). Overridden by sshdr.
eventHdr - - if not null, use this event header in the NOTIFY message
ssHdr - - if not null, use this subscription state header in the NOTIFY message instead of building one from other parameters given.
accHdr - - if not null, use this accept header. Otherwise build the default package one.
ctHdr - - if not null, use this content type header. Otherwise build the default package one.
viaProxy - If true, send the message to the proxy. In this case a Route header will be added. Else send the message as is.
Returns:
true if successful, false otherwise (call getErrorMessage() for details).


http://www.cafesip.org