All Downloads are FREE. Search and download functionalities are using the official Maven repository.

examples.nistgoodies.match.MatchTest Maven / Gradle / Ivy

There is a newer version: 1.3.0-91
Show newest version
/** An example that illustrates template matching on SIP headers and messages.
* This uses regular expressions for matching on portions of sip messages.
* This is useful for situations when say you want to match with certain
* response classes or request URIs or whatever.
* You construct a match template that can consist of portions that are exact
* matches and portions that use regular expressions for matching.
* This example uses plain strings for patters but you can do wildcard
* matching.
*/

package examples.nistgoodies.match;

import javax.sip.*;
import javax.sip.header.*;
import javax.sip.message.*;

import gov.nist.javax.sip.header.CSeq;
import gov.nist.javax.sip.message.*;


public class MatchTest {


static final String message1 = "INVITE sip:[email protected] SIP/2.0\r\n"+
"To: sip:[email protected]\r\n"+
"From: sip:[email protected] ;tag=1234\r\n"+
"Call-ID: [email protected]\r\n"+
"CSeq: 9 INVITE\r\n"+
"Via: SIP/2.0/UDP 135.180.130.133\r\n"+
"Content-Type: application/sdp\r\n"+
"\r\n"+
"v=0\r\n"+
"o=mhandley 29739 7272939 IN IP4 126.5.4.3\r\n" +
"c=IN IP4 135.180.130.88\r\n" +
"m=video 3227 RTP/AVP 31\r\n" +
"m=audio 4921 RTP/AVP 12\r\n" +
"a=rtpmap:31 LPC\r\n";



    public static void main( String[] args  ) throws Exception {
        SipFactory sipFactory = null;
        sipFactory = SipFactory.getInstance();
        sipFactory.setPathName("gov.nist");
        MessageFactory messageFactory = sipFactory.createMessageFactory();
        Message message = messageFactory.createRequest(message1);

        // Create an empty request.
        Message matchTemplate = messageFactory.createRequest(null);

        HeaderFactory headerFactory = sipFactory.createHeaderFactory();

        CSeqHeader cseqHeader =
            headerFactory.createCSeqHeader(1L,Request.INVITE);
        gov.nist.javax.sip.header.CSeq cseq = (CSeq)cseqHeader;


        matchTemplate.setHeader(cseqHeader);

        boolean retval =
        ((SIPRequest) message).match((SIPRequest)matchTemplate);

        System.out.println("match returned = " + retval);

        cseq.setMethod(Request.SUBSCRIBE);

        retval = ((SIPRequest) message).match((SIPRequest)matchTemplate);
        System.out.println("match returned = " + retval);


    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy