Package com.sun.jersey.api.representation

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


                            ClientResponse cr = handle(ClientRequest.create().build(requestTokenUri, HttpMethod.POST));
                            // requestToken request failed
                            if (cr.getStatus() >= 400) {
                                return cr;
                            }
                            Form response = cr.getEntity(Form.class);
                            String token = response.getFirst(OAuthParameters.TOKEN);
                            parameters.token(token);
                            secrets.tokenSecret(response.getFirst(OAuthParameters.TOKEN_SECRET));
                            state = State.REQUEST_TOKEN;
                            parameters.verifier(handler.authorize(getAuthorizationUri()));
                            return handle(request);
                        } finally {
                            if (state == State.UNMANAGED) {
                                parameters.token(null);
                                secrets.tokenSecret(null);
                            }
                            if (state != State.REQUEST_TOKEN) {
                                state = State.MANAGED;
                            }
                        }
                    }
                    break;
                case REQUEST_TOKEN:
                    if (parameters.getVerifier() == null) {
                        throw new UnauthorizedRequestException(parameters, getAuthorizationUri());
                    }
                    state = State.UNMANAGED;
                    try {
                        ClientResponse cr = handle(ClientRequest.create().build(accessTokenUri, HttpMethod.POST));
                        // accessToken request failed
                        if (cr.getStatus() >= 400) {
                            return cr;
                        }
                        Form response = cr.getEntity(Form.class);
                        String token = response.getFirst(OAuthParameters.TOKEN);
                        String secret = response.getFirst(OAuthParameters.TOKEN_SECRET);
                        if (token == null) {
                            throw new UnauthorizedRequestException(parameters, null);
                        }
                        parameters.token(token);
                        secrets.tokenSecret(secret);
                        handler.authorized(parameters.getToken(), secrets.getTokenSecret());
                        state = State.MANAGED;
                    } finally {
                        parameters.remove(OAuthParameters.VERIFIER);
                        if (state == State.UNMANAGED) {
                            parameters.token(null);
                            secrets.tokenSecret(null);
                            state = State.MANAGED;
                        }
                    }

            }
            final OAuthParameters p = (OAuthParameters)parameters.clone(); // make modifications to clone

            if (p.getTimestamp() == null) {
                p.setTimestamp();
            }

            if (p.getNonce() == null) {
                p.setNonce();
            }

            try {
                OAuthSignature.sign(new RequestWrapper(request, providers), p, secrets);
            }
            catch (OAuthSignatureException se) {
                throw new ClientHandlerException(se);
            }
        }

        // next filter in chain
        ClientResponse response;
        UniformInterfaceException uie = null;
        try {
            response = getNext().handle(request);
        } catch (UniformInterfaceException e) {
            response = e.getResponse();
            uie = e;
        }

        if (state == State.MANAGED && response.getClientResponseStatus() == ClientResponse.Status.UNAUTHORIZED) {
            request.getHeaders().remove("Authorization");
            parameters.token(null);
            secrets.tokenSecret(null);
            uie = null;
            return handle(request);
View Full Code Here


     * Test checks that POST on the '/form' resource gives a reponse page
     * with the entered data.
     */
    @Test
    public void testPostOnForm() {
        Form formData = new Form();
        formData.add("name", "testName");
        formData.add("colour", "red");
        formData.add("hint", "re");
        WebResource webResource = resource();
        ClientResponse response = webResource.path("form").type(MediaType.APPLICATION_FORM_URLENCODED)
                .post(ClientResponse.class, formData);
        assertEquals(Response.Status.OK, response.getResponseStatus());

View Full Code Here

  }

  public void test_filter_noActionOnPostNoForm() {
    ContainerRequest mock = Mockito.mock(ContainerRequest.class);
    when(mock.getMethod()).thenReturn("POST");
    when(mock.getFormParameters()).thenReturn(new Form());
   
    HttpMethodFilter test = new HttpMethodFilter();
    ContainerRequest result = test.filter(mock);
   
    assertSame(mock, result);
View Full Code Here

  }

  public void test_filter_noActionOnPostFormPut() {
    ContainerRequest mock = Mockito.mock(ContainerRequest.class);
    when(mock.getMethod()).thenReturn("POST");
    Form form = new Form();
    form.put("method", Arrays.asList("PUT"));
    when(mock.getFormParameters()).thenReturn(form);
   
    HttpMethodFilter test = new HttpMethodFilter();
    ContainerRequest result = test.filter(mock);
   
View Full Code Here

  }

  public void test_filter_noActionOnPostFormDelete() {
    ContainerRequest mock = Mockito.mock(ContainerRequest.class);
    when(mock.getMethod()).thenReturn("POST");
    Form form = new Form();
    form.put("method", Arrays.asList("DELETE"));
    when(mock.getFormParameters()).thenReturn(form);
   
    HttpMethodFilter test = new HttpMethodFilter();
    ContainerRequest result = test.filter(mock);
   
View Full Code Here

  }

  public void test_filter_noActionOnPostFormOptions() {
    ContainerRequest mock = Mockito.mock(ContainerRequest.class);
    when(mock.getMethod()).thenReturn("POST");
    Form form = new Form();
    form.put("method", Arrays.asList("OPTIONS"));
    when(mock.getFormParameters()).thenReturn(form);
   
    HttpMethodFilter test = new HttpMethodFilter();
    ContainerRequest result = test.filter(mock);
   
View Full Code Here

  }

  public void test_filter_noActionOnPostFormHead() {
    ContainerRequest mock = Mockito.mock(ContainerRequest.class);
    when(mock.getMethod()).thenReturn("POST");
    Form form = new Form();
    form.put("method", Arrays.asList("HEAD"));
    when(mock.getFormParameters()).thenReturn(form);
   
    HttpMethodFilter test = new HttpMethodFilter();
    ContainerRequest result = test.filter(mock);
   
View Full Code Here

  }

  public void test_filter_noActionOnPostFormPost() {
    ContainerRequest mock = Mockito.mock(ContainerRequest.class);
    when(mock.getMethod()).thenReturn("POST");
    Form form = new Form();
    form.put("method", Arrays.asList("POST"));
    when(mock.getFormParameters()).thenReturn(form);
   
    HttpMethodFilter test = new HttpMethodFilter();
    ContainerRequest result = test.filter(mock);
   
View Full Code Here

  }

  public void test_filter_noActionOnPostFormGet() {
    ContainerRequest mock = Mockito.mock(ContainerRequest.class);
    when(mock.getMethod()).thenReturn("POST");
    Form form = new Form();
    form.put("method", Arrays.asList("GET"));
    when(mock.getFormParameters()).thenReturn(form);
   
    HttpMethodFilter test = new HttpMethodFilter();
    ContainerRequest result = test.filter(mock);
   
View Full Code Here

  }

  public void test_filter_noActionOnPostFormNoMatch() {
    ContainerRequest mock = Mockito.mock(ContainerRequest.class);
    when(mock.getMethod()).thenReturn("POST");
    Form form = new Form();
    form.put("method", Arrays.asList("FOOBAR"));
    when(mock.getFormParameters()).thenReturn(form);
   
    HttpMethodFilter test = new HttpMethodFilter();
    ContainerRequest result = test.filter(mock);
   
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.