Quantcast

server side media type=multipart/form-data

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

server side media type=multipart/form-data

tomaz
On server side in glassfish4 I'm using jersey-media-multipart:2.10.4.

1) I register MultiPartFeature

package si.arnes.upis.server.basic;

UpisApp extends Application{

  @Override
     public Set<Class<?>> getClasses() {
         final Set<Class<?>> resources = new HashSet<>();
         resources.add(MultiPartFeature.class);

         ...}

}

2) In my web.xml

<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
         <init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>si.arnes.upis.server.ws;com.fasterxml.jackson.jaxrs.json;org.glassfish.jersey.media.multipart</param-value>

         </init-param>

3) In my resource

@GET
     @Path("{orgRegNumber}/zip")
     @Produces(MediaType.MULTIPART_FORM_DATA)
     public Response getUsersPdfZip(@PathParam("orgRegNumber") String
orgRegNumber){

...

zos.close();

return Response
                 .ok(zos, "multipart/form-data")
                 .header("Content-Disposition", "attachment;
filename=\""+orgRegNumber+"-UsersArnes.zip\"")
                 .build();

}


4) I'm getting error:

-------------------------

Info:   10042016 16:03 INFO  UpisInterceptor:65 - END:getOrgPdfsZip
[0.006 seconds] result=OutboundJaxrsResponse{status=200, reason=OK,
hasEntity=true, closed=false, buffered=false}
Severe:   MessageBodyWriter not found for media
type=multipart/form-data, type=class java.util.zip.ZipOutputStream,
genericType=class java.util.zip.ZipOutputStream.

--------------------------

What I'm doing wrong?


Regards, Tomaz

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: server side media type=multipart/form-data

tomaz
I figure it out, I want response which serve zip file, so what is my
solution

@GET
@Path("/{orgRegNumber}/zip")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getZip(@PathParam("orgRegNumber") String orgRegNumber){

     FileOutputStream fos = new FileOutputStream("orgRegNumber+".zip");
     StreamingOutput stream = new StreamingOutput() {
             @Override
             public void write(OutputStream output) throws IOException {
                 ZipOutputStream zos = new ZipOutputStream(output);
                 File pdf = getOrgPdfFile(orgRegNumber);
                 FileInputStream fis = new FileInputStream(pdf);
                 zos.putNextEntry(new ZipEntry(pdf.getName()));
                 byte[] buffer = new byte[1024];
                 int length;
                 while ((length = fis.read(buffer)) > 0) {
                           zos.write(buffer, 0, length);
                 }
                 fis.close();
                 zos.closeEntry();
                 zos.close();
             }
     }

     return Response.ok().entity(stream)
.header("Content-Disposition", "attachment; filename="+orgRegNumber+".zip")
                                         .header("Content-Type",
"application/zip")
                                         .build();
}

Regards, Tomaz


Tomaz Majerhold je 4.10.2016 ob 16:06 napisal:

> On server side in glassfish4 I'm using jersey-media-multipart:2.10.4.
>
> 1) I register MultiPartFeature
>
> package si.arnes.upis.server.basic;
>
> UpisApp extends Application{
>
>  @Override
>     public Set<Class<?>> getClasses() {
>         final Set<Class<?>> resources = new HashSet<>();
>         resources.add(MultiPartFeature.class);
>
>         ...}
>
> }
>
> 2) In my web.xml
>
> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
>
>         <init-param>
> <param-name>jersey.config.server.provider.packages</param-name>
> <param-value>si.arnes.upis.server.ws;com.fasterxml.jackson.jaxrs.json;org.glassfish.jersey.media.multipart</param-value>
>
>         </init-param>
>
> 3) In my resource
>
> @GET
>     @Path("{orgRegNumber}/zip")
>     @Produces(MediaType.MULTIPART_FORM_DATA)
>     public Response getUsersPdfZip(@PathParam("orgRegNumber") String
> orgRegNumber){
>
> ...
>
> zos.close();
>
> return Response
>                 .ok(zos, "multipart/form-data")
>                 .header("Content-Disposition", "attachment;
> filename=\""+orgRegNumber+"-UsersArnes.zip\"")
>                 .build();
>
> }
>
>
> 4) I'm getting error:
>
> -------------------------
>
> Info:   10042016 16:03 INFO  UpisInterceptor:65 - END:getOrgPdfsZip
> [0.006 seconds] result=OutboundJaxrsResponse{status=200, reason=OK,
> hasEntity=true, closed=false, buffered=false}
> Severe:   MessageBodyWriter not found for media
> type=multipart/form-data, type=class java.util.zip.ZipOutputStream,
> genericType=class java.util.zip.ZipOutputStream.
>
> --------------------------
>
> What I'm doing wrong?
>
>
> Regards, Tomaz


Loading...