Search in sources :

Example 61 with Response

use of javax.sip.message.Response in project load-balancer by RestComm.

the class TestSipListener method processCancel.

private void processCancel(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    try {
        cancelReceived = true;
        SipProvider sipProvider = (SipProvider) requestEvent.getSource();
        Request request = requestEvent.getRequest();
        Response response = protocolObjects.messageFactory.createResponse(Response.OK, request);
        ServerTransaction st = requestEvent.getServerTransaction();
        if (st == null) {
            st = sipProvider.getNewServerTransaction(request);
        }
        Dialog dialog = st.getDialog();
        logger.info("Shootme: dialog = " + dialog);
        st.sendResponse(response);
        response = protocolObjects.messageFactory.createResponse(Response.REQUEST_TERMINATED, inviteRequest);
        inviteServerTid.sendResponse(response);
    } catch (Exception ex) {
        ex.printStackTrace();
        logger.error("error sending CANCEL responses", ex);
    }
}
Also used : Response(javax.sip.message.Response) Dialog(javax.sip.Dialog) Request(javax.sip.message.Request) ServerTransaction(javax.sip.ServerTransaction) 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 62 with Response

use of javax.sip.message.Response in project load-balancer by RestComm.

the class TestSipListener method processNotify.

public void processNotify(RequestEvent requestEvent, ServerTransaction serverTransactionId) {
    SipProvider provider = (SipProvider) requestEvent.getSource();
    Request notify = requestEvent.getRequest();
    try {
        logger.info("subscriber:  got a notify count  " + this.notifyCount++);
        if (serverTransactionId == null) {
            logger.info("subscriber:  null TID.");
            serverTransactionId = provider.getNewServerTransaction(notify);
        }
        Dialog dialog = serverTransactionId.getDialog();
        // if ( dialog != subscriberDialog ) {
        // if (forkedDialog == null) {
        // forkedDialog = dialog;
        // } else  {
        // AbstractSubsnotifyTestCase.assertTrue("Dialog should be either the subscriber dialog ",
        // forkedDialog  == dialog);
        // }
        // }
        // 
        // this.dialogs.add(dialog);
        logger.info("Dialog State = " + dialog.getState());
        Response response = protocolObjects.messageFactory.createResponse(200, notify);
        // SHOULD add a Contact
        ContactHeader contact = (ContactHeader) contactHeader.clone();
        ((SipURI) contact.getAddress().getURI()).setParameter("id", "sub");
        response.addHeader(contact);
        logger.info("Transaction State = " + serverTransactionId.getState());
        serverTransactionId.sendResponse(response);
        logger.info("Dialog State = " + dialog.getState());
        SubscriptionStateHeader subscriptionState = (SubscriptionStateHeader) notify.getHeader(SubscriptionStateHeader.NAME);
        // Subscription is terminated?
        String state = subscriptionState.getState();
        allSubscriptionStates.add(state.toLowerCase());
        if (notify.getRawContent() != null) {
            this.lastMessageContent = new String(notify.getRawContent());
            allMessagesContent.add(new String(lastMessageContent));
        }
        if (state.equalsIgnoreCase(SubscriptionStateHeader.TERMINATED)) {
            if (subscriptionState.getReasonCode() == null) {
                dialog.delete();
            }
        } else if (state.equalsIgnoreCase(SubscriptionStateHeader.ACTIVE)) {
            if ("reg".equalsIgnoreCase(((EventHeader) notify.getHeader(EventHeader.NAME)).getEventType())) {
                if (sendByeBeforeTerminatingNotify) {
                    dialog.terminateOnBye(false);
                    sendBye();
                    Thread.sleep(1000);
                }
                logger.info("Subscriber: sending unSUBSCRIBE");
                // Else we end it ourselves
                Request unsubscribe = dialog.createRequest(Request.SUBSCRIBE);
                logger.info("dialog created:" + unsubscribe);
                // SHOULD add a Contact (done by dialog), lets mark it to test updates
                // ((SipURI) dialog.getLocalParty().getURI()).setParameter( "id", "unsub" );
                ExpiresHeader expires = protocolObjects.headerFactory.createExpiresHeader(0);
                unsubscribe.addHeader(expires);
                // JvB note : stack should do this!
                // copy
                unsubscribe.addHeader(notify.getHeader(EventHeader.NAME));
                // event
                // header
                logger.info("Sending Unsubscribe : " + unsubscribe);
                logger.info("unsubscribe dialog  " + dialog);
                ClientTransaction ct = sipProvider.getNewClientTransaction(unsubscribe);
                dialog.sendRequest(ct);
                if (sendByeAfterTerminatingNotify) {
                    Thread.sleep(1000);
                    sendBye();
                }
            } else if (sendByeBeforeTerminatingNotify) {
                sendBye();
            }
        } else {
            // pending
            logger.info("Subscriber: state now " + state);
        }
    } catch (Exception ex) {
        logger.error("Unexpected exception", ex);
    }
}
Also used : Response(javax.sip.message.Response) ContactHeader(javax.sip.header.ContactHeader) Dialog(javax.sip.Dialog) SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) EventHeader(javax.sip.header.EventHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) SipURI(javax.sip.address.SipURI) 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 63 with Response

