Search in sources :

Example 1 with EventHeader

use of javax.sip.header.EventHeader in project camel by apache.

the class SipPresenceAgentListener method processPublish.

private void processPublish(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    try {
        Request request = requestEvent.getRequest();
        LOG.debug("SipPresenceAgentListener: Received a Publish request, sending OK");
        LOG.debug("SipPresenceAgentListener request: {}", request);
        EventHeader eventHeader = (EventHeader) requestEvent.getRequest().getHeader(EventHeader.NAME);
        Response response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(202, request);
        sipPresenceAgent.getProvider().sendResponse(response);
        // Send notification to subscriber
        sendNotification(eventHeader, false, request.getContent());
    } catch (Exception e) {
        LOG.error("Exception thrown during publish/notify processing in the Sip Presence Agent Listener", e);
    }
}
Also used : Response(javax.sip.message.Response) Request(javax.sip.message.Request) EventHeader(javax.sip.header.EventHeader) SipException(javax.sip.SipException) ParseException(java.text.ParseException)

Example 2 with EventHeader

use of javax.sip.header.EventHeader in project camel by apache.

the class SipPresenceAgentListener method processSubscribe.

public void processSubscribe(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    try {
        LOG.debug("SipPresenceAgentListener: Received a Subscribe request, sending OK");
        LOG.debug("SipPresenceAgentListener request: {}", request);
        EventHeader eventHeader = (EventHeader) request.getHeader(EventHeader.NAME);
        if (eventHeader == null) {
            LOG.debug("Cannot find event header.... dropping request.");
            return;
        }
        // Always create a ServerTransaction, best as early as possible in the code
        Response response = null;
        ServerTransaction st = requestEvent.getServerTransaction();
        if (st == null) {
            st = sipProvider.getNewServerTransaction(request);
        }
        // Check if it is an initial SUBSCRIBE or a refresh / unsubscribe
        boolean isInitial = requestEvent.getDialog() == null;
        if (isInitial) {
            String toTag = UUID.randomUUID().toString();
            response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(202, request);
            ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
            // Application is supposed to set.
            toHeader.setTag(toTag);
            this.dialog = st.getDialog();
            // subscribe dialogs do not terminate on bye.
            this.dialog.terminateOnBye(false);
        } else {
            response = sipPresenceAgent.getConfiguration().getMessageFactory().createResponse(200, request);
        }
        // Both 2xx response to SUBSCRIBE and NOTIFY need a Contact
        response.addHeader(sipPresenceAgent.getConfiguration().getContactHeader());
        // Expires header is mandatory in 2xx responses to SUBSCRIBE
        response.addHeader(sipPresenceAgent.getConfiguration().getExpiresHeader());
        st.sendResponse(response);
        LOG.debug("SipPresenceAgentListener: Sent OK Message");
        LOG.debug("SipPresenceAgentListener response: {}", response);
        sendNotification(eventHeader, isInitial, request.getContent());
    } catch (Throwable e) {
        LOG.error("Exception thrown during Notify processing in the SipPresenceAgentListener.", e);
    }
}
Also used : Response(javax.sip.message.Response) Request(javax.sip.message.Request) ToHeader(javax.sip.header.ToHeader) EventHeader(javax.sip.header.EventHeader) ServerTransaction(javax.sip.ServerTransaction) SipProvider(javax.sip.SipProvider)

Example 3 with EventHeader

use of javax.sip.header.EventHeader in project XobotOS by xamarin.

the class SIPDialog method addTransaction.

/**
     * Add a transaction record to the dialog.
     * 
     * @param transaction is the transaction to add to the dialog.
     */
public void addTransaction(SIPTransaction transaction) {
    SIPRequest sipRequest = (SIPRequest) transaction.getOriginalRequest();
    // Proessing a re-invite.
    if (firstTransactionSeen && !firstTransactionId.equals(transaction.getBranchId()) && transaction.getMethod().equals(firstTransactionMethod)) {
        this.reInviteFlag = true;
    }
    if (firstTransactionSeen == false) {
        // Record the local and remote sequenc
        // numbers and the from and to tags for future
        // use on this dialog.
        storeFirstTransactionInfo(this, transaction);
        if (sipRequest.getMethod().equals(Request.SUBSCRIBE))
            this.eventHeader = (EventHeader) sipRequest.getHeader(EventHeader.NAME);
        this.setLocalParty(sipRequest);
        this.setRemoteParty(sipRequest);
        this.setCallId(sipRequest);
        if (this.originalRequest == null) {
            this.originalRequest = sipRequest;
        }
        if (this.method == null) {
            this.method = sipRequest.getMethod();
        }
        if (transaction instanceof SIPServerTransaction) {
            this.hisTag = sipRequest.getFrom().getTag();
        // My tag is assigned when sending response
        } else {
            setLocalSequenceNumber(sipRequest.getCSeq().getSeqNumber());
            this.originalLocalSequenceNumber = localSequenceNumber;
            this.myTag = sipRequest.getFrom().getTag();
            if (myTag == null)
                if (sipStack.isLoggingEnabled())
                    sipStack.getStackLogger().logError("The request's From header is missing the required Tag parameter.");
        }
    } else if (transaction.getMethod().equals(firstTransactionMethod) && firstTransactionIsServerTransaction != transaction.isServerTransaction()) {
        // This case occurs when you are processing a re-invite.
        // Switch from client side to server side for re-invite
        // (put the other side on hold).
        storeFirstTransactionInfo(this, transaction);
        this.setLocalParty(sipRequest);
        this.setRemoteParty(sipRequest);
        this.setCallId(sipRequest);
        this.originalRequest = sipRequest;
        this.method = sipRequest.getMethod();
    }
    if (transaction instanceof SIPServerTransaction)
        setRemoteSequenceNumber(sipRequest.getCSeq().getSeqNumber());
    // If this is a server transaction record the remote
    // sequence number to avoid re-processing of requests
    // with the same sequence number directed towards this
    // dialog.
    this.lastTransaction = transaction;
    // transaction.setDialog(this,sipRequest);
    if (sipStack.isLoggingEnabled()) {
        sipStack.getStackLogger().logDebug("Transaction Added " + this + myTag + "/" + hisTag);
        sipStack.getStackLogger().logDebug("TID = " + transaction.getTransactionId() + "/" + transaction.isServerTransaction());
        sipStack.getStackLogger().logStackTrace();
    }
}
Also used : EventHeader(javax.sip.header.EventHeader) SIPRequest(gov.nist.javax.sip.message.SIPRequest)

Aggregations

EventHeader (javax.sip.header.EventHeader)3 Request (javax.sip.message.Request)2 Response (javax.sip.message.Response)2 SIPRequest (gov.nist.javax.sip.message.SIPRequest)1 ParseException (java.text.ParseException)1 ServerTransaction (javax.sip.ServerTransaction)1 SipException (javax.sip.SipException)1 SipProvider (javax.sip.SipProvider)1 ToHeader (javax.sip.header.ToHeader)1