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);
}