@Override public void writeTo( Form t, Class<?> type, Type genericType, Annotation annotations[], MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { writeTo(t.asMap(), mediaType, entityStream); } }
@Override public void writeTo( Form t, Class<?> type, Type genericType, Annotation annotations[], MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { writeTo(t.asMap(), mediaType, entityStream); } }
public String start() { final Response response = addProperties(client.target(requestTokenUri).request()) .post(null); if (response.getStatus() != 200) { throw new RuntimeException(LocalizationMessages.ERROR_REQUEST_REQUEST_TOKEN(response.getStatus())); } final MultivaluedMap<String, String> formParams = response.readEntity(Form.class).asMap(); parameters.token(formParams.getFirst(OAuth1Parameters.TOKEN)); secrets.tokenSecret(formParams.getFirst(OAuth1Parameters.TOKEN_SECRET)); return UriBuilder.fromUri(authorizationUri).queryParam(OAuth1Parameters.TOKEN, parameters.getToken()) .build().toString(); }
public AccessToken finish(final String verifier) { parameters.setVerifier(verifier); final Response response = addProperties(client.target(accessTokenUri).request()).post(null); // accessToken request failed if (response.getStatus() >= 400) { throw new RuntimeException(LocalizationMessages.ERROR_REQUEST_ACCESS_TOKEN(response.getStatus())); } final Form form = response.readEntity(Form.class); final String accessToken = form.asMap().getFirst(OAuth1Parameters.TOKEN); final String accessTokenSecret = form.asMap().getFirst(OAuth1Parameters.TOKEN_SECRET); if (accessToken == null) { throw new NotAuthorizedException(LocalizationMessages.ERROR_REQUEST_ACCESS_TOKEN_NULL()); } parameters.token(accessToken); secrets.tokenSecret(accessTokenSecret); final AccessToken resultToken = new AccessToken(parameters.getToken(), secrets.getTokenSecret()); this.accessToken = resultToken; return resultToken; }
private Form switchUrlEncoding(final ContainerRequest request, final Form otherForm) { final Set<Map.Entry<String, List<String>>> entries = otherForm.asMap().entrySet(); MultivaluedMap<String, String> formMap = new NullableMultivaluedHashMap<>(); for (Map.Entry<String, List<String>> entry : entries) { final String charsetName = ReaderWriter.getCharset(MediaType.valueOf( request.getHeaderString(HttpHeaders.CONTENT_TYPE))).name(); String key; try { key = decode ? URLDecoder.decode(entry.getKey(), charsetName) : URLEncoder.encode(entry.getKey(), charsetName); for (String value : entry.getValue()) { if (value != null) { formMap.add(key, decode ? URLDecoder.decode(value, charsetName) : URLEncoder.encode(value, charsetName)); } else { formMap.add(key, null); } } } catch (UnsupportedEncodingException uee) { throw new ProcessingException(LocalizationMessages.ERROR_UNSUPPORTED_ENCODING(charsetName, extractor.getName()), uee); } } return new Form(formMap); }
private Form switchUrlEncoding(final ContainerRequest request, final Form otherForm) { final Set<Map.Entry<String, List<String>>> entries = otherForm.asMap().entrySet(); MultivaluedMap<String, String> formMap = new NullableMultivaluedHashMap<>(); for (Map.Entry<String, List<String>> entry : entries) { final String charsetName = ReaderWriter.getCharset(MediaType.valueOf( request.getHeaderString(HttpHeaders.CONTENT_TYPE))).name(); String key; try { key = decode ? URLDecoder.decode(entry.getKey(), charsetName) : URLEncoder.encode(entry.getKey(), charsetName); for (String value : entry.getValue()) { if (value != null) { formMap.add(key, decode ? URLDecoder.decode(value, charsetName) : URLEncoder.encode(value, charsetName)); } else { formMap.add(key, null); } } } catch (UnsupportedEncodingException uee) { throw new ProcessingException(LocalizationMessages.ERROR_UNSUPPORTED_ENCODING(charsetName, extractor.getName()), uee); } } return new Form(formMap); }
@Override public MultivaluedMap<String, String> get() { MultivaluedMap<String, String> params = null; final MediaType mediaType = context.getMediaType(); if (mediaType != null && MediaTypes.typeEqual(mediaType, MediaType.APPLICATION_FORM_URLENCODED_TYPE)) { final ContainerRequest jerseyRequest = (ContainerRequest) context; jerseyRequest.bufferEntity(); final Form form = jerseyRequest.readEntity(Form.class); params = form.asMap(); } return params; } });
final MultivaluedMap<String, String> formMap = form.asMap();
final MultivaluedMap<String, String> formMap = form.asMap();
final UriBuilder ub = request.getUriInfo().getRequestUriBuilder(); final Form f = ((ContainerRequest) request).readEntity(Form.class); for (final Map.Entry<String, List<String>> param : f.asMap().entrySet()) { ub.queryParam(param.getKey(), param.getValue().toArray());
final UriBuilder ub = request.getUriInfo().getRequestUriBuilder(); final Form f = ((ContainerRequest) request).readEntity(Form.class); for (final Map.Entry<String, List<String>> param : f.asMap().entrySet()) { ub.queryParam(param.getKey(), param.getValue().toArray());
final LinkedList<Cookie> cookies = new LinkedList<>(this.cookies); final Form form = new Form(); form.asMap().putAll(this.form.asMap()); final Annotation[][] paramAnns = method.getParameterAnnotations(); Object entity = null; if (entity == null && !form.asMap().isEmpty()) { entity = form; contentType = MediaType.APPLICATION_FORM_URLENCODED; contentType = MediaType.APPLICATION_OCTET_STREAM; if (!form.asMap().isEmpty()) { if (entity instanceof Form) { ((Form) entity).asMap().putAll(form.asMap()); } else {
resp.param(OAuth1Parameters.TOKEN, at.getToken()); resp.param(OAuth1Parameters.TOKEN_SECRET, at.getSecret()); resp.asMap().putAll(at.getAttributes()); return Response.ok(resp).build();
@Override public Object apply(ContainerRequest request) { Form form = getCachedForm(request, decode); if (form == null) { Form otherForm = getCachedForm(request, !decode); if (otherForm != null) { form = switchUrlEncoding(request, otherForm); cacheForm(request, form); } else { form = getForm(request); cacheForm(request, form); } } try { return extractor.extract(form.asMap()); } catch (ExtractorException e) { throw new ParamException.FormParamException(e.getCause(), extractor.getName(), extractor.getDefaultValueString()); } }
@Override public Object apply(ContainerRequest request) { Form form = getCachedForm(request, decode); if (form == null) { Form otherForm = getCachedForm(request, !decode); if (otherForm != null) { form = switchUrlEncoding(request, otherForm); cacheForm(request, form); } else { form = getForm(request); cacheForm(request, form); } } try { return extractor.extract(form.asMap()); } catch (ExtractorException e) { throw new ParamException.FormParamException(e.getCause(), extractor.getName(), extractor.getDefaultValueString()); } }
@Override public void writeTo(Form form, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { LogMessages.LOGGER.debugf("Provider : %s, Method : writeTo", getClass().getName()); new FormUrlEncodedProvider().writeTo(form.asMap(), null, null, annotations, mediaType, httpHeaders, entityStream); } }
private Form switchUrlEncoding(final ContainerRequest request, final Form otherForm) { final Set<Map.Entry<String, List<String>>> entries = otherForm.asMap().entrySet(); MultivaluedMap<String, String> formMap = new NullableMultivaluedHashMap<>(); for (Map.Entry<String, List<String>> entry : entries) { final String charsetName = ReaderWriter.getCharset(MediaType.valueOf( request.getHeaderString(HttpHeaders.CONTENT_TYPE))).name(); String key; try { key = decode ? URLDecoder.decode(entry.getKey(), charsetName) : URLEncoder.encode(entry.getKey(), charsetName); for (String value : entry.getValue()) { if (value != null) { formMap.add(key, decode ? URLDecoder.decode(value, charsetName) : URLEncoder.encode(value, charsetName)); } else { formMap.add(key, null); } } } catch (UnsupportedEncodingException uee) { throw new ProcessingException(LocalizationMessages.ERROR_UNSUPPORTED_ENCODING(charsetName, extractor.getName()), uee); } } return new Form(formMap); }
final UriBuilder ub = request.getUriInfo().getRequestUriBuilder(); final Form f = ((ContainerRequest) request).readEntity(Form.class); for (final Map.Entry<String, List<String>> param : f.asMap().entrySet()) { ub.queryParam(param.getKey(), param.getValue().toArray());
@Override public Object apply(ContainerRequest request) { Form form = getCachedForm(request, decode); if (form == null) { Form otherForm = getCachedForm(request, !decode); if (otherForm != null) { form = switchUrlEncoding(request, otherForm); cacheForm(request, form); } else { form = getForm(request); cacheForm(request, form); } } try { return extractor.extract(form.asMap()); } catch (ExtractorException e) { throw new ParamException.FormParamException(e.getCause(), extractor.getName(), extractor.getDefaultValueString()); } }
/** * Posts form data * @param form form values * @return JAXRS Response */ public Response form(Form form) { type(MediaType.APPLICATION_FORM_URLENCODED); return doInvoke(HttpMethod.POST, form.asMap(), null, Response.class, Response.class); }