Search in sources :

Example 6 with ContentDisposition

use of org.glassfish.jersey.media.multipart.ContentDisposition in project jersey by eclipse-ee4j.

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());
}
Also used : ContentDisposition(org.glassfish.jersey.media.multipart.ContentDisposition) Test(org.junit.Test) BodyPartTest(org.glassfish.jersey.media.multipart.BodyPartTest)

Example 7 with ContentDisposition

use of org.glassfish.jersey.media.multipart.ContentDisposition in project jersey by eclipse-ee4j.

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());
}
Also used : ContentDisposition(org.glassfish.jersey.media.multipart.ContentDisposition) Date(java.util.Date) Test(org.junit.Test)

Example 8 with ContentDisposition

use of org.glassfish.jersey.media.multipart.ContentDisposition in project jersey by eclipse-ee4j.

the class ContentDispositionTest method assertFileNameExt.

private void assertFileNameExt(final String expectedFileName, final String actualFileName, final String actualFileNameExt) throws ParseException {
    final Date date = new Date();
    final String dateString = HttpDateFormat.getPreferredDateFormat().format(date);
    final String prefixHeader = contentDispositionType + ";filename=\"" + actualFileName + "\";" + "creation-date=\"" + dateString + "\";modification-date=\"" + dateString + "\";read-date=\"" + dateString + "\";size=1222" + ";name=\"testData\";" + "filename*=\"";
    final String header = prefixHeader + actualFileNameExt + "\"";
    final ContentDisposition contentDisposition = new ContentDisposition(HttpHeaderReader.newInstance(header), true);
    assertEquals(expectedFileName, contentDisposition.getFileName());
}
Also used : ContentDisposition(org.glassfish.jersey.media.multipart.ContentDisposition) Date(java.util.Date)

Example 9 with ContentDisposition

use of org.glassfish.jersey.media.multipart.ContentDisposition in project joa by sebastianfrey.

the class GeoPackageService method addService.

@Override
public void addService(FormDataBodyPart body) throws InterruptedException {
    for (BodyPart part : body.getParent().getBodyParts()) {
        InputStream fileInputStream = part.getEntityAs(InputStream.class);
        ContentDisposition fileMetaData = part.getContentDisposition();
        try {
            int read = 0;
            byte[] bytes = new byte[1024];
            String fullFileName = fileMetaData.getFileName();
            String fileName = MoreFiles.getNameWithoutExtension(Paths.get(fullFileName));
            File target = Paths.get(workspace.toString(), fullFileName).toFile();
            OutputStream out = new FileOutputStream(target);
            while ((read = fileInputStream.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }
            out.flush();
            out.close();
            String[] cmd = { "ogr2ogr", "-f", "GPKG", fileName + ".gpkg", fullFileName, "-update", "-append" };
            ProcessBuilder b = new ProcessBuilder(cmd);
            b.directory(workspace);
            Process p = b.start();
            p.waitFor();
        } catch (IOException e) {
            throw new WebApplicationException("Error while uploading file. Please try again !!", e);
        }
    }
}
Also used : BodyPart(org.glassfish.jersey.media.multipart.BodyPart) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) WebApplicationException(javax.ws.rs.WebApplicationException) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ContentDisposition(org.glassfish.jersey.media.multipart.ContentDisposition) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 10 with ContentDisposition

use of org.glassfish.jersey.media.multipart.ContentDisposition in project winery by eclipse.

the class RestUtils method getYamlCSARofSelectedResource.

