Search in sources :

Example 1 with AllowHeader

use of javax.sip.header.AllowHeader 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 2 with AllowHeader

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

the class CallProcessing method sayBye.

// send message
// private void sendInfoMessage(Dialog dialog, String body)
// throws CommunicationsException {
// Request request = dialog.getFirstTransaction().getRequest();
// Request info = null;
// String contentType = "application/dtmd-relay";
// String[] contentTypeTab = contentType.split("/");
// ContentTypeHeader contentTypeHeader = null;
// try {
// info = dialog.createRequest(Request.INFO);
// try {
// contentTypeHeader = sipManCallback.headerFactory
// .createContentTypeHeader(contentTypeTab[0],
// contentTypeTab[1]);
// info.setContent(body, contentTypeHeader);
// }
// catch (ParseException ex) {
// 
// throw new CommunicationsException(
// "ContentType Header must look like type/subtype!",
// ex);
// }
// }
// catch (SipException ex) {
// 
// throw new CommunicationsException(
// "Failed to create bye request!", ex);
// }
// ClientTransaction clientTransaction = null;
// try {
// clientTransaction = sipManCallback.sipProvider
// .getNewClientTransaction(info);
// }
// catch (TransactionUnavailableException ex) {
// 
// throw new CommunicationsException(
// "Failed to construct a client transaction from the INFO request",
// ex);
// }
// try {
// dialog.sendRequest(clientTransaction);
// }
// catch (SipException ex1) {
// throw new CommunicationsException(
// "Failed to send the INFO request");
// }
// 
// } // send message
// Bye
private void sayBye(Dialog dialog) throws CommunicationsException {
    Request bye = null;
    bye = dialog.getFirstTransaction().getRequest();
    try {
        bye = dialog.createRequest(Request.BYE);
    } catch (SipException e) {
        Log.error("bye", e);
    }
    long cseq = ((CSeq) (bye.getHeader(CSeq.NAME))).getSequenceNumber() + 1;
    bye.removeHeader(CSeq.NAME);
    try {
        bye.addHeader(sipManCallback.headerFactory.createCSeqHeader(cseq, Request.BYE));
    } catch (Exception e) {
        Log.error("bye", e);
    }
    bye.removeHeader(ViaHeader.NAME);
    for (ViaHeader via : sipManCallback.getLocalViaHeaders()) bye.addHeader(via);
    ContactHeader contactHeader = sipManCallback.getContactHeader();
    bye.addHeader(contactHeader);
    AllowHeader allow = null;
    try {
        allow = sipManCallback.headerFactory.createAllowHeader("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
        bye.addHeader(allow);
    } catch (ParseException e) {
        Log.error(e);
    }
    // Transaction
    ClientTransaction inviteTransaction;
    try {
        inviteTransaction = sipManCallback.sipProvider.getNewClientTransaction(bye);
        dialog.sendRequest(inviteTransaction);
    } catch (SipException ee) {
        Log.error("bye", ee);
    }
    return;
}
Also used : ContactHeader(javax.sip.header.ContactHeader) ViaHeader(javax.sip.header.ViaHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) AllowHeader(javax.sip.header.AllowHeader) ParseException(java.text.ParseException) SipException(javax.sip.SipException) SipSecurityException(net.java.sipmack.sip.security.SipSecurityException) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) SipException(javax.sip.SipException) TransactionUnavailableException(javax.sip.TransactionUnavailableException)

Example 3 with AllowHeader

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

the class CallProcessing method invite.