use of javax.sip.message.Response in project load-balancer by RestComm.

the class TestSipListener method processPrack.

private void processPrack(Request request, ServerTransaction serverTransactionId) {
    try {
        prackReceived = true;
        prackRequestReceived = request;
        ServerTransaction st = serverTransactionId;
        if (st == null) {
            st = sipProvider.getNewServerTransaction(request);
        }
        Response response = protocolObjects.messageFactory.createResponse(200, request);
        st.sendResponse(response);
        Thread.sleep(200);
        inviteServerTid.sendResponse(getFinalResponse());
    } catch (Exception e) {
        logger.error("Unexpected exception while trying to send the 200 to PRACK " + request, e);
    }
}
Also used : Response(javax.sip.message.Response) ServerTransaction(javax.sip.ServerTransaction) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) SipException(javax.sip.SipException) TransactionDoesNotExistException(javax.sip.TransactionDoesNotExistException) TransactionUnavailableException(javax.sip.TransactionUnavailableException)

Example 64 with Response

use of javax.sip.message.Response in project load-balancer by RestComm.

the class TestSipListener method processInvite.

/**
 * Process the invite request.
 */
public void processInvite(RequestEvent requestEvent, ServerTransaction serverTransaction) {
    inviteReceived = true;
    SipProvider sipProvider = (SipProvider) requestEvent.getSource();
    Request request = requestEvent.getRequest();
    inviteRequest = request;
    logger.info("shootme: got an Invite " + request);
    try {
        ServerTransaction st = requestEvent.getServerTransaction();
        if (st == null) {
            st = sipProvider.getNewServerTransaction(request);
        }
        inviteServerTid = st;
        Dialog dialog = st.getDialog();
        if (request.getHeader(JoinHeader.NAME) != null) {
            setJoinRequestReceived(true);
            this.joinDialog = dialog;
        } else if (request.getHeader(ReplacesHeader.NAME) != null) {
            setReplacesRequestReceived(true);
            this.replacesDialog = dialog;
        } else {
            this.dialogCount++;
            this.dialog = dialog;
        }
        logger.info("Shootme: dialog = " + dialog);
        this.inviteRequest = request;
        boolean sendReliably = false;
        RequireHeader requireHeader = (RequireHeader) request.getHeader(RequireHeader.NAME);
        if (requireHeader != null && "100rel".equalsIgnoreCase(requireHeader.getOptionTag().trim())) {
            sendReliably = true;
        }
        if (respondWithError == null)
            for (int provisionalResponseToSend : provisionalResponsesToSend) {
                Thread.sleep(getTimeToWaitBetweenProvisionnalResponse());
                Response response = protocolObjects.messageFactory.createResponse(provisionalResponseToSend, request);
                if (provisionalResponseToSend >= Response.TRYING && provisionalResponseToSend < Response.OK) {
                    ToHeader toHeader = (ToHeader) response.getHeader(ToHeader.NAME);
                    if (provisionalResponseToSend != Response.TRYING && toHeader.getTag() == null) {
                        // Application is supposed to set.
                        toHeader.setTag(TO_TAG);
                    }
                    if (sendReliably && provisionalResponseToSend != Response.TRYING) {
                        requireHeader = protocolObjects.headerFactory.createRequireHeader("100rel");
                        response.addHeader(requireHeader);
                        Header rseqHeader = protocolObjects.headerFactory.createRSeqHeader(rseqNumber.getAndIncrement());
                        response.addHeader(rseqHeader);
                        dialog.sendReliableProvisionalResponse(response);
                    } else {
                        st.sendResponse(response);
                        eventListener.uasAfterResponse(response.getStatusCode(), appServer);
                    }
                }
            }
        if (respondWithError != null && !sendReliably) {
            Response response = protocolObjects.messageFactory.createResponse(respondWithError, request);
            response.setReasonPhrase("Unable to setup media services");
            st.sendResponse(response);
            eventListener.uasAfterResponse(response.getStatusCode(), appServer);
            return;
        }
        ContactHeader contactHeader = (ContactHeader) request.getHeader(ContactHeader.NAME);
        if (contactHeader != null && "0.0.0.0".equals(((SipURI) contactHeader.getAddress().getURI()).getHost())) {
            abortProcessing = true;
            throw new IllegalArgumentException("we received a contact header with 0.0.0.0 in an INVITE !");
        }
        if (!waitForCancel) {
            Address address = null;
            if (!isIpv6)
                address = protocolObjects.addressFactory.createAddress("Shootme <sip:127.0.0.1:" + myPort + ";transport=" + protocolObjects.transport + ">");
            else
                address = protocolObjects.addressFactory.createAddress("Shootme <sip:[::1]:" + myPort + ";transport=" + protocolObjects.transport + ">");
            contactHeader = protocolObjects.headerFactory.createContactHeader(address);
            setFinalResponse(protocolObjects.messageFactory.createResponse(finalResponseToSend, request));
            if (testAckViaParam) {
                ViaHeader viaHeader = (ViaHeader) getFinalResponse().getHeader(ViaHeader.NAME);
                viaHeader.setParameter("testAckViaParam", "true");
            }
            ToHeader toHeader = (ToHeader) getFinalResponse().getHeader(ToHeader.NAME);
            if (toHeader.getTag() == null) {
                // Application is supposed to set.
                toHeader.setTag(TO_TAG);
            }
            getFinalResponse().addHeader(contactHeader);
            if (!sendReliably) {
                Thread.sleep(2000);
                st.sendResponse(getFinalResponse());
                eventListener.uasAfterResponse(getFinalResponse().getStatusCode(), appServer);
            }
        } else {
            logger.info("Waiting for CANCEL, stopping the INVITE processing ");
            return;
        }
        if (("join").equalsIgnoreCase(((SipUri) request.getRequestURI()).getUser())) {
            sendJoinMessage = true;
        }
        if (("replaces").equalsIgnoreCase(((SipUri) request.getRequestURI()).getUser())) {
            sendReplacesMessage = true;
        }
    } catch (Exception ex) {
        logger.error("unexpected exception", ex);
        throw new RuntimeException(ex);
    }
}
Also used : ContactHeader(javax.sip.header.ContactHeader) Address(javax.sip.address.Address) Request(javax.sip.message.Request) RequireHeader(javax.sip.header.RequireHeader) SipURI(javax.sip.address.SipURI) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) SipException(javax.sip.SipException) TransactionDoesNotExistException(javax.sip.TransactionDoesNotExistException) TransactionUnavailableException(javax.sip.TransactionUnavailableException) Response(javax.sip.message.Response) ReasonHeader(javax.sip.header.ReasonHeader) RequireHeader(javax.sip.header.RequireHeader) SIPETagHeader(javax.sip.header.SIPETagHeader) ContactHeader(javax.sip.header.ContactHeader) ReferToHeader(javax.sip.header.ReferToHeader) ViaHeader(javax.sip.header.ViaHeader) SIPIfMatchHeader(javax.sip.header.SIPIfMatchHeader) AuthorizationHeader(javax.sip.header.AuthorizationHeader) CallIdHeader(javax.sip.header.CallIdHeader) ContentLengthHeader(javax.sip.header.ContentLengthHeader) ExtensionHeader(javax.sip.header.ExtensionHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) Header(javax.sip.header.Header) ReplacesHeader(gov.nist.javax.sip.header.extensions.ReplacesHeader) CSeqHeader(javax.sip.header.CSeqHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) JoinHeader(gov.nist.javax.sip.header.extensions.JoinHeader) MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ToHeader(javax.sip.header.ToHeader) RouteHeader(javax.sip.header.RouteHeader) ProxyAuthorizationHeader(javax.sip.header.ProxyAuthorizationHeader) SubscriptionStateHeader(javax.sip.header.SubscriptionStateHeader) EventHeader(javax.sip.header.EventHeader) FromHeader(javax.sip.header.FromHeader) ProxyAuthenticateHeader(javax.sip.header.ProxyAuthenticateHeader) RecordRouteHeader(javax.sip.header.RecordRouteHeader) ViaHeader(javax.sip.header.ViaHeader) Dialog(javax.sip.Dialog) ReferToHeader(javax.sip.header.ReferToHeader) ToHeader(javax.sip.header.ToHeader) ServerTransaction(javax.sip.ServerTransaction) SipProvider(javax.sip.SipProvider)

