Search in sources :

Example 21 with ViaHeader

use of javax.sip.header.ViaHeader in project Spark by igniterealtime.

the class RegisterProcessing method subscribe.

/**
 * Synchronize because of timer tasks
 *
 * @throws CommunicationsException
 */
synchronized void subscribe(String registrarAddress, int registrarPort, String registrarTransport) throws CommunicationsException {
    FromHeader fromHeader = sipManCallback.getFromHeader(true);
    Address fromAddress = fromHeader.getAddress();
    // Request URI
    URI requestURI = null;
    try {
        requestURI = sipManCallback.addressFactory.createSipURI(sipManCallback.getCurrentUsername(), registrarAddress);
    } catch (ParseException e) {
        Log.error(e);
    }
    // Call ID Header
    CallIdHeader callIdHeader = sipManCallback.sipProvider.getNewCallId();
    // CSeq Header
    CSeqHeader cSeqHeader = null;
    try {
        cSeqHeader = sipManCallback.headerFactory.createCSeqHeader((long) 1, Request.SUBSCRIBE);
    } catch (ParseException ex) {
        // Should never happen
        Log.error("register", ex);
    } catch (InvalidArgumentException ex) {
        // Should never happen
        Log.error("register", ex);
    }
    // To Header
    ToHeader toHeader = null;
    try {
        toHeader = sipManCallback.headerFactory.createToHeader(fromAddress, null);
    } catch (ParseException ex) {
        // throw was missing - reported by Eero Vaarnas
        throw new CommunicationsException("Could not create a To header " + "for address:" + fromHeader.getAddress(), ex);
    }
    // User Agent Header
    UserAgentHeader uaHeader = null;
    ArrayList<String> userAgentList = new ArrayList<String>();
    userAgentList.add(SoftPhoneManager.userAgent);
    try {
        uaHeader = sipManCallback.headerFactory.createUserAgentHeader(userAgentList);
    } catch (ParseException ex) {
        // throw was missing - reported by Eero Vaarnas
        throw new CommunicationsException("Could not create a To header " + "for address:" + fromHeader.getAddress(), ex);
    }
    // Via Headers
    ArrayList<ViaHeader> viaHeaders = sipManCallback.getLocalViaHeaders();
    // MaxForwardsHeader
    MaxForwardsHeader maxForwardsHeader = sipManCallback.getMaxForwardsHeader();
    // Request
    Request request = null;
    try {
        request = sipManCallback.messageFactory.createRequest(requestURI, Request.SUBSCRIBE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwardsHeader);
        request.setHeader(uaHeader);
    } catch (ParseException ex) {
        throw new CommunicationsException("Could not create the register request!", ex);
    }
    // Expires Header
    ExpiresHeader expHeader = null;
    try {
        expHeader = sipManCallback.headerFactory.createExpiresHeader(3000);
    } catch (InvalidArgumentException ex) {
    }
    request.addHeader(expHeader);
    try {
        EventHeader event = sipManCallback.headerFactory.createEventHeader("message-summary");
        request.addHeader(event);
    } catch (ParseException e) {
        Log.error(e);
    }
    // Contact Header should contain IP - bug report - Eero Vaarnas
    ContactHeader contactHeader = sipManCallback.getRegistrationContactHeader();
    request.addHeader(contactHeader);
    AllowHeader allow = null;
    try {
        allow = sipManCallback.headerFactory.createAllowHeader("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
        request.addHeader(allow);
    } catch (ParseException e) {
        Log.error(e);
    }
    // Transaction
    ClientTransaction regTrans = null;
    try {
        regTrans = sipManCallback.sipProvider.getNewClientTransaction(request);
    } catch (TransactionUnavailableException ex) {
        throw new CommunicationsException("Could not create a register transaction!\n" + "Check that the Registrar address is correct!");
    }
    try {
        regTrans.sendRequest();
    }// we sometimes get a null pointer exception here so catch them all
     catch (Exception ex) {
        // throw was missing - reported by Eero Vaarnas
        throw new CommunicationsException("Could not send out the register request!", ex);
    }
}
Also used : MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ContactHeader(javax.sip.header.ContactHeader) Address(javax.sip.address.Address) FromHeader(javax.sip.header.FromHeader) ClientTransaction(javax.sip.ClientTransaction) ArrayList(java.util.ArrayList) Request(javax.sip.message.Request) EventHeader(javax.sip.header.EventHeader) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI) SipSecurityException(net.java.sipmack.sip.security.SipSecurityException) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) SipException(javax.sip.SipException) TransactionUnavailableException(javax.sip.TransactionUnavailableException) CSeqHeader(javax.sip.header.CSeqHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) UserAgentHeader(javax.sip.header.UserAgentHeader) ViaHeader(javax.sip.header.ViaHeader) ToHeader(javax.sip.header.ToHeader) CallIdHeader(javax.sip.header.CallIdHeader) TransactionUnavailableException(javax.sip.TransactionUnavailableException) ParseException(java.text.ParseException) ExpiresHeader(javax.sip.header.ExpiresHeader) AllowHeader(javax.sip.header.AllowHeader)

