Package org.restlet.data

Examples of org.restlet.data.Form


            return;
        }

        // only deal with the form if the content type is "application/x-www-form-urlencoded"
        if (request.getEntity().getMediaType() != null && request.getEntity().getMediaType().equals(MediaType.APPLICATION_WWW_FORM)) {
            Form form = new Form(request.getEntity());
            for (Map.Entry<String, String> entry : form.getValuesMap().entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                if (value == null) {
                    inMessage.setBody(key);
                    LOG.debug("Populate exchange from Restlet request body: {}", key);
View Full Code Here


    }

    public void populateRestletRequestFromExchange(Request request, Exchange exchange) {
        request.setReferrerRef("camel-restlet");
        String body = exchange.getIn().getBody(String.class);
        Form form = new Form();
        // add the body as the key in the form with null value
        form.add(body, null);

        MediaType mediaType = exchange.getIn().getHeader(Exchange.CONTENT_TYPE, MediaType.class);
        if (mediaType == null) {
            mediaType = MediaType.APPLICATION_WWW_FORM;
        }

        LOG.debug("Populate Restlet request from exchange body: {} using media type {}", body, mediaType);

        // login and password are filtered by header filter strategy
        String login = exchange.getIn().getHeader(RestletConstants.RESTLET_LOGIN, String.class);
        String password = exchange.getIn().getHeader(RestletConstants.RESTLET_PASSWORD, String.class);

        if (login != null && password != null) {
            ChallengeResponse authentication = new ChallengeResponse(ChallengeScheme.HTTP_BASIC, login, password);
            request.setChallengeResponse(authentication);
            LOG.debug("Basic HTTP Authentication has been applied");
        }

        for (Map.Entry<String, Object> entry : exchange.getIn().getHeaders().entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            if (!headerFilterStrategy.applyFilterToCamelHeaders(key, value, exchange)) {
                // Use forms only for GET and POST/x-www-form-urlencoded
                if (request.getMethod() == Method.GET || (request.getMethod() == Method.POST && mediaType == MediaType.APPLICATION_WWW_FORM)) {
                    if (key.startsWith("org.restlet.")) {
                        // put the org.restlet headers in attributes
                        request.getAttributes().put(key, value);
                    } else {
                        // put the user stuff in the form
                        form.add(key, value.toString());
                    }
                } else {
                    // For non-form post put all the headers in attributes
                    request.getAttributes().put(key, value);
                }
                LOG.debug("Populate Restlet request from exchange header: {} value: {}", key, value);
            }
        }

        LOG.debug("Using Content Type: {} for POST data: {}", mediaType, body);

        // Only URL Encode for GET and form POST
        if (request.getMethod() == Method.GET || (request.getMethod() == Method.POST && mediaType == MediaType.APPLICATION_WWW_FORM)) {
            request.setEntity(form.getWebRepresentation());
        } else {
            request.setEntity(body, mediaType);
        }

        MediaType acceptedMediaType = exchange.getIn().getHeader(Exchange.ACCEPT_CONTENT_TYPE, MediaType.class);
View Full Code Here

    @Test
    public void testInvalidPaging() throws IOException, ResourceException, JSONException
    {
        ClientResource resource = new ClientResource(TestComponent.getBaseUrl() + "/numbers");
        resource.getRequest().getAttributes()
                .put(HeaderConstants.ATTRIBUTE_HEADERS, new Form(PagingHeaderResource.ITEM_RANGE_HEADER + "=foo"));
        assertError(resource);
    }
View Full Code Here

    {
        ClientResource resource = new ClientResource(TestComponent.getBaseUrl() + "/numbers");
        resource.getRequest()
                .getAttributes()
                .put(HeaderConstants.ATTRIBUTE_HEADERS,
                        new Form(PagingHeaderResource.ITEM_RANGE_HEADER + "=items=5-23"));
        assertJson(resource);
    }
View Full Code Here

        {
            return null;
        }
        verifyInput(input, Form.class);

        Form form = (Form) input;
        String offset = form.getFirstValue(OFFSET);
        String pageSize = form.getFirstValue(PAGE_SIZE);

        int offsetValue = convertInt(offset, "Paging info contains the invalid offset: \"%s\"", offset);
        int pageSizeValue = convertInt(pageSize, "Paging info contains the invalid page size: \"%s\"", pageSize);
        return new PageInfo(offsetValue, pageSizeValue);
    }
View Full Code Here

    }


    private Form formFor(int offset, int pageSize)
    {
        Form form = new Form();
        form.add(PageInfoParser.OFFSET, String.valueOf(offset));
        form.add(PageInfoParser.PAGE_SIZE, String.valueOf(pageSize));
        return form;
    }
View Full Code Here

public class TheAnswerCheck implements SecurityCheck
{
    @Override
    public void check(Request request, Response response) throws SecurityException
    {
        Form form = request.getResourceRef().getQueryAsForm();
        String answer = form.getFirstValue("answer");
        if (answer == null)
        {
            throw new SecurityException("No answer");
        }
        if (!"42".equals(answer))
View Full Code Here

     */
    @Override
    @SuppressWarnings("unchecked")
    public Series<Parameter> getRequestHeaders() {
        if (this.requestHeaders == null) {
            this.requestHeaders = new Form();

            // Copy the headers from the request object
            String headerName;
            String headerValue;
            for (final Enumeration<String> names = getRequest()
View Full Code Here

    public void doGet(Request request, Response response) throws Exception{
        String layer = (String) request.getAttributes().get("layer");
        String namespace = (String) request.getAttributes().get("namespace");
        String feature = (String) request.getAttributes().get("feature");

        Form form = request.getResourceRef().getQueryAsForm();
        String reqRaw = form.getFirstValue("raw");
       
        ClientInfo cliInfo = request.getClientInfo();
        String agent = null;
        if(cliInfo != null) {
            agent = cliInfo.getAgent();
        }
       
        boolean wantsRaw = (
                agent == null
                || cliInfo.getAgent().contains("Googlebot")
                || (reqRaw != null && Boolean.parseBoolean(reqRaw)) );
       
        // We only show the actual KML placemark to googlebot or users who append ?raw=true
        if ( ! wantsRaw ) {
            response.redirectSeeOther(feature+".html");
        } else {
            int startIndex = 0;
            int maxFeatures = 100;
            String regionateBy = null;
            String regionateAttr = null;

            try {
                startIndex = Integer.valueOf(form.getFirstValue("startindex",
                        true));
            } catch (Exception e) {
            }

            try {
                maxFeatures = Integer.valueOf(form.getFirstValue("maxfeatures",
                        true));
            } catch (Exception e) {
            }

            regionateBy = form.getFirstValue("regionateBy", true);
            // if (regionateBy == null) regionateBy = "sld";
            regionateBy = "random";

            regionateAttr = form.getFirstValue("regionateAttr", true);

            NamespaceInfo ns = catalog.getNamespaceByPrefix(namespace);
            if (ns == null) {
                throw new RestletException("No such namespace:" + namespace,
                        Status.CLIENT_ERROR_NOT_FOUND);
View Full Code Here

public class ExceptionThrowingResource extends Resource {

    @Override
    public void handleGet() {
        Form f = getRequest().getResourceRef().getQueryAsForm();
        String message= f.getFirstValue("message");
        String code = f.getFirstValue("code");
       
        throw new RestletException( message != null ? message : "Unknown error"
                code != null ? new Status( Integer.parseInt(code)) : Status.SERVER_ERROR_INTERNAL );
    }
View Full Code Here

TOP

Related Classes of org.restlet.data.Form

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.