i'm learning jersey trying create rest service receives image client, processes image , returns new image additional information (i.e., processing details).
so far, uploading works fine. i'm concerned creating response. i'm thinking of creating multipart response contains new image in 1 bodypart while adding json string (that contains additional info) body part. wasn't successful. code follows:
file image = process(oldimage); info info = getinfo(); string jsonstr = tojson(info); mimemultipart multipart = new mimemultipart(); mimebodypart imagepart = new mimebodypart(); imagepart.setcontent(files.readallbytes(image.topath()), mediatype.application_octet_stream); mimebodypart jsonpart = new mimebodypart(); jsonpart.setcontent(jsonstr, mediatype.application_json); multipart.addbodypart(imagepart); multipart.addbodypart(jsonpart); return response.ok(multipart, "multipart/mixed").build();
i received error message follows:
messagebodywriter not found media type=multipart/mixed, type=class com.sun.xml.internal.messaging.saaj.packaging.mime.internet.mimemultipart, generictype=class com.sun.xml.internal.messaging.saaj.packaging.mime.internet.mimemultipart.
i've been searching while haven't found anyway fix it. great of can pointing out what's wrong code , should approach take regarding issue.
i think com.sun.xml.internal.messaging.saaj.packaging.mime.internet.mimemultipart
not class want.
jersey 2.x
for jersey 2.x, use multipart
class org.glassfish.jersey.media.multipart
package.
to use multipart features need add jersey-media-multipart
module pom.xml
file:
<dependency> <groupid>org.glassfish.jersey.media</groupid> <artifactid>jersey-media-multipart</artifactid> <version>2.22.2</version> </dependency>
and don't forget registering multipartfeature
:
final application application = new resourceconfig() .packages("org.glassfish.jersey.examples.multipart") .register(multipartfeature.class)
there's example of multipart request on jersey github repository.
for more details, have @ jersey 2.x documentation.
jersey 1.x
for old jersey 1.x, can use multipart
class com.sun.jersey.multipart
package.
the jersey-multipart
dependecy necessary:
<dependency> <groupid>com.sun.jersey.contribs</groupid> <artifactid>jersey-multipart</artifactid> <version>1.19.1</version> </dependency>
Comments
Post a Comment