Search in sources :

Example 11 with Address

use of javax.sip.address.Address in project load-balancer by RestComm.

the class TestSipListener method processResponse.

public void processResponse(ResponseEvent responseReceivedEvent) {
    if (abortProcessing) {
        logger.error("Processing aborted");
        return;
    }
    Response response = (Response) responseReceivedEvent.getResponse();
    System.out.println("Process response : " + response);
    eventListener.uacAfterResponse(response.getStatusCode(), appServer);
    if (response.getStatusCode() == 491)
        numberOf491s++;
    RecordRouteHeader recordRouteHeader = (RecordRouteHeader) response.getHeader(RecordRouteHeader.NAME);
    ContactHeader contactHeader = (ContactHeader) response.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 a response !");
    }
    if (response.getStatusCode() >= 400 && response.getStatusCode() < 999) {
        this.serverErrorReceived = true;
    }
    if (response.getStatusCode() == 503) {
        this.serviceUnavailableReceived = true;
    }
    if (response.toString().toLowerCase().contains("info")) {
        lastInfoResponseTime = System.currentTimeMillis();
    }
    ClientTransaction tid = responseReceivedEvent.getClientTransaction();
    CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);
    logger.info("Response received : Status Code = " + response.getStatusCode() + " " + cseq);
    // not dropping in PRACK case on REINVITE the ClientTx can be null it seems
    if (tid == null && !prackSent) {
        if (countRetrans) {
            nbRetrans++;
        }
        logger.info("Stray response -- dropping ");
        return;
    }
    if (tid != null) {
        logger.info("transaction state is " + tid.getState());
        logger.info("Dialog = " + tid.getDialog());
        if (tid.getDialog() != null) {
            logger.info("Dialog State is " + tid.getDialog().getState());
        }
    }
    try {
        if (response.getStatusCode() > 100 && response.getStatusCode() < 200) {
            informationalResponse = response;
        }
        if (response.getStatusCode() >= 200 && response.getStatusCode() < 700) {
            logger.info("final response received : status code " + response.getStatusCode());
            finalResponseReceived = true;
            setFinalResponseStatus(response.getStatusCode());
            setFinalResponse(response);
        }
        if (response.getStatusCode() == Response.OK) {
            if (cseq.getMethod().equals(Request.INVITE) && sendAck) {
                inviteOkResponse = response;
                @SuppressWarnings("deprecation") Request ackRequest = responseReceivedEvent.getClientTransaction().createAck();
                if (useToURIasRequestUri) {
                    ackRequest.setRequestURI(requestURI);
                }
                if (timeToWaitBeforeAck > 0) {
                    Thread.sleep(timeToWaitBeforeAck);
                }
                if (!sendSubsequentRequestsThroughSipProvider && tid.getDialog() != null) {
                    tid.getDialog().sendAck(ackRequest);
                } else {
                    sipProvider.sendRequest(ackRequest);
                }
                ackSent = true;
                // If the caller is supposed to send the bye
                if (sendReinvite && !reinviteSent) {
                    List<Header> headers = new ArrayList<Header>();
                    Header reinviteHeader = protocolObjects.headerFactory.createHeader("ReInvite", "true");
                    headers.add(reinviteHeader);
                    if (prackSent) {
                        headers.add(protocolObjects.headerFactory.createHeader(RequireHeader.NAME, "100rel"));
                    }
                    sendInDialogSipRequest("INVITE", null, null, null, headers, null);
                    reinviteSent = true;
                    return;
                }
                if (sendBye) {
                    // Thread.sleep(30000);
                    sendBye();
                }
                if (sendByeAfterTerminatingNotify) {
                    tid.getDialog().terminateOnBye(false);
                }
            } else if (cseq.getMethod().equals(Request.BYE)) {
                okToByeReceived = true;
            } else if (cseq.getMethod().equals(Request.CANCEL)) {
                this.cancelOkReceived = true;
            // if (tid.getDialog().getState() == DialogState.CONFIRMED) {
            // // oops cancel went in too late. Need to hang up the
            // // dialog.
            // logger.info("Sending BYE -- cancel went in too late !!");
            // Request byeRequest = dialog.createRequest(Request.BYE);
            // ClientTransaction ct = sipProvider
            // .getNewClientTransaction(byeRequest);
            // tid.getDialog().sendRequest(ct);
            // }
            } else if (cseq.getMethod().equals(Request.PUBLISH)) {
                SIPETagHeader sipTagHeader = (SIPETagHeader) response.getHeader(SIPETag.NAME);
                sipETag = sipTagHeader.getETag();
            } else if (cseq.getMethod().equals(Request.PRACK)) {
                okToPrackReceived = true;
            }
        } else if (response.getStatusCode() == Response.MOVED_TEMPORARILY) {
            // Dialog dies as soon as you get an error response.
            if (cseq.getMethod().equals(Request.INVITE)) {
                // lookup the contact header
                ContactHeader contHdr = (ContactHeader) response.getHeader(ContactHeader.NAME);
                // we can re-use the from header
                FromHeader from = ((FromHeader) response.getHeader(FromHeader.NAME));
                // we use the to-address, but without the tag
                ToHeader to = (ToHeader) (response.getHeader(ToHeader.NAME)).clone();
                to.removeParameter("tag");
                // the call-id can be re-used
                CallIdHeader callID = ((CallIdHeader) response.getHeader(CallIdHeader.NAME));
                // we take the next cseq
                long seqNo = (((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getSeqNumber());
                logger.info("seqNo = " + seqNo);
                CSeqHeader cseqNew = protocolObjects.headerFactory.createCSeqHeader(++seqNo, "INVITE");
                // Create ViaHeaders (either use tcp or udp)
                ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
                ViaHeader viaHeader = null;
                if (!isIpv6)
                    viaHeader = protocolObjects.headerFactory.createViaHeader("127.0.0.1", sipProvider.getListeningPoint(protocolObjects.transport).getPort(), protocolObjects.transport, null);
                else
                    viaHeader = protocolObjects.headerFactory.createViaHeader("::1", sipProvider.getListeningPoint(protocolObjects.transport).getPort(), protocolObjects.transport, null);
                // add via headers
                viaHeaders.add(viaHeader);
                // create max forwards
                MaxForwardsHeader maxForwardsHeader = protocolObjects.headerFactory.createMaxForwardsHeader(10);
                // create invite Request
                SipURI newUri = (SipURI) this.requestURI.clone();
                newUri.setParameter("redirection", "true");
                requestURI = newUri;
                Request invRequest = protocolObjects.messageFactory.createRequest(newUri, "INVITE", callID, cseqNew, from, to, viaHeaders, maxForwardsHeader);
                // we set the Request URI to the address given
                SipURI contactURI = protocolObjects.addressFactory.createSipURI(null, this.listeningPoint.getIPAddress());
                contactURI.setPort(this.listeningPoint.getPort());
                contactURI.setTransportParam(protocolObjects.transport);
                Address address = protocolObjects.addressFactory.createAddress(contactURI);
                ContactHeader contact = protocolObjects.headerFactory.createContactHeader(address);
                invRequest.addHeader(contact);
                // the contacat header in the response contains where to redirect
                // the request to -- which in this case happens to be back to the
                // same location.
                ContactHeader chdr = (ContactHeader) response.getHeader(ContactHeader.NAME);
                SipURI sipUri = (SipURI) chdr.getAddress().getURI();
                // sipUri.setLrParam();
                RouteHeader routeHeader = protocolObjects.headerFactory.createRouteHeader(chdr.getAddress());
                invRequest.addHeader(routeHeader);
                invRequest.setRequestURI(sipUri);
                logger.info("Sending INVITE to " + contHdr.getAddress().getURI().toString());
                inviteClientTid = sipProvider.getNewClientTransaction(invRequest);
                logger.info("New TID = " + inviteClientTid);
                inviteClientTid.sendRequest();
                logger.info("sendReqeust succeeded " + inviteClientTid);
                Dialog dialog = inviteClientTid.getDialog();
                this.dialogCount++;
                this.dialog = dialog;
            }
        } else if (response.getStatusCode() == Response.REQUEST_TERMINATED) {
            if (cseq.getMethod().equals(Request.INVITE)) {
                this.requestTerminatedReceived = true;
            }
        } else if (response.getStatusCode() == Response.RINGING && sendUpdateOn180) {
            Request updateRequest = dialog.createRequest(Request.UPDATE);
            ClientTransaction ct = sipProvider.getNewClientTransaction(updateRequest);
            dialog.sendRequest(ct);
        } else if (response.getStatusCode() > Response.TRYING && response.getStatusCode() < Response.OK) {
            RequireHeader requireHeader = (RequireHeader) response.getHeader(RequireHeader.NAME);
            if (requireHeader != null && "100rel".equalsIgnoreCase(requireHeader.getOptionTag().trim())) {
                Request prack = dialog.createPrack(response);
                ClientTransaction ct = sipProvider.getNewClientTransaction(prack);
                dialog.sendRequest(ct);
                prackSent = true;
            }
        }
    /**
     * end of modified code
     */
    } catch (Exception ex) {
        logger.error("An unexpected exception occured while processing the response", ex);
    }
}
Also used : MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ContactHeader(javax.sip.header.ContactHeader) RouteHeader(javax.sip.header.RouteHeader) RecordRouteHeader(javax.sip.header.RecordRouteHeader) Address(javax.sip.address.Address) FromHeader(javax.sip.header.FromHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) ArrayList(java.util.ArrayList) RecordRouteHeader(javax.sip.header.RecordRouteHeader) 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) CSeqHeader(javax.sip.header.CSeqHeader) 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) SIPETagHeader(javax.sip.header.SIPETagHeader) ViaHeader(javax.sip.header.ViaHeader) Dialog(javax.sip.Dialog) ReferToHeader(javax.sip.header.ReferToHeader) ToHeader(javax.sip.header.ToHeader) CallIdHeader(javax.sip.header.CallIdHeader)

