Package javax.ws.rs.core

Examples of javax.ws.rs.core.Form


    }
    return false;
  }

  private Form computeForm( Method method, Object[] parameter ) {
    Form result = new Form();
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    for( int i = 0; i < parameterAnnotations.length; i++ ) {
      Annotation[] annotations = parameterAnnotations[ i ];
      String paramName = extractFormParam( annotations );
      if( paramName != null ) {
        result.param( paramName, parameter[ i ].toString() );
      }
    }
    return result.asMap().isEmpty() ? null : result;
  }
View Full Code Here


    logger.info("Requesting access and refresh tokens");
    Client client = getClient();
    client.register(HttpAuthenticationFeature.basic(jiveInstance.getClientId(), jiveInstance.getClientSecret()));
    WebTarget target = client.target(jiveInstance.getJiveUrl() + "/oauth2/token");
    Form form = new Form("grant_type", "authorization_code");
    form.param("code", jiveInstance.getCode());
    form.param("client_id", jiveInstance.getClientId());

    JiveOAuthResponse response = target.request().post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED),JiveOAuthResponse.class);

    logger.info("Access Token : Response : " + response);
View Full Code Here

    logger.info("Exchanging refresh token for access token");
    Client client = getClient();
    client.register(HttpAuthenticationFeature.basic(jiveInstance.getClientId(), jiveInstance.getClientSecret()));
    OAuthCredentials credentials = jiveInstance.getCredentials();
    WebTarget target = client.target(jiveInstance.getJiveUrl() + "/oauth2/token");
    Form form = new Form("grant_type", "refresh_token");
    form.param("refresh_token", credentials.getRefreshToken());
    form.param("client_id", jiveInstance.getClientId());

    JiveOAuthResponse response = target.request().post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED),JiveOAuthResponse.class);

    logger.info("Access Token : Response : " + response);
View Full Code Here

    }

    @Override
    public Object provide() {
        final ContainerRequest request = getContainerRequest();
        Form form = getCachedForm(request, decode);

        if (form == null) {
            final Form otherForm = getCachedForm(request, !decode);
            if (otherForm != null) {
                form = switchUrlEncoding(request, otherForm);
                cacheForm(request, form);
            } else {
                form = getForm(request);
View Full Code Here

        }
    }

    private Form switchUrlEncoding(final ContainerRequest request, final Form otherForm) {
        final Set<Map.Entry<String, List<String>>> entries = otherForm.asMap().entrySet();
        final Form newForm = new Form();

        for (Map.Entry<String, List<String>> entry : entries) {
            final String charsetName = ReaderWriter.getCharset(MediaType.valueOf(
                    request.getHeaderString(HttpHeaders.CONTENT_TYPE))).name();

            try {
                final String key = decode ?
                        URLDecoder.decode(entry.getKey(), charsetName) : URLEncoder.encode(entry.getKey(), charsetName);

                for (String value : entry.getValue()) {
                    newForm.asMap().add(key, decode ?
                            URLDecoder.decode(value, charsetName) : URLEncoder.encode(value, charsetName));
                }

            } catch (UnsupportedEncodingException uee) {
                throw new ProcessingException(LocalizationMessages.ERROR_UNSUPPORTED_ENCODING(charsetName,
View Full Code Here

    private Form getFormParameters(final ContainerRequest request) {
        if (MediaTypes.typeEqual(MediaType.APPLICATION_FORM_URLENCODED_TYPE, request.getMediaType())) {
            request.bufferEntity();

            final Form form;
            if (decode) {
                form = request.readEntity(Form.class);
            } else {
                Annotation[] annotations = new Annotation[1];
                annotations[0] = ENCODED_ANNOTATIONS;
View Full Code Here

    }

    @Test
    public void shouldReturnMessageWhenMessageIsPresent() throws IOException {
        final String customMessage = "Custom Message";
        final Form form = new Form("message", customMessage);
        final Response response = target("/optional/message").request().post(Entity.form(form));

        assertThat(response.readEntity(String.class)).isEqualTo(customMessage);
    }
View Full Code Here

    }

    @Test
    public void shouldReturnMyMessageWhenMyMessageIsPresent() throws IOException {
        final String myMessage = "My Message";
        final Form form = new Form("mymessage", myMessage);
        final Response response = target("/optional/my-message").request().post(Entity.form(form));

        assertThat(response.readEntity(String.class)).isEqualTo(myMessage);
    }
View Full Code Here

    }

    @Test
    public void shouldThrowBadRequestExceptionWhenInvalidUUIDIsPresent() throws IOException {
        final String invalidUUID = "invalid-uuid";
        final Form form = new Form("uuid", invalidUUID);
        final Response response = target("/optional/uuid").request().post(Entity.form(form));

        assertThat(response.getStatus()).isEqualTo(Response.Status.BAD_REQUEST.getStatusCode());
    }
View Full Code Here

    }

    @Test
    public void shouldReturnUUIDWhenValidUUIDIsPresent() throws IOException {
        final String uuid = "fd94b00d-bd50-46b3-b42f-905a9c9e7d78";
        final Form form = new Form("uuid", uuid);
        final Response response = target("/optional/uuid").request().post(Entity.form(form));

        assertThat(response.readEntity(String.class)).isEqualTo(uuid);
    }
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.