⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callprocessing.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            Request reoriginatedRequest = null;

            ClientTransaction retryTran = sipManCallback.sipSecurityManager.
            		handleChallenge(response, clientTransaction.getBranchId(),
                                challengedRequest);

//            Dialog dialog = clientTransaction.getDialog();


            //dialog.sendRequest(retryTran);
            retryTran.sendRequest();
        }
        catch (SipSecurityException exc) {
            sipManCallback.fireCommunicationsError(
                new CommunicationsException("Authorization failed!", exc));
        }
//        catch(){}
        catch (Exception exc) {
            sipManCallback.fireCommunicationsError(
                new CommunicationsException("Failed to resend a request "
                                            + "after a security challenge!",
                                            exc)
                );
        }
        finally {
            callDispatcher.findCall(clientTransaction.getDialog()).
                setState(Call.FAILED);
            console.logExit();
        }
    }

    //-------------------------- Requests ---------------------------------
    public void processInvite(ServerTransaction serverTransaction, Request invite)
    {
        try {
            console.logEntry();

            Dialog dialog = serverTransaction.getDialog();
            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();
            if (calleeURI.isSipURI()) {
                String calleeUser = ( (SipURI) calleeURI).getUser();
                String localUser = sipManCallback.getLocalUser();
                //user info is case sensitive according to rfc3261
                if (!calleeUser.equals(localUser)) {
                    sipManCallback.fireCallRejectedLocally(
                        "The user specified by the caller did not match the local user!",
                        invite
                        );
                    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);
                        if( console.isDebugEnabled() )
                            console.debug("sent a not found response: " + 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;
                    }
                    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);
                if( console.isDebugEnabled() )
                    console.debug("sent a ringing response: " + ringing);
            }
            catch (SipException ex) {
                call.setState(Call.DISCONNECTED);
                sipManCallback.fireCommunicationsError(
                    new CommunicationsException(
                    "Failed to send a RINGING response to an INVITE request!"
                    , ex)
                    );
                return;
            }
        }
        finally
        {
            console.logExit();
        }

    }

    public void processTimeout(Transaction transaction, Request request)
    {
        try
        {
            console.logEntry();

            Call call = callDispatcher.findCall(transaction.getDialog());
            if (call == null) {
                return;
            }
            sipManCallback.fireCommunicationsError(
                new CommunicationsException("The remote party has not replied!"
                                            + "The call will be disconnected")
                );
            //change status
            call.setState(Call.DISCONNECTED);
        }
        finally
        {
            console.logExit();
        }
    }

    public void processBye(ServerTransaction serverTransaction, Request byeRequest)
    {
        try
        {
            console.logEntry();

            //find the call
            Call call = callDispatcher.findCall(serverTransaction.
                                                getDialog());
            if (call == null) {
                sipManCallback.fireUnknownMessageReceived(byeRequest);
                return;
            }
            //change status
            call.setState(Call.DISCONNECTED);
            //Send OK
            Response ok = null;
            try {
                ok = sipManCallback.messageFactory.
                    createResponse(Response.OK, byeRequest);
                sipManCallback.attachToTag(ok, call.getDialog());
            }
            catch (ParseException ex) {
                sipManCallback.fireCommunicationsError(
                    new CommunicationsException(
                    "Failed to construct an OK response to a BYE request!",
                    ex)
                    );
                return;
            }
            try {
                serverTransaction.sendResponse(ok);
                if( console.isDebugEnabled() )
                    console.debug("sent response " + ok);
            }
            catch (SipException ex) {
                //This is not really a problem according to the RFC
                //so just dump to stdout should someone be interested
                console.error("Failed to send an OK response to BYE request,"
                              + "exception was:\n",
                              ex);
            }
        }
        finally
        {
            console.logExit();
        }

    }

    public void processAck(ServerTransaction serverTransaction, Request ackRequest)
    {
        try
        {
            console.logEntry();

            if (!serverTransaction.getDialog().getFirstTransaction().getRequest().
                getMethod().equals(Request.INVITE)) {
                console.debug("ignored ack");
                return;
            }
            //find the call
            Call call = callDispatcher.findCall(serverTransaction.
                                                getDialog());
            if (call == null) {
                //this is most probably the ack for a killed call - don't signal it
                //sipManCallback.fireUnknownMessageReceived(ackRequest);
                console.debug("didn't find an ack's call, returning");
                return;
            }
            ContentLengthHeader cl = ackRequest.getContentLength();
            if (cl != null
                && cl.getContentLength() > 0)
            {
                call.setRemoteSdpDescription(new String(ackRequest.getRawContent()));
            }
            //change status
            call.setState(Call.CONNECTED);
        }
        finally
        {
            console.logExit();
        }

    }

    public void processCancel(ServerTransaction serverTransaction,
                       Request cancelRequest)
    {
        try
        {
            console.logEntry();

            if (!serverTransaction.getDialog().getFirstTransaction().getRequest().
                getMethod().equals(Request.INVITE)) {
                //For someone else
                console.debug("ignoring request");
                return;
            }
            //find the call
            Call call = callDispatcher.findCall(serverTransaction.
                                                getDialog());
            if (call == null) {
                sipManCallback.fireUnknownMessageReceived(cancelRequest);
                return;
            }
            //change status
            call.setState(Call.DISCONNECTED);
            // Cancels should be OK-ed and the initial transaction - terminated
            // (report and fix by Ranga)
            try {
                Response ok = sipManCallback.messageFactory.createResponse(Response.
                    OK, cancelRequest);
                sipManCallback.attachToTag(ok, call.getDialog());
                serverTransaction.sendResponse(ok);
                if( console.isDebugEnabled() )
                    console.debug("sent ok response: " + ok);
            }
            catch (ParseException ex) {
                sipManCallback.fireCommunicationsError(
                    new CommunicationsException(
                    "Failed to create an OK Response to an CANCEL request.", ex));
            }
            catch (SipException ex) {
                sipManCallback.fireCommunicationsError(
                    new CommunicationsException(
                    "Failed to send an OK Response to an CANCEL request.", ex));
            }
            try {
                //stop the invite transaction as well
                Transaction tran = call.getDialog().getFirstTransaction();
                //should be server transaction and misplaced cancels should be
                //filtered by the stack but it doesn't hurt checking anyway
                if (! (tran instanceof ServerTransaction)) {
                    sipManCallback.fireCommunicationsError(
                        new CommunicationsException(
                        "Received a misplaced CANCEL request!"));
                    return;
                }
                ServerTransaction inviteTran = (ServerTransaction) tran;
                Request invite = call.getDialog().getFirstTransaction().getRequest();
                Response requestTerminated =
                    sipManCallback.
                    messageFactory.
                    createResponse(Response.REQUEST_TERMINATED, invite);
                sipManCallback.attachToTag(requestTerminated, call.getDialog());
                inviteTran.sendResponse(requestTerminated);
                if( console.isDebugEnabled() )
                    console.debug("sent request terminated response: "
                                  + requestTerminated);
            }
            catch (ParseException ex) {
                sipManCallback.fireCommunicationsError(
                    new CommunicationsException(
                    "Failed to create a REQUEST_TERMINATED Response to an INVITE request.",
                    ex));
            }
            catch (SipException ex) {
                sipManCallback.fireCommunicationsError(
                    new CommunicationsException(
                    "Failed to send an REQUEST_TERMINATED Response to an INVITE request.",
                    ex));
            }
        }
        finally
        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -