Changeset 695
- Timestamp:
- 03/07/10 15:19:30 (6 months ago)
- Location:
- trunk
- Files:
-
- 2 edited
-
TEST_SUITE (modified) (2 diffs)
-
src/com/calenco/resource/workspace/ContentResource.java (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/TEST_SUITE
r631 r695 1 Calenco V2 Test Suite (Last updated 20 09-12-29)1 Calenco V2 Test Suite (Last updated 2010-03-07) 2 2 3 3 This file describes some basic test procedures to excercise the V2 core. The … … 154 154 - Try to get backup of a non-existing workspace, as sysadmin: MUST FAIL with 404 155 155 curl -uadmin@calenco.com:admin -i http://localhost:9000/workspaces/Non%20Existing 156 156 - Backup content of w1 (should get a zip file with a folder named 'content' with all content for w1 in it) 157 curl -uadminw1@calenco.com:very_secret -HAccept:application/zip http://localhost:9000/workspaces/Workspace%201/content > W1.zip 157 158 158 159 11. List files -
trunk/src/com/calenco/resource/workspace/ContentResource.java
r692 r695 76 76 import org.apache.commons.io.input.AutoCloseInputStream; 77 77 import org.json.JSONObject; 78 import org.restlet.Request; 79 import org.restlet.Response; 80 import org.restlet.Uniform; 78 81 import org.restlet.data.CharacterSet; 79 82 import org.restlet.data.Disposition; … … 121 124 String path = null; 122 125 String fileName = null; 126 File tempFile = null; 123 127 124 128 @Override … … 169 173 } 170 174 path = String.format("%s/content%s", workspace.href, "".equals(fileName) ? fileName : "/" + fileName); 175 setOnSent(new CleanupTempFile()); 171 176 } 172 177 … … 460 465 ContentDAO dao = new ContentDAO(session, workspace); 461 466 if (MediaType.APPLICATION_ZIP.equals(mt)) { // Export 462 File exportFile = dao.export(); 463 FileUtils.forceDeleteOnExit(exportFile); 464 Representation rep = new FileRepresentation(exportFile, mt); 467 tempFile = dao.export(); 468 Representation rep = new FileRepresentation(tempFile, mt); 465 469 Disposition disposition = new Disposition(Disposition.TYPE_ATTACHMENT); 466 disposition.setFilename( exportFile.getName());467 disposition.setSize( exportFile.length());470 disposition.setFilename(tempFile.getName()); 471 disposition.setSize(tempFile.length()); 468 472 rep.setDisposition(disposition); 469 473 return rep; … … 533 537 Set<Association> deps = adao.findByKindFrom(Association.HAS_DEP_CALLED, content.href); 534 538 storeDeps(session, deps, Language.INTL, tempFolder); 535 File zipFile = new File(Constants.IO_TMPDIR, String.format("%s-EXPORT-%d.zip", langOrFile, rstart));536 new Packer().zip(tempFolder, zipFile);537 FileRepresentation rep = new FileRepresentation( zipFile, MediaType.APPLICATION_ZIP);539 tempFile = new File(Constants.IO_TMPDIR, String.format("%s-EXPORT-%d.zip", langOrFile, rstart)); 540 new Packer().zip(tempFolder, tempFile); 541 FileRepresentation rep = new FileRepresentation(tempFile, MediaType.APPLICATION_ZIP); 538 542 return rep; 539 543 } else { // Stream file back … … 551 555 return new EmptyRepresentation(); // No entity body allowed with http 304 responses 552 556 } 553 File tempFile = File.createTempFile("cco", null); // NOI18N 554 FileUtils.forceDeleteOnExit(tempFile); 557 tempFile = File.createTempFile("cco", null); // NOI18N 555 558 FileOutputStream fos = FileUtils.openOutputStream(tempFile); 556 559 IOUtils.copy(new AutoCloseInputStream(content.getFstream()), fos); … … 654 657 Set<Association> deps = adao.findByKindFrom(Association.HAS_DEP_CALLED, content.href); 655 658 storeDeps(session, deps, lang, tempFolder); 656 File zipFile = new File(Constants.IO_TMPDIR, String.format("%s-EXPORT-%d.zip", file, rstart));657 new Packer().zip(tempFolder, zipFile);658 FileRepresentation rep = new FileRepresentation( zipFile, MediaType.APPLICATION_ZIP);659 tempFile = new File(Constants.IO_TMPDIR, String.format("%s-EXPORT-%d.zip", file, rstart)); 660 new Packer().zip(tempFolder, tempFile); 661 FileRepresentation rep = new FileRepresentation(tempFile, MediaType.APPLICATION_ZIP); 659 662 return rep; 660 663 } else { // Stream back … … 672 675 return new EmptyRepresentation(); // No entity body allowed with http 304 responses 673 676 } 674 File tempFile = File.createTempFile("cco", null); 675 FileUtils.forceDeleteOnExit(tempFile); 677 tempFile = File.createTempFile("cco", null); 676 678 FileOutputStream fos = FileUtils.openOutputStream(tempFile); 677 679 IOUtils.copy(new AutoCloseInputStream(content.getFstream()), fos); … … 1235 1237 new AssociationDAO(session, workspace).add(hasAuthor); 1236 1238 } 1237 1239 1240 1241 /** 1242 * Delete temporary file, if any. This is used to delete files after they 1243 * have been downloaded by the client. 1244 */ 1245 class CleanupTempFile implements Uniform { 1246 @Override 1247 public void handle(Request rqst, Response rspns) { 1248 if (Method.GET.equals(rqst.getMethod()) && tempFile != null) { 1249 FileUtils.deleteQuietly(tempFile); 1250 } 1251 } 1252 } 1253 1238 1254 }
Note: See TracChangeset
for help on using the changeset viewer.
