Package net.sourceforge.peers.sip.transport

Examples of net.sourceforge.peers.sip.transport.SipMessage


       
        String startLine = reader.readLine();
        while (startLine == null || startLine.equals("")) {
            startLine = reader.readLine();
        }
        SipMessage sipMessage;
        if (startLine.toUpperCase().startsWith(RFC3261.DEFAULT_SIP_VERSION)) {
            sipMessage = parseSipResponse(startLine);
        }
        else {
            sipMessage = parseSipRequest(startLine);
View Full Code Here


public class SipParserTestNG {

    @Test
    public void testParse() throws SipParserException, IOException {
        //request
        SipMessage sipMessage = parse("INVITE sip:UAB@example.com SIP/2.0\r\n"
                + "\r\n");
        assert SipRequest.class.equals(sipMessage.getClass());
        //response
        sipMessage = parse("SIP/2.0 100 Trying\r\n"
                + "\r\n");
        assert SipResponse.class.equals(sipMessage.getClass());
        //empty first lines
        sipMessage = parse("\r\n"
                + "\r\n"
                + "\r\n"
                + "INVITE sip:UAB@example.com SIP/2.0\r\n"
                + "\r\n");
        assert SipRequest.class.equals(sipMessage.getClass());
    }
View Full Code Here

        assert SipRequest.class.equals(sipMessage.getClass());
    }

    @Test
    public void testParseHeaders() throws SipParserException, IOException {
        SipMessage sipMessage = parse("INVITE sip:UAB@example.com SIP/2.0\r\n"
                + "Via: SIP/2.0/UDP 10.20.30.40:5060\r\n"
                + "\r\n");
        assert sipMessage != null;
        SipHeaders sipHeaders = sipMessage.getSipHeaders();
        assert 1 == sipHeaders.getCount();
        SipHeaderFieldName via = new SipHeaderFieldName("Via");
        SipHeaderFieldValue value = sipHeaders.get(via);
        assert value != null;
        assert "SIP/2.0/UDP 10.20.30.40:5060".equals(value.toString());
View Full Code Here

        assert "SIP/2.0/UDP 10.20.30.40:5060".equals(value.toString());
    }
   
    @Test
    public void testParseMultilineHeader() throws SipParserException, IOException {
        SipMessage sipMessage = parse("INVITE sip:UAB@example.com SIP/2.0\r\n"
                + "Via: SIP/2.0/UDP 10.20.30.40:5060\r\n"
                + "Subject: I know you're there,\r\n"
                + "         pick up the phone\r\n"
                + "         and talk to me!\r\n"
                + "\r\n");
        assert sipMessage != null;
        SipHeaders sipHeaders = sipMessage.getSipHeaders();
        assert 2 == sipHeaders.getCount();
        SipHeaderFieldValue value = sipHeaders.get(new SipHeaderFieldName("Subject"));
        assert !(value instanceof SipHeaderFieldMultiValue);
        assert "I know you're there, pick up the phone and talk to me!".equals(
                value.toString());
View Full Code Here

                value.toString());
    }
   
    @Test
    public void testParseMultiHeader() throws SipParserException, IOException {
        SipMessage sipMessage = parse("INVITE sip:UAB@example.com SIP/2.0\r\n"
                + "Route: <sip:alice@atlanta.com>\r\n"
                + "Subject: Lunch\r\n"
                + "Route: <sip:bob@biloxi.com>\r\n"
                + "Route: <sip:carol@chicago.com>\r\n"
                + "\r\n");
        SipHeaders sipHeaders = sipMessage.getSipHeaders();
        assert sipHeaders != null;
        assert 2 == sipHeaders.getCount();
        SipHeaderFieldValue subject = sipHeaders.get(new SipHeaderFieldName("Subject"));
        assert subject != null;
        assert "Lunch".equals(subject.toString());
View Full Code Here

            .equals(route.toString());
    }
   
    @Test
    public void testHeaderParams() throws SipParserException, IOException {
        SipMessage sipMessage = parse("INVITE sip:UAB@example.com SIP/2.0\r\n"
                + "Via: <sip:alice@atlanta.com>;transport=TCP\r\n"
                + "\r\n");
        SipHeaderFieldValue value =
            sipMessage.getSipHeaders().get(new SipHeaderFieldName("Via"));
        assert "TCP".equals(value.getParam(new SipHeaderParamName("transport")));
        assert "TCP".equals(value.getParam(new SipHeaderParamName("Transport")));
    }
