@Override public Object readFrom(Class clazz, Type genericType, Annotation[] annotations, MediaType mt, MultivaluedMap headers, InputStream is) throws IOException { Predicate isContentTyoe = h -> CONTENT_TYPE.equalsIgnoreCase(h.toString()); Optional<String> element = headers.keySet() .stream() .filter(isContentTyoe) .findFirst(); if (!element.isPresent() || hasinValidValue(element.get(), MetadataMap.class.cast(headers))) { throw new WebApplicationException(new IllegalArgumentException("The Content-Type header is missing on this request you should define: " + CONTENT_TYPE), status(BAD_REQUEST).build()); } return super.readFrom(clazz, genericType, annotations, mt, headers, is); }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public Map<String, Object> readFrom(Class<Map<String, Object>> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException { FormEncodingProvider delegate = new FormEncodingProvider(); MultivaluedMap<String, String> multi = (MultivaluedMap<String, String>) delegate.readFrom(MultivaluedMap.class, null, null, mediaType, httpHeaders, entityStream); Map<String, Object> map = Maps.newHashMapWithExpectedSize(multi.keySet().size()); for (String key : multi.keySet()) { List<String> value = multi.get(key); if (value.size() > 1) { map.put(key, Lists.newArrayList(value)); } else if (value.size() == 1) { map.put(key, Iterables.getOnlyElement(value)); } else { map.put(key, null); } } return map; } }
public static Form readForm(FormEncodingProvider<Form> provider, Message message) throws Exception { return provider.readFrom(Form.class, Form.class, new Annotation[]{}, MediaType.APPLICATION_FORM_URLENCODED_TYPE, new MetadataMap<String, String>(), message.getContent(InputStream.class)); }
public static Form readForm(FormEncodingProvider<Form> provider, Message message) throws Exception { return provider.readFrom(Form.class, Form.class, new Annotation[]{}, MediaType.APPLICATION_FORM_URLENCODED_TYPE, new MetadataMap<String, String>(), message.getContent(InputStream.class)); }
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)); return resp; }