Example 22 with ViaHeader

use of javax.sip.header.ViaHeader in project Spark by igniterealtime.

the class SipManager method getLocalViaHeaders.

/**
 * Initializes (if null) and returns an ArrayList with a single ViaHeader
 * containing localhost's address. This ArrayList may be used when sending
 * requests.
 *
 * @return ViaHeader-s list to be used when sending requests.
 * @throws CommunicationsException if a ParseException is to occur while initializing the array
 *                                 list.
 */
public ArrayList<ViaHeader> getLocalViaHeaders() throws CommunicationsException {
    ListeningPoint lp = sipProvider.getListeningPoints()[0];
    viaHeaders = new ArrayList<ViaHeader>();
    try {
        ViaHeader viaHeader = headerFactory.createViaHeader(SIPConfig.getIPAddress(), lp.getPort(), lp.getTransport(), null);
        viaHeader.setParameter("rport", null);
        viaHeaders.add(viaHeader);
        return viaHeaders;
    } catch (ParseException ex) {
        throw new CommunicationsException("A ParseException occurred while creating Via Headers!");
    } catch (InvalidArgumentException ex) {
        throw new CommunicationsException("Unable to create a via header for port " + lp.getPort(), ex);
    }
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException) ViaHeader(javax.sip.header.ViaHeader) ListeningPoint(javax.sip.ListeningPoint) ParseException(java.text.ParseException)

Example 23 with ViaHeader

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

the class SipHelper method sendReinvite.

public ClientTransaction sendReinvite(Dialog dialog, String sessionDescription) throws SipException {
    try {
        Request request = dialog.createRequest(Request.INVITE);
        request.setContent(sessionDescription, mHeaderFactory.createContentTypeHeader("application", "sdp"));
        // Adding rport argument in the request could fix some SIP servers
        // in resolving the initiator's NAT port mapping for relaying the
        // response message from the other end.
        ViaHeader viaHeader = (ViaHeader) request.getHeader(ViaHeader.NAME);
        if (viaHeader != null)
            viaHeader.setRPort();
        ClientTransaction clientTransaction = mSipProvider.getNewClientTransaction(request);
        if (DEBUG)
            Log.d(TAG, "send RE-INVITE: " + request);
        dialog.sendRequest(clientTransaction);
        return clientTransaction;
    } catch (ParseException e) {
        throw new SipException("sendReinvite()", e);
    }
}
Also used : ViaHeader(javax.sip.header.ViaHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) ParseException(java.text.ParseException) SipException(javax.sip.SipException)

Example 24 with ViaHeader

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

the class SipHelper method createRequest.

