Search in sources :

Example 21 with InvalidArgumentException

use of javax.sip.InvalidArgumentException in project XobotOS by xamarin.

the class SIPDialog method resendAck.

/**
     * Resend the last ack.
     */
public void resendAck() throws SipException {
    if (this.getLastAckSent() != null) {
        if (getLastAckSent().getHeader(TimeStampHeader.NAME) != null && sipStack.generateTimeStampHeader) {
            TimeStamp ts = new TimeStamp();
            try {
                ts.setTimeStamp(System.currentTimeMillis());
                getLastAckSent().setHeader(ts);
            } catch (InvalidArgumentException e) {
            }
        }
        this.sendAck(getLastAckSent(), false);
    }
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException) TimeStamp(gov.nist.javax.sip.header.TimeStamp)

Example 22 with InvalidArgumentException

use of javax.sip.InvalidArgumentException in project XobotOS by xamarin.

the class SIPDialog method sendRequest.

public void sendRequest(ClientTransaction clientTransactionId, boolean allowInterleaving) throws TransactionDoesNotExistException, SipException {
    if ((!allowInterleaving) && clientTransactionId.getRequest().getMethod().equals(Request.INVITE)) {
        new Thread((new ReInviteSender(clientTransactionId))).start();
        return;
    }
    SIPRequest dialogRequest = ((SIPClientTransaction) clientTransactionId).getOriginalRequest();
    if (sipStack.isLoggingEnabled())
        sipStack.getStackLogger().logDebug("dialog.sendRequest " + " dialog = " + this + "\ndialogRequest = \n" + dialogRequest);
    if (clientTransactionId == null)
        throw new NullPointerException("null parameter");
    if (dialogRequest.getMethod().equals(Request.ACK) || dialogRequest.getMethod().equals(Request.CANCEL))
        throw new SipException("Bad Request Method. " + dialogRequest.getMethod());
    // JvB: added, allow re-sending of BYE after challenge
    if (byeSent && isTerminatedOnBye() && !dialogRequest.getMethod().equals(Request.BYE)) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logError("BYE already sent for " + this);
        throw new SipException("Cannot send request; BYE already sent");
    }
    if (dialogRequest.getTopmostVia() == null) {
        Via via = ((SIPClientTransaction) clientTransactionId).getOutgoingViaHeader();
        dialogRequest.addHeader(via);
    }
    if (!this.getCallId().getCallId().equalsIgnoreCase(dialogRequest.getCallId().getCallId())) {
        if (sipStack.isLoggingEnabled()) {
            sipStack.getStackLogger().logError("CallID " + this.getCallId());
            sipStack.getStackLogger().logError("RequestCallID = " + dialogRequest.getCallId().getCallId());
            sipStack.getStackLogger().logError("dialog =  " + this);
        }
        throw new SipException("Bad call ID in request");
    }
    // Set the dialog back pointer.
    ((SIPClientTransaction) clientTransactionId).setDialog(this, this.dialogId);
    this.addTransaction((SIPTransaction) clientTransactionId);
    // Enable the retransmission filter for the transaction
    ((SIPClientTransaction) clientTransactionId).isMapped = true;
    From from = (From) dialogRequest.getFrom();
    To to = (To) dialogRequest.getTo();
    // tag assignment is OK.
    if (this.getLocalTag() != null && from.getTag() != null && !from.getTag().equals(this.getLocalTag()))
        throw new SipException("From tag mismatch expecting  " + this.getLocalTag());
    if (this.getRemoteTag() != null && to.getTag() != null && !to.getTag().equals(this.getRemoteTag())) {
        if (sipStack.isLoggingEnabled())
            this.sipStack.getStackLogger().logWarning("To header tag mismatch expecting " + this.getRemoteTag());
    }
    /*
         * The application is sending a NOTIFY before sending the response of the dialog.
         */
    if (this.getLocalTag() == null && dialogRequest.getMethod().equals(Request.NOTIFY)) {
        if (!this.getMethod().equals(Request.SUBSCRIBE))
            throw new SipException("Trying to send NOTIFY without SUBSCRIBE Dialog!");
        this.setLocalTag(from.getTag());
    }
    try {
        if (this.getLocalTag() != null)
            from.setTag(this.getLocalTag());
        if (this.getRemoteTag() != null)
            to.setTag(this.getRemoteTag());
    } catch (ParseException ex) {
        InternalErrorHandler.handleException(ex);
    }
    Hop hop = ((SIPClientTransaction) clientTransactionId).getNextHop();
    if (sipStack.isLoggingEnabled()) {
        sipStack.getStackLogger().logDebug("Using hop = " + hop.getHost() + " : " + hop.getPort());
    }
    try {
        MessageChannel messageChannel = sipStack.createRawMessageChannel(this.getSipProvider().getListeningPoint(hop.getTransport()).getIPAddress(), this.firstTransactionPort, hop);
        MessageChannel oldChannel = ((SIPClientTransaction) clientTransactionId).getMessageChannel();
        // Remove this from the connection cache if it is in the
        // connection
        // cache and is not yet active.
        oldChannel.uncache();
        // Not configured to cache client connections.
        if (!sipStack.cacheClientConnections) {
            oldChannel.useCount--;
            if (sipStack.isLoggingEnabled())
                sipStack.getStackLogger().logDebug("oldChannel: useCount " + oldChannel.useCount);
        }
        if (messageChannel == null) {
            /*
                 * At this point the procedures of 8.1.2 and 12.2.1.1 of RFC3261 have been tried
                 * but the resulting next hop cannot be resolved (recall that the exception thrown
                 * is caught and ignored in SIPStack.createMessageChannel() so we end up here with
                 * a null messageChannel instead of the exception handler below). All else
                 * failing, try the outbound proxy in accordance with 8.1.2, in particular: This
                 * ensures that outbound proxies that do not add Record-Route header field values
                 * will drop out of the path of subsequent requests. It allows endpoints that
                 * cannot resolve the first Route URI to delegate that task to an outbound proxy.
                 * 
                 * if one considers the 'first Route URI' of a request constructed according to
                 * 12.2.1.1 to be the request URI when the route set is empty.
                 */
            if (sipStack.isLoggingEnabled())
                sipStack.getStackLogger().logDebug("Null message channel using outbound proxy !");
            Hop outboundProxy = sipStack.getRouter(dialogRequest).getOutboundProxy();
            if (outboundProxy == null)
                throw new SipException("No route found! hop=" + hop);
            messageChannel = sipStack.createRawMessageChannel(this.getSipProvider().getListeningPoint(outboundProxy.getTransport()).getIPAddress(), this.firstTransactionPort, outboundProxy);
            if (messageChannel != null)
                ((SIPClientTransaction) clientTransactionId).setEncapsulatedChannel(messageChannel);
        } else {
            ((SIPClientTransaction) clientTransactionId).setEncapsulatedChannel(messageChannel);
            if (sipStack.isLoggingEnabled()) {
                sipStack.getStackLogger().logDebug("using message channel " + messageChannel);
            }
        }
        if (messageChannel != null)
            messageChannel.useCount++;
        // See if we need to release the previously mapped channel.
        if ((!sipStack.cacheClientConnections) && oldChannel != null && oldChannel.useCount <= 0)
            oldChannel.close();
    } catch (Exception ex) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logException(ex);
        throw new SipException("Could not create message channel", ex);
    }
    try {
        // Increment before setting!!
        localSequenceNumber++;
        dialogRequest.getCSeq().setSeqNumber(getLocalSeqNumber());
    } catch (InvalidArgumentException ex) {
        sipStack.getStackLogger().logFatalError(ex.getMessage());
    }
    try {
        ((SIPClientTransaction) clientTransactionId).sendMessage(dialogRequest);
        /*
             * Note that if the BYE is rejected then the Dialog should bo back to the ESTABLISHED
             * state so we only set state after successful send.
             */
        if (dialogRequest.getMethod().equals(Request.BYE)) {
            this.byeSent = true;
            /*
                 * Dialog goes into TERMINATED state as soon as BYE is sent. ISSUE 182.
                 */
            if (isTerminatedOnBye()) {
                this.setState(DialogState._TERMINATED);
            }
        }
    } catch (IOException ex) {
        throw new SipException("error sending message", ex);
    }
}
Also used : Hop(javax.sip.address.Hop) From(gov.nist.javax.sip.header.From) IOException(java.io.IOException) SIPRequest(gov.nist.javax.sip.message.SIPRequest) DialogDoesNotExistException(javax.sip.DialogDoesNotExistException) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) ObjectInUseException(javax.sip.ObjectInUseException) SipException(javax.sip.SipException) IOException(java.io.IOException) TransactionDoesNotExistException(javax.sip.TransactionDoesNotExistException) Via(gov.nist.javax.sip.header.Via) InvalidArgumentException(javax.sip.InvalidArgumentException) To(gov.nist.javax.sip.header.To) ParseException(java.text.ParseException) SipException(javax.sip.SipException)

