Search in sources :

Example 51 with InvalidArgumentException

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

the class TimeStamp method setTime.

public void setTime(long timeStamp) throws InvalidArgumentException {
    if (timeStamp < -1)
        throw new InvalidArgumentException("Illegal timestamp");
    this.timeStamp = timeStamp;
    this.timeStampFloat = -1;
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException)

Example 52 with InvalidArgumentException

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

the class MessageProcessor method getViaHeader.

/**
     * Get the Via header to assign for this message processor. The topmost via
     * header of the outoging messages use this.
     *
     * @return the ViaHeader to be used by the messages sent via this message processor.
     */
public Via getViaHeader() {
    try {
        Via via = new Via();
        if (this.sentByHostPort != null) {
            via.setSentBy(sentByHostPort);
            via.setTransport(this.getTransport());
        } else {
            Host host = new Host();
            host.setHostname(this.getIpAddress().getHostAddress());
            via.setHost(host);
            via.setPort(this.getPort());
            via.setTransport(this.getTransport());
        }
        return via;
    } catch (ParseException ex) {
        ex.printStackTrace();
        return null;
    } catch (InvalidArgumentException ex) {
        ex.printStackTrace();
        return null;
    }
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException) Host(gov.nist.core.Host) ParseException(java.text.ParseException) Via(gov.nist.javax.sip.header.Via)

Example 53 with InvalidArgumentException

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

the class PPreferredServiceParser method parse.

/**
     * "The URN consists of a hierarchical service identifier or application
     * identifier, with a sequence of labels separated by periods.The left-most label is
     * the most significant one and is called 'top-level service
     * identifier', while names to the right are called 'sub-services' or
     * 'sub-applications'.
     *
     * For any given service identifier, labels can be removed right-to-left and
     * the resulting URN is still valid, referring a more generic
     * service, with the exception of the top-level service identifier
     * and possibly the first sub-service or sub-application identifier.
     *
     *  Labels cannot be removed beyond a defined basic service, for
     *  example, the label w.x may define a service, but the label w may
     *  only define an assignment authority for assigning subsequent
     *  values and not define a service in its own right.  In other words,
     *  if a service identifier 'w.x.y.z' exists, the URNs 'w.x' and
     *  'w.x.y' are also valid service identifiers, but w may not be a
     *  valid service identifier if it merely defines who is responsible"
     *
     * TODO: PLEASE VALIDATE MY UNDERSTANDING OF THE ABOVE TEXT :)
     * @ranga: Please validate my understanding of the above text in the draft :)
     *         This last para is a little ambiguous.I will only check that atleast
     *         1 sub-service or 1 sub-application is present in the URN declaration.
     *         If not, I throw an exception. I thought of not throwing an exception
     *         and returning whatever was encoded..but the resultant encoding wont
     *         make sense. It would be something like-->
     *         urn:urn-7:3gpp-service OR urn:urn-7:3gpp-application alone with no sub-services
     *         or sub-applications. This is bound to cause an error at the recepient later.
     *
     * Sub-service and Application identifiers are not maintained by IANA and
     * are organization/application dependent (Section 8.2). So we cannot gurantee what lies
     * beyond the first sub-service or sub-application identifier. It should be the responsibility
     * of the application to make sense of the entire URN holistically. We can only check for the
     * standardized part as per the ABNF.
     */
public SIPHeader parse() throws ParseException {
    if (debug)
        dbg_enter("PPreferredServiceParser.parse");
    try {
        this.lexer.match(TokenTypes.P_PREFERRED_SERVICE);
        this.lexer.SPorHT();
        this.lexer.match(':');
        this.lexer.SPorHT();
        PPreferredService pps = new PPreferredService();
        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(serviceID);
            } 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(appID);
            } else {
                try {
                    throw new InvalidArgumentException("URN is not well formed");
                } catch (InvalidArgumentException e) {
                    e.printStackTrace();
                }
            }
        }
        super.parse();
        return pps;
    } finally {
        if (debug)
            dbg_enter("PPreferredServiceParser.parse");
    }
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException) PPreferredService(gov.nist.javax.sip.header.ims.PPreferredService)

Example 54 with InvalidArgumentException

use of javax.sip.InvalidArgumentException in project Spark by igniterealtime.

the class CallProcessing method processInvite.

