Source:
<code>protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String url = req.getRequestURI(); String maven_url = ""; if (url.contains(URL_CONTEXT_STR)) { maven_url = url.substring(url.indexOf(URL_CONTEXT_STR) + URL_CONTEXT_STR.length()); } else { maven_url = url; } if (maven_url.startsWith("/")) { maven_url = maven_url.substring(1); } String[] tokens = maven_url.split("/"); if (tokens != null && tokens.length > 0) { String groupId = ""; String version = ""; String artifactId = ""; String file_name = ""; if (tokens.length >= 4) { file_name = tokens[tokens.length - 1]; MavenArtifactWrapper artifact = null; if (file_name.contains(".")) { version = tokens[tokens.length - 2]; for (int i = 0; i < tokens.length - 2; i++) { if (i < tokens.length - 3) { if (i != 0) { groupId += "."; } groupId += tokens[i]; } else { artifactId = tokens[i]; } } try { artifact = service.getArtifactContent(file_name, groupId, artifactId, version); if (artifact != null) { resp.setContentLength(artifact.getContentLength()); <START> resp.getOutputStream().write(artifact.getContent()); <END> resp.addHeader("Content-Disposition", "attachment; filename=" + artifact.getFileName()); resp.setContentType(artifact.getContentType()); } } catch (SrampAtomException e) { logger.info(Messages.i18n.format("maven.servlet.artifact.content.get.exception", groupId, artifactId, version, file_name)); } } if (artifact == null) { listItemsResponse(req, resp, maven_url); } } else { listItemsResponse(req, resp, maven_url); } } }</code><technical_language>write output stream _last_ operation, response headers properly sent. addHeader() setContentType() calls this line need moved up. do a byte[] - is inputstream stream content response</technical_language>

Target:
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String url = req.getRequestURI(); String maven_url = ""; if (url.contains(URL_CONTEXT_STR)) { maven_url = url.substring(url.indexOf(URL_CONTEXT_STR) + URL_CONTEXT_STR.length()); } else { maven_url = url; } if (maven_url.startsWith("/")) { maven_url = maven_url.substring(1); } String[] tokens = maven_url.split("/"); if (tokens != null && tokens.length > 0) { String groupId = ""; String version = ""; String artifactId = ""; String file_name = ""; if (tokens.length >= 4) { file_name = tokens[tokens.length - 1]; MavenArtifactWrapper artifact = null; if (file_name.contains(".")) { version = tokens[tokens.length - 2]; for (int i = 0; i < tokens.length - 2; i++) { if (i < tokens.length - 3) { if (i != 0) { groupId += "."; } groupId += tokens[i]; } else { artifactId = tokens[i]; } } try { artifact = service.getArtifactContent(file_name, groupId, artifactId, version); if (artifact != null) { resp.setContentLength(artifact.getContentLength()); resp.addHeader("Content-Disposition", "attachment; filename=" + artifact.getFileName()); resp.setContentType(artifact.getContentType()); IOUtils.copy(artifact.getContent(), resp.getOutputStream()); } } catch (SrampAtomException e) { logger.info(Messages.i18n.format("maven.servlet.artifact.content.get.exception", groupId, artifactId, version, file_name)); } finally { if (artifact != null && artifact.getContent() != null) { artifact.getContent().close(); } } } if (artifact == null) { listItemsResponse(req, resp, maven_url); } } else { listItemsResponse(req, resp, maven_url); } } }