01: /** An example that illustrates template matching on SIP headers and messages.
02: * This uses regular expressions for matching on portions of sip messages.
03: * This is useful for situations when say you want to match with certain
04: * response classes or request URIs or whatever.
05: * You construct a match template that can consist of portions that are exact
06: * matches and portions that use regular expressions for matching.
07: * This example uses plain strings for patters but you can do wildcard
08: * matching.
09: */package examples.nistgoodies.match;
10:
11: import javax.sip.*;
12: import javax.sip.header.*;
13: import javax.sip.message.*;
14:
15: import gov.nist.javax.sip.header.CSeq;
16: import gov.nist.javax.sip.message.*;
17:
18: public class MatchTest {
19:
20: static final String message1 = "INVITE sip:joe@company.com SIP/2.0\r\n"
21: + "To: sip:joe@company.com\r\n"
22: + "From: sip:caller@university.edu ;tag=1234\r\n"
23: + "Call-ID: 0ha0isnda977644900765@10.0.0.1\r\n"
24: + "CSeq: 9 INVITE\r\n"
25: + "Via: SIP/2.0/UDP 135.180.130.133\r\n"
26: + "Content-Type: application/sdp\r\n"
27: + "\r\n"
28: + "v=0\r\n"
29: + "o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n"
30: + "c=IN IP4 135.180.130.88\r\n"
31: + "m=video 3227 RTP/AVP 31\r\n"
32: + "m=audio 4921 RTP/AVP 12\r\n" + "a=rtpmap:31 LPC\r\n";
33:
34: public static void main(String[] args) throws Exception {
35: SipFactory sipFactory = null;
36: sipFactory = SipFactory.getInstance();
37: sipFactory.setPathName("gov.nist");
38: MessageFactory messageFactory = sipFactory
39: .createMessageFactory();
40: Message message = messageFactory.createRequest(message1);
41:
42: // Create an empty request.
43: Message matchTemplate = messageFactory.createRequest(null);
44:
45: HeaderFactory headerFactory = sipFactory.createHeaderFactory();
46:
47: CSeqHeader cseqHeader = headerFactory.createCSeqHeader(1L,
48: Request.INVITE);
49: gov.nist.javax.sip.header.CSeq cseq = (CSeq) cseqHeader;
50:
51: matchTemplate.setHeader(cseqHeader);
52:
53: boolean retval = ((SIPRequest) message)
54: .match((SIPRequest) matchTemplate);
55:
56: System.out.println("match returned = " + retval);
57:
58: cseq.setMethod(Request.SUBSCRIBE);
59:
60: retval = ((SIPRequest) message)
61: .match((SIPRequest) matchTemplate);
62: System.out.println("match returned = " + retval);
63:
64: }
65:
66: }
|