Example 12 with Address

use of javax.sip.address.Address in project load-balancer by RestComm.

the class TestSipListener method createInvite.

public Request createInvite(String callId, long cseq) throws ParseException, InvalidArgumentException {
    String fromName = "BigGuy";
    String fromSipAddress = "here.com";
    String fromDisplayName = "The Master Blaster";
    String toSipAddress = "there.com";
    String toUser = "LittleGuy";
    String toDisplayName = "The Little Blister";
    // create >From Header
    SipURI fromAddress = protocolObjects.addressFactory.createSipURI(fromName, fromSipAddress);
    Address fromNameAddress = protocolObjects.addressFactory.createAddress(fromAddress);
    fromNameAddress.setDisplayName(fromDisplayName);
    FromHeader fromHeader = protocolObjects.headerFactory.createFromHeader(fromNameAddress, "12345");
    // create To Header
    SipURI toAddress = protocolObjects.addressFactory.createSipURI(toUser, toSipAddress);
    Address toNameAddress = protocolObjects.addressFactory.createAddress(toAddress);
    toNameAddress.setDisplayName(toDisplayName);
    ToHeader toHeader = protocolObjects.headerFactory.createToHeader(toNameAddress, null);
    // create Request URI
    SipURI requestURI = protocolObjects.addressFactory.createSipURI(toUser, peerHostPort);
    // Create ViaHeaders
    ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
    ViaHeader viaHeader = null;
    if (!isIpv6)
        viaHeader = protocolObjects.headerFactory.createViaHeader("127.0.0.1", listeningPoint.getPort(), listeningPoint.getTransport(), null);
    else
        viaHeader = protocolObjects.headerFactory.createViaHeader("::1", listeningPoint.getPort(), listeningPoint.getTransport(), null);
    // add via headers
    viaHeaders.add(viaHeader);
    // Create ContentTypeHeader
    ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory.createContentTypeHeader("application", "sdp");
    // Create a new CallId header
    CallIdHeader callIdHeader;
    callIdHeader = sipProvider.getNewCallId();
    if (callId.trim().length() > 0)
        callIdHeader.setCallId(callId);
    // Create a new Cseq header
    CSeqHeader cSeqHeader = protocolObjects.headerFactory.createCSeqHeader(cseq, Request.INVITE);
    // Create a new MaxForwardsHeader
    MaxForwardsHeader maxForwards = protocolObjects.headerFactory.createMaxForwardsHeader(70);
    // Create the request.
    Request request = protocolObjects.messageFactory.createRequest(requestURI, Request.INVITE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
    // Create contact headers
    String host = null;
    if (!isIpv6)
        host = "127.0.0.1";
    else
        host = "::1";
    SipURI contactUrl = protocolObjects.addressFactory.createSipURI(fromName, host);
    contactUrl.setPort(listeningPoint.getPort());
    // Create the contact name address.
    SipURI contactURI = protocolObjects.addressFactory.createSipURI(fromName, host);
    contactURI.setPort(listeningPoint.getPort());
    Address contactAddress = protocolObjects.addressFactory.createAddress(contactURI);
    // Add the contact address.
    contactAddress.setDisplayName(fromName);
    contactHeader = protocolObjects.headerFactory.createContactHeader(contactAddress);
    request.addHeader(contactHeader);
    String sdpData = "v=0\r\n" + "o=4855 13760799956958020 13760799956958020" + " IN IP4  129.6.55.78\r\n" + "s=mysession session\r\n" + "p=+46 8 52018010\r\n" + "c=IN IP4  129.6.55.78\r\n" + "t=0 0\r\n" + "m=audio 6022 RTP/AVP 0 4 18\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:4 G723/8000\r\n" + "a=rtpmap:18 G729A/8000\r\n" + "a=ptime:20\r\n";
    byte[] contents = sdpData.getBytes();
    request.setContent(contents, contentTypeHeader);
    Header callInfoHeader = protocolObjects.headerFactory.createHeader("Call-Info", "<http://www.antd.nist.gov>");
    request.addHeader(callInfoHeader);
    return request;
}
Also used : MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) Address(javax.sip.address.Address) FromHeader(javax.sip.header.FromHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ArrayList(java.util.ArrayList) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI) CSeqHeader(javax.sip.header.CSeqHeader) 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) ReferToHeader(javax.sip.header.ReferToHeader) ToHeader(javax.sip.header.ToHeader) CallIdHeader(javax.sip.header.CallIdHeader)

Example 13 with Address

use of javax.sip.address.Address in project load-balancer by RestComm.

the class Shootist method sendInitial.

public void sendInitial(String fromUser, String fromHost, String method, RouteHeader route, String[] headerNames, String[] headerContents) {
    try {
        if (!started)
            start();
        String fromName = fromUser;
        String fromSipAddress = fromHost;
        String fromDisplayName = "The Master Blaster";
        String toSipAddress = "there.com";
        String toUser = "LittleGuy";
        String toDisplayName = "The Little Blister";
        // create >From Header
        SipURI fromAddress = addressFactory.createSipURI(fromName, fromSipAddress);
        Address fromNameAddress = addressFactory.createAddress(fromAddress);
        fromNameAddress.setDisplayName(fromDisplayName);
        FromHeader fromHeader = headerFactory.createFromHeader(fromNameAddress, "12345");
        // create To Header
        SipURI toAddress = addressFactory.createSipURI(toUser, toSipAddress);
        Address toNameAddress = addressFactory.createAddress(toAddress);
        toNameAddress.setDisplayName(toDisplayName);
        ToHeader toHeader = headerFactory.createToHeader(toNameAddress, null);
        // create Request URI
        SipURI requestURI = addressFactory.createSipURI(toUser, peerHostPort);
        // Create ViaHeaders
        ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
        String ipAddress = null;
        if (fromUser.equals("KostyaNosach"))
            ipAddress = "127.0.0.2";
        else
            ipAddress = listeningPoint.getIPAddress();
        ViaHeader viaHeader = headerFactory.createViaHeader(ipAddress, sipProvider.getListeningPoint(transport).getPort(), transport, null);
        // add via headers
        viaHeaders.add(viaHeader);
        // Create ContentTypeHeader
        ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "sdp");
        // Create a new CallId header
        CallIdHeader callIdHeader = sipProvider.getNewCallId();
        // Create a new Cseq header
        CSeqHeader cSeqHeader = headerFactory.createCSeqHeader(1L, method);
        // Create a new MaxForwardsHeader
        MaxForwardsHeader maxForwards = headerFactory.createMaxForwardsHeader(70);
        // Create the request.
        Request request = messageFactory.createRequest(requestURI, method, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
        // Create contact headers
        String host = localIPAddress;
        SipURI contactUrl = addressFactory.createSipURI(fromName, host);
        contactUrl.setPort(listeningPoint.getPort());
        contactUrl.setLrParam();
        // Create the contact name address.
        SipURI contactURI = addressFactory.createSipURI(fromName, host);
        contactURI.setPort(sipProvider.getListeningPoint(transport).getPort());
        Address contactAddress = addressFactory.createAddress(contactURI);
        // Add the contact address.
        contactAddress.setDisplayName(fromName);
        contactHeader = headerFactory.createContactHeader(contactAddress);
        request.addHeader(contactHeader);
        // to the outgoing SIP request.
        // Add the extension header.
        Header extensionHeader = headerFactory.createHeader("My-Header", "my header value");
        request.addHeader(extensionHeader);
        if (headerNames != null) {
            for (int q = 0; q < headerNames.length; q++) {
                Header h = headerFactory.createHeader(headerNames[q], headerContents[q]);
                // if(setHeader) {
                request.setHeader(h);
            // } else {
            // request.addHeader(h);
            // }
            }
        }
        if (route != null)
            request.addHeader(route);
        String sdpData = "v=0\r\n" + "o=4855 13760799956958020 13760799956958020" + " IN IP4  129.6.55.78\r\n" + "s=mysession session\r\n" + "p=+46 8 52018010\r\n" + "c=IN IP4  129.6.55.78\r\n" + "t=0 0\r\n" + "m=audio 6022 RTP/AVP 0 4 18\r\n" + "a=rtpmap:0 PCMU/8000\r\n" + "a=rtpmap:4 G723/8000\r\n" + "a=rtpmap:18 G729A/8000\r\n" + "a=ptime:20\r\n";
        byte[] contents = sdpData.getBytes();
        request.setContent(contents, contentTypeHeader);
        // You can add as many extension headers as you
        // want.
        extensionHeader = headerFactory.createHeader("My-Other-Header", "my new header value ");
        request.addHeader(extensionHeader);
        Header callInfoHeader = headerFactory.createHeader("Call-Info", "<http://www.antd.nist.gov>");
        request.addHeader(callInfoHeader);
        // Create the client transaction.
        inviteTid = sipProvider.getNewClientTransaction(request);
        // send the request out.
        inviteTid.sendRequest();
        dialog = inviteTid.getDialog();
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
        ex.printStackTrace();
        fail("Unxpected exception ");
    }
}
Also used : MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) Address(javax.sip.address.Address) FromHeader(javax.sip.header.FromHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ArrayList(java.util.ArrayList) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI) ListeningPoint(javax.sip.ListeningPoint) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) TransactionAlreadyExistsException(javax.sip.TransactionAlreadyExistsException) PeerUnavailableException(javax.sip.PeerUnavailableException) SipException(javax.sip.SipException) TransactionUnavailableException(javax.sip.TransactionUnavailableException) CSeqHeader(javax.sip.header.CSeqHeader) ContactHeader(javax.sip.header.ContactHeader) ViaHeader(javax.sip.header.ViaHeader) CallIdHeader(javax.sip.header.CallIdHeader) Header(javax.sip.header.Header) CSeqHeader(javax.sip.header.CSeqHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ToHeader(javax.sip.header.ToHeader) RouteHeader(javax.sip.header.RouteHeader) FromHeader(javax.sip.header.FromHeader) ViaHeader(javax.sip.header.ViaHeader) ToHeader(javax.sip.header.ToHeader) CallIdHeader(javax.sip.header.CallIdHeader)

Example 14 with Address

use of javax.sip.address.Address in project load-balancer by RestComm.

the class TestSipListener method sendSipRequest.

public Request sendSipRequest(String method, URI fromURI, URI toURI, String messageContent, SipURI route, boolean useToURIasRequestUri, String[] headerNames, String[] headerContents, boolean setHeader) throws SipException, ParseException, InvalidArgumentException {
    this.useToURIasRequestUri = useToURIasRequestUri;
    // create >From Header
    Address fromNameAddress = protocolObjects.addressFactory.createAddress(fromURI);
    FromHeader fromHeader = protocolObjects.headerFactory.createFromHeader(fromNameAddress, Integer.toString(new Random().nextInt(10000000)));
    // create To Header
    Address toNameAddress = protocolObjects.addressFactory.createAddress(toURI);
    ToHeader toHeader = protocolObjects.headerFactory.createToHeader(toNameAddress, null);
    if (toURI instanceof SipURI) {
        SipURI toSipUri = (SipURI) toURI;
        // create Request URI
        this.requestURI = protocolObjects.addressFactory.createSipURI(toSipUri.getUser(), peerHostPort);
        ((SipURI) this.requestURI).setPort(peerPort);
        if (setTransport) {
            ((SipURI) this.requestURI).setTransportParam(listeningPoint.getTransport());
        }
    }
    if (useToURIasRequestUri || toURI instanceof TelURL) {
        this.requestURI = toURI;
    }
    // Create ViaHeaders
    List<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
    ViaHeader viaHeader = null;
    if (!isIpv6)
        viaHeader = protocolObjects.headerFactory.createViaHeader("127.0.0.1", sipProvider.getListeningPoint(protocolObjects.transport).getPort(), listeningPoint.getTransport(), null);
    else
        viaHeader = protocolObjects.headerFactory.createViaHeader("::1", sipProvider.getListeningPoint(protocolObjects.transport).getPort(), listeningPoint.getTransport(), null);
    // add via headers
    viaHeaders.add(viaHeader);
    // Create ContentTypeHeader
    // ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory
    // .createContentTypeHeader("application", "sdp");
    // Create a new CallId header
    CallIdHeader callIdHeader = sipProvider.getNewCallId();
    // Create a new Cseq header
    CSeqHeader cSeqHeader = protocolObjects.headerFactory.createCSeqHeader(1L, method);
    // Create a new MaxForwardsHeader
    MaxForwardsHeader maxForwards = protocolObjects.headerFactory.createMaxForwardsHeader(70);
    // Create the request.
    Request request = protocolObjects.messageFactory.createRequest(requestURI, method, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
    // Create contact headers
    String host = null;
    if (!isIpv6)
        host = "127.0.0.1";
    else
        host = "::1";
    URI contactUrl = null;
    if (fromURI instanceof SipURI) {
        contactUrl = protocolObjects.addressFactory.createSipURI(((SipURI) fromURI).getUser(), host);
        /**
         * either use tcp or udp
         */
        ((SipURI) contactUrl).setPort(listeningPoint.getPort());
        if (setTransport) {
            ((SipURI) contactUrl).setTransportParam(listeningPoint.getTransport());
            ((SipURI) contactUrl).setLrParam();
        }
    } else {
        contactUrl = fromURI;
    }
    // Create the contact name address.
    Address contactAddress = protocolObjects.addressFactory.createAddress(contactUrl);
    // Add the contact address.
    // contactAddress.setDisplayName(fromName);
    contactHeader = protocolObjects.headerFactory.createContactHeader(contactAddress);
    request.addHeader(contactHeader);
    SipURI uri = null;
    if (!isIpv6)
        uri = protocolObjects.addressFactory.createSipURI(null, "127.0.0.1");
    else
        uri = protocolObjects.addressFactory.createSipURI(null, "::1");
    uri.setLrParam();
    uri.setTransportParam(protocolObjects.transport);
    uri.setPort(this.peerPort);
    if (route != null) {
        Address address = protocolObjects.addressFactory.createAddress(route);
        RouteHeader routeHeader = protocolObjects.headerFactory.createRouteHeader(address);
        request.addHeader(routeHeader);
    } else if (useDefaultRoute) {
        Address address = protocolObjects.addressFactory.createAddress(uri);
        RouteHeader routeHeader = protocolObjects.headerFactory.createRouteHeader(address);
        request.addHeader(routeHeader);
    }
    // set the message content
    if (messageContent != null) {
        ContentLengthHeader contentLengthHeader = protocolObjects.headerFactory.createContentLengthHeader(messageContent.length());
        ContentTypeHeader contentTypeHeader = protocolObjects.headerFactory.createContentTypeHeader(TEXT_CONTENT_TYPE, PLAIN_UTF8_CONTENT_SUBTYPE);
        byte[] contents = messageContent.getBytes();
        request.setContent(contents, contentTypeHeader);
        request.setContentLength(contentLengthHeader);
    }
    if (headerNames != null) {
        for (int q = 0; q < headerNames.length; q++) {
            Header h = protocolObjects.headerFactory.createHeader(headerNames[q], headerContents[q]);
            if (setHeader) {
                request.setHeader(h);
            } else {
                request.addHeader(h);
            }
        }
    }
    addSpecificHeaders(method, request);
    // Create the client transaction.
    inviteClientTid = sipProvider.getNewClientTransaction(request);
    // send the request out.
    inviteClientTid.sendRequest();
    logger.info("client tx = " + inviteClientTid);
    if (!Request.MESSAGE.equalsIgnoreCase(method)) {
        dialog = inviteClientTid.getDialog();
    }
    if (Request.INVITE.equalsIgnoreCase(method)) {
        inviteRequest = request;
    }
    this.dialogCount++;
    return inviteRequest;
}
Also used : MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) RouteHeader(javax.sip.header.RouteHeader) RecordRouteHeader(javax.sip.header.RecordRouteHeader) Address(javax.sip.address.Address) FromHeader(javax.sip.header.FromHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ArrayList(java.util.ArrayList) Request(javax.sip.message.Request) ContentLengthHeader(javax.sip.header.ContentLengthHeader) SipURI(javax.sip.address.SipURI) TelURL(javax.sip.address.TelURL) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI) ListeningPoint(javax.sip.ListeningPoint) CSeqHeader(javax.sip.header.CSeqHeader) Random(java.util.Random) 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) ReferToHeader(javax.sip.header.ReferToHeader) ToHeader(javax.sip.header.ToHeader) CallIdHeader(javax.sip.header.CallIdHeader)

