Search in sources :

Example 1 with SIPResponse

use of gov.nist.javax.sip.message.SIPResponse in project XobotOS by xamarin.

the class SipProviderImpl method sendResponse.

/*
     * (non-Javadoc)
     *
     * @see javax.sip.SipProvider#sendResponse(javax.sip.message.Response)
     */
public void sendResponse(Response response) throws SipException {
    if (!sipStack.isAlive())
        throw new SipException("Stack is stopped");
    SIPResponse sipResponse = (SIPResponse) response;
    Via via = sipResponse.getTopmostVia();
    if (via == null)
        throw new SipException("No via header in response!");
    SIPServerTransaction st = (SIPServerTransaction) sipStack.findTransaction((SIPMessage) response, true);
    if (st != null && st.getState() != TransactionState.TERMINATED && this.isAutomaticDialogSupportEnabled()) {
        throw new SipException("Transaction exists -- cannot send response statelessly");
    }
    String transport = via.getTransport();
    // check to see if Via has "received paramaeter". If so
    // set the host to the via parameter. Else set it to the
    // Via host.
    String host = via.getReceived();
    if (host == null)
        host = via.getHost();
    // Symmetric nat support
    int port = via.getRPort();
    if (port == -1) {
        port = via.getPort();
        if (port == -1) {
            if (transport.equalsIgnoreCase("TLS"))
                port = 5061;
            else
                port = 5060;
        }
    }
    // for correct management of IPv6 addresses.
    if (host.indexOf(":") > 0)
        if (host.indexOf("[") < 0)
            host = "[" + host + "]";
    Hop hop = sipStack.getAddressResolver().resolveAddress(new HopImpl(host, port, transport));
    try {
        ListeningPointImpl listeningPoint = (ListeningPointImpl) this.getListeningPoint(transport);
        if (listeningPoint == null)
            throw new SipException("whoopsa daisy! no listening point found for transport " + transport);
        MessageChannel messageChannel = sipStack.createRawMessageChannel(this.getListeningPoint(hop.getTransport()).getIPAddress(), listeningPoint.port, hop);
        messageChannel.sendMessage(sipResponse);
    } catch (IOException ex) {
        throw new SipException(ex.getMessage());
    }
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) MessageChannel(gov.nist.javax.sip.stack.MessageChannel) Hop(javax.sip.address.Hop) SIPMessage(gov.nist.javax.sip.message.SIPMessage) IOException(java.io.IOException) SipException(javax.sip.SipException) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) ListeningPoint(javax.sip.ListeningPoint) HopImpl(gov.nist.javax.sip.stack.HopImpl) Via(gov.nist.javax.sip.header.Via)

Example 2 with SIPResponse

use of gov.nist.javax.sip.message.SIPResponse in project XobotOS by xamarin.

the class SipProviderImpl method getNewDialog.

/*
     * (non-Javadoc)
     *
     * @see javax.sip.SipProvider#getNewDialog(javax.sip.Transaction)
     */
public Dialog getNewDialog(Transaction transaction) throws SipException {
    if (transaction == null)
        throw new NullPointerException("Null transaction!");
    if (!sipStack.isAlive())
        throw new SipException("Stack is stopped.");
    if (isAutomaticDialogSupportEnabled())
        throw new SipException(" Error - AUTOMATIC_DIALOG_SUPPORT is on");
    if (!sipStack.isDialogCreated(transaction.getRequest().getMethod()))
        throw new SipException("Dialog cannot be created for this method " + transaction.getRequest().getMethod());
    SIPDialog dialog = null;
    SIPTransaction sipTransaction = (SIPTransaction) transaction;
    if (transaction instanceof ServerTransaction) {
        SIPServerTransaction st = (SIPServerTransaction) transaction;
        Response response = st.getLastResponse();
        if (response != null) {
            if (response.getStatusCode() != 100)
                throw new SipException("Cannot set dialog after response has been sent");
        }
        SIPRequest sipRequest = (SIPRequest) transaction.getRequest();
        String dialogId = sipRequest.getDialogId(true);
        dialog = sipStack.getDialog(dialogId);
        if (dialog == null) {
            dialog = sipStack.createDialog((SIPTransaction) transaction);
            // create and register the dialog and add the inital route set.
            dialog.addTransaction(sipTransaction);
            dialog.addRoute(sipRequest);
            sipTransaction.setDialog(dialog, null);
        } else {
            sipTransaction.setDialog(dialog, sipRequest.getDialogId(true));
        }
        if (sipRequest.getMethod().equals(Request.INVITE) && this.isDialogErrorsAutomaticallyHandled()) {
            sipStack.putInMergeTable(st, sipRequest);
        }
    } else {
        SIPClientTransaction sipClientTx = (SIPClientTransaction) transaction;
        SIPResponse response = sipClientTx.getLastResponse();
        if (response == null) {
            // A response has not yet been received, then set this up as the
            // default dialog.
            SIPRequest request = (SIPRequest) sipClientTx.getRequest();
            String dialogId = request.getDialogId(false);
            dialog = sipStack.getDialog(dialogId);
            if (dialog != null) {
                throw new SipException("Dialog already exists!");
            } else {
                dialog = sipStack.createDialog(sipTransaction);
            }
            sipClientTx.setDialog(dialog, null);
        } else {
            throw new SipException("Cannot call this method after response is received!");
        }
    }
    dialog.addEventListener(this);
    return dialog;
}
Also used : Response(javax.sip.message.Response) SIPResponse(gov.nist.javax.sip.message.SIPResponse) SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) SIPResponse(gov.nist.javax.sip.message.SIPResponse) SIPDialog(gov.nist.javax.sip.stack.SIPDialog) SIPTransaction(gov.nist.javax.sip.stack.SIPTransaction) SipException(javax.sip.SipException) ServerTransaction(javax.sip.ServerTransaction) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) SIPServerTransaction(gov.nist.javax.sip.stack.SIPServerTransaction) SIPRequest(gov.nist.javax.sip.message.SIPRequest)

