Class FormDataBodyPart
java.lang.Object
org.glassfish.jersey.media.multipart.BodyPart
org.glassfish.jersey.media.multipart.FormDataBodyPart
- All Implemented Interfaces:
EntityPart
- Direct Known Subclasses:
FileDataBodyPart
,StreamDataBodyPart
Subclass of
BodyPart
with specialized support for media type
multipart/form-data
. See
RFC 2388
for the formal definition of this media type.
For a server side application wishing to process an incoming
multipart/form-data
message, the following features
are provided:
- Property accessor to retrieve the control name.
- Property accessor to retrieve the field value for a simple String field.
- Convenience accessor to retrieve the field value after conversion
through an appropriate
MessageBodyReader
.
multipart/form-data
message, the following features
are provided:
- Convenience constructors for named fields with either simple string values, or arbitrary entities and media types.
- Property accessor to set the control name.
- Property accessor to set the field value for a simple String field.
- Convenience accessor to set the media type and value of a "file" field.
- Author:
- Craig McClanahan, Imran M Yousuf (imran at smartitengineering.com), Paul Sandoz, Michal Gajdos
-
Nested Class Summary
Nested classes/interfaces inherited from interface jakarta.ws.rs.core.EntityPart
EntityPart.Builder
-
Field Summary
Fields inherited from class org.glassfish.jersey.media.multipart.BodyPart
contentDisposition, messageBodyWorkers
-
Constructor Summary
ConstructorDescriptionFormDataBodyPart
(boolean fileNameFix) Instantiates an unnamed newFormDataBodyPart
withmediaType
oftext/plain
and setting the flag for applying the fix for erroneous file name value if content disposition header of messages coming from MS Internet Explorer (see JERSEY-759).FormDataBodyPart
(MediaType mediaType) Instantiates an unnamedFormDataBodyPart
with the specified characteristics.FormDataBodyPart
(Object entity, MediaType mediaType) Instantiates an unnamedFormDataBodyPart
with the specified characteristics.FormDataBodyPart
(String name, Object entity, MediaType mediaType) Instantiates a namedFormDataBodyPart
with the specified characteristics.FormDataBodyPart
(String name, String value) Instantiates a namedFormDataBodyPart
with a media type oftext/plain
and String value.FormDataBodyPart
(FormDataContentDisposition formDataContentDisposition, Object entity, MediaType mediaType) Instantiates a namedFormDataBodyPart
with the specified characteristics.FormDataBodyPart
(FormDataContentDisposition formDataContentDisposition, String value) Instantiates a namedFormDataBodyPart
with the specified characteristics. -
Method Summary
Modifier and TypeMethodDescription<T> T
getContent
(GenericType<T> type) <T> T
getContent
(Class<T> type) Overrides the behaviour onBodyPart
to ensure that only instances ofFormDataContentDisposition
can be obtained.Gets the form data content disposition.getName()
Gets the control name.getValue()
Gets the field value for this body part.<T> T
getValueAs
(Class<T> clazz) Gets the field value after appropriate conversion to the requested type.boolean
isSimple()
void
setContentDisposition
(ContentDisposition contentDisposition) Overrides the behaviour onBodyPart
to ensure that only instances ofFormDataContentDisposition
can be set.void
setFormDataContentDisposition
(FormDataContentDisposition formDataContentDisposition) Sets the form data content disposition.void
Sets the control name.void
Sets the field media type and value for this body part.void
Sets the field value for this body part.Methods inherited from class org.glassfish.jersey.media.multipart.BodyPart
cleanup, contentDisposition, entity, getEntity, getEntityAs, getHeaders, getMediaType, getParameterizedHeaders, getParent, getProviders, setEntity, setMediaType, setMessageBodyWorkers, setParent, setProviders, type
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface jakarta.ws.rs.core.EntityPart
getHeaders, getMediaType
-
Field Details
-
contentRead
-
-
Constructor Details
-
FormDataBodyPart
public FormDataBodyPart() -
FormDataBodyPart
public FormDataBodyPart(boolean fileNameFix) Instantiates an unnamed newFormDataBodyPart
withmediaType
oftext/plain
and setting the flag for applying the fix for erroneous file name value if content disposition header of messages coming from MS Internet Explorer (see JERSEY-759).- Parameters:
fileNameFix
- If set totrue
, header parser will not treat backslash as an escape character when retrieving the value offilename
parameter ofContent-Disposition
header.
-
FormDataBodyPart
Instantiates an unnamedFormDataBodyPart
with the specified characteristics.- Parameters:
mediaType
- theMediaType
for this body part.
-
FormDataBodyPart
Instantiates an unnamedFormDataBodyPart
with the specified characteristics.- Parameters:
entity
- the entity for this body part.mediaType
- theMediaType
for this body part.
-
FormDataBodyPart
Instantiates a namedFormDataBodyPart
with a media type oftext/plain
and String value.- Parameters:
name
- the control name for this body part.value
- the value for this body part.
-
FormDataBodyPart
Instantiates a namedFormDataBodyPart
with the specified characteristics.- Parameters:
name
- the control name for this body part.entity
- the entity for this body part.mediaType
- theMediaType
for this body part.
-
FormDataBodyPart
Instantiates a namedFormDataBodyPart
with the specified characteristics.- Parameters:
formDataContentDisposition
- the content disposition header for this body part.value
- the value for this body part.
-
FormDataBodyPart
public FormDataBodyPart(FormDataContentDisposition formDataContentDisposition, Object entity, MediaType mediaType) Instantiates a namedFormDataBodyPart
with the specified characteristics.- Parameters:
formDataContentDisposition
- the content disposition header for this body part.entity
- the entity for this body part.mediaType
- theMediaType
for this body part.
-
-
Method Details
-
getFormDataContentDisposition
Gets the form data content disposition.- Returns:
- the form data content disposition.
-
setFormDataContentDisposition
Sets the form data content disposition.- Parameters:
formDataContentDisposition
- the form data content disposition.
-
getContentDisposition
Overrides the behaviour onBodyPart
to ensure that only instances ofFormDataContentDisposition
can be obtained.- Overrides:
getContentDisposition
in classBodyPart
- Returns:
- the content disposition.
- Throws:
IllegalArgumentException
- if the content disposition header cannot be parsed.
-
setContentDisposition
Overrides the behaviour onBodyPart
to ensure that only instances ofFormDataContentDisposition
can be set.- Overrides:
setContentDisposition
in classBodyPart
- Parameters:
contentDisposition
- the content disposition which must be an instance ofFormDataContentDisposition
.- Throws:
IllegalArgumentException
- if the content disposition is not an instance ofFormDataContentDisposition
.
-
getName
Gets the control name.- Specified by:
getName
in interfaceEntityPart
- Returns:
- the control name.
-
getFileName
- Specified by:
getFileName
in interfaceEntityPart
-
getContent
- Specified by:
getContent
in interfaceEntityPart
-
getContent
- Specified by:
getContent
in interfaceEntityPart
-
getContent
- Specified by:
getContent
in interfaceEntityPart
-
setName
Sets the control name.- Parameters:
name
- the control name.
-
getValue
Gets the field value for this body part. This should be called only on body parts representing simple field values.- Returns:
- the simple field value.
- Throws:
ProcessingException
- if an IO error arises during reading the value.IllegalStateException
- if called on a body part with a media type other thantext/plain
-
getValueAs
Gets the field value after appropriate conversion to the requested type. This is useful only when the containingFormDataMultiPart
instance has been received, which causes theproviders
property to have been set.- Type Parameters:
T
- the type of the field value.- Parameters:
clazz
- Desired class into which the field value should be converted.- Returns:
- the field value.
- Throws:
ProcessingException
- if an IO error arises during reading an entity.IllegalArgumentException
- if noMessageBodyReader
can be found to perform the requested conversion.IllegalStateException
- if this method is called when theproviders
property has not been set or when the entity instance is not the unconverted content of the body part entity.
-
setValue
Sets the field value for this body part. This should be called only on body parts representing simple field values.- Parameters:
value
- the field value.- Throws:
IllegalStateException
- if called on a body part with a media type other thantext/plain
.
-
setValue
Sets the field media type and value for this body part.- Parameters:
mediaType
- the media type for this field value.value
- the field value as a Java object.
-
isSimple
public boolean isSimple()- Returns:
true
if this body part represents a simple, string-based, field value, otherwisefalse
.
-