private Request createRequest(String requestType, SipProfile caller, SipProfile callee, String tag) throws ParseException, SipException {
    FromHeader fromHeader = createFromHeader(caller, tag);
    ToHeader toHeader = createToHeader(callee);
    SipURI requestURI = callee.getUri();
    List<ViaHeader> viaHeaders = createViaHeaders();
    CallIdHeader callIdHeader = createCallIdHeader();
    CSeqHeader cSeqHeader = createCSeqHeader(requestType);
    MaxForwardsHeader maxForwards = createMaxForwardsHeader();
    Request request = mMessageFactory.createRequest(requestURI, requestType, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
    request.addHeader(createContactHeader(caller));
    return request;
}
Also used : CSeqHeader(javax.sip.header.CSeqHeader) MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ViaHeader(javax.sip.header.ViaHeader) FromHeader(javax.sip.header.FromHeader) ToHeader(javax.sip.header.ToHeader) Request(javax.sip.message.Request) CallIdHeader(javax.sip.header.CallIdHeader) SipURI(javax.sip.address.SipURI)

Example 25 with ViaHeader

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

the class BackToBackUserAgent method processRequest.

public void processRequest(RequestEvent requestEvent) {
    try {
        Request request = requestEvent.getRequest();
        if (request.getMethod().equals(Request.INVITE)) {
            ServerTransaction st = sp.getNewServerTransaction(requestEvent.getRequest());
            incomingDialog = st.getDialog();
            try {
                replyToRequestEvent(requestEvent.getRequest(), st, Response.TRYING);
                Request newRequest = (Request) request.clone();
                newRequest.removeHeader(RouteHeader.NAME);
                newRequest.removeHeader(RecordRouteHeader.NAME);
                FromHeader fromHeader = (FromHeader) newRequest.getHeader(FromHeader.NAME);
                fromHeader.setTag(Long.toString(Math.abs(new Random().nextLong())));
                ViaHeader viaHeader = ((ListeningPointExt) sp.getListeningPoint(transport)).createViaHeader();
                newRequest.setHeader(viaHeader);
                ContactHeader contactHeader = ((ListeningPointExt) sp.getListeningPoint(transport)).createContactHeader();
                newRequest.setHeader(contactHeader);
                SipURI route = this.protocolObjects.addressFactory.createSipURI("lbint", lbAddress + ":" + lbPort);
                route.setParameter("node_host", "127.0.0.1");
                route.setParameter("node_port", "" + port);
                route.setLrParam();
                RouteHeader routeHeader = (RouteHeader) this.protocolObjects.headerFactory.createRouteHeader(this.protocolObjects.addressFactory.createAddress(route));
                newRequest.setHeader(routeHeader);
                clientTransaction = sp.getNewClientTransaction(newRequest);
                outgoingDialog = clientTransaction.getDialog();
                clientTransaction.setApplicationData(st);
                clientTransaction.sendRequest();
            } catch (Throwable e) {
                e.printStackTrace();
                replyToRequestEvent(request, st, Response.SERVICE_UNAVAILABLE);
            }
        } else if (request.getMethod().equals(Request.BYE)) {
            ServerTransaction st = requestEvent.getServerTransaction();
            replyToRequestEvent(requestEvent.getRequest(), st, Response.OK);
            Dialog peerDialog = getPeerDialog(requestEvent.getDialog());
            Request outgoingRequest = peerDialog.createRequest(requestEvent.getRequest().getMethod());
            final ClientTransaction ct = sp.getNewClientTransaction(outgoingRequest);
            peerDialog.sendRequest(ct);
        } else if (request.getMethod().equals(Request.CANCEL)) {
            try {
                final Dialog peerDialog = outgoingDialog;
                final DialogState peerDialogState = peerDialog.getState();
                if (peerDialogState == null || peerDialogState == DialogState.EARLY) {
                    Request cancelRequest = clientTransaction.createCancel();
                    sp.sendRequest(cancelRequest);
                } else {
                    clientTransaction = sp.getNewClientTransaction(peerDialog.createRequest(Request.BYE));
                    clientTransaction.sendRequest();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : ContactHeader(javax.sip.header.ContactHeader) RouteHeader(javax.sip.header.RouteHeader) RecordRouteHeader(javax.sip.header.RecordRouteHeader) DialogState(javax.sip.DialogState) FromHeader(javax.sip.header.FromHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) SipException(javax.sip.SipException) ListeningPointExt(gov.nist.javax.sip.ListeningPointExt) Random(java.util.Random) ViaHeader(javax.sip.header.ViaHeader) Dialog(javax.sip.Dialog) ServerTransaction(javax.sip.ServerTransaction)

Aggregations

ViaHeader (javax.sip.header.ViaHeader)40 Request (javax.sip.message.Request)24 ParseException (java.text.ParseException)23 SipURI (javax.sip.address.SipURI)23 FromHeader (javax.sip.header.FromHeader)23 ToHeader (javax.sip.header.ToHeader)23 CallIdHeader (javax.sip.header.CallIdHeader)21 ContactHeader (javax.sip.header.ContactHeader)20 MaxForwardsHeader (javax.sip.header.MaxForwardsHeader)20 SipException (javax.sip.SipException)19 InvalidArgumentException (javax.sip.InvalidArgumentException)18 CSeqHeader (javax.sip.header.CSeqHeader)18 RouteHeader (javax.sip.header.RouteHeader)15 TransactionUnavailableException (javax.sip.TransactionUnavailableException)14 Address (javax.sip.address.Address)14 ContentTypeHeader (javax.sip.header.ContentTypeHeader)14 Header (javax.sip.header.Header)14 ListeningPoint (javax.sip.ListeningPoint)13 RecordRouteHeader (javax.sip.header.RecordRouteHeader)13 ClientTransaction (javax.sip.ClientTransaction)12