Skip to main content

How do i create SIPMessage from String?

2 replies [Last post]
parasuraman
Offline
Joined: 2008-11-07
Points: 0

Hello ,

I have String object that has SIPMessage with all the headers.
How do i convert String into an SIPMessage?

Is there any api to convert string into a SIP request message or SIP response message.?

Thanks in advance..!!

Regards
Parasuraman

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
sangee
Offline
Joined: 2008-12-08
Points: 0

Hi

Hope this piece of code will suffice your need...

public static void main(String[] args) throws Exception {
SipFactory sipFactory = null;
MessageFactory messageFactory;

sipFactory = SipFactory.getInstance();
sipFactory.setPathName("gov.nist");

messageFactory = sipFactory.createMessageFactory();
// If you get a request from a socket, you can use the jsip api to parse it.
String request = "INVITE sip:00001002000022@p25dr;user=TIA-P25-SU SIP/2.0\r\n"
+ "CSeq: 1 INVITE\r\n"
+ "From: ;tag=841\r\n"
+ "To: \r\n"
+ "Via: SIP/2.0/UDP 02.002.00001.p25dr;branch=z9hG4bKa10f04383e3d8e8dbf3f6d06f6bb6880\r\n"
+ "Max-Forwards: 70\r\n"
+ "Route: ,\r\n"
+ "Contact: \r\n"
+ "Timestamp: 1154567665687\r\n"
+ "Allow: REGISTER,INVITE,ACK,BYE,CANCEL\r\n"
+ "Accept: application/sdp ;level=1,application/x-tia-p25-issi\r\n"
+ "Call-ID: c6a12ddad0ddc1946d9f443c884a7768@127.0.0.1\r\n"
+ "Content-Type: application/sdp;level=1\r\n"
+ "P-Asserted-Identity: \r\n"
+ "P-Preferred-Identity: \r\n"
+ "Content-Length: 145\r\n\r\n"
+ "v=0\r\n"
+ "o=- 30576 0 IN IP4 127.0.0.1\r\n"
+ "s=TIA-P25-SuToSuCall\r\n"
+ "t=0 0\r\n"
+ "c=IN IP4 127.0.0.1\r\n"
+ "m=audio 12412 RTP/AVP 100\r\n"
+ "a=rtpmap:100 X-TIA-P25-IMBE/8000\r\n";
Request sipRequest = messageFactory.createRequest(request);
byte[] contentBytes = sipRequest.getRawContent();
String contentString = new String(contentBytes);
System.out.println("------------ SIP Message -------------");
System.out.println(sipRequest);

System.out.println("------------ To get A particular Header Value -------------");
FromHeader from = (FromHeader) sipRequest.getHeader(FromHeader.NAME);
System.out.println(from);

}
}

parasuraman
Offline
Joined: 2008-11-07
Points: 0

Hello Sangee,

I agree with your reply,
but in the String object, there is multiple of from header is available..!
if we have multiples of from Header in the String object, the create request or response has a single header.
How do i resolve it?

Regards
Parasuraman