Package org.restlet.data

Examples of org.restlet.data.Parameter


        MediaType mt2 = MediaType.APPLICATION_XML;
        assertTrue(mt1.equals(mt2));
        assertEquals(mt1, mt2);

        final Series<Parameter> mediaParams1 = new Form();
        mediaParams1.add(new Parameter("charset", "ISO-8859-1"));
        final MediaType mt1Bis = new MediaType("application/xml", mediaParams1);

        final Series<Parameter> mediaParams2 = new Form();
        mediaParams2.add(new Parameter("charset", "ISO-8859-1"));
        final MediaType mt2Bis = new MediaType("application/xml", mediaParams2);

        final Series<Parameter> mediaParams3 = new Form();
        mediaParams3.add(new Parameter("charset", "ISO-8859-15"));
        final MediaType mt3 = new MediaType("application/xml", mediaParams3);

        assertTrue(mt1Bis.equals(mt2Bis));
        assertEquals(mt1, mt2);
        assertTrue(mt1Bis.equals(mt1, true));
View Full Code Here


        MediaType mt1 = new MediaType("application/xml");
        MediaType mt2 = new MediaType("application/xml2");
        assertFalse(mt1.equals(mt2));

        final Series<Parameter> mediaParams1 = new Form();
        mediaParams1.add(new Parameter("charset", "ISO-8859-1"));
        final MediaType mt1Bis = new MediaType("application/xml", mediaParams1);

        final Series<Parameter> mediaParams3 = new Form();
        mediaParams3.add(new Parameter("charset", "ISO-8859-15"));
        final MediaType mt3 = new MediaType("application/xml", mediaParams3);

        assertFalse(mt1Bis.equals(mt1));
        assertFalse(mt1Bis.equals(mt3));
View Full Code Here

* @author Jerome Louvel
*/
public class RecipientInfoTestCase extends RestletTestCase {

    public void testVia() {
        Parameter via1a = new Parameter(HeaderConstants.HEADER_VIA,
                "1.0 fred, 1.1 nowhere.com (Apache/1.1)");
        Parameter via1b = new Parameter(HeaderConstants.HEADER_VIA,
                "HTTP/1.0 fred, HTTP/1.1 nowhere.com (Apache/1.1)");
        Parameter via1c = new Parameter(HeaderConstants.HEADER_VIA,
                "HTTP/1.0 fred (Apache/1.1), HTTP/1.1 nowhere.com");
        Parameter via1d = new Parameter(HeaderConstants.HEADER_VIA,
        "HTTP/1.0 fred (Apache/1.1), HTTP/1.1 nowhere.com:8111");
       
        List<RecipientInfo> recipients = new ArrayList<RecipientInfo>();
        RecipientInfoReader.addValues(via1a, recipients);

        assertEquals(2, recipients.size());

        RecipientInfo recipient1 = recipients.get(0);
        RecipientInfo recipient2 = recipients.get(1);

        assertEquals("1.0", recipient1.getProtocol().getVersion());
        assertEquals("1.1", recipient2.getProtocol().getVersion());

        assertEquals("fred", recipient1.getName());
        assertEquals("nowhere.com", recipient2.getName());

        assertNull(recipient1.getComment());
        assertEquals("Apache/1.1", recipient2.getComment());

        String header = RecipientInfoWriter.write(recipients);
        assertEquals(via1b.getValue(), header);

        recipients = new ArrayList<RecipientInfo>();
        RecipientInfoReader.addValues(via1c, recipients);
        recipient1 = recipients.get(0);
        recipient2 = recipients.get(1);

        assertEquals("1.0", recipient1.getProtocol().getVersion());
        assertEquals("1.1", recipient2.getProtocol().getVersion());

        assertEquals("fred", recipient1.getName());
        assertEquals("nowhere.com", recipient2.getName());

        assertEquals("Apache/1.1", recipient1.getComment());
        assertNull(recipient2.getComment());

        recipients = new ArrayList<RecipientInfo>();
        RecipientInfoReader.addValues(via1d, recipients);
        recipient1 = recipients.get(0);
        recipient2 = recipients.get(1);

        assertEquals("1.0", recipient1.getProtocol().getVersion());
        assertEquals("1.1", recipient2.getProtocol().getVersion());

        assertEquals("fred", recipient1.getName());
        assertEquals("nowhere.com:8111", recipient2.getName());

        assertEquals("Apache/1.1", recipient1.getComment());
        assertNull(recipient2.getComment());

        header = RecipientInfoWriter.write(recipients);
        assertEquals(via1d.getValue(), header);
    }
View Full Code Here

