use of org.glassfish.api.admin.Payload.Outbound in project Payara by payara.
the class GetPayloadCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport ar = context.getActionReport();
Job job = registry.get(jobID);
if (job == null) {
ar.setActionExitCode(ActionReport.ExitCode.FAILURE);
ar.setMessage(strings.getLocalString("getPayload.wrong.commandinstance.id", "Command instance {0} does not exist.", jobID));
return;
}
Outbound jobPayload = job.getPayload();
if (jobPayload == null) {
ar.setMessage(strings.getLocalString("getPayload.nopayload", "Outbound payload does not exist."));
// Just return. This is OK.
return;
}
Outbound paylaod = context.getOutboundPayload();
if ((paylaod instanceof PayloadImpl.Outbound) && (jobPayload instanceof PayloadImpl.Outbound)) {
PayloadImpl.Outbound destination = (PayloadImpl.Outbound) paylaod;
PayloadImpl.Outbound source = (PayloadImpl.Outbound) jobPayload;
destination.getParts().addAll(source.getParts());
} else {
ar.setActionExitCode(ActionReport.ExitCode.FAILURE);
ar.setMessage(strings.getLocalString("getPayload.unsupported", "Payload type is not supported. Can not download data."));
}
}
use of org.glassfish.api.admin.Payload.Outbound in project Payara by payara.
the class PayloadFilesManagerTest method simplePermanentTransferDirTest.
@Test
public void simplePermanentTransferDirTest() throws Exception {
final String DIR = "x/y/z/";
final String FILE_PREFIX = "x/y/z/";
final String FILE_NAME = "fileB.txt";
final Set<File> desiredResults = new HashSet<File>();
/*
* Create a directory into which we'll transfer some small files.
*/
final File origDir = File.createTempFile("pfm", "");
origDir.delete();
File targetDir = null;
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
targetDir = File.createTempFile("tgt", "");
targetDir.delete();
targetDir.mkdir();
origDir.mkdir();
/*
* Add the directory first, then add a file in the directory. That
* will let us check to make sure the PayloadFileManager set the
* lastModified time on the directory correctly.
*/
final URI dirURI = URI.create(DIR);
final File dir = new File(origDir, DIR);
dir.mkdirs();
desiredResults.add(dir);
final File file = new File(dir, FILE_NAME);
desiredResults.add(new File(targetDir.toURI().resolve(FILE_PREFIX + FILE_NAME)));
writeFile(file, "Here is the File", "which has an", "additional line");
final long dirCreationTime = dir.lastModified();
new CommonPermTest() {
@Override
protected CommonPermTest init(File targetDir) {
super.init(targetDir);
return this;
}
@Override
protected void addParts(Outbound ob, PayloadFilesManager instance) throws Exception {
ob.attachFile("application/octet-stream", URI.create(DIR), "test-xfer", dir);
ob.attachFile("text/plain", URI.create(FILE_PREFIX + file.getName()), "test-xfer", file);
}
@Override
protected void checkResults(Inbound ib, PayloadFilesManager instance) throws Exception {
/*
* Extract files to where we want them.
*/
instance.processParts(ib);
final URI extractedDirURI = myTargetDir.toURI().resolve(dirURI);
final File extractedDir = new File(extractedDirURI);
final long extractedLastModified = extractedDir.lastModified();
assertEquals("Directory lastModified mismatch after extraction", dirCreationTime, extractedLastModified);
}
@Override
protected void cleanup() {
for (File f : desiredResults) {
f.delete();
}
PayloadFilesManagerTest.cleanup(origDir);
}
}.init(targetDir).run("simplePermanentTransferDirTest");
} finally {
if (targetDir != null) {
FileUtils.whack(targetDir);
}
}
}
use of org.glassfish.api.admin.Payload.Outbound in project Payara by payara.
the class PayloadFilesManagerTest method simplePermanentDirWithNoSlashRemovalTest.
@Test
public void simplePermanentDirWithNoSlashRemovalTest() throws Exception {
final String DIR = "x/";
final String DIR_WITH_NO_SLASH = "x";
final String FILE_A_PREFIX = DIR;
final String FILE_A_NAME = "fileA.txt";
final Set<File> desiredAbsent = new HashSet<File>();
/*
* Create a directory into which we'll copy some small files.
*/
final File origDir = File.createTempFile("pfm", "");
origDir.delete();
origDir.mkdir();
final File dir = new File(origDir, DIR);
dir.mkdir();
final File fileA = new File(dir, FILE_A_NAME);
writeFile(fileA, "This is FileA", "with two lines of content");
File targetDir = null;
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
targetDir = File.createTempFile("tgt", "");
targetDir.delete();
targetDir.mkdir();
desiredAbsent.add(new File(targetDir.toURI().resolve(FILE_A_PREFIX + FILE_A_NAME)));
new CommonPermTest() {
@Override
protected CommonPermTest init(File targetDir) {
super.init(targetDir);
return this;
}
@Override
protected void addParts(Outbound ob, PayloadFilesManager instance) throws Exception {
ob.attachFile("application/octet-stream", URI.create(DIR), "test-xfer", dir, true);
}
@Override
protected void checkResults(Inbound ib, PayloadFilesManager instance) throws Exception {
/*
* Extract files to where we want them.
*/
instance.processParts(ib);
// listDir("After creation, before deletion", myTargetDir);
/*
* Now ask another PayloadFilesManager to remove a directory
* recursively.
*/
Payload.Outbound ob = PayloadImpl.Outbound.newInstance();
ob.requestFileRemoval(URI.create(DIR_WITH_NO_SLASH), "removeTest", /* dataRequestName */
null, /* props */
true);
ob.requestFileRemoval(URI.create("notThere"), "removeTest", null, true);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
ob.writeTo(baos);
baos.close();
final PayloadFilesManager remover = new PayloadFilesManager.Perm(instance.getTargetDir(), null, debugLogger());
final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
Payload.Inbound removerIB = PayloadImpl.Inbound.newInstance("application/zip", bais);
remover.processParts(removerIB);
// listDir("After deletion" , myTargetDir);
final Set<File> unexpectedlyPresent = new HashSet<File>();
for (File f : desiredAbsent) {
if (f.exists()) {
unexpectedlyPresent.add(f);
}
}
assertEquals("Unexpected files remain after removal request", Collections.EMPTY_SET, unexpectedlyPresent);
}
@Override
protected void cleanup() {
for (File f : desiredAbsent) {
if (f.exists()) {
f.delete();
}
}
PayloadFilesManagerTest.cleanup(origDir);
}
}.init(targetDir).run("simplePermanentDirWithNoSlashRemovalTest");
} finally {
if (targetDir != null) {
FileUtils.whack(targetDir);
}
}
}
use of org.glassfish.api.admin.Payload.Outbound in project Payara by payara.
the class PayloadFilesManagerTest method simpleTempRecursiveTransferDirOnlyTest.
@Test
public void simpleTempRecursiveTransferDirOnlyTest() throws Exception {
final String DIR = "x/";
final String Y_SUBDIR = "y/";
final String Z_SUBDIR = "z/";
final List<String> desiredResultsNamePrefixes = new ArrayList<String>();
/*
* Create a directory into which we'll copy some small files.
*/
final File origDir = File.createTempFile("pfm", "");
origDir.delete();
origDir.mkdir();
final File dir = new File(origDir, DIR);
dir.mkdir();
final File ySubdir = new File(dir, Y_SUBDIR);
ySubdir.mkdir();
final File zSubdir = new File(ySubdir, Z_SUBDIR);
zSubdir.mkdir();
File targetDir = null;
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
targetDir = File.createTempFile("tgt", "");
targetDir.delete();
targetDir.mkdir();
desiredResultsNamePrefixes.add("/x");
desiredResultsNamePrefixes.add("/x/y");
desiredResultsNamePrefixes.add("/x/y/z");
/*
* Add the original directory recursively.
*/
new CommonTempTest() {
@Override
protected void addParts(Outbound ob, PayloadFilesManager instance) throws Exception {
ob.attachFile("application/octet-stream", URI.create(DIR), "test-xfer", dir, true);
}
@Override
protected void checkResults(Inbound ib, PayloadFilesManager instance) throws Exception {
/*
* Extract files to where we want them.
*/
final List<File> files = instance.processParts(ib);
checkNextFile: for (File f : files) {
for (ListIterator<String> it = desiredResultsNamePrefixes.listIterator(); it.hasNext(); ) {
final String desiredPrefix = it.next().replace("/", File.separator);
if (f.getPath().contains(desiredPrefix)) {
it.remove();
continue checkNextFile;
}
}
}
assertEquals("Unexpected missing files after extraction", Collections.EMPTY_LIST, desiredResultsNamePrefixes);
}
@Override
protected void doCleanup() {
PayloadFilesManagerTest.cleanup(origDir);
}
}.run("simpleTempRecursiveTransferDirOnlyTest");
} finally {
if (targetDir != null) {
FileUtils.whack(targetDir);
}
}
}
use of org.glassfish.api.admin.Payload.Outbound in project Payara by payara.
the class PayloadFilesManagerTest method simplePermanentTransferTest.
// @Test
// public void testWindowsPath() throws Exception {
// //System.out.println("testWindowsPath");
// testForBadChars("C:\\Program Files\\someDir");
// }
//
// @Test
// public void testNonWindowsPath() throws Exception {
// //System.out.println("testNonWindowsPath");
// testForBadChars("/Users/whoever/someDir");
//
// }
@Test
public void simplePermanentTransferTest() throws Exception {
final String FILE_A_PREFIX = "";
final String FILE_A_NAME = "fileA.txt";
final String FILE_B_PREFIX = "x/y/z";
final String FILE_B_NAME = "fileB.txt";
final Set<File> desiredResults = new HashSet<File>();
/*
* Create a directory into which we'll transfer some small files.
*/
final File origDir = File.createTempFile("pfm", "");
origDir.delete();
File targetDir = null;
try {
/*
* Choose the directory into which we want the PayloadFilesManager to
* deliver the files.
*/
targetDir = File.createTempFile("tgt", "");
targetDir.delete();
targetDir.mkdir();
origDir.mkdir();
final File fileA = new File(origDir, FILE_A_NAME);
writeFile(fileA, "This is File A", "and another line");
desiredResults.add(new File(targetDir.toURI().resolve(FILE_A_PREFIX + FILE_A_NAME)));
final File fileB = new File(origDir, FILE_B_NAME);
desiredResults.add(new File(targetDir.toURI().resolve(FILE_B_PREFIX + FILE_B_NAME)));
writeFile(fileB, "Here is File B", "which has an", "additional line");
new CommonPermTest() {
@Override
protected CommonPermTest init(File targetDir) {
super.init(targetDir);
return this;
}
@Override
protected void addParts(Outbound ob, PayloadFilesManager instance) throws Exception {
ob.attachFile("application/octet-stream", URI.create(FILE_A_PREFIX + fileA.getName()), "test-xfer", fileA);
ob.attachFile("text/plain", URI.create(FILE_B_PREFIX + fileB.getName()), "test-xfer", fileB);
}
@Override
protected void checkResults(Inbound ib, PayloadFilesManager instance) throws Exception {
/*
* Extract files to where we want them.
*/
instance.processParts(ib);
final Set<File> missing = new HashSet<File>();
for (File f : desiredResults) {
if (!f.exists()) {
missing.add(f);
}
}
assertEquals("Unexpected missing files after extraction", Collections.EMPTY_SET, missing);
}
@Override
protected void cleanup() {
for (File f : desiredResults) {
f.delete();
}
PayloadFilesManagerTest.cleanup(origDir);
}
}.init(targetDir).run("simplePermanentTransferTest");
} finally {
if (targetDir != null) {
FileUtils.whack(targetDir);
}
}
}
Aggregations