added Content-Disposition HTTP header for better support of download file's name

This commit is contained in:
2017-12-05 21:06:07 +01:00
parent cc12bd69db
commit 719230bb4e

View File

@@ -29,9 +29,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import java.io.*;
import java.net.URI;
import java.nio.file.Files;
import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -284,6 +282,22 @@ public class PacmanWebService
}
}
@POST
@Path("/doYouWantAny")
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response doYouWantAny(List<String> filenames)
{
Set<String> result = new HashSet<>(filenames);
if(!result.isEmpty())
{
TypedQuery<String> query = em.createQuery("SELECT pkg.fileName from PkgData pkg WHERE pkg.fileName in :filenames", String.class);
query.setParameter("filenames", filenames);
Set<String> toBeRemoved = new HashSet(query.getResultList());
result.removeAll(toBeRemoved);
}
return Response.ok(result).build();
}
@POST
@Path("/upload")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@@ -466,7 +480,7 @@ public class PacmanWebService
}
}
};
return Response.ok(stream).build();
return Response.ok(stream).header("Content-Disposition", "attachment; filename=pkgs.tar").build();
}
private Response manageQueryResult(List<PkgData> list)