// -------------------------------- User Initiated processing
// ---------------------------------
Call invite(String callee, String sdpContent) throws CommunicationsException {
    callee = callee.trim();
    // Remove excessive characters from phone numbers such as '
    // ','(',')','-'
    String excessiveChars = SIPConfig.getExcessiveURIChar();
    if (excessiveChars != null) {
        StringBuffer calleeBuff = new StringBuffer(callee);
        for (int i = 0; i < excessiveChars.length(); i++) {
            String charToDeleteStr = excessiveChars.substring(i, i + 1);
            int charIndex = -1;
            while ((charIndex = calleeBuff.indexOf(charToDeleteStr)) != -1) calleeBuff.delete(charIndex, charIndex + 1);
        }
        callee = calleeBuff.toString();
    }
    // Handle default domain name (i.e. transform 1234 -> 1234@sip.com
    String defaultDomainName = SIPConfig.getDefaultDomain();
    if (// no sip scheme
    defaultDomainName != null && !callee.trim().startsWith("tel:") && // most probably a sip uri
    callee.indexOf('@') == -1) {
        callee = callee + "@" + defaultDomainName;
    }
    // Let's be uri fault tolerant
    if (// no sip scheme
    callee.toLowerCase().indexOf("sip:") == -1 && // most probably a sip uri
    callee.indexOf('@') != -1) {
        callee = "sip:" + callee;
    }
    // Request URI
    URI requestURI;
    try {
        requestURI = sipManCallback.addressFactory.createURI(callee);
    } catch (ParseException ex) {
        throw new CommunicationsException(callee + " is not a legal SIP uri!", ex);
    }
    // Call ID
    CallIdHeader callIdHeader = sipManCallback.sipProvider.getNewCallId();
    // CSeq
    CSeqHeader cSeqHeader;
    try {
        cSeqHeader = sipManCallback.headerFactory.createCSeqHeader(1L, Request.INVITE);
    } catch (ParseException ex) {
        throw new CommunicationsException("An unexpected erro occurred while" + "constructing the CSeqHeadder", ex);
    } catch (InvalidArgumentException ex) {
        // Shouldn't happen
        throw new CommunicationsException("An unexpected erro occurred while" + "constructing the CSeqHeadder", ex);
    }
    // FromHeader
    FromHeader fromHeader = sipManCallback.getFromHeader();
    // ToHeader
    Address toAddress = sipManCallback.addressFactory.createAddress(requestURI);
    ToHeader toHeader;
    try {
        toHeader = sipManCallback.headerFactory.createToHeader(toAddress, null);
    } catch (ParseException ex) {
        // Shouldn't happen
        throw new CommunicationsException("Null is not an allowed tag for the to header!", ex);
    }
    // ViaHeaders
    ArrayList<ViaHeader> viaHeaders = sipManCallback.getLocalViaHeaders();
    // MaxForwards
    MaxForwardsHeader maxForwards = sipManCallback.getMaxForwardsHeader();
    // Contact
    ContactHeader contactHeader = sipManCallback.getContactHeader();
    Request invite = null;
    try {
        invite = sipManCallback.messageFactory.createRequest(requestURI, Request.INVITE, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwards);
    } catch (ParseException ex) {
        throw new CommunicationsException("Failed to create invite Request!", ex);
    }
    // 
    invite.addHeader(contactHeader);
    AllowHeader allow = null;
    try {
        allow = sipManCallback.headerFactory.createAllowHeader("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
        invite.addHeader(allow);
    } catch (ParseException e) {
        Log.error(e);
    }
    // Content
    ContentTypeHeader contentTypeHeader = null;
    try {
        // content type should be application/sdp (not applications)
        // reported by Oleg Shevchenko (Miratech)
        contentTypeHeader = sipManCallback.headerFactory.createContentTypeHeader("application", "sdp");
    } catch (ParseException ex) {
        // Shouldn't happen
        throw new CommunicationsException("Failed to create a content type header for the INVITE request", ex);
    }
    try {
        invite.setContent(sdpContent, contentTypeHeader);
    } catch (ParseException ex) {
        throw new CommunicationsException("Failed to parse sdp data while creating invite request!", ex);
    }
    // Transaction
    ClientTransaction inviteTransaction;
    try {
        inviteTransaction = sipManCallback.sipProvider.getNewClientTransaction(invite);
    } catch (TransactionUnavailableException ex) {
        throw new CommunicationsException("Failed to create inviteTransaction.\n" + "This is most probably a network connection error.", ex);
    }
    try {
        inviteTransaction.sendRequest();
    } catch (SipException ex) {
        throw new CommunicationsException("An error occurred while sending invite request", ex);
    }
    Call call = callDispatcher.createCall(inviteTransaction.getDialog(), invite);
    call.setState(Call.DIALING);
    return call;
}
Also used : MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) ContactHeader(javax.sip.header.ContactHeader) Address(javax.sip.address.Address) FromHeader(javax.sip.header.FromHeader) ContentTypeHeader(javax.sip.header.ContentTypeHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI) CSeqHeader(javax.sip.header.CSeqHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) ViaHeader(javax.sip.header.ViaHeader) ToHeader(javax.sip.header.ToHeader) CallIdHeader(javax.sip.header.CallIdHeader) TransactionUnavailableException(javax.sip.TransactionUnavailableException) ParseException(java.text.ParseException) AllowHeader(javax.sip.header.AllowHeader) SipException(javax.sip.SipException)

Example 4 with AllowHeader

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

the class RegisterProcessing method register.