Example 23 with InvalidArgumentException

use of javax.sip.InvalidArgumentException in project XobotOS by xamarin.

the class SIPMessage method attachHeader.

/**
     * Attach the header to the SIP Message structure at a specified position in its list of
     * headers.
     * 
     * @param header Header to attach.
     * @param replaceFlag If true then replace the existing header.
     * @param top Location in the header list to insert the header.
     * @exception SIPDuplicateHeaderException if the header is of a type that cannot tolerate
     *            duplicates and one of this type already exists (e.g. CSeq header).
     * @throws IndexOutOfBoundsException If the index specified is greater than the number of
     *         headers that are in this message.
     */
public void attachHeader(SIPHeader header, boolean replaceFlag, boolean top) throws SIPDuplicateHeaderException {
    if (header == null) {
        throw new NullPointerException("null header");
    }
    SIPHeader h;
    if (ListMap.hasList(header) && !SIPHeaderList.class.isAssignableFrom(header.getClass())) {
        SIPHeaderList<SIPHeader> hdrList = ListMap.getList(header);
        hdrList.add(header);
        h = hdrList;
    } else {
        h = header;
    }
    String headerNameLowerCase = SIPHeaderNamesCache.toLowerCase(h.getName());
    if (replaceFlag) {
        nameTable.remove(headerNameLowerCase);
    } else if (nameTable.containsKey(headerNameLowerCase) && !(h instanceof SIPHeaderList)) {
        if (h instanceof ContentLength) {
            try {
                ContentLength cl = (ContentLength) h;
                contentLengthHeader.setContentLength(cl.getContentLength());
            } catch (InvalidArgumentException e) {
            }
        }
        // Just ignore duplicate header.
        return;
    }
    SIPHeader originalHeader = (SIPHeader) getHeader(header.getName());
    // Delete the original header from our list structure.
    if (originalHeader != null) {
        Iterator<SIPHeader> li = headers.iterator();
        while (li.hasNext()) {
            SIPHeader next = (SIPHeader) li.next();
            if (next.equals(originalHeader)) {
                li.remove();
            }
        }
    }
    if (!nameTable.containsKey(headerNameLowerCase)) {
        nameTable.put(headerNameLowerCase, h);
        headers.add(h);
    } else {
        if (h instanceof SIPHeaderList) {
            SIPHeaderList<?> hdrlist = (SIPHeaderList<?>) nameTable.get(headerNameLowerCase);
            if (hdrlist != null)
                hdrlist.concatenate((SIPHeaderList) h, top);
            else
                nameTable.put(headerNameLowerCase, h);
        } else {
            nameTable.put(headerNameLowerCase, h);
        }
    }
    // Direct accessor fields for frequently accessed headers.
    if (h instanceof From) {
        this.fromHeader = (From) h;
    } else if (h instanceof ContentLength) {
        this.contentLengthHeader = (ContentLength) h;
    } else if (h instanceof To) {
        this.toHeader = (To) h;
    } else if (h instanceof CSeq) {
        this.cSeqHeader = (CSeq) h;
    } else if (h instanceof CallID) {
        this.callIdHeader = (CallID) h;
    } else if (h instanceof MaxForwards) {
        this.maxForwardsHeader = (MaxForwards) h;
    }
}
Also used : SIPHeaderList(gov.nist.javax.sip.header.SIPHeaderList) CSeq(gov.nist.javax.sip.header.CSeq) CallID(gov.nist.javax.sip.header.CallID) MaxForwards(gov.nist.javax.sip.header.MaxForwards) From(gov.nist.javax.sip.header.From) InvalidArgumentException(javax.sip.InvalidArgumentException) SIPHeader(gov.nist.javax.sip.header.SIPHeader) ContentLength(gov.nist.javax.sip.header.ContentLength) To(gov.nist.javax.sip.header.To) InReplyTo(gov.nist.javax.sip.header.InReplyTo)

