【问题标题】:SIP Servlets: SipServletRequest getcontent as xmlSIP Servlet:SipServletRequest getcontent as xml
【发布时间】:2014-11-30 18:41:33
【问题描述】:

我正在使用 SIP Servlets API 在 SIP SIMPLE 上进行 POC。

在发布请求中,我想读取已发布 XML 的内容。 我知道请求的内容类型是application/pidf+xml。但我无法将它转换为 XML,我不知道哪个类处理这个问题,当我尝试找出对象的类名时,它也返回一些值,如 [B

protected void doPublish(SipServletRequest req) throws ServletException,
            IOException {
        // TODO Auto-generated method stub
        super.doPublish(req);       
        Object o = req.getContent();
        System.out.println("ContentType "+req.getContentType());
        System.out.println("Class "+o.getClass().getName());
    }

请告诉我如何将返回的对象转换为 XML。我真的很难找到正确的方法。

谢谢

我的解决方案: 不知道这是解决方案还是解决方法,但以下是我所做的:

byte[] o = (byte[]) req.getContent();
String s = new String(o);
System.out.println("Class type "+s);

所以,s 现在有了可以转换为 XML 的 XML 字符串。

如果有更好的解决方案,请发帖。

谢谢

【问题讨论】:

    标签: java sip user-presence sip-servlet


    【解决方案1】:

    不知道这是解决方案还是变通方法,但以下是我所做的:

    byte[] o = (byte[]) req.getContent();
    String s = new String(o);
    System.out.println("Class type "+s);
    

    所以,s 现在有了可以转换为 XML 的 XML 字符串。

    如果有更好的解决方案,请发帖。

    谢谢

    【讨论】:

    • 这是一个好的开始,但对于一般的解决方案,您需要在获取 XML 之前清理任何 MIME 标头,如果它是多部分的 SDP,您还需要清理可能出现在 PIDF 之前的 SDP 部分
    猜你喜欢
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 2013-11-01
    • 2018-01-13
    • 2017-08-13
    • 2012-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多