Example 3 with SIPResponse

use of gov.nist.javax.sip.message.SIPResponse in project XobotOS by xamarin.

the class DialogFilter method sendLoopDetectedResponse.

/**
     * Send back a LOOP Detected Response.
     * 
     * @param sipRequest
     * @param transaction
     * 
     */
private void sendLoopDetectedResponse(SIPRequest sipRequest, SIPServerTransaction transaction) {
    SIPResponse sipResponse = sipRequest.createResponse(Response.LOOP_DETECTED);
    ServerHeader serverHeader = MessageFactoryImpl.getDefaultServerHeader();
    if (serverHeader != null) {
        sipResponse.setHeader(serverHeader);
    }
    try {
        sipStack.addTransactionPendingAck(transaction);
        transaction.sendResponse(sipResponse);
        transaction.releaseSem();
    } catch (Exception ex) {
        sipStack.getStackLogger().logError("Problem sending error response", ex);
        transaction.releaseSem();
        sipStack.removeTransaction(transaction);
    }
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) ServerHeader(javax.sip.header.ServerHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) SipException(javax.sip.SipException) IOException(java.io.IOException) ObjectInUseException(javax.sip.ObjectInUseException)

Example 4 with SIPResponse

use of gov.nist.javax.sip.message.SIPResponse in project XobotOS by xamarin.

the class DialogFilter method sendRequestPendingResponse.

/**
     * Send back a Request Pending response.
     * 
     * @param sipRequest
     * @param transaction
     */
private void sendRequestPendingResponse(SIPRequest sipRequest, SIPServerTransaction transaction) {
    SIPResponse sipResponse = sipRequest.createResponse(Response.REQUEST_PENDING);
    ServerHeader serverHeader = MessageFactoryImpl.getDefaultServerHeader();
    if (serverHeader != null) {
        sipResponse.setHeader(serverHeader);
    }
    try {
        RetryAfter retryAfter = new RetryAfter();
        retryAfter.setRetryAfter(1);
        sipResponse.setHeader(retryAfter);
        if (sipRequest.getMethod().equals(Request.INVITE)) {
            sipStack.addTransactionPendingAck(transaction);
        }
        transaction.sendResponse(sipResponse);
        transaction.releaseSem();
    } catch (Exception ex) {
        sipStack.getStackLogger().logError("Problem sending error response", ex);
        transaction.releaseSem();
        sipStack.removeTransaction(transaction);
    }
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) RetryAfter(gov.nist.javax.sip.header.RetryAfter) ServerHeader(javax.sip.header.ServerHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) SipException(javax.sip.SipException) IOException(java.io.IOException) ObjectInUseException(javax.sip.ObjectInUseException)

Example 5 with SIPResponse

use of gov.nist.javax.sip.message.SIPResponse in project XobotOS by xamarin.

the class DialogFilter method sendBadRequestResponse.

/**
     * Send a BAD REQUEST response.
     * 
     * @param sipRequest
     * @param transaction
     * @param reasonPhrase
     */
private void sendBadRequestResponse(SIPRequest sipRequest, SIPServerTransaction transaction, String reasonPhrase) {
    SIPResponse sipResponse = sipRequest.createResponse(Response.BAD_REQUEST);
    if (reasonPhrase != null)
        sipResponse.setReasonPhrase(reasonPhrase);
    ServerHeader serverHeader = MessageFactoryImpl.getDefaultServerHeader();
    if (serverHeader != null) {
        sipResponse.setHeader(serverHeader);
    }
    try {
        if (sipRequest.getMethod().equals(Request.INVITE)) {
            sipStack.addTransactionPendingAck(transaction);
        }
        transaction.sendResponse(sipResponse);
        transaction.releaseSem();
    } catch (Exception ex) {
        sipStack.getStackLogger().logError("Problem sending error response", ex);
        transaction.releaseSem();
        sipStack.removeTransaction(transaction);
    }
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) ServerHeader(javax.sip.header.ServerHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) SipException(javax.sip.SipException) IOException(java.io.IOException) ObjectInUseException(javax.sip.ObjectInUseException)

Aggregations

SIPResponse (gov.nist.javax.sip.message.SIPResponse)22 SipException (javax.sip.SipException)14 IOException (java.io.IOException)12 ObjectInUseException (javax.sip.ObjectInUseException)10 SIPRequest (gov.nist.javax.sip.message.SIPRequest)9 InvalidArgumentException (javax.sip.InvalidArgumentException)8 ParseException (java.text.ParseException)7 ServerHeader (javax.sip.header.ServerHeader)5 RSeq (gov.nist.javax.sip.header.RSeq)4 SIPMessage (gov.nist.javax.sip.message.SIPMessage)3 SIPClientTransaction (gov.nist.javax.sip.stack.SIPClientTransaction)3 SIPServerTransaction (gov.nist.javax.sip.stack.SIPServerTransaction)3 Response (javax.sip.message.Response)3 RAck (gov.nist.javax.sip.header.RAck)2 Require (gov.nist.javax.sip.header.Require)2 RetryAfter (gov.nist.javax.sip.header.RetryAfter)2 Via (gov.nist.javax.sip.header.Via)2 SIPDialog (gov.nist.javax.sip.stack.SIPDialog)2 SIPTransaction (gov.nist.javax.sip.stack.SIPTransaction)2 DialogDoesNotExistException (javax.sip.DialogDoesNotExistException)2