@Test public void testMimeType() throws Exception { ReleaseTest.prepareReleaseWithFiles(); FileUtil.createFile("releases/xyz/file3.jar", "jar file"); FileUtil.createFile("releases/xyz/file4.zip", "zip file"); MockRequest request = new MockRequest(); request.addInput("release", "xyz"); request.setResource("file3.jar"); Response response = responder.makeResponse(context, request); assertEquals("application/x-java-archive", response.getContentType()); request.setResource("file4.zip"); response = responder.makeResponse(context, request); assertEquals("application/zip", response.getContentType()); }
public Response makeResponse(FitNesseContext fitNesseContext, Request request) throws Exception { releaseName = (String) request.getInput("release"); release = new Release(releaseName); filename = request.getResource(); if (!release.exists()) return new ErrorResponder("There is no release named " + releaseName ).makeResponse(fitNesseContext, request); ReleaseFile releaseFile = release.getFile(filename); if (releaseFile == null) return new ErrorResponder( "The " + releaseName + " doesn't have a file named " + filename ).makeResponse(fitNesseContext, request); InputStreamResponse response = new InputStreamResponse(); response.setContentType(FileResponder.getContentType(filename)); InputStream input = releaseFile.getDownloadStream(); response.setBody(input, (int) releaseFile.getByteCount()); release.saveInfo(); return response; }
DownloadResponder implements Responder { public Response makeResponse(FitNesseContext fitNesseContext, Request request) throws Exception { releaseName = (String) request.getInput("release"); release = new Release(releaseName); filename = request.getResource(); if (!release.exists()) return new ErrorResponder("There is no release named " + releaseName ).makeResponse(fitNesseContext, request); ReleaseFile releaseFile = release.getFile(filename); if (releaseFile == null) return new ErrorResponder( "The " + releaseName + " doesn't have a file named " + filename ).makeResponse(fitNesseContext, request); InputStreamResponse response = new InputStreamResponse(); response.setContentType(FileResponder.getContentType(filename)); InputStream input = releaseFile.getDownloadStream(); response.setBody(input, (int) releaseFile.getByteCount()); release.saveInfo(); return response; } }
DownloadResponder implements Responder { public Response makeResponse(FitNesseContext fitNesseContext, Request request) throws Exception { releaseName = (String) request.getInput("release"); release = new Release(releaseName); filename = request.getResource(); if (!release.exists()) return new ErrorResponder("There is no release named " + releaseName ).makeResponse(fitNesseContext, request); ReleaseFile releaseFile = release.getFile(filename); if (releaseFile == null) return new ErrorResponder( "The " + releaseName + " doesn't have a file named " + filename ).makeResponse(fitNesseContext, request); InputStreamResponse response = new InputStreamResponse(); response.setContentType(FileResponder.getContentType(filename)); InputStream input = releaseFile.getDownloadStream(); response.setBody(input, (int) releaseFile.getByteCount()); release.saveInfo(); return response; }  }
DownloadResponder implements Responder { public Response makeResponse(FitNesseContext fitNesseContext, Request request) throws Exception { releaseName = (String) request.getInput("release"); release = new Release(releaseName); filename = request.getResource(); if (!release.exists()) return new ErrorResponder("There is no release named " + releaseName ).makeResponse(fitNesseContext, request); ReleaseFile releaseFile = release.getFile(filename); if (releaseFile == null) return new ErrorResponder( "The " + releaseName + " doesn't have a file named " + filename ).makeResponse(fitNesseContext, request); InputStreamResponse response = new InputStreamResponse(); response.setContentType(FileResponder.getContentType(filename)); InputStream input = releaseFile.getDownloadStream(); response.setBody(input, (int) releaseFile.getByteCount()); release.saveInfo(); return response; }  Response makeResponse(FitNesseContext fitNesseContext, Request request); String getReleaseName(); String getFilename(); }
DownloadResponder implements Responder { public Response makeResponse(FitNesseContext fitNesseContext, Request request) throws Exception { releaseName = (String) request.getInput("release"); release = new Release(releaseName); filename = request.getResource(); if (!release.exists()) return new ErrorResponder("There is no release named " + releaseName ).makeResponse(fitNesseContext, request); ReleaseFile releaseFile = release.getFile(filename); if (releaseFile == null) return new ErrorResponder( "The " + releaseName + " doesn't have a file named " + filename ).makeResponse(fitNesseContext, request); InputStreamResponse response = new InputStreamResponse(); response.setContentType(FileResponder.getContentType(filename)); InputStream input = releaseFile.getDownloadStream(); response.setBody(input, (int) releaseFile.getByteCount()); release.saveInfo(); return response; }  Response makeResponse(FitNesseContext fitNesseContext, Request request); String getReleaseName(); String getFilename();  }