如何改写一个SIP Message中的SDP内容

The message here is either a Request or a Response.

The sample code is as below:

if(message.getContentLength() > 0)

{

    String contentType = message.getContentType();

    message.setContentType("text/plain"); //The SIP Container only can realize this type

    String sdpContent = message.getContent().toString();

    ......// OK,now it just need some operation on String,as the code below

    private void addSDP(SipServletMessage re, String sessionID) {
        try {
            re.setContentType("text/plain");
            String regEx1 = "o=.+";
            String regEx2 = "c=.+";
            String newstr1 = "o=SuperServlet %s IN IP4 %s";
            String newstr2 = "c=IN IP4 0.0.0.0";
            if (re.getContent() != null) {
                String sdp = re.getContent().toString();
                sdp = replace(sdp, regEx1, newstr1);
                sdp = replace(sdp, regEx2, newstr2);
                sdp = String.format(sdp, sessionID, MusicServerIP);
                re.setContent(sdp, "text/plain");
                re.setContentType("application/sdp");
                log("TestServlet: addSDP : Result is " + sdp);
            } else { 
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static String replace(String str, String regex, String newStr) {
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);
        String s = m.replaceAll(newStr);
        return s;
    } 
    message.setContent(sdpContent,"text/plain");
    message.setContentType(contentType);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值