@Override public void inboundBufferUpdated(final ChannelHandlerContext ctx, final ByteBuf in) throws Exception { if (log.isLoggable(Level.FINEST)) { log.finest("Using the " + this.getClass().getSimpleName()); } try { // Read in the archive using the isolated CL context of this domain final InputStream instream = new ByteBufInputStream(in); final GenericArchive archive = NettyServer.this.getShrinkwrapDomain().getArchiveFactory() .create(ZipImporter.class).importFrom(instream).as(GenericArchive.class); instream.close(); if (log.isLoggable(Level.FINEST)) { log.finest("Got archive: " + archive.toString(true)); } // Store the archive final String id = archive.getId(); NettyServer.this.getDeployedArchives().put(id, archive); // Tell the client OK, and let it know the ID of the archive (so it may be undeployed) final ByteBuf out = ctx.nextOutboundByteBuffer(); NettyServer.sendResponse(ctx, out, WireProtocol.RESPONSE_OK_PREFIX + WireProtocol.COMMAND_DEPLOY_PREFIX + id); } finally { NettyServer.this.resetPipeline(ctx.pipeline()); } } }
@After public void ls() { System.out.println("test@jboss:/$ ls -l " + archive.getName()); System.out.println(archive.toString(true)); }
/** * Ensures that an import of {@link InputStream} results in {@link ArchiveImportException} if an unexpected error * occurred. * * @throws Exception */ @Test(expected = ArchiveImportException.class) public void shouldThrowExceptionOnErrorInImportFromStream() throws Exception { final InputStream exceptionIn = this.getExceptionThrowingInputStream(); // Get the importer final Class<T> importerClass = this.getImporterClass(); assert importerClass != null : "Importer class must be specified by implementations"; final T importer = ShrinkWrap.create(importerClass, "test.jar"); try { final GenericArchive archive = importer.importFrom(exceptionIn).as(GenericArchive.class); log.info("Imported: " + archive.toString(true)); } finally { exceptionIn.close(); } }
/** * Test to ensure that the export process accepts an archive with only directories, no assets. * * @throws Exception */ @Test public void testExportArchiveWithOnlyDirectories() throws IOException { // Create an archive with directories final ArchivePath path = ArchivePaths.create("/test/game"); final Archive<?> archive = ShrinkWrap.create(JavaArchive.class, NAME_ARCHIVE).addAsDirectories(path); // Fully export by reading all content (export is on-demand) final InputStream content = this.exportAsInputStream(archive); final ByteArrayOutputStream exportedContents = new ByteArrayOutputStream(); IOUtil.copyWithClose(content, exportedContents); final GenericArchive roundtrip = ShrinkWrap.create(this.getImporterClass(), "roundtrip.zip") .importFrom(new ByteArrayInputStream(exportedContents.toByteArray())).as(GenericArchive.class); log.info(roundtrip.toString(true)); Assert.assertTrue(roundtrip.contains(path)); }