Search in sources :

Example 16 with Response

use of javax.sip.message.Response in project XobotOS by xamarin.

the class SipHelper method sendInviteOk.

/**
     * @param event the INVITE request event
     */
public ServerTransaction sendInviteOk(RequestEvent event, SipProfile localProfile, String sessionDescription, ServerTransaction inviteTransaction, String externalIp, int externalPort) throws SipException {
    try {
        Request request = event.getRequest();
        Response response = mMessageFactory.createResponse(Response.OK, request);
        response.addHeader(createContactHeader(localProfile, externalIp, externalPort));
        response.setContent(sessionDescription, mHeaderFactory.createContentTypeHeader("application", "sdp"));
        if (inviteTransaction == null) {
            inviteTransaction = getServerTransaction(event);
        }
        if (inviteTransaction.getState() != TransactionState.COMPLETED) {
            if (DEBUG)
                Log.d(TAG, "send OK: " + response);
            inviteTransaction.sendResponse(response);
        }
        return inviteTransaction;
    } catch (ParseException e) {
        throw new SipException("sendInviteOk()", e);
    }
}
Also used : Response(javax.sip.message.Response) Request(javax.sip.message.Request) ParseException(java.text.ParseException) SipException(javax.sip.SipException)

Example 17 with Response

use of javax.sip.message.Response in project XobotOS by xamarin.

the class SipHelper method sendInviteAck.

/**
     * @param event the INVITE ACK request event
     */
public void sendInviteAck(ResponseEvent event, Dialog dialog) throws SipException {
    Response response = event.getResponse();
    long cseq = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getSeqNumber();
    Request ack = dialog.createAck(cseq);
    if (DEBUG)
        Log.d(TAG, "send ACK: " + ack);
    dialog.sendAck(ack);
}
Also used : Response(javax.sip.message.Response) CSeqHeader(javax.sip.header.CSeqHeader) Request(javax.sip.message.Request)

Example 18 with Response

use of javax.sip.message.Response in project XobotOS by xamarin.

the class SipSessionGroup method expectResponse.

/**
     * @return true if the event is a response event and the CSeqHeader method
     * match the given arguments; false otherwise
     */
private static boolean expectResponse(String expectedMethod, EventObject evt) {
    if (evt instanceof ResponseEvent) {
        ResponseEvent event = (ResponseEvent) evt;
        Response response = event.getResponse();
        return expectedMethod.equalsIgnoreCase(getCseqMethod(response));
    }
    return false;
}
Also used : Response(javax.sip.message.Response) SIPResponse(gov.nist.javax.sip.message.SIPResponse) ResponseEvent(javax.sip.ResponseEvent)

Example 19 with Response

use of javax.sip.message.Response in project XobotOS by xamarin.

the class SipSessionGroup method expectResponse.

/**
     * @return true if the event is a response event and the response code and
     *      CSeqHeader method match the given arguments; false otherwise
     */
private static boolean expectResponse(int responseCode, String expectedMethod, EventObject evt) {
    if (evt instanceof ResponseEvent) {
        ResponseEvent event = (ResponseEvent) evt;
        Response response = event.getResponse();
        if (response.getStatusCode() == responseCode) {
            return expectedMethod.equalsIgnoreCase(getCseqMethod(response));
        }
    }
    return false;
}
Also used : Response(javax.sip.message.Response) SIPResponse(gov.nist.javax.sip.message.SIPResponse) ResponseEvent(javax.sip.ResponseEvent)

Example 20 with Response

use of javax.sip.message.Response in project XobotOS by xamarin.

the class DialogFilter method processResponse.

/**
     * Process the response.
     * 
     * @exception SIPServerException is thrown when there is an error processing the response
     * @param incomingMessageChannel -- message channel on which the response is received.
     */
