Download der zip-Datei mithilfe von Restful-services

Im Versuch zu erstellen und laden Sie eine zip-Datei, die in java Verwendung von restful-service. Aber seine nicht funktioniert für mich. Bitte finden Sie den code unten:

        @GET
    @Path("/exportZip")
    @Produces("application/zip")
    public Response download(@QueryParam("dim") final String dimId,
            @QueryParam("client") final String clientId,
            @QueryParam("type") final String type,
            @Context UriInfo ui) {
        System.out.println("Start");

        ResponseBuilder response = null ;

        String filetype = "";

        if(type.equalsIgnoreCase("u")){
            filetype = "UnMapped";

        }else if(type.equalsIgnoreCase("m")){
            filetype = "Mapped";

        }
        try {

            byte[] workbook = null;
            workbook = engineService.export(dim, client, type);

            InputStream is = new ByteArrayInputStream(workbook);

            FileOutputStream out = new FileOutputStream(filetype + "tmp.zip");

            int bufferSize = 1024;
            byte[] buf = new byte[bufferSize];
            int n = is.read(buf);
            while (n >= 0) {
                out.write(buf, 0, n);
              n = is.read(buf);
            }

            response = Response.ok((Object) out);

            response.header("Content-Disposition",
                    "attachment; filename=\"" + filetype + " - " + new Date().toString() + ".zip\"");

            out.flush();
            out.close();


        catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("End");
        return response.build();
    }

Dies gibt mir die folgende Fehlermeldung:
javax.ws.rs.WebApplicationException: com.Sonne.jersey.api.MessageException: Ein message-body-writer für die Java-Klasse java.io.FileOutputStream und Java-Typ class java.io.FileOutputStream und MIME-media-Typ application/zip nicht gefunden wurde

Warum gibst du den FileOutputStream als Antwort Körper?
Du hast Recht. Ich entfernt, dass etwas, und ich nur an den byte-array in response als Antwort.ok((object) Arbeitsmappe). Und die zip-Datei war dowloadable.

InformationsquelleAutor | 2014-04-14

Schreibe einen Kommentar