|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.stanbol.entityhub.jersey.utils.MessageBodyReaderUtils
public final class MessageBodyReaderUtils
Utilities for implementing MessageBodyReader.
| Nested Class Summary | |
|---|---|
static class |
MessageBodyReaderUtils.RequestData
Simple class that holds the MediaType, Name and the content as InputStream. |
| Method Summary | |
|---|---|
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
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 plattform
IllegalArgumentException - In case of a Response.Status.BAD_REQUEST
public 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)
BodyParts
IOException - an any Exception while reading the stream or
MessagingException exceptions other than ParseExceptions
IllegalArgumentException - If a InputStream is not available
for any BodyPart or on ParseExceptions while reading the
MimeData from the stream.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||