View Full Code Here

        assert "TCP".equals(value.getParam(new SipHeaderParamName("Transport")));
    }
   
    @Test
    public void testCompactHeaders() throws SipParserException, IOException {
        SipMessage sipMessage = parse("OPTIONS sip:h@google.com SIP/2.0\r\n" +
                "i: mldkjf43532@host.domain\r\n" +
                "m: <192.168.5.6:43673>\r\n" +
                "e:gzip\r\n" +
                "l: \r\n" +
                "  15\r\n" +
                "c: text/html\r\n" +
                "f:\"Jessy James\" <sip:jenny@jones.com>;tag=kpo34fz\r\n" +
                "s:what about the wheather today\r\n" +
                "k: INVITE,BYE, CANCEL\r\n" +
                "t: john the ripper <sip:john@ripper.com;killer>;tag=kpsd4fz\r\n" +
                "v: SIP/2.0/UDP 192.168.20.2;branch=mdsif12f\r\n" +
                "v: SIP/2.0/UDP 172.20.2.168;branch=msdf343f\r\n" +
                "v: SIP/2.0/UDP 10.1.5.7;branch=mfdf343f\r\n" +
                "v: SIP/2.0/UDP 64.32.165.46;branch=m134343f\r\n" +
                "\r\n" +
                "kd\r\n" +
                "pe0_\n" +
                ";_{\r" +
                " p");
        SipHeaders sipHeaders = sipMessage.getSipHeaders();
        SipHeaderFieldValue callId =
            sipHeaders.get(new SipHeaderFieldName(RFC3261.HDR_CALLID));
        assert callId != null;
        assert callId.getValue().indexOf("ldkjf43532@host.domain") > -1;
        SipHeaderFieldValue contact =
            sipHeaders.get(new SipHeaderFieldName(RFC3261.HDR_CONTACT));
        assert contact != null;
        assert contact.getValue().indexOf("<192.168.5.6:43673>") > -1;
        SipHeaderFieldValue contentEncoding =
            sipHeaders.get(new SipHeaderFieldName(RFC3261.HDR_CONTENT_ENCODING));
        assert contentEncoding != null;
        assert contentEncoding.getValue().indexOf("gzip") > -1;
        SipHeaderFieldValue contentlLength =
            sipHeaders.get(new SipHeaderFieldName(RFC3261.HDR_CONTENT_LENGTH));
        assert contentlLength != null;
        assert contentlLength.getValue().indexOf("15") > -1;
        assert sipMessage.getBody().length == 15;
        SipHeaderFieldValue contentType =
            sipHeaders.get(new SipHeaderFieldName(RFC3261.HDR_CONTENT_TYPE));
        assert contentType != null;
        assert contentType.getValue().indexOf("text/html") > -1;
        SipHeaderFieldValue from =
View Full Code Here

        assert values.get(3).getValue().indexOf("SIP/2.0/UDP 64.32.165.46") > -1;
    }
   
    @Test
    public void testMultiValueHeader() throws IOException, SipParserException {
        SipMessage sipMessage = parse("SIP/2.0 200 OK\r\n"
                + "From: <sip:ymartineau@ippi.fr>;tag=MMnvBY6R\r\n"
                + "Call-ID: 2Lb6Uyyx-1290462442914@192.168.1.23\r\n"
                + "CSeq: 4 INVITE\r\n"
                + "Via: SIP/2.0/UDP 192.168.1.23:6060;rport=6060;branch=z9hG4bKnksFOe9ut;received=77.193.94.155\r\n"
                + "To: <sip:2233400543@sip2sip.info>;tag=rZPsRkLoKg\r\n"
                + "Content-Length: 234\r\n"
                + "Content-Type: application/sdp\r\n"
                + "Record-Route: <sip:81.23.228.129;lr;ftag=MMnvBY6R;did=1a1.f7c24a35>, <sip:85.17.186.7;lr;ftag=MMnvBY6R;did=1a1.c11e9535>, <sip:213.215.45.230;lr=on>\r\n"
                + "Contact: <sip:77.193.94.155:6062;transport=UDP>\r\n"
                + "\r\n"
                + "v=0\r\n"
                + "o=user1 881398656 1035667908 IN IP4 213.215.45.245\r\n"
                + "s=-\r\n"
                + "c=IN IP4 213.215.45.245\r\n"
                + "t=0 0\r\n"
                + "m=audio 53452 RTP/AVP 0 8 101\r\n"
                + "a=rtpmap:0 PCMU/8000\r\n"
                + "a=rtpmap:8 PCMA/8000\r\n"
                + "a=rtpmap:101 telephone-event/8000\r\n"
                + "a=sendrecv\r\n"
                + "a=nortpproxy:yes\r\n");
        SipHeaders sipHeaders = sipMessage.getSipHeaders();
        SipHeaderFieldValue recordRoute = sipHeaders.get(
                new SipHeaderFieldName(RFC3261.HDR_RECORD_ROUTE));
        assert recordRoute instanceof SipHeaderFieldMultiValue;
        SipHeaderFieldMultiValue recordRouteMulti = (SipHeaderFieldMultiValue)recordRoute;
        List<SipHeaderFieldValue> values = recordRouteMulti.getValues();
View Full Code Here

        assert "<sip:213.215.45.230;lr=on>".equals(values.get(2).getValue().trim());
    }

    @Test
    public void testParseBody() throws SipParserException, IOException {
        SipMessage sipMessage = parse("INVITE sip:UAB@example.com SIP/2.0\r\n"
                + "Via: <sip:alice@atlanta.com>;transport=TCP\r\n"
                + "Content-Length: 15\r\n"
                + "\r\n"
                + "a=134\r\n"
                + "b=test\r\n");
        assert sipMessage != null;
        assert 2 == sipMessage.getSipHeaders().getCount();
        byte[] expectedBody = "a=134\r\nb=test\r\n".getBytes();
        byte[] realBody = sipMessage.getBody();
        assert expectedBody.length == realBody.length;
        for (int i = 0; i < expectedBody.length; ++i) {
            assert expectedBody[i] == realBody[i];
        }
       
        byte[] binaryBody = new byte[0x10];
        for (byte i = 0x0; i < binaryBody.length; ++i) {
            binaryBody[i] = i;
        }
        sipMessage = parse("INVITE sip:UAB@example.com SIP/2.0\r\n"
                + "Via: <sip:alice@atlanta.com>;transport=TCP\r\n"
                + "Content-Length: " + binaryBody.length + "\r\n"
                + "\r\n"
                + new String(binaryBody));
        realBody = sipMessage.getBody();
        assert binaryBody.length == realBody.length;
        for (int i = 0; i < expectedBody.length; ++i) {
            assert binaryBody[i] == realBody[i];
        }
    }
View Full Code Here

    }
   
    private SipMessage parse(String message) throws SipParserException, IOException {
        ByteArrayInputStream bais = new ByteArrayInputStream(message.getBytes());
        SipParser sipParser = new SipParser();
        SipMessage sipMessage = sipParser.parse(bais);
        return sipMessage;
    }
View Full Code Here

TOP

Related Classes of net.sourceforge.peers.sip.transport.SipMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.