Example 24 with InvalidArgumentException

use of javax.sip.InvalidArgumentException in project XobotOS by xamarin.

the class PAssertedServiceParser method parse.

public SIPHeader parse() throws ParseException {
    if (debug)
        dbg_enter("PAssertedServiceParser.parse");
    try {
        this.lexer.match(TokenTypes.P_ASSERTED_SERVICE);
        this.lexer.SPorHT();
        this.lexer.match(':');
        this.lexer.SPorHT();
        PAssertedService pps = new PAssertedService();
        String urn = this.lexer.getBuffer();
        if (urn.contains(ParameterNamesIms.SERVICE_ID)) {
            if (urn.contains(ParameterNamesIms.SERVICE_ID_LABEL)) {
                String serviceID = urn.split(ParameterNamesIms.SERVICE_ID_LABEL + ".")[1];
                if (serviceID.trim().equals(""))
                    try {
                        throw new InvalidArgumentException("URN should atleast have one sub-service");
                    } catch (InvalidArgumentException e) {
                        e.printStackTrace();
                    }
                else
                    pps.setSubserviceIdentifiers(urn.split(ParameterNamesIms.SERVICE_ID_LABEL)[1]);
            } else if (urn.contains(ParameterNamesIms.APPLICATION_ID_LABEL)) {
                String appID = urn.split(ParameterNamesIms.APPLICATION_ID_LABEL + ".")[1];
                if (appID.trim().equals(""))
                    try {
                        throw new InvalidArgumentException("URN should atleast have one sub-application");
                    } catch (InvalidArgumentException e) {
                        e.printStackTrace();
                    }
                else
                    pps.setApplicationIdentifiers(urn.split(ParameterNamesIms.APPLICATION_ID_LABEL)[1]);
            } else {
                try {
                    throw new InvalidArgumentException("URN is not well formed");
                } catch (InvalidArgumentException e) {
                    e.printStackTrace();
                }
            }
        }
        super.parse();
        return pps;
    } finally {
        if (debug)
            dbg_enter("PAssertedServiceParser.parse");
    }
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException) PAssertedService(gov.nist.javax.sip.header.ims.PAssertedService)

Example 25 with InvalidArgumentException

use of javax.sip.InvalidArgumentException in project XobotOS by xamarin.

the class PMediaAuthorizationParser method parse.

public SIPHeader parse() throws ParseException {
    PMediaAuthorizationList mediaAuthorizationList = new PMediaAuthorizationList();
    if (debug)
        dbg_enter("MediaAuthorizationParser.parse");
    try {
        headerName(TokenTypes.P_MEDIA_AUTHORIZATION);
        PMediaAuthorization mediaAuthorization = new PMediaAuthorization();
        mediaAuthorization.setHeaderName(SIPHeaderNamesIms.P_MEDIA_AUTHORIZATION);
        while (lexer.lookAhead(0) != '\n') {
            this.lexer.match(TokenTypes.ID);
            Token token = lexer.getNextToken();
            try {
                mediaAuthorization.setMediaAuthorizationToken(token.getTokenValue());
            } catch (InvalidArgumentException e) {
                throw createParseException(e.getMessage());
            }
            mediaAuthorizationList.add(mediaAuthorization);
            this.lexer.SPorHT();
            if (lexer.lookAhead(0) == ',') {
                this.lexer.match(',');
                mediaAuthorization = new PMediaAuthorization();
            }
            this.lexer.SPorHT();
        }
        return mediaAuthorizationList;
    } finally {
        if (debug)
            dbg_leave("MediaAuthorizationParser.parse");
    }
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException) PMediaAuthorization(gov.nist.javax.sip.header.ims.PMediaAuthorization) Token(gov.nist.core.Token) PMediaAuthorizationList(gov.nist.javax.sip.header.ims.PMediaAuthorizationList)

Aggregations

InvalidArgumentException (javax.sip.InvalidArgumentException)38 ParseException (java.text.ParseException)10 IOException (java.io.IOException)9 SipException (javax.sip.SipException)9 SipURI (javax.sip.address.SipURI)7 SIPRequest (gov.nist.javax.sip.message.SIPRequest)6 Via (gov.nist.javax.sip.header.Via)5 From (gov.nist.javax.sip.header.From)4 To (gov.nist.javax.sip.header.To)4 DialogDoesNotExistException (javax.sip.DialogDoesNotExistException)4 ObjectInUseException (javax.sip.ObjectInUseException)4 TransactionDoesNotExistException (javax.sip.TransactionDoesNotExistException)4 CSeq (gov.nist.javax.sip.header.CSeq)3 ClientTransaction (javax.sip.ClientTransaction)3 Hop (javax.sip.address.Hop)3 Request (javax.sip.message.Request)3 ListeningPointImpl (gov.nist.javax.sip.ListeningPointImpl)2 MaxForwards (gov.nist.javax.sip.header.MaxForwards)2 SIPHeader (gov.nist.javax.sip.header.SIPHeader)2 TimeStamp (gov.nist.javax.sip.header.TimeStamp)2