Search in sources :

Example 26 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 27 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 28 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 29 with InvalidArgumentException

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

the class SipHelper method createSipUri.

private SipURI createSipUri(String username, String transport, String ip, int port) throws ParseException {
    SipURI uri = mAddressFactory.createSipURI(username, ip);
    try {
        uri.setPort(port);
        uri.setTransportParam(transport);
    } catch (InvalidArgumentException e) {
        throw new RuntimeException(e);
    }
    return uri;
}
Also used : InvalidArgumentException(javax.sip.InvalidArgumentException) SipURI(javax.sip.address.SipURI)

Example 30 with InvalidArgumentException

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

the class AuthenticationHelperImpl method handleChallenge.

/*
     * (non-Javadoc)
     *
     * @see gov.nist.javax.sip.clientauthutils.AuthenticationHelper#handleChallenge(javax.sip.message.Response,
     *      javax.sip.ClientTransaction, javax.sip.SipProvider)
     */
public ClientTransaction handleChallenge(Response challenge, ClientTransaction challengedTransaction, SipProvider transactionCreator, int cacheTime) throws SipException, NullPointerException {
    try {
        if (sipStack.isLoggingEnabled()) {
            sipStack.getStackLogger().logDebug("handleChallenge: " + challenge);
        }
        SIPRequest challengedRequest = ((SIPRequest) challengedTransaction.getRequest());
        Request reoriginatedRequest = null;
        /*
             * If the challenged request is part of a Dialog and the
             * Dialog is confirmed the re-originated request should be
             * generated as an in-Dialog request.
             */
        if (challengedRequest.getToTag() != null || challengedTransaction.getDialog() == null || challengedTransaction.getDialog().getState() != DialogState.CONFIRMED) {
            reoriginatedRequest = (Request) challengedRequest.clone();
        } else {
            /*
                 * Re-originate the request by consulting the dialog. In particular
                 * the route set could change between the original request and the 
                 * in-dialog challenge.
                 */
            reoriginatedRequest = challengedTransaction.getDialog().createRequest(challengedRequest.getMethod());
            Iterator<String> headerNames = challengedRequest.getHeaderNames();
            while (headerNames.hasNext()) {
                String headerName = headerNames.next();
                if (reoriginatedRequest.getHeader(headerName) != null) {
                    ListIterator<Header> iterator = reoriginatedRequest.getHeaders(headerName);
                    while (iterator.hasNext()) {
                        reoriginatedRequest.addHeader(iterator.next());
                    }
                }
            }
        }
        // remove the branch id so that we could use the request in a new
        // transaction
        removeBranchID(reoriginatedRequest);
        if (challenge == null || reoriginatedRequest == null) {
            throw new NullPointerException("A null argument was passed to handle challenge.");
        }
        ListIterator authHeaders = null;
        if (challenge.getStatusCode() == Response.UNAUTHORIZED) {
            authHeaders = challenge.getHeaders(WWWAuthenticateHeader.NAME);
        } else if (challenge.getStatusCode() == Response.PROXY_AUTHENTICATION_REQUIRED) {
            authHeaders = challenge.getHeaders(ProxyAuthenticateHeader.NAME);
        } else {
            throw new IllegalArgumentException("Unexpected status code ");
        }
        if (authHeaders == null) {
            throw new IllegalArgumentException("Could not find WWWAuthenticate or ProxyAuthenticate headers");
        }
        // Remove all authorization headers from the request (we'll re-add them
        // from cache)
        reoriginatedRequest.removeHeader(AuthorizationHeader.NAME);
        reoriginatedRequest.removeHeader(ProxyAuthorizationHeader.NAME);
        // rfc 3261 says that the cseq header should be augmented for the new
        // request. do it here so that the new dialog (created together with
        // the new client transaction) takes it into account.
        // Bug report - Fredrik Wickstrom
        CSeqHeader cSeq = (CSeqHeader) reoriginatedRequest.getHeader((CSeqHeader.NAME));
        try {
            cSeq.setSeqNumber(cSeq.getSeqNumber() + 1l);
        } catch (InvalidArgumentException ex) {
            throw new SipException("Invalid CSeq -- could not increment : " + cSeq.getSeqNumber());
        }
        /* Resolve this to the next hop based on the previous lookup. If we are not using
             * lose routing (RFC2543) then just attach hop as a maddr param.
             */
        if (challengedRequest.getRouteHeaders() == null) {
            Hop hop = ((SIPClientTransaction) challengedTransaction).getNextHop();
            SipURI sipUri = (SipURI) reoriginatedRequest.getRequestURI();
            // BEGIN android-added
            if (!hop.getHost().equalsIgnoreCase(sipUri.getHost()) && !hop.equals(sipStack.getRouter(challengedRequest).getOutboundProxy()))
                // END android-added
                sipUri.setMAddrParam(hop.getHost());
            if (hop.getPort() != -1)
                sipUri.setPort(hop.getPort());
        }
        ClientTransaction retryTran = transactionCreator.getNewClientTransaction(reoriginatedRequest);
        WWWAuthenticateHeader authHeader = null;
        SipURI requestUri = (SipURI) challengedTransaction.getRequest().getRequestURI();
        while (authHeaders.hasNext()) {
            authHeader = (WWWAuthenticateHeader) authHeaders.next();
            String realm = authHeader.getRealm();
            AuthorizationHeader authorization = null;
            String sipDomain;
            if (this.accountManager instanceof SecureAccountManager) {
                UserCredentialHash credHash = ((SecureAccountManager) this.accountManager).getCredentialHash(challengedTransaction, realm);
                URI uri = reoriginatedRequest.getRequestURI();
                sipDomain = credHash.getSipDomain();
                authorization = this.getAuthorization(reoriginatedRequest.getMethod(), uri.toString(), (reoriginatedRequest.getContent() == null) ? "" : new String(reoriginatedRequest.getRawContent()), authHeader, credHash);
            } else {
                UserCredentials userCreds = ((AccountManager) this.accountManager).getCredentials(challengedTransaction, realm);
                sipDomain = userCreds.getSipDomain();
                if (userCreds == null)
                    throw new SipException("Cannot find user creds for the given user name and realm");
                // we haven't yet authenticated this realm since we were
                // started.
                authorization = this.getAuthorization(reoriginatedRequest.getMethod(), reoriginatedRequest.getRequestURI().toString(), (reoriginatedRequest.getContent() == null) ? "" : new String(reoriginatedRequest.getRawContent()), authHeader, userCreds);
            }
            if (sipStack.isLoggingEnabled())
                sipStack.getStackLogger().logDebug("Created authorization header: " + authorization.toString());
            if (cacheTime != 0)
                cachedCredentials.cacheAuthorizationHeader(sipDomain, authorization, cacheTime);
            reoriginatedRequest.addHeader(authorization);
        }
        if (sipStack.isLoggingEnabled()) {
            sipStack.getStackLogger().logDebug("Returning authorization transaction." + retryTran);
        }
        return retryTran;
    } catch (SipException ex) {
        throw ex;
    } catch (Exception ex) {
        sipStack.getStackLogger().logError("Unexpected exception ", ex);
        throw new SipException("Unexpected exception ", ex);
    }
}
Also used : SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) SIPClientTransaction(gov.nist.javax.sip.stack.SIPClientTransaction) ClientTransaction(javax.sip.ClientTransaction) ProxyAuthorizationHeader(javax.sip.header.ProxyAuthorizationHeader) AuthorizationHeader(javax.sip.header.AuthorizationHeader) Request(javax.sip.message.Request) SIPRequest(gov.nist.javax.sip.message.SIPRequest) Hop(javax.sip.address.Hop) WWWAuthenticateHeader(javax.sip.header.WWWAuthenticateHeader) ListIterator(java.util.ListIterator) SipURI(javax.sip.address.SipURI) SIPRequest(gov.nist.javax.sip.message.SIPRequest) URI(javax.sip.address.URI) SipURI(javax.sip.address.SipURI) InvalidArgumentException(javax.sip.InvalidArgumentException) ParseException(java.text.ParseException) SipException(javax.sip.SipException) CSeqHeader(javax.sip.header.CSeqHeader) InvalidArgumentException(javax.sip.InvalidArgumentException) CSeqHeader(javax.sip.header.CSeqHeader) ProxyAuthorizationHeader(javax.sip.header.ProxyAuthorizationHeader) ProxyAuthenticateHeader(javax.sip.header.ProxyAuthenticateHeader) ViaHeader(javax.sip.header.ViaHeader) WWWAuthenticateHeader(javax.sip.header.WWWAuthenticateHeader) AuthorizationHeader(javax.sip.header.AuthorizationHeader) Header(javax.sip.header.Header) SipException(javax.sip.SipException)

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