Package org.restlet.data

Examples of org.restlet.data.Parameter


        assertEquals(null, response.getEntity().getText());
    }

    /** test with one test header */
    public void test1() throws Exception {
        Response response = getWithParams(new Parameter(TEST_HEADER, "a"));
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("a\n", response.getEntity().getText());
    }
View Full Code Here


        assertEquals("a\n", response.getEntity().getText());
    }

    /** test with two test headers */
    public void test2() throws Exception {
        Response response = getWithParams(new Parameter(TEST_HEADER, "a"),
                new Parameter(TEST_HEADER, "b"));
        assertEquals(Status.SUCCESS_OK, response.getStatus());
        assertEquals("a\nb\n", response.getEntity().getText());
    }
View Full Code Here

                    hValue = formatDate((Date) headerValue, false);
                } else {
                    hValue = headerValue.toString();
                }

                headers.add(new Parameter(headerName, hValue));
            }
        }

        if (restletResponse.getEntity() == null) {
            restletResponse.setEntity(new EmptyRepresentation());
View Full Code Here

     *            The header line to parse.
     * @return The header read or null.
     * @throws IOException
     */
    public static Parameter readHeader(CharSequence header) throws IOException {
        Parameter result = null;

        if (header.length() > 0) {
            // Detect the end of headers
            int start = 0;
            int index = 0;
            int next = header.charAt(index++);

            if (isCarriageReturn(next)) {
                next = header.charAt(index++);

                if (!isLineFeed(next)) {
                    throw new IOException(
                            "Invalid end of headers. Line feed missing after the carriage return.");
                }
            } else {
                result = new Parameter();

                // Parse the header name
                while ((index < header.length()) && (next != ':')) {
                    next = header.charAt(index++);
                }

                if (index == header.length()) {
                    throw new IOException(
                            "Unable to parse the header name. End of line reached too early.");
                }

                result.setName(header.subSequence(start, index - 1).toString());
                next = header.charAt(index++);

                while (isSpace(next)) {
                    // Skip any separator space between colon and header value
                    next = header.charAt(index++);
                }

                start = index - 1;

                // Parse the header value
                result.setValue(header.subSequence(start, header.length())
                        .toString());
            }
        }

        return result;
View Full Code Here

     * @return The header read or null.
     * @throws IOException
     */
    public static Parameter readHeader(InputStream is, StringBuilder sb)
            throws IOException {
        Parameter result = null;

        // Detect the end of headers
        int next = is.read();
        if (isCarriageReturn(next)) {
            next = is.read();
            if (!isLineFeed(next)) {
                throw new IOException(
                        "Invalid end of headers. Line feed missing after the carriage return.");
            }
        } else {
            result = new Parameter();

            // Parse the header name
            while ((next != -1) && (next != ':')) {
                sb.append((char) next);
                next = is.read();
            }

            if (next == -1) {
                throw new IOException(
                        "Unable to parse the header name. End of stream reached too early.");
            }

            result.setName(sb.toString());
            sb.delete(0, sb.length());

            next = is.read();
            while (isSpace(next)) {
                // Skip any separator space between colon and header value
                next = is.read();
            }

            // Parse the header value
            while ((next != -1) && (!isCarriageReturn(next))) {
                sb.append((char) next);
                next = is.read();
            }

            if (next == -1) {
                throw new IOException(
                        "Unable to parse the header value. End of stream reached too early.");
            }
            next = is.read();

            if (isLineFeed(next)) {
                result.setValue(sb.toString());
                sb.delete(0, sb.length());
            } else {
                throw new IOException(
                        "Unable to parse the HTTP header value. The carriage return must be followed by a line feed.");
            }
View Full Code Here

     * @param value
     *            The parameter value or null.
     * @return The new parameter.
     */
    protected Parameter createParameter(String name, String value) {
        return new Parameter(name, value);
    }
View Full Code Here

     *
     * @return The next pair as a parameter.
     * @throws IOException
     */
    public Parameter readParameter() throws IOException {
        Parameter result = null;
        String name = readToken();
        int nextChar = read();

        if (name.length() > 0) {
            if (nextChar == '=') {
View Full Code Here

         */
        Object getParamValue(final Form form, final String paramName)
                throws ConvertParameterException {
            final List<Parameter> parameters = form.subList(paramName);
            if (this.collType == null) { // no collection parameter
                final Parameter firstFormParam = form.getFirst(paramName);
                final String queryParamValue = WrapperUtil
                        .getValue(firstFormParam);
                return convertParamValue(queryParamValue);
            }
            ParamValueIter queryParamValueIter;
View Full Code Here

                return rt;
            }
        }
        final Series<Parameter> headers = getHeaders();
        if (headers != null) {
            final Parameter first = headers.getFirst(headerName);
            if (first == null) {
                return null;
            }
            return first.getValue();
        }
        return null;
    }
View Full Code Here

                    }

                    readStartLine();
                }
            } else if (getMessageState() == MessageState.HEADERS) {
                Parameter header = readHeader();

                if (header != null) {
                    if (getHeaders() == null) {
                        setHeaders(new Form());
                    }
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.