public SipTransaction sendReply(RequestEvent request, Response response) {
    initErrorInfo();

    if (request == null) {
      setReturnCode(INVALID_ARGUMENT);
      setErrorMessage("A response cannot be sent because the request event is null.");
      return null;
    }

    // The ServerTransaction needed will be in the
    // RequestEvent if the dialog already existed. Otherwise, create it
    // here.

    Request req = request.getRequest();
    if (req == null) {
      setReturnCode(INVALID_ARGUMENT);
      setErrorMessage("A response cannot be sent because the request is null.");
      return null;
    }

    ServerTransaction trans = request.getServerTransaction();
    if (trans == null) {
      try {
        trans = parent.getSipProvider().getNewServerTransaction(req);
      } catch (TransactionAlreadyExistsException ex) {
        /*
         * TransactionAlreadyExistsException - this can happen if a transaction already exists that
         * is already handling this Request. This may happen if the application gets retransmits of
         * the same request before the initial transaction is allocated.
         */

        setErrorMessage(
            "Error: Can't get transaction object. If you've already called sendReply(RequestEvent, ...) with this RequestEvent, use the SipTransaction it returned to call sendReply(SipTransaction, ...) for subsequent replies to that request.");
        setReturnCode(INTERNAL_ERROR);
        return null;
      } catch (Exception ex) {
        setException(ex);
        setErrorMessage("Exception: " + ex.getClass().getName() + ": " + ex.getMessage());
        setReturnCode(EXCEPTION_ENCOUNTERED);
        return null;
      }
    }

    // create the SipTransaction, put the ServerTransaction in it
    SipTransaction transaction = new SipTransaction();
    transaction.setServerTransaction(trans);

    return sendReply(transaction, response);
  }
public SipTransaction sendReply ( RequestEvent request , Response response ) { initErrorInfo ( ) ; if ( request == null ) { setReturnCode ( INVALID_ARGUMENT ) ; setErrorMessage ( "A response cannot be sent because the request event is null." ) ; return null ; } Request req = request . getRequest ( ) ; if ( req == null ) { setReturnCode ( INVALID_ARGUMENT ) ; setErrorMessage ( "A response cannot be sent because the request is null." ) ; return null ; } ServerTransaction trans = request . getServerTransaction ( ) ; if ( trans == null ) { try { trans = parent . getSipProvider ( ) . getNewServerTransaction ( req ) ; } catch ( TransactionAlreadyExistsException ex ) { setErrorMessage ( "Error: Can't get transaction object. If you've already called sendReply(RequestEvent, ...) with this RequestEvent, use the SipTransaction it returned to call sendReply(SipTransaction, ...) for subsequent replies to that request." ) ; setReturnCode ( INTERNAL_ERROR ) ; return null ; } catch ( Exception ex ) { setException ( ex ) ; setErrorMessage ( "Exception: " + ex . getClass ( ) . getName ( ) + ": " + ex . getMessage ( ) ) ; setReturnCode ( EXCEPTION_ENCOUNTERED ) ; return null ; } } SipTransaction transaction = new SipTransaction ( ) ; transaction . setServerTransaction ( trans ) ; return sendReply ( transaction , response ) ; }
This method sends a stateful response to a previously received request. Call this method after
calling waitRequest(). The returned SipTransaction object must be used in any subsequent calls
to sendReply() for the same received request, if there are any.

@param request The RequestEvent object that was returned by a previous call to waitRequest().
@param response The response to send, as is.
@return A SipTransaction object that must be passed in to any subsequent call to sendReply()
for the same received request, or null if an error was encountered while sending the
response. The calling program doesn't need to do anything with the returned
SipTransaction other than pass it in to a subsequent call to sendReply() for the same
received request.