synchronized void register(String registrarAddress, int registrarPort, String registrarTransport, int expires) throws CommunicationsException {
    try {
        isUnregistering = false;
        // From
        FromHeader fromHeader = sipManCallback.getFromHeader(true);
        Address fromAddress = fromHeader.getAddress();
        sipManCallback.fireRegistering(fromAddress.toString());
        // Request URI
        SipURI requestURI = null;
        try {
            requestURI = sipManCallback.addressFactory.createSipURI(null, registrarAddress);
        } catch (ParseException ex) {
            throw new CommunicationsException("Bad registrar address:" + registrarAddress, ex);
        } catch (NullPointerException ex) {
            // Do not throw an exc, we should rather silently notify the
            // user
            // throw new CommunicationsException("A registrar address was
            // not specified!", ex);
            sipManCallback.fireUnregistered(fromAddress.getURI().toString() + " (registrar not specified)");
            return;
        }
        /*
            requestURI.setPort(registrarPort);
            try {
                requestURI.setTransportParam(registrarTransport);
            }
            catch (ParseException ex) {
                throw new CommunicationsException(registrarTransport
                        + " is not a valid transport!", ex);
            }
            */
        // Call ID Header
        CallIdHeader callIdHeader = sipManCallback.sipProvider.getNewCallId();
        // CSeq Header
        CSeqHeader cSeqHeader = null;
        try {
            cSeqHeader = sipManCallback.headerFactory.createCSeqHeader((long) 1, Request.REGISTER);
        } 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.REGISTER, callIdHeader, cSeqHeader, fromHeader, toHeader, viaHeaders, maxForwardsHeader);
            request.setHeader(uaHeader);
        } catch (ParseException ex) {
            // throw was missing - reported by Eero Vaarnas
            throw new CommunicationsException("Could not create the register request!", ex);
        }
        // Expires Header
        ExpiresHeader expHeader = null;
        for (int retry = 0; retry < 2; retry++) {
            try {
                expHeader = sipManCallback.headerFactory.createExpiresHeader(expires);
            } catch (InvalidArgumentException ex) {
                if (retry == 0) {
                    expires = 3600;
                    continue;
                }
                throw new CommunicationsException("Invalid registrations expiration parameter - " + expires, ex);
            }
        }
        request.addHeader(expHeader);
        // Contact Header should contain IP - bug report - Eero Vaarnas
        ContactHeader contactHeader = sipManCallback.getRegistrationContactHeader();
        request.addHeader(contactHeader);
        AllowHeader allow = sipManCallback.headerFactory.createAllowHeader("INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY, MESSAGE, SUBSCRIBE, INFO");
        request.addHeader(allow);
        // 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);
        }
        this.registerRequest = request;
    } catch (Exception e) {
        Log.error("register", e);
        sipManCallback.fireRegistrationFailed(registrarAddress == null ? "" : registrarAddress, RegistrationEvent.Type.TimeOut);
    }
}
Also used : MaxForwardsHeader(javax.sip.header.MaxForwardsHeader) Address(javax.sip.address.Address) ArrayList(java.util.ArrayList) SipURI(javax.sip.address.SipURI) InvalidArgumentException(javax.sip.InvalidArgumentException) UserAgentHeader(javax.sip.header.UserAgentHeader) ToHeader(javax.sip.header.ToHeader) CallIdHeader(javax.sip.header.CallIdHeader) ExpiresHeader(javax.sip.header.ExpiresHeader) ContactHeader(javax.sip.header.ContactHeader) FromHeader(javax.sip.header.FromHeader) ClientTransaction(javax.sip.ClientTransaction) Request(javax.sip.message.Request) 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) ViaHeader(javax.sip.header.ViaHeader) TransactionUnavailableException(javax.sip.TransactionUnavailableException) ParseException(java.text.ParseException) AllowHeader(javax.sip.header.AllowHeader)

Aggregations

ParseException (java.text.ParseException)4 ClientTransaction (javax.sip.ClientTransaction)4 InvalidArgumentException (javax.sip.InvalidArgumentException)4 SipException (javax.sip.SipException)4 TransactionUnavailableException (javax.sip.TransactionUnavailableException)4 AllowHeader (javax.sip.header.AllowHeader)4 ContactHeader (javax.sip.header.ContactHeader)4 ViaHeader (javax.sip.header.ViaHeader)4 Request (javax.sip.message.Request)4 Address (javax.sip.address.Address)3 SipURI (javax.sip.address.SipURI)3 CSeqHeader (javax.sip.header.CSeqHeader)3 CallIdHeader (javax.sip.header.CallIdHeader)3 FromHeader (javax.sip.header.FromHeader)3 MaxForwardsHeader (javax.sip.header.MaxForwardsHeader)3 ToHeader (javax.sip.header.ToHeader)3 SipSecurityException (net.java.sipmack.sip.security.SipSecurityException)3 ArrayList (java.util.ArrayList)2 URI (javax.sip.address.URI)2 ExpiresHeader (javax.sip.header.ExpiresHeader)2