// -------------------------- Requests ---------------------------------
void processInvite(ServerTransaction serverTransaction, Request invite) {
    Dialog dialog = serverTransaction.getDialog();
    if (!sipManCallback.isBusy() && !(PhoneManager.isUseStaticLocator() && PhoneManager.isUsingMediaLocator())) {
        Call call = callDispatcher.createCall(dialog, invite);
        sipManCallback.fireCallReceived(call);
        // change status
        call.setState(Call.ALERTING);
        // sdp description may be in acks - bug report Laurent Michel
        ContentLengthHeader cl = invite.getContentLength();
        if (cl != null && cl.getContentLength() > 0) {
            call.setRemoteSdpDescription(new String(invite.getRawContent()));
        }
        // Are we the one they are looking for?
        URI calleeURI = ((ToHeader) invite.getHeader(ToHeader.NAME)).getAddress().getURI();
        /**
         * @todo We shoud rather ask the user what to do here as some
         *       would add prefixes or change user URIs
         */
        if (calleeURI.isSipURI()) {
            boolean assertUserMatch = SIPConfig.isFailCallInUserMismatch();
            // user info is case sensitive according to rfc3261
            if (assertUserMatch) {
                String calleeUser = ((SipURI) calleeURI).getUser();
                String localUser = sipManCallback.getLocalUser();
                if (calleeUser != null && !calleeUser.equals(localUser)) {
                    sipManCallback.fireCallRejectedLocally("The user specified by the caller did not match the local user!", invite, call);
                    call.setState(Call.DISCONNECTED);
                    Response notFound = null;
                    try {
                        notFound = sipManCallback.messageFactory.createResponse(Response.NOT_FOUND, invite);
                        sipManCallback.attachToTag(notFound, dialog);
                    } catch (ParseException ex) {
                        call.setState(Call.DISCONNECTED);
                        sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to create a NOT_FOUND response to an INVITE request!", ex));
                        return;
                    }
                    try {
                        serverTransaction.sendResponse(notFound);
                    } catch (SipException ex) {
                        call.setState(Call.DISCONNECTED);
                        sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", ex));
                        return;
                    } catch (InvalidArgumentException e) {
                        call.setState(Call.DISCONNECTED);
                        sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", e));
                        return;
                    }
                    return;
                }
            }
        }
        // Send RINGING
        Response ringing = null;
        try {
            ringing = sipManCallback.messageFactory.createResponse(Response.RINGING, invite);
            sipManCallback.attachToTag(ringing, dialog);
        } catch (ParseException ex) {
            call.setState(Call.DISCONNECTED);
            sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to create a RINGING response to an INVITE request!", ex));
            return;
        }
        try {
            serverTransaction.sendResponse(ringing);
        } catch (SipException ex) {
            call.setState(Call.DISCONNECTED);
            sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a RINGING response to an INVITE request!", ex));
            return;
        } catch (InvalidArgumentException e) {
            call.setState(Call.DISCONNECTED);
            sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a NOT_FOUND response to an INVITE request!", e));
            return;
        }
    } else {
        // Send BUSY_HERE
        Response busy = null;
        try {
            busy = sipManCallback.messageFactory.createResponse(Response.BUSY_HERE, invite);
            sipManCallback.attachToTag(busy, dialog);
        } catch (ParseException ex) {
            sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to create a RINGING response to an INVITE request!", ex));
            return;
        }
        try {
            serverTransaction.sendResponse(busy);
        } catch (SipException ex) {
            sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a RINGING response to an INVITE request!", ex));
            return;
        } catch (InvalidArgumentException e) {
            sipManCallback.fireCommunicationsError(new CommunicationsException("Failed to send a RINGING response to an INVITE request!", e));
            return;
        }
    }
}
Also used : Response(javax.sip.message.Response) InvalidArgumentException(javax.sip.InvalidArgumentException) Dialog(javax.sip.Dialog) ContentLengthHeader(javax.sip.header.ContentLengthHeader) ParseException(java.text.ParseException) SipURI(javax.sip.address.SipURI) SipException(javax.sip.SipException) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI)

Example 55 with InvalidArgumentException

use of javax.sip.InvalidArgumentException in project Spark by igniterealtime.

the class CallProcessing method sayInternalError.

// answer call
// ------------------ Internal Error
void sayInternalError(int callID) throws CommunicationsException {
    Call call = callDispatcher.getCall(callID);
    if (call == null) {
        throw new CommunicationsException("Failed to find call with id=" + callID);
    }
    Dialog dialog = call.getDialog();
    if (dialog == null) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to extract call's associated dialog! Ending Call!");
    }
    Transaction transaction = dialog.getFirstTransaction();
    if (transaction == null || !dialog.isServer()) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to extract a transaction from the call's associated dialog!");
    }
    ServerTransaction serverTransaction = (ServerTransaction) transaction;
    Response internalError = null;
    try {
        internalError = sipManCallback.messageFactory.createResponse(Response.SERVER_INTERNAL_ERROR, dialog.getFirstTransaction().getRequest());
        sipManCallback.attachToTag(internalError, dialog);
    } catch (ParseException ex) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to construct an OK response to an INVITE request", ex);
    }
    ContactHeader contactHeader = sipManCallback.getContactHeader();
    internalError.addHeader(contactHeader);
    try {
        serverTransaction.sendResponse(internalError);
    } catch (SipException ex) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to send an OK response to an INVITE request", ex);
    } catch (InvalidArgumentException e) {
        call.setState(Call.DISCONNECTED);
        throw new CommunicationsException("Failed to send an OK response to an INVITE request", e);
    }
}
Also used : Response(javax.sip.message.Response) ContactHeader(javax.sip.header.ContactHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) ServerTransaction(javax.sip.ServerTransaction) Transaction(javax.sip.Transaction) ClientTransaction(javax.sip.ClientTransaction) Dialog(javax.sip.Dialog) ParseException(java.text.ParseException) ServerTransaction(javax.sip.ServerTransaction) SipException(javax.sip.SipException)

Aggregations

InvalidArgumentException (javax.sip.InvalidArgumentException)61 ParseException (java.text.ParseException)32 SipException (javax.sip.SipException)31 Request (javax.sip.message.Request)16 SipURI (javax.sip.address.SipURI)15 ClientTransaction (javax.sip.ClientTransaction)12 Response (javax.sip.message.Response)12 TransactionUnavailableException (javax.sip.TransactionUnavailableException)11 URI (javax.sip.address.URI)11 ContactHeader (javax.sip.header.ContactHeader)10 ViaHeader (javax.sip.header.ViaHeader)10 IOException (java.io.IOException)9 ObjectInUseException (javax.sip.ObjectInUseException)8 CallIdHeader (javax.sip.header.CallIdHeader)8 FromHeader (javax.sip.header.FromHeader)8 ToHeader (javax.sip.header.ToHeader)8 SIPRequest (gov.nist.javax.sip.message.SIPRequest)7 Address (javax.sip.address.Address)7 CSeqHeader (javax.sip.header.CSeqHeader)7 MaxForwardsHeader (javax.sip.header.MaxForwardsHeader)7