public void processResponse(SIPResponse response, MessageChannel incomingMessageChannel, SIPDialog dialog) {
    if (sipStack.isLoggingEnabled()) {
        sipStack.getStackLogger().logDebug("PROCESSING INCOMING RESPONSE" + response.encodeMessage());
    }
    if (listeningPoint == null) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logError("Dropping message: No listening point" + " registered!");
        return;
    }
    if (sipStack.checkBranchId() && !Utils.getInstance().responseBelongsToUs(response)) {
        if (sipStack.isLoggingEnabled()) {
            sipStack.getStackLogger().logError("Dropping response - topmost VIA header does not originate from this stack");
        }
        return;
    }
    SipProviderImpl sipProvider = listeningPoint.getProvider();
    if (sipProvider == null) {
        if (sipStack.isLoggingEnabled()) {
            sipStack.getStackLogger().logError("Dropping message:  no provider");
        }
        return;
    }
    if (sipProvider.getSipListener() == null) {
        if (sipStack.isLoggingEnabled()) {
            sipStack.getStackLogger().logError("No listener -- dropping response!");
        }
        return;
    }
    SIPClientTransaction transaction = (SIPClientTransaction) this.transactionChannel;
    SipStackImpl sipStackImpl = sipProvider.sipStack;
    if (sipStack.isLoggingEnabled()) {
        sipStackImpl.getStackLogger().logDebug("Transaction = " + transaction);
    }
    if (transaction == null) {
        // we cannot drop the response.
        if (dialog != null) {
            if (response.getStatusCode() / 100 != 2) {
                if (sipStack.isLoggingEnabled()) {
                    sipStack.getStackLogger().logDebug("Response is not a final response and dialog is found for response -- dropping response!");
                }
                return;
            } else if (dialog.getState() == DialogState.TERMINATED) {
                if (sipStack.isLoggingEnabled()) {
                    sipStack.getStackLogger().logDebug("Dialog is terminated -- dropping response!");
                }
                return;
            } else {
                boolean ackAlreadySent = false;
                if (dialog.isAckSeen() && dialog.getLastAckSent() != null) {
                    if (dialog.getLastAckSent().getCSeq().getSeqNumber() == response.getCSeq().getSeqNumber()) {
                        // the last ack sent corresponded to this 200
                        ackAlreadySent = true;
                    }
                }
                // 200 retransmission for the final response.
                if (ackAlreadySent && response.getCSeq().getMethod().equals(dialog.getMethod())) {
                    try {
                        // dont pass up the null transaction
                        if (sipStack.isLoggingEnabled()) {
                            sipStack.getStackLogger().logDebug("Retransmission of OK detected: Resending last ACK");
                        }
                        dialog.resendAck();
                        return;
                    } catch (SipException ex) {
                        // What to do here ?? kill the dialog?
                        sipStack.getStackLogger().logError("could not resend ack", ex);
                    }
                }
            }
        }
        if (sipStack.isLoggingEnabled()) {
            sipStack.getStackLogger().logDebug("could not find tx, handling statelessly Dialog =  " + dialog);
        }
        // Pass the response up to the application layer to handle
        // statelessly.
        ResponseEventExt sipEvent = new ResponseEventExt(sipProvider, transaction, dialog, (Response) response);
        if (response.getCSeqHeader().getMethod().equals(Request.INVITE)) {
            SIPClientTransaction forked = this.sipStack.getForkedTransaction(response.getTransactionId());
            sipEvent.setOriginalTransaction(forked);
        }
        sipProvider.handleEvent(sipEvent, transaction);
        return;
    }
    ResponseEventExt responseEvent = null;
    // Here if there is an assigned dialog
    responseEvent = new ResponseEventExt(sipProvider, (ClientTransactionExt) transaction, dialog, (Response) response);
    if (response.getCSeqHeader().getMethod().equals(Request.INVITE)) {
        SIPClientTransaction forked = this.sipStack.getForkedTransaction(response.getTransactionId());
        responseEvent.setOriginalTransaction(forked);
    }
    // Set the Dialog for the response.
    if (dialog != null && response.getStatusCode() != 100) {
        // set the last response for the dialog.
        dialog.setLastResponse(transaction, response);
        transaction.setDialog(dialog, dialog.getDialogId());
    }
    sipProvider.handleEvent(responseEvent, transaction);
}
Also used : SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) Response(javax.sip.message.Response) SIPResponse(gov.nist.javax.sip.message.SIPResponse) SipException(javax.sip.SipException)

Aggregations

Response (javax.sip.message.Response)21 SipException (javax.sip.SipException)10 Request (javax.sip.message.Request)9 ParseException (java.text.ParseException)8 SIPResponse (gov.nist.javax.sip.message.SIPResponse)6 ServerTransaction (javax.sip.ServerTransaction)5 SIPClientTransaction (gov.nist.javax.sip.stack.SIPClientTransaction)3 ResponseEvent (javax.sip.ResponseEvent)3 SipProvider (javax.sip.SipProvider)3 ToHeader (javax.sip.header.ToHeader)3 SipUri (gov.nist.javax.sip.address.SipUri)2 SIPRequest (gov.nist.javax.sip.message.SIPRequest)2 SIPDialog (gov.nist.javax.sip.stack.SIPDialog)2 SIPServerTransaction (gov.nist.javax.sip.stack.SIPServerTransaction)2 SIPTransaction (gov.nist.javax.sip.stack.SIPTransaction)2 ClientTransaction (javax.sip.ClientTransaction)2 Dialog (javax.sip.Dialog)2 InvalidArgumentException (javax.sip.InvalidArgumentException)2 SipURI (javax.sip.address.SipURI)2 CSeqHeader (javax.sip.header.CSeqHeader)2