Package com.sun.jersey.api.representation

Examples of com.sun.jersey.api.representation.Form


        // test with rep=2
        responseStatus = webResource.path("resource3")
                .path(arg1).path(arg2).queryParam("rep", "2").head().getStatus();
        assertEquals("Response status 200 not found for request to resource 3 with rep=2", 200, responseStatus);
        Form f = webResource.path("resource3")
                .path(arg1).path(arg2).queryParam("rep", "2").get(Form.class);
        assertEquals("FormURLEncodedRepresentation", f.getFirst("representation"));
        assertEquals("Master Duke", f.getFirst("name"));
        assertEquals("male", f.getFirst("sex"));
        assertEquals("firstArg", f.getFirst("arg1"));
        assertEquals("secondArg", f.getFirst("arg2"));

        // test with rep>3
        responseStatus = webResource.path("resource3")
                .path(arg1).path(arg2).queryParam("rep", "4").head().getStatus();
        assertEquals("Response status 200 not found for request to resource 3 with rep>3", 200, responseStatus);
View Full Code Here


    private void filterFormParameters(HttpServletRequest hsr, ContainerRequest cr) throws IOException {
        if (cr.getMethod().equals("POST")
                && MediaTypes.typeEquals(MediaType.APPLICATION_FORM_URLENCODED_TYPE, cr.getMediaType())
                && !isEntityPresent(cr)) {
            Form f = new Form();

            Enumeration e = hsr.getParameterNames();
            while (e.hasMoreElements()) {
                String name = (String) e.nextElement();
                String[] values = hsr.getParameterValues(name);

                f.put(name, Arrays.asList(values));
            }

            if (!f.isEmpty()) {
                cr.getProperties().put(FormDispatchProvider.FORM_PROPERTY, f);
                if (LOGGER.isLoggable(Level.WARNING)) {
                    LOGGER.log(Level.WARNING,
                            "A servlet POST request, to the URI " + cr.getRequestUri() + ", " +
                                    "contains form parameters in " +
View Full Code Here

                in = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
                setEntityInputStream(in);
            }

            ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) in;
            Form f = getEntity(Form.class);
            byteArrayInputStream.reset();
            return f;
        } else {
            return new Form();
        }
    }
View Full Code Here

    private void filterFormParameters(HttpServletRequest hsr, ContainerRequest cr) throws IOException {
        if (cr.getMethod().equals("POST")
                && MediaTypes.typeEquals(MediaType.APPLICATION_FORM_URLENCODED_TYPE, cr.getMediaType())
                && !isEntityPresent(cr)) {
            Form f = new Form();

            Enumeration e = hsr.getParameterNames();
            while (e.hasMoreElements()) {
                String name = (String) e.nextElement();
                String[] values = hsr.getParameterValues(name);

                f.put(name, Arrays.asList(values));
            }

            if (!f.isEmpty()) {
                cr.getProperties().put(FormDispatchProvider.FORM_PROPERTY, f);
                if (LOGGER.isLoggable(Level.WARNING)) {
                    LOGGER.log(Level.WARNING,
                            "A servlet POST request, to the URI " + cr.getRequestUri() + ", " +
                                    "contains form parameters in " +
View Full Code Here

            MediaType mediaType,
            MultivaluedMap<String, String> httpHeaders,
            InputStream entityStream) throws IOException {
        String encoded = readFromAsString(entityStream, mediaType);
   
        Form map = new Form();
        StringTokenizer tokenizer = new StringTokenizer(encoded, "&");
        String token;
        while (tokenizer.hasMoreTokens()) {
            token = tokenizer.nextToken();
            int idx = token.indexOf('=');
            if (idx < 0) {
                map.add(URLDecoder.decode(token,"UTF-8"), null);
            } else if (idx > 0) {
                map.add(URLDecoder.decode(token.substring(0, idx),"UTF-8"),
                        URLDecoder.decode(token.substring(idx+1),"UTF-8"));
            }
        }
        return map;
    }
View Full Code Here

                in = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
                setEntityInputStream(in);
            }

            ByteArrayInputStream byteArrayInputStream = (ByteArrayInputStream) in;
            Form f = getEntity(Form.class);
            byteArrayInputStream.reset();
            return f;
        } else {
            return new Form();
        }
    }
View Full Code Here

            this.extractor = extractor;
            this.decode = decode;
        }
       
        public Object getValue(HttpContext context) {
            Form form = (Form)
                    context.getProperties().get(FormDispatchProvider.FORM_PROPERTY);
            if (form == null) {
                form = getForm(context);
                if (form == null)
                    throw new IllegalStateException(
View Full Code Here

                return null;

            if (!MediaTypes.typeEquals(MediaType.APPLICATION_FORM_URLENCODED_TYPE, r.getMediaType()))
                return null;

            final Form form = r.getFormParameters();
            context.getProperties().put(FormDispatchProvider.FORM_PROPERTY, form);
            return form;
        }
View Full Code Here

                in = new ByteArrayInputStream(baos.toByteArray());
                setEntityInputStream(in);
            }

            ByteArrayInputStream bais = (ByteArrayInputStream)in;
            Form f = getEntity(Form.class);
            bais.reset();
            return f;
        } else {
            return new Form();
        }
    }
View Full Code Here

            if(at == null) {
                throw new OAuthException(Response.Status.BAD_REQUEST, null);
            }

            // Preparing the response.
            Form resp = new Form();
            resp.putSingle(OAuthParameters.TOKEN, at.getToken());
            resp.putSingle(OAuthParameters.TOKEN_SECRET, at.getSecret());
            resp.putAll(at.getAttributes());
            return Response.ok(resp).build();
        } catch (OAuthException e) {
            // map the exception to avoid having to add the mapper to the providers
            return e.toResponse();
        }
View Full Code Here

TOP

Related Classes of com.sun.jersey.api.representation.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.