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

📄 responseforwarding.java

📁 First of all, the Applet-phone is a SIP User-Agent with audio and text messaging capabilities. But
💻 JAVA
字号:
/* * ResponseForwarding.java * * Created on April 16, 2003, 11:09 AM */package gov.nist.examples.bps.gateway;import java.util.*;import javax.sip.*;import javax.sip.message.*;import javax.sip.header.*;import javax.sip.address.*;import tools.rtpgateway.*;/** * * @author  deruelle */public class ResponseForwarding {        protected Gateway gateway;        /** Creates a new instance of ResponseForwarding */    public ResponseForwarding(Gateway gateway) {        this.gateway=gateway;    }        public void forwardResponse(SipProvider sipProvider,    Response response,ClientTransaction clientTransaction) {        MessageFactory messageFactory=gateway.getMessageFactory();        HeaderFactory headerFactory=gateway.getHeaderFactory();        AddressFactory addressFactory=gateway.getAddressFactory();        Configuration configuration=gateway.getConfiguration();        try{            /*******************************************************************************//***********************  gateway BEHAVIOR    ************************************//*******************************************************************************/                                Response clonedResponse = (Response) response.clone();            /*             String textsdp="v=0\n"+"o=Pingtel 5 5 IN IP4 129.6.50.25\n"+"s=phone-call\n"+"c=IN IP4 129.6.50.25\n"+"t=0 0\n"+"m=audio 8770 RTP/AVP 0 8\n";//+//"a=rtpmap:0 pcmu/8000/1\n"+//"a=rtpmap:8 pcma/8000/1\n";              ContentTypeHeader contentTypeHeader1=headerFactory.createContentTypeHeader(                            "application","sdp");                  clonedResponse.setContent(textsdp,contentTypeHeader1);                             System.out.println(response);             */            if (clientTransaction == null)  {                if (GatewayDebug.debug)                    GatewayDebug.println                    ("ResponseForwarding, forwardResponse(), the client transaction"+                    " does not exist, we"+                    " will forward the response statelessly!");                               // if (gatewayUtilities.hasTopViaHeadergateway(sipStack,response) ) {                    ListIterator viaList=clonedResponse.getHeaders(ViaHeader.NAME);                    clonedResponse.removeHeader(ViaHeader.NAME);                    Vector v=new Vector();                    viaList.next();                    while (viaList!=null && viaList.hasNext()) {                        ViaHeader viaHeader=(ViaHeader) viaList.next();                        v.addElement(viaHeader);                    }                    for (int j=0;j<v.size();j++) {                        ViaHeader viaHeader=(ViaHeader) v.elementAt(j);                        clonedResponse.addHeader(viaHeader);                    }                                        viaList=clonedResponse.getHeaders(ViaHeader.NAME);                    if (viaList==null || !viaList.hasNext()) {                        if (GatewayDebug.debug)                            GatewayDebug.println                            ("ResponseForwarding, forwardResponse(), the response (Via header)does"+                            " not have any Via header, the response is silently discarded");                    }                    else {                        // let's hope the sipProvider will take the Viaheader to                        // forward the response...                                                // We have to open a hole                        CSeqHeader cseqHeader=(CSeqHeader)clonedResponse.getHeader(CSeqHeader.NAME);                        if ( clonedResponse.getStatusCode() == 200 &&                        cseqHeader.getMethod().equals("INVITE") && configuration.enableRTPGateway) {                            try{                                                               Object content=clonedResponse.getContent();                                String text=null;                                if (content instanceof String)                                    text=(String)content;                                else                                    if (content instanceof byte[] ) {                                        text=new String(  (byte[])content  );                                    }                                                                GatewayDebug.println                                ("ResponseForwarding, forwardResponse(), SDP text:"+text);                                if (text!=null) {                                     ContentTypeHeader contentTypeHeader=gateway.                                        headerFactory.createContentTypeHeader(                                        "application","sdp");                                    // The SDP is received let's open a hole:                                    SipStack sipStack=sipProvider.getSipStack();                                    SipStack opp=gateway.getOppositeSipStack(sipStack.getIPAddress());                                                                        CallIdHeader callIdHeader=(CallIdHeader)clonedResponse.                                    getHeader(CallIdHeader.NAME);                                                                                                    RTPHole secondRTPHole=gateway.rtpHolesManager.createRTPHole(                                    callIdHeader.getCallId(),                                    text,                                    opp.getIPAddress(),                                    sipStack.getIPAddress());                                                                        GatewayDebug.println                                    ("ResponseForwarding, forwardResponse(), we open this hole...");                                                                        secondRTPHole.open();                                                                                                            String generatedSDPHole=secondRTPHole.getGeneratedSDPHole();                                    clonedResponse.setContent(generatedSDPHole,contentTypeHeader);                                    clonedResponse.removeHeader(ContactHeader.NAME);                                                                    }                            }                            catch(Exception e){                                e.printStackTrace();                                GatewayDebug.println                                    ("ResponseForwarding, forwardResponse(), problem"+                                    " to open the RTP hole...");                                                                }                        }                                    sipProvider.sendResponse(clonedResponse);                                     if (GatewayDebug.debug)                            GatewayDebug.println                            ("ResponseForwarding, forwardResponse(), the response statelessly forwarded:\n"+                            clonedResponse.toString());                    }                    return;                }                else {                    //If the address does not match the                    //gateway, the message MUST be silently discarded.                    if (GatewayDebug.debug)                        GatewayDebug.println                        ("ResponseForwarding, forwardResponse(), the address (Via header)does not"+                        " match the gateway, the message is silently discarded");                    return;                }                            //}                     }        catch (Exception ex) {            if (GatewayDebug.debug) {                GatewayDebug.println("ResponseForwarding, forwardResponse(), internal error, "+                "exception raised:");                GatewayDebug.logException(ex);            }        }    }}

⌨️ 快捷键说明

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