Example 15 with Address

use of javax.sip.address.Address in project camel by apache.

the class SipConfiguration method createToHeader.

private void createToHeader() throws ParseException {
    SipURI toAddress = getAddressFactory().createSipURI(getToUser(), getToHost());
    toAddress.setPort(getToPort());
    Address toNameAddress = addressFactory.createAddress(toAddress);
    toNameAddress.setDisplayName(getToUser());
    setToHeader(headerFactory.createToHeader(toNameAddress, getToUser() + "_Header"));
}
Also used : Address(javax.sip.address.Address) SipURI(javax.sip.address.SipURI)

Aggregations

Address (javax.sip.address.Address)24 SipURI (javax.sip.address.SipURI)22 Request (javax.sip.message.Request)12 ParseException (java.text.ParseException)11 ContactHeader (javax.sip.header.ContactHeader)9 FromHeader (javax.sip.header.FromHeader)9 SipException (javax.sip.SipException)8 ToHeader (javax.sip.header.ToHeader)8 ViaHeader (javax.sip.header.ViaHeader)8 InvalidArgumentException (javax.sip.InvalidArgumentException)7 CSeqHeader (javax.sip.header.CSeqHeader)7 CallIdHeader (javax.sip.header.CallIdHeader)7 MaxForwardsHeader (javax.sip.header.MaxForwardsHeader)7 SubscriptionStateHeader (javax.sip.header.SubscriptionStateHeader)7 InetAddress (java.net.InetAddress)6 ArrayList (java.util.ArrayList)6 ContentTypeHeader (javax.sip.header.ContentTypeHeader)6 Header (javax.sip.header.Header)6 EventHeader (javax.sip.header.EventHeader)5 ExpiresHeader (javax.sip.header.ExpiresHeader)5