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

📄 sipmanager.java

📁 jtapi for telephone
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    }
    
    
    /**
     * Causes CallProcessing to send a 200 OK response, with the specified
     * sdp description, to the specified call's remote party.
     * @param callID the id of the call that is to be answered.
     * @param sdpContent this party's media description (as defined by SDP).
     * @throws CommunicationsException if an axeption occurs while invoking this
     * method.
     */
    public void answerCall(int callID, String sdpContent) throws
    CommunicationsException
    {
        try
        {
            console.logEntry();
            checkIfStarted();
            callProcessing.sayOK(callID, sdpContent);
        }
        finally
        {
            console.logExit();
        }
    } //answer to
    
    /**
     * Sends a NOT_IMPLEMENTED response through the specified transaction.
     * @param serverTransaction the transaction to send the response through.
     * @param request the request that is being answered.
     */
    void sendNotImplemented(ServerTransaction serverTransaction,
    Request request)
    {
        try
        {
            console.logEntry();
            Response notImplemented = null;
            try
            {
                notImplemented =
                messageFactory.createResponse(Response.NOT_IMPLEMENTED,
                request);
                attachToTag(notImplemented, serverTransaction.getDialog());
            }
            catch (ParseException ex)
            {
                fireCommunicationsError(
                new CommunicationsException(
                "Failed to create a NOT_IMPLEMENTED response to a "
                + request.getMethod()
                + " request!",
                ex)
                );
                return;
            }
            try
            {
                serverTransaction.sendResponse(notImplemented);
            }
            catch (SipException ex)
            {
                fireCommunicationsError(
                new CommunicationsException(
                "Failed to create a NOT_IMPLEMENTED response to a "
                + request.getMethod()
                + " request!",
                ex)
                );
            }
        }
        finally
        {
            console.logExit();
        }
    }
    
    //============================= Utility Methods ==================================
    /**
     * Initialises SipManager's fromHeader field in accordance with
     * net.java.sip.communicator.sip.PUBLIC_ADDRESS
     * net.java.sip.communicator.sip.DISPLAY_NAME
     * net.java.sip.communicator.sip.TRANSPORT
     * net.java.sip.communicator.sip.PREFERRED_LOCAL_PORT and returns a
     * reference to it.
     * @return a reference to SipManager's fromHeader field.
     * @throws CommunicationsException if a ParseException occurs while
     * initially composing the FromHeader.
     */
    public FromHeader getFromHeader() throws CommunicationsException
    {
        try
        {
            console.logEntry();
            if (fromHeader != null)
            {
                return fromHeader;
            }
            try
            {
                SipURI fromURI = (SipURI) addressFactory.createURI(
                currentlyUsedURI);
                //Unnecessary test (report by Willem Romijn)
                //if (console.isDebugEnabled())
                fromURI.setTransportParam(listeningPoint.getTransport());
                
                fromURI.setPort(listeningPoint.getPort());
                Address fromAddress = addressFactory.createAddress(fromURI);
                if (displayName != null && displayName.trim().length() > 0)
                {
                    fromAddress.setDisplayName(displayName);
                }
                fromHeader = headerFactory.createFromHeader(fromAddress,
                Integer.toString(hashCode()));
                console.debug("Generated from header: " + fromHeader);
            }
            catch (ParseException ex)
            {
                console.error(
                "A ParseException occurred while creating From Header!", ex);
                throw new CommunicationsException(
                "A ParseException occurred while creating From Header!", ex);
            }
            return fromHeader;
        }
        finally
        {
            console.logExit();
        }
    }
    
    /**
     * Same as calling getContactHeader(true)
     *
     * @return the result of getContactHeader(true)
     * @throws CommunicationsException if an exception is thrown while calling
     * getContactHeader(false)
     */
    public ContactHeader getContactHeader() throws CommunicationsException
    {
        return getContactHeader(true);
    }
    
    /**
     * Same as calling getContactHeader(true).
     * @return the result of calling getContactHeader(true).
     * @throws CommunicationsException if an exception occurs while executing
     * getContactHeader(true).
     */
    public ContactHeader getRegistrationContactHeader() throws CommunicationsException
    {
        return getContactHeader(true);
    }
    
    /**
     * Initialises SipManager's contactHeader field in accordance with
     * javax.sip.IP_ADDRESS
     * net.java.sip.communicator.sip.DISPLAY_NAME
     * net.java.sip.communicator.sip.TRANSPORT
     * net.java.sip.communicator.sip.PREFERRED_LOCAL_PORT and returns a
     * reference to it.
     * @param useLocalHostAddress specifies whether the SipURI in the contact
     * header should contain the value of javax.sip.IP_ADDRESS (true) or that of
     * net.java.sip.communicator.sip.PUBLIC_ADDRESS (false).
     * @return a reference to SipManager's contactHeader field.
     * @throws CommunicationsException if a ParseException occurs while
     * initially composing the FromHeader.
     */
    public ContactHeader getContactHeader(boolean useLocalHostAddress) throws
    CommunicationsException
    {
        try
        {
            console.logEntry();
            if (contactHeader != null)
            {
                return contactHeader;
            }
            try
            {
                
                SipURI contactURI;
                if (useLocalHostAddress)
                {
                    
                    contactURI = (SipURI) addressFactory.createSipURI(null,
                    publicIpAddress.getAddress().getHostAddress());
                }
                else
                {
                    contactURI = (SipURI) addressFactory.createURI(
                    currentlyUsedURI);
                }
                contactURI.setTransportParam(listeningPoint.getTransport());
                contactURI.setPort(publicIpAddress.getPort());
                Address contactAddress = addressFactory.createAddress(
                contactURI);
                if (displayName != null && displayName.trim().length() > 0)
                {
                    contactAddress.setDisplayName(displayName);
                }
                contactHeader = headerFactory.createContactHeader(
                contactAddress);
                if (console.isDebugEnabled())
                {
                    console.debug("generated contactHeader:" + contactHeader);
                }
            }
            catch (ParseException ex)
            {
                console.error(
                "A ParseException occurred while creating From Header!", ex);
                throw new CommunicationsException(
                "A ParseException occurred while creating From Header!", ex);
            }
            return contactHeader;
        }
        finally
        {
            console.logExit();
        }
    }
    
    /**
     * Initializes (if null) and returns an ArrayList with a single ViaHeader
     * containing localhost's address. This ArrayList may be used when sending
     * requests.
     * @return ViaHeader-s list to be used when sending requests.
     * @throws CommunicationsException if a ParseException is to occur while
     * initializing the array list.
     */
    public ArrayList getLocalViaHeaders() throws CommunicationsException
    {
        try
        {
            console.logEntry();
            if (viaHeaders != null)
            {
                return viaHeaders;
            }
            ListeningPoint lp = sipProvider.getListeningPoint();
            viaHeaders = new ArrayList();
            try
            {
                ViaHeader viaHeader = headerFactory.createViaHeader(
                sipStack.getIPAddress(),
                lp.getPort(),
                lp.getTransport(),
                null
                );
                viaHeaders.add(viaHeader);
                if (console.isDebugEnabled())
                {
                    console.debug("generated via headers:" + viaHeader);
                }
                return viaHeaders;
            }
            catch (ParseException ex)
            {
                console.error(
                "A ParseException occurred while creating Via Headers!");
                throw new CommunicationsException(
                "A ParseException occurred while creating Via Headers!");
            }
            catch (InvalidArgumentException ex)
            {
                console.error(
                "Unable to create a via header for port " + lp.getPort(),
                ex);
                throw new CommunicationsException(
                "Unable to create a via header for port " + lp.getPort(),
                ex);
            }
        }
        finally
        {
            console.logExit();
        }
    }
    
    /**
     * Initializes and returns SipManager's maxForwardsHeader field using the
     * value specified by MAX_FORWARDS.
     * @return an instance of a MaxForwardsHeader that can be used when
     * sending requests
     * @throws CommunicationsException if MAX_FORWARDS has an invalid value.
     */
    public MaxForwardsHeader getMaxForwardsHeader() throws CommunicationsException
    {
        try
        {
            console.logEntry();
            if (maxForwardsHeader != null)
            {
                return maxForwardsHeader;
            }
            try
            {
                maxForwardsHeader = headerFactory.createMaxForwardsHeader(MAX_FORWARDS);
                if (console.isDebugEnabled())
                {
                    console.debug("generate max forwards: "
                    + maxForwardsHeader.toString());
                }
                return maxForwardsHeader;
            }
            catch (InvalidArgumentException ex)
            {
                throw new CommunicationsException(
                "A problem occurred while creating MaxForwardsHeader", ex);
            }
        }
        finally
        {
            console.logExit();
        }
    }
    
    /**
     * Returns the user used to create the From Header URI.
     * @return the user used to create the From Header URI.
     */
    public String getLocalUser()
    {
        try
        {
            console.logEntry();
            return ( (SipURI) getFromHeader().getAddress().getURI()).getUser();
        }
        catch (CommunicationsException ex)
        {
            return "";
        }
        finally
        {
            console.logExit();
        }
    }
    
    /**
     * Generates a ToTag (the containingDialog's hashCode())and attaches it to
     * response's ToHeader.
     * @param response the response that is to get the ToTag.
     * @param containingDialog the Dialog instance that is to extract a unique
     * Tag value (containingDialog.hashCode())
     */
    public void attachToTag(Response response, Dialog containingDialog)
    {
        try
        {
            console.logEntry();
            ToHeader to = (ToHeader) response.getHeader(ToHeader.NAME);
            if (to == null)
            {
                fireCommunicationsError(
                new CommunicationsException(
                "No TO header found in, attaching a to tag is therefore impossible"));
            }
            try
            {
                if (to.getTag() == null || to.getTag().trim().length() == 0)
                {
                    if (console.isDebugEnabled())
                    {
                        console.debug("generated to tag: " +
                        containingDialog.hashCode());

⌨️ 快捷键说明

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