@GET
@Path("{packageName}/binary")
@Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response getPackageBinary(@PathParam("packageName") String packageName) throws SerializationException {
try {
ModuleItem p = rulesRepository.loadModule(packageName);
String fileName = packageName + ".pkg";
byte[] result;
if (p.isBinaryUpToDate()) {
result = p.getCompiledBinaryBytes();
} else {
BuilderResult builderResult = repositoryPackageService.buildPackage(p.getUUID(), true);
if (builderResult != null) {
StringBuilder errs = new StringBuilder();
errs.append("Unable to build package name [").append(packageName).append("]\n");
for (BuilderResultLine resultLine : builderResult.getLines()) {
errs.append(resultLine.toString()).append("\n");
}
return Response.status(500).entity(errs.toString()).build();
}
result = rulesRepository.loadModule(packageName).getCompiledBinaryBytes();
}
return Response.ok(result).header("Content-Disposition", "attachment; filename=" + fileName).
header("Last-Modified", createDateFormat().format(this.convertToGmt(p.getLastModified()).getTime())).build();
} catch (Exception e) {
//catch RulesRepositoryException and other exceptions. For example when the package does not exists.
throw new WebApplicationException(e);
}
}