final String contentType = fileMatcher.getContentType();
final String file = fileMatcher.getFile();
final HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
final JbpmContext jbpmContext = JbpmConfiguration.getInstance().createJbpmContext();
try {
final ProcessDefinition processDefinition = jbpmContext.getGraphSession().getProcessDefinition(id);
if (processDefinition == null) {
try {
response.sendError(404, "Process definition " + id + " does not exist");
facesContext.responseComplete();
break;
} catch (IOException e) {
log.log(Level.SEVERE, "Failed to send 404 Not Found to client", e);
}
}
if (!processDefinition.getFileDefinition().hasFile(file)) {
try {
response.sendError(404, "Process definition " + id + " does not contain file '" + file + "'");
facesContext.responseComplete();
break;
} catch (IOException e) {
log.log(Level.SEVERE, "Failed to send 404 Not Found to client", e);
}
}
final byte[] bytes;
bytes = processDefinition.getFileDefinition().getBytes(file);
response.setContentLength(bytes.length);
response.setContentType(contentType);
try {
final OutputStream outputStream = response.getOutputStream();
try {