Search in sources :

Example 36 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 37 with InvalidArgumentException

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

the class SIPDialog method createRequest.

/**
     * The method that actually does the work of creating a request.
     * 
     * @param method
     * @param response
     * @return
     * @throws SipException
     */
private Request createRequest(String method, SIPResponse sipResponse) throws SipException {
    if (method == null || sipResponse == null)
        throw new NullPointerException("null argument");
    if (method.equals(Request.CANCEL))
        throw new SipException("Dialog.createRequest(): Invalid request");
    if (this.getState() == null || (this.getState().getValue() == TERMINATED_STATE && !method.equalsIgnoreCase(Request.BYE)) || (this.isServer() && this.getState().getValue() == EARLY_STATE && method.equalsIgnoreCase(Request.BYE)))
        throw new SipException("Dialog  " + getDialogId() + " not yet established or terminated " + this.getState());
    SipUri sipUri = null;
    if (this.getRemoteTarget() != null)
        sipUri = (SipUri) this.getRemoteTarget().getURI().clone();
    else {
        sipUri = (SipUri) this.getRemoteParty().getURI().clone();
        sipUri.clearUriParms();
    }
    CSeq cseq = new CSeq();
    try {
        cseq.setMethod(method);
        cseq.setSeqNumber(this.getLocalSeqNumber());
    } catch (Exception ex) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logError("Unexpected error");
        InternalErrorHandler.handleException(ex);
    }
    /*
         * Add a via header for the outbound request based on the transport of the message
         * processor.
         */
    ListeningPointImpl lp = (ListeningPointImpl) this.sipProvider.getListeningPoint(sipResponse.getTopmostVia().getTransport());
    if (lp == null) {
        if (sipStack.isLoggingEnabled())
            sipStack.getStackLogger().logError("Cannot find listening point for transport " + sipResponse.getTopmostVia().getTransport());
        throw new SipException("Cannot find listening point for transport " + sipResponse.getTopmostVia().getTransport());
    }
    Via via = lp.getViaHeader();
    From from = new From();
    from.setAddress(this.localParty);
    To to = new To();
    to.setAddress(this.remoteParty);
    SIPRequest sipRequest = sipResponse.createRequest(sipUri, via, cseq, from, to);
    if (SIPRequest.isTargetRefresh(method)) {
        ContactHeader contactHeader = ((ListeningPointImpl) this.sipProvider.getListeningPoint(lp.getTransport())).createContactHeader();
        ((SipURI) contactHeader.getAddress().getURI()).setSecure(this.isSecure());
        sipRequest.setHeader(contactHeader);
    }
    try {
        /*
             * Guess of local sequence number - this is being re-set when the request is actually
             * dispatched
             */
        cseq = (CSeq) sipRequest.getCSeq();
        cseq.setSeqNumber(this.localSequenceNumber + 1);
    } catch (InvalidArgumentException ex) {
        InternalErrorHandler.handleException(ex);
    }
    if (method.equals(Request.SUBSCRIBE)) {
        if (eventHeader != null)
            sipRequest.addHeader(eventHeader);
    }
    try {
        if (this.getLocalTag() != null) {
            from.setTag(this.getLocalTag());
        } else {
            from.removeTag();
        }
        if (this.getRemoteTag() != null) {
            to.setTag(this.getRemoteTag());
        } else {
            to.removeTag();
        }
    } catch (ParseException ex) {
        InternalErrorHandler.handleException(ex);
    }
    // get the route list from the dialog.
    this.updateRequest(sipRequest);
    return sipRequest;
}
Also used : ContactHeader(javax.sip.header.ContactHeader) ListeningPointImpl(gov.nist.javax.sip.ListeningPointImpl) CSeq(gov.nist.javax.sip.header.CSeq) From(gov.nist.javax.sip.header.From) SipUri(gov.nist.javax.sip.address.SipUri) SipURI(javax.sip.address.SipURI) 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 38 with InvalidArgumentException

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

the class SIPDialog method createReliableProvisionalResponse.

/*
     * (non-Javadoc)
     * 
     * @see javax.sip.Dialog#createReliableProvisionalResponse(int)
     */
public Response createReliableProvisionalResponse(int statusCode) throws InvalidArgumentException, SipException {
    if (!(firstTransactionIsServerTransaction)) {
        throw new SipException("Not a Server Dialog!");
    }
    /*
         * A UAS MUST NOT attempt to send a 100 (Trying) response reliably. Only provisional
         * responses numbered 101 to 199 may be sent reliably. If the request did not include
         * either a Supported or Require header field indicating this feature, the UAS MUST NOT
         * send the provisional response reliably.
         */
    if (statusCode <= 100 || statusCode > 199)
        throw new InvalidArgumentException("Bad status code ");
    SIPRequest request = this.originalRequest;
    if (!request.getMethod().equals(Request.INVITE))
        throw new SipException("Bad method");
    ListIterator<SIPHeader> list = request.getHeaders(SupportedHeader.NAME);
    if (list == null || !optionPresent(list, "100rel")) {
        list = request.getHeaders(RequireHeader.NAME);
        if (list == null || !optionPresent(list, "100rel")) {
            throw new SipException("No Supported/Require 100rel header in the request");
        }
    }
    SIPResponse response = request.createResponse(statusCode);
    /*
         * The provisional response to be sent reliably is constructed by the UAS core according
         * to the procedures of Section 8.2.6 of RFC 3261. In addition, it MUST contain a Require
         * header field containing the option tag 100rel, and MUST include an RSeq header field.
         * The value of the header field for the first reliable provisional response in a
         * transaction MUST be between 1 and 2**31 - 1. It is RECOMMENDED that it be chosen
         * uniformly in this range. The RSeq numbering space is within a single transaction. This
         * means that provisional responses for different requests MAY use the same values for the
         * RSeq number.
         */
    Require require = new Require();
    try {
        require.setOptionTag("100rel");
    } catch (Exception ex) {
        InternalErrorHandler.handleException(ex);
    }
    response.addHeader(require);
    RSeq rseq = new RSeq();
    /*
         * set an arbitrary sequence number. This is actually set when the response is sent out
         */
    rseq.setSeqNumber(1L);
    /*
         * Copy the record route headers from the request to the response ( Issue 160 ). Note that
         * other 1xx headers do not get their Record Route headers copied over but reliable
         * provisional responses do. See RFC 3262 Table 2.
         */
    RecordRouteList rrl = request.getRecordRouteHeaders();
    if (rrl != null) {
        RecordRouteList rrlclone = (RecordRouteList) rrl.clone();
        response.setHeader(rrlclone);
    }
    return response;
}
Also used : SIPResponse(gov.nist.javax.sip.message.SIPResponse) Require(gov.nist.javax.sip.header.Require) InvalidArgumentException(javax.sip.InvalidArgumentException) SIPHeader(gov.nist.javax.sip.header.SIPHeader) RecordRouteList(gov.nist.javax.sip.header.RecordRouteList) RSeq(gov.nist.javax.sip.header.RSeq) SipException(javax.sip.SipException) 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)

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