Example 65 with Response

use of javax.sip.message.Response in project load-balancer by RestComm.

the class Shootist method processInvite.

public void processInvite(Request request, ServerTransaction stx) {
    try {
        inviteRequest = request;
        Response response = messageFactory.createResponse(180, request);
        contactHeader = headerFactory.createContactHeader(addressFactory.createAddress("sip:here@" + localIPAddress + ":" + localPort));
        response.addHeader(contactHeader);
        dialog = stx.getDialog();
        // check removing incorrect patching last via https://github.com/RestComm/load-balancer/issues/97
        FromHeader fromHeader = (FromHeader) response.getHeader(From.NAME);
        URI currUri = fromHeader.getAddress().getURI();
        String fromUser = null;
        if (currUri.isSipURI()) {
            fromUser = ((SipURI) currUri).getUser();
            if (fromUser.equals("senderToNexmo")) {
                ViaHeader lastViaHeader = null;
                ListIterator<ViaHeader> it = response.getHeaders(ViaHeader.NAME);
                while (it.hasNext()) lastViaHeader = it.next();
                lastViaHeader.setReceived("127.0.0.2");
                lastViaHeader.setParameter("rport", "1111");
            }
        }
        stx.sendResponse(response);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        response = messageFactory.createResponse(200, request);
        contactHeader = headerFactory.createContactHeader(addressFactory.createAddress("sip:here@" + localIPAddress + ":" + localPort));
        response.addHeader(contactHeader);
        dialog = stx.getDialog();
        stx.sendResponse(response);
    } catch (SipException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvalidArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : Response(javax.sip.message.Response) InvalidArgumentException(javax.sip.InvalidArgumentException) ViaHeader(javax.sip.header.ViaHeader) FromHeader(javax.sip.header.FromHeader) ParseException(java.text.ParseException) SipException(javax.sip.SipException) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI)

Aggregations

Response (javax.sip.message.Response)77 ParseException (java.text.ParseException)42 SipException (javax.sip.SipException)41 InvalidArgumentException (javax.sip.InvalidArgumentException)32 Request (javax.sip.message.Request)28 ServerTransaction (javax.sip.ServerTransaction)22 TransactionUnavailableException (javax.sip.TransactionUnavailableException)20 Dialog (javax.sip.Dialog)18 ToHeader (javax.sip.header.ToHeader)17 Test (org.junit.Test)17 ListeningPoint (javax.sip.ListeningPoint)16 ContactHeader (javax.sip.header.ContactHeader)16 SipURI (javax.sip.address.SipURI)13 SIPResponse (gov.nist.javax.sip.message.SIPResponse)12 ClientTransaction (javax.sip.ClientTransaction)12 SipProvider (javax.sip.SipProvider)11 TransactionDoesNotExistException (javax.sip.TransactionDoesNotExistException)11 ViaHeader (javax.sip.header.ViaHeader)11 FromHeader (javax.sip.header.FromHeader)10 CSeqHeader (javax.sip.header.CSeqHeader)9