Package org.restlet.ext.sip

Examples of org.restlet.ext.sip.Address


     */
    public UacClientResource(String uri) {
        this.clientResource = new SipClientResource(uri);
        this.clientResource.setCallId("a84b4c76e66710@pc33.atlanta.com");
        this.clientResource.setCommandSequence("314159");
        this.clientResource.setFrom(new Address("sip:alice@atlanta.com",
                "Alice"));
        this.clientResource.setTo(new Address("sip:bob@biloxi.com", "Bob"));

        Client client = new Client(new Context(), Protocol.SIP);
        client.getContext().getParameters().add("minThreads", "1");
        client.getContext().getParameters().add("tracing", "true");
        client.getContext().getParameters().add("proxyHost", "localhost");
View Full Code Here


    @Test
    public void testParsing() throws Exception {
        String str = "Anonymous <sip:c8oqz84zk7z@privacy.org>;tag=hyh8";
        AddressReader r = new AddressReader(str);
        Address a = r.readValue();

        assertEquals("Anonymous", a.getDisplayName());
        assertEquals("sip:c8oqz84zk7z@privacy.org", a.getReference().toString());
        assertEquals(1, a.getParameters().size());
        Parameter parameter = a.getParameters().get(0);
        assertEquals("tag", parameter.getName());
        assertEquals("hyh8", parameter.getValue());

        str = "sip:+12125551212@server.phone2net.com;tag=887s";
        r = new AddressReader(str);
        a = r.readValue();
        assertNull(a.getDisplayName());
        assertEquals("sip:+12125551212@server.phone2net.com", a.getReference()
                .toString());
        assertEquals(1, a.getParameters().size());
        parameter = a.getParameters().get(0);
        assertEquals("tag", parameter.getName());
        assertEquals("887s", parameter.getValue());

        str = "\"A. G. Bell\" <sip:agb@bell-telephone.com> ;tag=a48s";
        r = new AddressReader(str);
        a = r.readValue();
        assertEquals("A. G. Bell", a.getDisplayName());
        assertEquals("sip:agb@bell-telephone.com", a.getReference().toString());
        assertEquals(1, a.getParameters().size());
        parameter = a.getParameters().get(0);
        assertEquals("tag", parameter.getName());
        assertEquals("a48s", parameter.getValue());

        str = "A. G. Bell <sip:agb@bell-telephone.com> ;tag=a48s";
        r = new AddressReader(str);
        a = r.readValue();
        r = new AddressReader(str);
        a = r.readValue();
        assertEquals("A. G. Bell", a.getDisplayName());
        assertEquals("sip:agb@bell-telephone.com", a.getReference().toString());
        assertEquals(1, a.getParameters().size());
        parameter = a.getParameters().get(0);
        assertEquals("tag", parameter.getName());
        assertEquals("a48s", parameter.getValue());
    }
View Full Code Here

        assertEquals("a48s", parameter.getValue());
    }

    @Test
    public void testWriting() {
        Address a = new Address();
        a.setDisplayName("A. G. Bell");
        a.setReference(new Reference("sip:agb@bell-telephone.com"));
        a.getParameters().add("tag", "a48s");

        AddressWriter w = new AddressWriter();
        assertEquals("\"A. G. Bell\" <sip:agb@bell-telephone.com> ;tag=a48s", w
                .append(a).toString());

        w = new AddressWriter();
        a = new Address();
        a.setDisplayName(null);
        a.setReference(new Reference("sip:agb@bell-telephone.com"));
        a.getParameters().add("tag", "a48s");
        assertEquals("<sip:agb@bell-telephone.com> ;tag=a48s", w.append(a)
                .toString());
    }
View Full Code Here

        return result;
    }

    @Override
    public Address readValue() throws IOException {
        Address result = null;

        skipSpaces();
        if (peek() != -1) {
            result = new Address();
            if (peek() == '"') {
                result.setDisplayName(readQuotedString());
                skipSpaces();
                result.setReference(new Reference(readReference()));
            } else if (peek() == '<') {
                result.setReference(new Reference(readReference()));
            } else if (HeaderUtils.isTokenChar(peek())) {
                // Read value until end or value or parameter separator
                StringBuilder sb = null;
                int next = read();

                while ((next != -1) && !isComma(next) && !isSemiColon(next)) {
                    if (sb == null) {
                        sb = new StringBuilder();
                    }

                    sb.append((char) next);
                    next = read();
                }

                // Remove trailing spaces
                if (sb != null) {
                    for (int i = sb.length() - 1; (i >= 0)
                            && isLinearWhiteSpace(sb.charAt(i)); i--) {
                        sb.deleteCharAt(i);
                    }
                }

                // Unread the separator
                if (isComma(next) || isSemiColon(next)) {
                    unread();
                }

                // The last token is the reference
                int index = sb.lastIndexOf(" ");
                if (index != -1) {
                    if (sb.charAt(index + 1) == '<') {
                        if (sb.charAt(sb.length() - 1) == '>') {
                            result.setReference(new Reference(sb.substring(
                                    index + 2, sb.length() - 1)));
                        } else {
                            throw new IOException(
                                    "Unexpected end of reference. Please check your value");
                        }
                    }
                    result.setDisplayName(sb.substring(0, index).trim());
                } else {
                    result.setReference(new Reference(sb.toString()));
                }
            }
        }

        // Read address parameters.
        if (skipParameterSeparator()) {
            Parameter param = readParameter();

            while (param != null) {
                result.getParameters().add(param);

                if (skipParameterSeparator()) {
                    param = readParameter();
                } else {
                    param = null;
View Full Code Here

TOP

Related Classes of org.restlet.ext.sip.Address

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.