2

I need to extrapolate the SDP from a SIP message in a SIP application. I've tried to do something like:

protected void doInvite(SipServletRequest req) throws ServletException, IOException {
String = req.getContent().toString();
}

But it doesn't return me the SDP. Some advices to solve the problem? Thank you!

MrDjToto
  • 119
  • 2
  • 11

3 Answers3

3

This usually depends on the Content-Type header but given this is an INVITE I'm assuming the Content-Type is application/sdp. If that's the case, did you try the following ?

String sdp = new String(req.getContent())

jeand
  • 2,325
  • 14
  • 12
  • it doesnt work for me, it says "The constructor String(Object) is undefined" – shabby Oct 06 '16 at 09:34
  • @shabby What is your content type or SIP Message coming in with the SDP ? – jeand Oct 06 '16 at 17:38
  • it is not a runtime error, its there at the compile time, the invite packet has SDP in its message body and the request parameter type in the overloaded doInvite method is javax.servlet.sip.SipServletRequest. – shabby Oct 11 '16 at 09:15
  • It can be a byte[] too, see javadoc http://documentation.telestax.com/core/sip_servlets/javadocs/javax/servlet/sip/SipServletMessage.html#getContent() – jeand Oct 11 '16 at 09:38
2

But it doesn't return me the SDP. Some advices to solve the problem?

Try the following to get SDP, I am using it to pack SDP in session_progress, in the doInvite method:

@Override
protected void doInvite(SipServletRequest request) throws ServletException, IOException {
    byte[] sdpOffer = request.getRawContent();

    try {
        SipServletResponse response = request.createResponse(SipServletResponse.SC_SESSION_PROGRESS);
        response.setContent(sdpOffer, "application/sdp");
        response.send();
        logger.info("SESSION_PROGRESS sent");
    } catch (Exception exp) {
        logger.error("exception in sending SP", exp);
    }
}

Note: the code is not complete, you need to do other things as well when you are replying with Session_Progress

shabby
  • 3,002
  • 3
  • 39
  • 59
0

I put json text string as sip message content. After I set the request.setContentType("text/json"); in both client and server code, I can get the content json string right.

Jue Wang
  • 11
  • 2