Search in sources :

Example 1 with SIPIfMatchHeader

use of javax.sip.header.SIPIfMatchHeader in project load-balancer by RestComm.

the class TestSipListener method processPublish.

private void processPublish(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    try {
        SipProvider sipProvider = (SipProvider) requestEvent.getSource();
        Request request = requestEvent.getRequest();
        logger.info("shootist:  got a publish . ServerTxId = " + serverTransactionId);
        ServerTransaction st = requestEvent.getServerTransaction();
        if (st == null) {
            st = sipProvider.getNewServerTransaction(request);
        }
        inviteServerTid = st;
        Dialog dialog = st.getDialog();
        this.dialogCount++;
        this.dialog = dialog;
        logger.info("Shootme: dialog = " + dialog);
        if (request.getRawContent() != null) {
            this.lastMessageContent = new String(request.getRawContent());
            allMessagesContent.add(new String(lastMessageContent));
        }
        SIPIfMatchHeader sipIfMatchHeader = (SIPIfMatchHeader) request.getHeader(SIPIfMatchHeader.NAME);
        boolean sipIfMatchFound = true;
        if (sipIfMatchHeader != null && sipIfMatchHeader.getETag() != null && !sipIfMatchHeader.getETag().equals(sipETag)) {
            sipIfMatchFound = false;
        }
        if (sipIfMatchFound) {
            Response response = protocolObjects.messageFactory.createResponse(200, request);
            sipETag = Integer.toString(new Random().nextInt(10000000));
            SIPETagHeader sipTagHeader = protocolObjects.headerFactory.createSIPETagHeader(sipETag);
            response.addHeader(sipTagHeader);
            response.addHeader(request.getHeader(ExpiresHeader.NAME));
            st.sendResponse(response);
            logger.info("shootist:  Sending OK.");
        } else {
            Response response = protocolObjects.messageFactory.createResponse(500, request);
            serverTransactionId.sendResponse(response);
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Response(javax.sip.message.Response) Random(java.util.Random) SIPETagHeader(javax.sip.header.SIPETagHeader) Dialog(javax.sip.Dialog) Request(javax.sip.message.Request) ServerTransaction(javax.sip.ServerTransaction) SIPIfMatchHeader(javax.sip.header.SIPIfMatchHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) SipException(javax.sip.SipException) TransactionDoesNotExistException(javax.sip.TransactionDoesNotExistException) TransactionUnavailableException(javax.sip.TransactionUnavailableException) SipProvider(javax.sip.SipProvider)

Example 2 with SIPIfMatchHeader

use of javax.sip.header.SIPIfMatchHeader in project load-balancer by RestComm.

the class TestSipListener method addSpecificHeaders.

private void addSpecificHeaders(String method, Request request) throws ParseException, InvalidArgumentException {
    if (Request.SUBSCRIBE.equals(method) || Request.PUBLISH.equals(method)) {
        // Create an event header for the subscription.
        EventHeader eventHeader = protocolObjects.headerFactory.createEventHeader(publishEvent);
        request.addHeader(eventHeader);
        ExpiresHeader expires = protocolObjects.headerFactory.createExpiresHeader(200);
        request.addHeader(expires);
    }
    if (Request.PUBLISH.equals(method)) {
        if (sipETag != null) {
            SIPIfMatchHeader sipIfMatchHeader = protocolObjects.headerFactory.createSIPIfMatchHeader(sipETag);
            request.addHeader(sipIfMatchHeader);
        }
        if (publishContentMessage != null) {
            ContentLengthHeader contentLengthHeader = protocolObjects.headerFactory.createContentLengthHeader(publishContentMessage.length());
            ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory.createContentTypeHeader(APPLICATION_CONTENT_TYPE, PIDF_XML_SUBTYPE);
            request.setContentLength(contentLengthHeader);
            request.setContent(publishContentMessage, contentTypeHeader);
        }
    }
    if (Request.REFER.equals(method)) {
        ReferToHeader referToHeader = (ReferToHeader) protocolObjects.headerFactory.createHeader(ReferToHeader.NAME, "sip:refer-to@nist.gov");
        request.addHeader(referToHeader);
    }
}
Also used : ContentTypeHeader(javax.sip.header.ContentTypeHeader) ContentLengthHeader(javax.sip.header.ContentLengthHeader) ReferToHeader(javax.sip.header.ReferToHeader) EventHeader(javax.sip.header.EventHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) SIPIfMatchHeader(javax.sip.header.SIPIfMatchHeader)

Aggregations

SIPIfMatchHeader (javax.sip.header.SIPIfMatchHeader)2 ParseException (java.text.ParseException)1 Random (java.util.Random)1 Dialog (javax.sip.Dialog)1 InvalidArgumentException (javax.sip.InvalidArgumentException)1 ServerTransaction (javax.sip.ServerTransaction)1 SipException (javax.sip.SipException)1 SipProvider (javax.sip.SipProvider)1 TransactionDoesNotExistException (javax.sip.TransactionDoesNotExistException)1 TransactionUnavailableException (javax.sip.TransactionUnavailableException)1 ContentLengthHeader (javax.sip.header.ContentLengthHeader)1 ContentTypeHeader (javax.sip.header.ContentTypeHeader)1 EventHeader (javax.sip.header.EventHeader)1 ExpiresHeader (javax.sip.header.ExpiresHeader)1 ReferToHeader (javax.sip.header.ReferToHeader)1 SIPETagHeader (javax.sip.header.SIPETagHeader)1 Request (javax.sip.message.Request)1 Response (javax.sip.message.Response)1