use of org.glassfish.jersey.media.multipart.ContentDisposition in project jersey by jersey.
the class StreamDataBodyPartTest method testBuildContentDispositionWithoutFilename.
@Test
public void testBuildContentDispositionWithoutFilename() {
String name = "foo";
String expectedType = "form-data";
String expectedFilename = "foo";
cut.setName(name);
ContentDisposition actual = cut.buildContentDisposition();
assertEquals(expectedType, actual.getType());
assertEquals(expectedFilename, actual.getFileName());
}
use of org.glassfish.jersey.media.multipart.ContentDisposition in project winery by eclipse.
the class RestUtils method getCsarOfSelectedResource.
/**
* @param options the set of options that are applicable for exporting a csar
*/
public static Response getCsarOfSelectedResource(final AbstractComponentInstanceResource resource, CsarExportOptions options) {
long start = System.currentTimeMillis();
final CsarExporter exporter = new CsarExporter(RepositoryFactory.getRepository());
Map<String, Object> exportConfiguration = new HashMap<>();
StreamingOutput so = output -> {
try {
// check which options are chosen
if (options.isAddToProvenance()) {
// We wait for the accountability layer to confirm the transaction
String result = exporter.writeCsarAndSaveManifestInProvenanceLayer(resource.getId(), output).get();
LOGGER.debug("Stored state in accountability layer in transaction " + result);
} else if (options.isIncludeDependencies() && resource.getId() instanceof ServiceTemplateId) {
SelfContainmentPackager packager = new SelfContainmentPackager(RepositoryFactory.getRepository());
DefinitionsChildId selfContainedVersion = packager.createSelfContainedVersion(resource.getId());
exporter.writeSelfContainedCsar(RepositoryFactory.getRepository(), selfContainedVersion, output, exportConfiguration);
} else {
exporter.writeCsar(resource.getId(), output, exportConfiguration);
}
long duration = (System.currentTimeMillis() - start) / 1000;
LOGGER.debug("CSAR export lasted {} min {} s", (int) duration / 60, duration % 60);
} catch (Exception e) {
LOGGER.error("Error while exporting CSAR", e);
throw new WebApplicationException(e);
}
};
String contentDisposition = String.format("attachment;filename=\"%s%s\"", resource.getXmlId().getEncoded(), Constants.SUFFIX_CSAR);
return Response.ok().header("Content-Disposition", contentDisposition).type(MimeTypes.MIMETYPE_ZIP).entity(so).build();
}
use of org.glassfish.jersey.media.multipart.ContentDisposition in project jersey by jersey.
the class ContentDispositionTest method testCreate.
@Test
public void testCreate() {
ContentDisposition contentDisposition = ContentDisposition.type(null).build();
assertNotNull(contentDisposition);
assertEquals(null, contentDisposition.getType());
contentDisposition = ContentDisposition.type(contentDispositionType).build();
assertNotNull(contentDisposition);
assertEquals(contentDispositionType, contentDisposition.getType());
final Date date = new Date();
contentDisposition = ContentDisposition.type(contentDispositionType).fileName("test.file").creationDate(date).modificationDate(date).readDate(date).size(1222).build();
assertContentDisposition(contentDisposition, date);
String header = contentDispositionType;
try {
contentDisposition = new ContentDisposition(contentDisposition.toString());
assertNotNull(contentDisposition);
contentDisposition = new ContentDisposition(header);
assertNotNull(contentDisposition);
assertEquals(contentDispositionType, contentDisposition.getType());
final String dateString = HttpDateFormat.getPreferredDateFormat().format(date);
header = contentDispositionType + ";filename=\"test.file\";creation-date=\"" + dateString + "\";modification-date=\"" + dateString + "\";read-date=\"" + dateString + "\";size=1222";
contentDisposition = new ContentDisposition(header);
assertContentDisposition(contentDisposition, date);
contentDisposition = new ContentDisposition(HttpHeaderReader.newInstance(header), true);
assertContentDisposition(contentDisposition, date);
} catch (final ParseException ex) {
fail(ex.getMessage());
}
try {
new ContentDisposition((HttpHeaderReader) null, true);
fail("NullPointerException was expected to be thrown.");
} catch (final ParseException exception) {
fail(exception.getMessage());
} catch (final NullPointerException exception) {
//expected
}
}
use of org.glassfish.jersey.media.multipart.ContentDisposition in project jersey by jersey.
the class ContentDispositionTest method testToString.
@Test
public void testToString() {
final Date date = new Date();
final ContentDisposition contentDisposition = ContentDisposition.type(contentDispositionType).fileName("test.file").creationDate(date).modificationDate(date).readDate(date).size(1222).build();
final String dateString = HttpDateFormat.getPreferredDateFormat().format(date);
final String header = contentDispositionType + "; filename=\"test.file\"; creation-date=\"" + dateString + "\"; modification-date=\"" + dateString + "\"; read-date=\"" + dateString + "\"; size=1222";
assertEquals(header, contentDisposition.toString());
}
use of org.glassfish.jersey.media.multipart.ContentDisposition in project jersey by jersey.
the class StreamDataBodyPartTest method testBuildContentDisposition.
///////////////////////////////////////////////////////////////////////////
// Content disposition building tests
///////////////////////////////////////////////////////////////////////////
@Test
public void testBuildContentDisposition() {
String name = "foo";
String expectedType = "form-data";
String expectedFilename = "bar.txt";
cut.setName(name);
cut.setFilename(expectedFilename);
ContentDisposition actual = cut.buildContentDisposition();
assertEquals(expectedType, actual.getType());
assertEquals(expectedFilename, actual.getFileName());
}
Aggregations