Package javax.ws.rs.core

Examples of javax.ws.rs.core.Form


   
    @Test
    public void testReadFromForm() throws Exception {
        FormEncodingProvider<Form> ferp = new FormEncodingProvider<Form>();
        InputStream is = getClass().getResourceAsStream("singleValPostBody.txt");
        Form form = ferp.readFrom(Form.class, null,
                new Annotation[]{}, MediaType.APPLICATION_FORM_URLENCODED_TYPE, null, is);
        MultivaluedMap<String, String> mvMap = form.asMap();
        assertEquals("Wrong entry for foo", "bar", mvMap.getFirst("foo"));
        assertEquals("Wrong entry for boo", "far", mvMap.getFirst("boo"));

    }
View Full Code Here


        assertEquals("Wrong value", "a=a1&b=b1", result)
    }
   
    @Test
    public void testWriteForm() throws Exception {
        Form form = new Form(new MetadataMap<String, String>());
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        FormEncodingProvider<Form> ferp
            = new FormEncodingProvider<Form>();
        ferp.writeTo(form.param("a", "a1").param("b", "b1"), Form.class, Form.class,
                     new Annotation[0], MediaType.APPLICATION_FORM_URLENCODED_TYPE,
                     new MetadataMap<String, Object>(), bos);
        String result = bos.toString();
        assertEquals("Wrong value", "a=a1&b=b1", result)
    }
View Full Code Here

        }
        return (MultivaluedMap<String, String>)clazz.newInstance();
    }
   
    private T getFormObject(Class<T> clazz, MultivaluedMap<String, String> params) {
        return clazz.cast(Form.class.isAssignableFrom(clazz) ? new Form(params) : params);
    }
View Full Code Here

    public void testBookFromForm() throws Exception {
       
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstorestorage/bookforms",
                                        "foo", "bar", null);
        wc.accept("application/xml");
        Response r = wc.form(new Form().param("name", "CXF Rocks").param("id", "123"));
       
        Book b = readBook((InputStream)r.getEntity());
        assertEquals("CXF Rocks", b.getName());
        assertEquals(123L, b.getId());
    }
View Full Code Here

    public void testBookFromHttpRequestParameters() throws Exception {
       
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstorestorage/bookforms2",
                                        "foo", "bar", null);
        wc.accept("application/xml");
        Response r = wc.form(new Form().param("name", "CXF Rocks").param("id", "123"));
       
        Book b = readBook((InputStream)r.getEntity());
        assertEquals("CXF Rocks", b.getName());
        assertEquals(123L, b.getId());
    }
View Full Code Here

                                                   Map<String, String> extraParams,
                                                   String defaultTokenType,
                                                   boolean setAuthorizationHeader)
        throws OAuthServiceException {   
       
        Form form = new Form(grant.toMap());
        if (extraParams != null) {
            for (Map.Entry<String, String> entry : extraParams.entrySet()) {
                form.param(entry.getKey(), entry.getValue());
            }
        }
        if (consumer != null) {
            if (setAuthorizationHeader) {
                StringBuilder sb = new StringBuilder();
                sb.append("Basic ");
                try {
                    String data = consumer.getKey() + ":" + consumer.getSecret();
                    sb.append(Base64Utility.encode(data.getBytes("UTF-8")));
                } catch (Exception ex) {
                    throw new ProcessingException(ex);
                }
                accessTokenService.header("Authorization", sb.toString());
            } else {
                form.param(OAuthConstants.CLIENT_ID, consumer.getKey());
                if (consumer.getSecret() != null) {
                    form.param(OAuthConstants.CLIENT_SECRET, consumer.getSecret());
                }
            }
        } else {
            // in this case the AccessToken service is expected to find a mapping between
            // the authenticated credentials and the client registration id
View Full Code Here

public class FormTest extends Assert {

    @Test
    public void testToString() {
        Form form = new Form().param("a", "b").param("c", "d");
        assertEquals("a=b&c=d", FormUtils.formToString(form));
    }
View Full Code Here

        samlOAuthValidator = validator;
    }
   
    public void filter(ContainerRequestContext context) {
        Message message = JAXRSUtils.getCurrentMessage();
        Form form = readFormData(message);
        MultivaluedMap<String, String> formData = form.asMap();
        String assertionType = formData.getFirst(Constants.CLIENT_AUTH_ASSERTION_TYPE);
        String decodedAssertionType = assertionType != null ? HttpUtils.urlDecode(assertionType) : null;
        if (decodedAssertionType == null || !Constants.CLIENT_AUTH_SAML2_BEARER.equals(decodedAssertionType)) {
            throw new NotAuthorizedException(errorResponse());
        }
View Full Code Here

                                                 "POST",
                                                 tokenService.getBaseURI().toString(),
                                                 parameters);
        try {
            tokenService.replaceHeader("Authorization", header);
            Form form = tokenService.post(null, Form.class);
            return new Token(form.asMap().getFirst("oauth_token"),
                    form.asMap().getFirst("oauth_token_secret"));
        } catch (WebApplicationException ex) {
            throw new OAuthServiceException(ex);
        }
    }
View Full Code Here

    }

    public OOBAuthorizationResponse readFrom(
        Class<OOBAuthorizationResponse> clazz, Type genericType, Annotation[] annotations, MediaType mt,
        MultivaluedMap<String, String> headers, InputStream is) throws IOException {
        Form form = formProvider.readFrom(Form.class, Form.class, annotations, mt, headers, is);
        MultivaluedMap<String, String> data = form.asMap();
        OOBAuthorizationResponse resp = new OOBAuthorizationResponse();
       
        resp.setRequestToken(data.getFirst(OAuth.OAUTH_TOKEN));
        resp.setVerifier(data.getFirst(OAuth.OAUTH_VERIFIER));
        resp.setState(data.getFirst(OAuthConstants.X_OAUTH_STATE));
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.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.