Search in sources :

Example 41 with InvalidArgumentException

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

the class SipTPCCallAgent method initiateCall.

/*
     * Begin Third-Party Call Control.
     */
public void initiateCall() throws IOException {
    try {
        try {
            busyTreatment = new TreatmentManager("busy.au", 0);
        } catch (IOException e) {
            Logger.println("Invalid busy treatment:  " + e.getMessage());
        }
        Logger.writeFile("Call " + cp + ":   Begin SIP third party call");
        setState(CallState.INVITED);
        InetSocketAddress isa = callHandler.getReceiveAddress();
        if (isa == null) {
            throw new IOException("can't get receiver socket!");
        }
        // send INVITE to the CallParticipant
        clientTransaction = sipUtil.sendInvite(cp, isa);
        if (clientTransaction == null) {
            Logger.error("Error placing call:  " + cp);
            setState(CallState.ENDED, "Reason='Error placing call'");
            throw new IOException("Error placing call:  " + cp);
        }
        CallIdHeader callIdHeader = (CallIdHeader) clientTransaction.getRequest().getHeader(CallIdHeader.NAME);
        sipCallId = callIdHeader.getCallId();
        sipServerCallback = SipServer.getSipServerCallback();
        sipServerCallback.addSipListener(sipCallId, this);
    } catch (java.text.ParseException e) {
        Logger.println("Call " + cp + " Error placing call " + cp + ":  " + e.getMessage());
        setState(CallState.ENDED, "Reason='Error placing call " + cp + " " + e.getMessage() + "'");
        throw new IOException("Error placing call " + cp + " " + e.getMessage());
    } catch (InvalidArgumentException e) {
        Logger.println("Call " + cp + " Error placing call " + cp + ":  " + e.getMessage());
        setState(CallState.ENDED, "Reason='Error placing call " + cp + " " + e.getMessage() + "'");
        throw new IOException("Error placing call " + cp + " " + e.getMessage());
    } catch (SipException e) {
        Logger.println("Call " + cp + " Error placing call " + cp + ":  " + e.getMessage());
        setState(CallState.ENDED, "Reason='Error placing call " + cp + " " + e.getMessage() + "'");
        throw new IOException("Error placing call " + cp + " " + e.getMessage());
    }
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException) InetSocketAddress(java.net.InetSocketAddress) TreatmentManager(com.sun.voip.TreatmentManager) IOException(java.io.IOException) ParseException(java.text.ParseException)

Example 42 with InvalidArgumentException

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

the class SimpleSession method sendNotify.

public void sendNotify(Dialog dialog) throws ParseException, SipException, InvalidArgumentException {
    Request notifyRequest = prepareNotifyRequest(dialog);
    try {
        User me = XMPPServer.getInstance().getUserManager().getUser(getJID().getNode());
        Presence myPresence = XMPPServer.getInstance().getPresenceManager().getPresence(me);
        String presenceContent;
        SimplePresence simplePresence = new SimplePresence();
        simplePresence.setEntity("pres:" + registration.getUsername() + "@" + sipHost);
        simplePresence.setDmNote(myPresence.getStatus());
        if (myPresence.getStatus() != null && myPresence.getStatus().equalsIgnoreCase("Offline"))
            simplePresence.setTupleStatus(SimplePresence.TupleStatus.CLOSED);
        else {
            simplePresence.setTupleStatus(SimplePresence.TupleStatus.OPEN);
            if (myPresence.getShow() != null) {
                switch(myPresence.getShow()) {
                    case away:
                        simplePresence.setRpid(SimplePresence.Rpid.AWAY);
                        break;
                    case dnd:
                        simplePresence.setRpid(SimplePresence.Rpid.BUSY);
                        break;
                    case xa:
                        simplePresence.setRpid(SimplePresence.Rpid.AWAY);
                        break;
                    default:
                        break;
                }
            }
        }
        presenceContent = simplePresence.toXML();
        ContentTypeHeader contentTypeHeader = headerFactory.createContentTypeHeader("application", "pidf+xml");
        notifyRequest.setContent(presenceContent, contentTypeHeader);
    } catch (Exception e) {
        Log.debug("Unable to include presence details in the packet.", e);
    }
    sendRequest(notifyRequest, ListeningPoint.UDP, dialog);
}
Also used : User(org.jivesoftware.openfire.user.User) ContentTypeHeader(javax.sip.header.ContentTypeHeader) Request(javax.sip.message.Request) Presence(org.xmpp.packet.Presence) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) NotFoundException(org.jivesoftware.util.NotFoundException) TooManyListenersException(java.util.TooManyListenersException) SipException(javax.sip.SipException) UserNotFoundException(org.jivesoftware.openfire.user.UserNotFoundException)

Example 43 with InvalidArgumentException

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

the class SimpleSession method prepareMessageRequest.

private Request prepareMessageRequest(MessageContent content, String destination) throws InvalidArgumentException, ParseException {
    String destUsername = destination;
    String destHost = sipHost;
    if (destination.indexOf("@") == 0 || destination.indexOf("@") == destination.length() - 1) {
        throw new InvalidArgumentException("The address provided is invalid!");
    } else if (destination.indexOf("@") > 0) {
        destUsername = destination.substring(0, destination.indexOf("@"));
        destHost = destination.substring(destination.indexOf("@") + 1);
    }
    SipURI destUri = addressFactory.createSipURI(destUsername, destHost);
    Request messageRequest = prepareRequest(RequestType.MESSAGE, destUri, null, destUri, sessionId, seqNum++);
    messageRequest.setContent(content.content, content.contentTypeHeader);
    return messageRequest;
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException) Request(javax.sip.message.Request) SipURI(javax.sip.address.SipURI)

Example 44 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 45 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)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