public static Response getYamlCSARofSelectedResource(final AbstractComponentInstanceResource resource) {
    LocalDateTime start = LocalDateTime.now();
    final YamlExporter exporter = new YamlExporter(RepositoryFactory.getRepository());
    Map<String, Object> exportConfiguration = new HashMap<>();
    StreamingOutput so = output -> {
        try {
            exporter.writeCsar(resource.getId(), output, exportConfiguration);
            LOGGER.debug("CSAR export lasted {}", Duration.between(LocalDateTime.now(), start).toString());
        } 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();
}
Also used : LocalDateTime(java.time.LocalDateTime) MimeTypes(org.eclipse.winery.common.constants.MimeTypes) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) FileTime(java.nio.file.attribute.FileTime) HasType(org.eclipse.winery.model.tosca.HasType) CsarExportConfiguration(org.eclipse.winery.repository.export.CsarExportConfiguration) TRelationshipTypeImplementation(org.eclipse.winery.model.tosca.TRelationshipTypeImplementation) WineryVersion(org.eclipse.winery.common.version.WineryVersion) MediaType(javax.ws.rs.core.MediaType) IPersistable(org.eclipse.winery.repository.rest.resources._support.IPersistable) Duration(java.time.Duration) Map(java.util.Map) GenericId(org.eclipse.winery.model.ids.GenericId) QNameApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameApiData) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) WineryVersionUtils(org.eclipse.winery.repository.backend.WineryVersionUtils) EdmmManager(org.eclipse.winery.edmm.EdmmManager) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) Constants(org.eclipse.winery.common.Constants) Set(java.util.Set) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) CsarExportOptions(org.eclipse.winery.repository.export.CsarExportOptions) VersionUtils(org.eclipse.winery.common.version.VersionUtils) WebApplicationException(javax.ws.rs.WebApplicationException) LocalNameForAngular(org.eclipse.winery.repository.rest.datatypes.LocalNameForAngular) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) LocalDateTime(java.time.LocalDateTime) ArrayList(java.util.ArrayList) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) EdmmType(org.eclipse.winery.edmm.model.EdmmType) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) XmlId(org.eclipse.winery.model.ids.XmlId) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ResourceResult(org.eclipse.winery.repository.rest.resources._support.ResourceResult) StringWriter(java.io.StringWriter) IOException(java.io.IOException) Family(javax.ws.rs.core.Response.Status.Family) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) UiConfigurationObject(org.eclipse.winery.common.configuration.UiConfigurationObject) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) TNodeTypeImplementation(org.eclipse.winery.model.tosca.TNodeTypeImplementation) SortedSet(java.util.SortedSet) Date(java.util.Date) EdmmConverter(org.eclipse.winery.edmm.model.EdmmConverter) LoggerFactory(org.slf4j.LoggerFactory) Namespace(org.eclipse.winery.model.ids.Namespace) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) ContentDisposition(org.glassfish.jersey.media.multipart.ContentDisposition) NamespaceAndDefinedLocalNamesForAngular(org.eclipse.winery.repository.rest.datatypes.NamespaceAndDefinedLocalNamesForAngular) TServiceTemplate(org.eclipse.winery.model.tosca.TServiceTemplate) SelfContainmentPackager(org.eclipse.winery.repository.backend.selfcontainmentpackager.SelfContainmentPackager) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) Locale(java.util.Locale) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) Util(org.eclipse.winery.repository.common.Util) URI(java.net.URI) QNameConverter(org.eclipse.winery.repository.rest.resources.apiData.converter.QNameConverter) RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) Collection(java.util.Collection) StreamingOutput(javax.ws.rs.core.StreamingOutput) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) JAXBException(javax.xml.bind.JAXBException) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) Objects(java.util.Objects) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) List(java.util.List) NamespaceAndDefinedLocalNames(org.eclipse.winery.repository.backend.xsd.NamespaceAndDefinedLocalNames) HttpHeaders(javax.ws.rs.core.HttpHeaders) TExtensibleElements(org.eclipse.winery.model.tosca.TExtensibleElements) YamlExporter(org.eclipse.winery.repository.yaml.export.YamlExporter) Response(javax.ws.rs.core.Response) IRepository(org.eclipse.winery.repository.backend.IRepository) AccessControlException(java.security.AccessControlException) MediaTypes(org.eclipse.winery.repository.backend.constants.MediaTypes) Marshaller(javax.xml.bind.Marshaller) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) HashSet(java.util.HashSet) ClientBuilder(javax.ws.rs.client.ClientBuilder) TConstraint(org.eclipse.winery.model.tosca.TConstraint) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) Application(org.eclipse.winery.model.selfservice.Application) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) Status(javax.ws.rs.core.Response.Status) JAXBContext(javax.xml.bind.JAXBContext) CsarExporter(org.eclipse.winery.repository.export.CsarExporter) ToscaExportUtil(org.eclipse.winery.repository.export.ToscaExportUtil) Logger(org.slf4j.Logger) Environments(org.eclipse.winery.common.configuration.Environments) AbstractComponentInstanceResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResource) TTag(org.eclipse.winery.model.tosca.TTag) ToscaElementId(org.eclipse.winery.model.ids.elements.ToscaElementId) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) EntityGraph(io.github.edmm.core.parser.EntityGraph) NamespaceManager(org.eclipse.winery.repository.backend.NamespaceManager) TRelationshipType(org.eclipse.winery.model.tosca.TRelationshipType) ComponentId(org.eclipse.winery.repository.rest.datatypes.ComponentId) PolicyTemplateId(org.eclipse.winery.model.ids.definitions.PolicyTemplateId) AbstractComponentsResource(org.eclipse.winery.repository.rest.resources._support.AbstractComponentsResource) InputStream(java.io.InputStream) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) IHasName(org.eclipse.winery.repository.rest.resources._support.IHasName) YamlExporter(org.eclipse.winery.repository.yaml.export.YamlExporter) WebApplicationException(javax.ws.rs.WebApplicationException) HashMap(java.util.HashMap) UiConfigurationObject(org.eclipse.winery.common.configuration.UiConfigurationObject) StreamingOutput(javax.ws.rs.core.StreamingOutput) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) AccessControlException(java.security.AccessControlException)

Aggregations

ContentDisposition (org.glassfish.jersey.media.multipart.ContentDisposition)22 Date (java.util.Date)8 Test (org.junit.Test)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)6 IOException (java.io.IOException)5 WebApplicationException (javax.ws.rs.WebApplicationException)4 BodyPartTest (org.glassfish.jersey.media.multipart.BodyPartTest)4 InputStream (java.io.InputStream)3 URI (java.net.URI)3 FileTime (java.nio.file.attribute.FileTime)3 ParseException (java.text.ParseException)3 Response (javax.ws.rs.core.Response)3 StreamingOutput (javax.ws.rs.core.StreamingOutput)3 HttpHead (org.apache.http.client.methods.HttpHead)3 EntityGraph (io.github.edmm.core.parser.EntityGraph)2 StringWriter (java.io.StringWriter)2 HttpHeaders (java.net.http.HttpHeaders)2 AccessControlException (java.security.AccessControlException)2 Duration (java.time.Duration)2 LocalDateTime (java.time.LocalDateTime)2