use of org.glassfish.api.admin.Payload.Part in project Payara by payara.
the class MultipartProprietaryWriter method writeTo.
public void writeTo(final Payload.Outbound payload, final ParameterMap parameters, final ActionReport ar, final OutputStream os, final ContentTypeWriter contentTypeWriter) throws IOException {
final String boundary = getBoundary();
// Content-Type
String ctType = "form-data";
if (parameters == null || parameters.size() == 0) {
ctType = "mixed";
}
contentTypeWriter.writeContentType("multipart", ctType, boundary);
// Write content
final Writer writer = new BufferedWriter(new OutputStreamWriter(os));
// Parameters
if (parameters != null) {
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
for (String value : entry.getValue()) {
writeParam(writer, os, boundary, entry.getKey(), value);
}
}
}
// ActionReport
if (ar != null) {
writeActionReport(writer, os, boundary, ar);
}
// Payload
if (payload != null) {
Iterator<Part> parts = payload.parts();
while (parts.hasNext()) {
writePayloadPart(writer, os, boundary, parts.next());
}
}
// Write the final boundary string
multiWrite(writer, BOUNDERY_DELIMIT, boundary, BOUNDERY_DELIMIT, EOL);
writer.flush();
}
use of org.glassfish.api.admin.Payload.Part in project Payara by payara.
the class PayloadFilesManager method processPartsExtended.
/**
* Returns all Files extracted from the Payload, treating each Part as a
* separate file, via a Map from each File to its associated Properties.
*
* @param inboundPayload Payload containing file data to be extracted
* @return map from each extracted File to its corresponding Properties
* @throws java.io.IOException
*/
public Map<File, Properties> processPartsExtended(final Payload.Inbound inboundPayload) throws Exception {
if (inboundPayload == null) {
return Collections.EMPTY_MAP;
}
final Map<File, Properties> result = new LinkedHashMap<File, Properties>();
boolean isReportProcessed = false;
Part possibleUnrecognizedReportPart = null;
StringBuilder uploadedEntryNames = new StringBuilder();
for (Iterator<Payload.Part> partIt = inboundPayload.parts(); partIt.hasNext(); ) {
Payload.Part part = partIt.next();
DataRequestType drt = DataRequestType.getType(part);
if (drt != null) {
result.put(drt.processPart(this, part, part.getName()), part.getProperties());
isReportProcessed |= (drt == DataRequestType.REPORT);
uploadedEntryNames.append(part.getName()).append(" ");
} else {
if ((!isReportProcessed) && possibleUnrecognizedReportPart == null) {
possibleUnrecognizedReportPart = part;
}
}
}
if ((!isReportProcessed) && possibleUnrecognizedReportPart != null) {
DataRequestType.REPORT.processPart(this, possibleUnrecognizedReportPart, possibleUnrecognizedReportPart.getName());
isReportProcessed = true;
}
postProcessParts();
return result;
}
use of org.glassfish.api.admin.Payload.Part in project Payara by payara.
the class PayloadFilesManagerTest method testBraces.
@Test
public void testBraces() throws Exception {
// //System.out.println("testBraces");
final File tmpDir = File.createTempFile("gfpayl{braces}", "tmp");
tmpDir.delete();
tmpDir.mkdir();
try {
final PayloadFilesManager instance = new PayloadFilesManager.Perm(tmpDir, null, Logger.getAnonymousLogger());
final String originalPath = "some/path";
final Part testPart = PayloadImpl.Part.newInstance("text/plain", originalPath, null, "random content");
final URI result = instance.getOutputFileURI(testPart, testPart.getName());
// //System.out.println(" " + originalPath + " -> " + result);
assertFalse(result.toASCIIString().contains("{"));
} finally {
PayloadFilesManagerTest.cleanup(tmpDir);
}
}
use of org.glassfish.api.admin.Payload.Part in project Payara by payara.
the class PayloadFilesManagerTest method testGetOutputFileURI.
/**
* Test of getOutputFileURI method, of class PayloadFilesManager.
*/
@Test
public void testGetOutputFileURI() throws Exception {
// //System.out.println("getOutputFileURI");
PayloadFilesManager.Temp instance = new PayloadFilesManager.Temp(Logger.getAnonymousLogger());
try {
String originalPath = "way/over/there/myApp.ear";
Part testPart = PayloadImpl.Part.newInstance("text/plain", originalPath, null, "random content");
URI result = instance.getOutputFileURI(testPart, testPart.getName());
// //System.out.println(" " + originalPath + " -> " + result);
assertTrue(result.toASCIIString().endsWith("/myApp.ear"));
} finally {
instance.cleanup();
}
}
use of org.glassfish.api.admin.Payload.Part in project Payara by payara.
the class CheckpointHelper method loadOutbound.
private void loadOutbound(Outbound outbound, File outboundFile) throws IOException {
if (outbound == null || !outboundFile.exists()) {
return;
}
Inbound outboundSource = loadInbound(outboundFile);
Iterator<Part> parts = outboundSource.parts();
File topDir = createTempDir("checkpoint", "");
topDir.deleteOnExit();
while (parts.hasNext()) {
Part part = parts.next();
File sourceFile = File.createTempFile("source", "", topDir);
FileUtils.copy(part.getInputStream(), new FileOutputStream(sourceFile), Long.MAX_VALUE);
outbound.addPart(part.getContentType(), part.getName(), part.getProperties(), new FileInputStream(sourceFile));
}
outbound.resetDirty();
}
Aggregations