            String nextNonce = null;
            String qop = null;
            String responseAuth = null;
            String cnonce = null;
            int nonceCount = 0;
            Parameter param = hr.readValue();

            while (param != null) {
                try {
                    if ("nextnonce".equals(param.getName())) {
                        nextNonce = param.getValue();
                    } else if ("qop".equals(param.getName())) {
                        qop = param.getValue();
                    } else if ("rspauth".equals(param.getName())) {
                        responseAuth = param.getValue();
                    } else if ("cnonce".equals(param.getName())) {
                        cnonce = param.getValue();
                    } else if ("nc".equals(param.getName())) {
                        nonceCount = Integer.parseInt(param.getValue(), 16);
                    }

                    if (hr.skipValueSeparator()) {
                        param = hr.readValue();
                    } else {
View Full Code Here

        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(Protocol.SIP, s.getProtocol());
        assertEquals("UDP", s.getTransport());
        assertEquals("192.0.2.1:5060", s.getName());

        assertEquals(2, s.getParameters().size());
        Parameter parameter = s.getParameters().get(0);
        assertEquals("received", parameter.getName());
        assertEquals("192.0.2.207", parameter.getValue());
        parameter = s.getParameters().get(1);
        assertEquals("branch", parameter.getName());
        assertEquals("z9hG4bK77asjd", parameter.getValue());
        assertNull(s.getComment());

        str = "SIP/2.0/UDP 192.0.2.1:5060 ;received=192.0.2.207;branch=z9hG4bK77asjd (this is a comment)";
        r = new SipRecipientInfoReader(str);
        s = r.readValue();

        assertEquals(Protocol.SIP, s.getProtocol());
        assertEquals("UDP", s.getTransport());
        assertEquals("192.0.2.1:5060", s.getName());

        assertEquals(2, s.getParameters().size());
        parameter = s.getParameters().get(0);
        assertEquals("received", parameter.getName());
        assertEquals("192.0.2.207", parameter.getValue());
        parameter = s.getParameters().get(1);
        assertEquals("branch", parameter.getName());
        assertEquals("z9hG4bK77asjd", parameter.getValue());
        assertEquals("this is a comment", s.getComment());

        str = "SIP/2.0/TCP 127.0.0.1:5061;branch=z9hG4bK-6503-1-0";
        r = new SipRecipientInfoReader(str);
        s = r.readValue();

        assertEquals(Protocol.SIP, s.getProtocol());
        assertEquals("TCP", s.getTransport());
        assertEquals("127.0.0.1:5061", s.getName());

        assertEquals(1, s.getParameters().size());
        parameter = s.getParameters().get(0);
        assertEquals("branch", parameter.getName());
        assertEquals("z9hG4bK-6503-1-0", parameter.getValue());

        str = "SIP/2.0/TCP [fe80::223:dfff:fe7f:7b1a%en0]:5061;branch=z9hG4bK-409-1-0";
        r = new SipRecipientInfoReader(str);
        s = r.readValue();

        assertEquals(Protocol.SIP, s.getProtocol());
        assertEquals("TCP", s.getTransport());
        assertEquals("[fe80::223:dfff:fe7f:7b1a%en0]:5061", s.getName());
        assertEquals(1, s.getParameters().size());
        parameter = s.getParameters().get(0);
        assertEquals("branch", parameter.getName());
        assertEquals("z9hG4bK-409-1-0", parameter.getValue());
        assertNull(s.getComment());
    }
View Full Code Here

        assertEquals(18000, a.getDelay());
        assertEquals(3600, a.getDuration());
        assertNull(a.getComment());
        assertEquals(1, a.getParameters().size());
        Parameter parameter = a.getParameters().get(0);
        assertEquals("tag", parameter.getName());
        assertEquals("hyh8", parameter.getValue());

        str = "120 (I'm in a meeting)";
        r = new AvailabilityReader(str);
        a = r.readValue();
        assertEquals(120, a.getDelay());
View Full Code Here

                              pvalue = attChild.getBaseURI().resolve(phref).toString();
                           }
                           if (pvalue==null) {
                              pvalue = "";
                           }
                           values.add(new Parameter(pname,pvalue));
                        }
                     } else {
                        // Switch to DOM
                        try {
                           StringWriter xml = new StringWriter();
                           XMLWriter.writeElement(attChild, xml);
                           LOG.fine("Attribute XML: "+xml.toString());
                           values.add(docBuilder.parse(new InputSource(new StringReader(xml.toString()))));
                        } catch (Exception ex) {
                           LOG.log(Level.SEVERE,"Cannot serialize attribute XML.",ex);
                        }

                     }
                  }
                  LOG.fine("Attribute: "+name+" is list of values.");
                  appContext.getAttributes().put(name,values);
               }
            } else if (child.getName().equals(PARAMETER)) {
               Element paramE = child;
               String pname = paramE.getAttributeValue("name");
               if (pname!=null) {
                  String value = paramE.getAttributeValue("value");
                  String href = paramE.getAttributeValue("href");
                  if (href!=null) {
                     value = paramE.getBaseURI().resolve(href).toString();
                  }
                  String resource = paramE.getAttributeValue("resource");
                  String ref = paramE.getAttributeValue("ref");
                  LOG.fine("resource="+resource+", ref="+ref);
                  if (resource!=null && ref!=null) {
                     ClassLoader loader = loaders.get(ref);
                     if (loader==null) {
                        Class targetClass = definitions.get(ref);
                        if (targetClass!=null) {
                           targetClass.getClassLoader();
                        }
                     }
                     if (loader!=null) {
                        URL uvalue = loader.getResource(resource);
                        if (uvalue!=null) {
                           value = uvalue.toString();
                        }
                     } else {
                        LOG.warning("Cannot find definition of "+ref);
                     }
                  }
                  if (value==null) {
                     value = "";
                  }
                  LOG.fine("Setting parameter "+pname+"="+value);
                  if ("true".equals(paramE.getAttributeValue("replace"))) {
                     Parameter toRemove;
                     while ((toRemove = appContext.getParameters().getFirst(pname))!=null) {
                        appContext.getParameters().remove(toRemove);
                     }
                  }
                  appContext.getParameters().add(pname,value);
View Full Code Here

     *            the {@link Context} within which the check is performed.
     * @param n
     *            the name of the {@code init-param} to check for.
     */
    private void checkNegativeParam(String msg, Context ctx, String n) {
        Parameter p = ctx.getParameters().getFirst(n);
        assertNull(msg + " Parameter '" + n + "' MUST be null", p);
    }
View Full Code Here

     * @param v
     *            the expected value of the named {@code init-param}.
     */
    private void checkPositiveParam(String msg, Context ctx, String n, String v) {
        assertNotNull(msg + "Context MUST NOT be null", ctx);
        Parameter p = ctx.getParameters().getFirst(n);
        assertNotNull(msg + "Parameter '" + n + "' MUST NOT be null", p);
        String pValue = p.getValue();
        assertNotNull(msg + "Parameter '" + n + "' MUST NOT have a null value",
                pValue);
        assertEquals(msg + "Parameter '" + n + "' has unexpected value", v,
                pValue);
    }
View Full Code Here

TOP

Related Classes of org.restlet.data.Parameter

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.