public final class MessageBodyReaderUtils extends Object
MessageBodyReader.| Modifier and Type | Class and Description |
|---|---|
static class |
MessageBodyReaderUtils.RequestData
Simple class that holds the MediaType, Name and the content as
InputStream. |
| Modifier and Type | Method and Description |
|---|---|
static MessageBodyReaderUtils.RequestData |
formForm(InputStream formData,
String charset,
String encodingParam,
List<String> contentParams)
Returns content parsed as
MediaType.APPLICATION_FORM_URLENCODED. |
static List<MessageBodyReaderUtils.RequestData> |
fromMultipart(InputStream mimeData,
javax.ws.rs.core.MediaType mediaType)
Returns content parsed from
MediaType.MULTIPART_FORM_DATA. |
public static MessageBodyReaderUtils.RequestData formForm(InputStream formData, String charset, String encodingParam, List<String> contentParams) throws IOException, UnsupportedEncodingException, IllegalArgumentException
MediaType.APPLICATION_FORM_URLENCODED.
It assumes that the encoding and the content is defined by own parameters.
For the content this method allows to parse several parameters. The first
existing one is used to get the content. The parameter actually used to
retrieve the content will be available via MessageBodyReaderUtils.RequestData.getName().
This Method will load the content several time into memory and should
not be used for big contents. However this should be fine in cases
data are parsed as MediaType.APPLICATION_FORM_URLENCODED
This Method is necessary because within MessageBodyReader one
can not use the FormParam annotations because only the
InputStream is parsed to the
MessageBodyReader.readFrom(Class, Type, java.lang.annotation.Annotation[], MediaType, javax.ws.rs.core.MultivaluedMap, InputStream)
method
To test this Method with curl use:
Note that between {contentParam} and the datafile MUST NOT be a '='!
curl -v -X POST --data-urlencode "{encodingParam}=application/rdf+xml"
--data-urlencode "{contentParam}@{datafile}"
{serviceURL}
formData - the data of the form as streamcharset - the charset used for the form dataencodingParam - the parameter name used to parse the encodingcontentParams - the list of parameters used for the content. The first
existing parameter is used to parse the content. Additional ones are
ignored.IOException - On any exception while reading from the parsed stream.UnsupportedEncodingException - if the parsed charset is not supported
by this plattformIllegalArgumentException - In case of a Response.Status.BAD_REQUESTpublic static List<MessageBodyReaderUtils.RequestData> fromMultipart(InputStream mimeData, javax.ws.rs.core.MediaType mediaType) throws IOException, IllegalArgumentException
MediaType.MULTIPART_FORM_DATA.
It iterates over all BodyParts and tries to create MessageBodyReaderUtils.RequestData
instances. In case the Part.getContentType() is not present or
can not be parsed, the MessageBodyReaderUtils.RequestData.getMediaType() is set to
null. If Part.getInputStream() is not defined an
IllegalArgumentException is thrown. The Part.getFileName()
is used for MessageBodyReaderUtils.RequestData.getName(). The ordering of the returned
Content instances is the same as within the MimeMultipart instance
parsed from the input stream.
This Method does NOT load the data into memory, but returns directly the
InputStreams as returned by the BodyParts. Therefore
it is saved to be used with big attachments.
This Method is necessary because within MessageBodyReader one
can not use the usual annotations as used within Resources. so this method
allows to access the data directly from the parameters available from the
MessageBodyReader.readFrom(Class, Type, java.lang.annotation.Annotation[], MediaType, javax.ws.rs.core.MultivaluedMap, InputStream)
method
To test this Method with curl use:
Note that between {contentParam} and the datafile MUST NOT be a '='!
curl -v -X POST -F "content=@{dataFile};type={mimeType}"
{serviceURL}
mimeData - the mime encoded datamediaType - the mediaType (parsed to the ByteArrayDataSource
constructor)BodyPartsIOException - an any Exception while reading the stream or
MessagingException exceptions other than ParseExceptionsIllegalArgumentException - If a InputStream is not available
for any BodyPart or on ParseExceptions while reading the
MimeData from the stream.Copyright © 2010-2014 The Apache Software Foundation. All Rights Reserved.