Java Code Examples for org.apache.cxf.jaxrs.ext.multipart.Attachment#getObject()
The following examples show how to use
org.apache.cxf.jaxrs.ext.multipart.Attachment#getObject() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestDocumentService.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
@Override @POST @Path("/create") @Consumes(MediaType.MULTIPART_FORM_DATA) @ApiOperation(nickname = "createDocument", value = "Creates a new document", notes = "Creates a new document using the metadata document object provided as JSON/XML", response = WSDocument.class) @ApiImplicitParams({ @ApiImplicitParam(name = "document", value = "The document metadata provided as WSDocument object encoded in JSON/XML format", required = true, dataType = "string", paramType = "form", examples = @Example(value = { @ExampleProperty(value = "{ \"fileName\":\"Help.pdf\",\"folderId\": 4, \"language\":\"en\" }") })), @ApiImplicitParam(name = "content", value = "File data", required = true, dataType = "file", paramType = "form") }) @ApiResponses(value = { @ApiResponse(code = 401, message = "Authentication failed"), @ApiResponse(code = 500, message = "Generic error, see the response message") }) public Response create(@ApiParam(hidden = true) List<Attachment> atts) throws Exception { log.debug("create()"); String sid = validateSession(); WSDocument document = null; DataHandler content = null; for (Attachment att : atts) { if ("document".equals(att.getContentDisposition().getParameter("name"))) { document = att.getObject(WSDocument.class); } else if ("content".equals(att.getContentDisposition().getParameter("name"))) { content = att.getDataHandler(); } } log.debug("document: {}", document); log.debug("content: {}", content); try { // return super.create(sid, document, content); WSDocument cdoc = super.create(sid, document, content); return Response.ok().entity(cdoc).build(); } catch (Exception e) { log.error(e.getMessage(), e); return Response.status(500).entity(e.getMessage()).build(); } }
Example 2
Source File: RestDocumentService.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
@Override @POST @Path("/uploadResource") @Consumes(MediaType.MULTIPART_FORM_DATA) @ApiOperation( value = "Uploads a new resource of the document", notes = "Uploads a new resource attached to the given document. If the resource already exists it is overwritten") @ApiImplicitParams({ @ApiImplicitParam(name = "docId", value = "the document id", required = true, dataType = "integer", paramType = "form"), @ApiImplicitParam(name = "fileVersion", value = "the specific file version", required = false, dataType = "string", paramType = "form"), @ApiImplicitParam(name = "suffix", value = "suffix specification(it cannot be empty, use 'conversion.pdf' to put the PDF conversion)", required = true, dataType = "string", paramType = "form"), @ApiImplicitParam(name = "content", value = "raw content of the file", required = true, dataType = "file", paramType = "form"), }) public void uploadResource(List<Attachment> attachments) throws Exception { String sid = validateSession(); Long docId = null; String fileVersion = null; String suffix = null; DataHandler datah = null; for (Attachment att : attachments) { Map<String, String> params = att.getContentDisposition().getParameters(); // log.debug("keys: {}", params.keySet()); // log.debug("name: {}", params.get("name")); if ("docId".equals(params.get("name"))) { docId = Long.parseLong(att.getObject(String.class)); } else if ("fileVersion".equals(params.get("fileVersion"))) { fileVersion = att.getObject(String.class); } else if ("suffix".equals(params.get("suffix"))) { suffix = att.getObject(String.class); } else if ("content".equals(params.get("content"))) { datah = att.getDataHandler(); } } super.uploadResource(sid, docId, fileVersion, suffix, datah); }
Example 3
Source File: DocumentService.java From document-management-system with GNU General Public License v2.0 | 5 votes |
@POST @Path("/create") @Consumes(MediaType.MULTIPART_FORM_DATA) // The "doc" and "content" parameters comes in the POST request body (encoded as XML or JSON). public Document create(List<Attachment> atts) throws GenericException { try { log.debug("create({})", atts); Document doc = null; InputStream is = null; for (Attachment att : atts) { if ("doc".equals(att.getContentDisposition().getParameter("name"))) { doc = att.getObject(Document.class); } else if ("content".equals(att.getContentDisposition().getParameter("name"))) { is = att.getDataHandler().getInputStream(); } } DocumentModule dm = ModuleManager.getDocumentModule(); Document newDocument = dm.create(null, doc, is); IOUtils.closeQuietly(is); log.debug("create: {}", newDocument); return newDocument; } catch (Exception e) { throw new GenericException(e); } }
Example 4
Source File: DocumentService.java From document-management-system with GNU General Public License v2.0 | 5 votes |
@POST @Path("/createSimple") @Consumes(MediaType.MULTIPART_FORM_DATA) // The "docPath" and "content" parameters comes in the POST request body. public Document createSimple(List<Attachment> atts) throws GenericException { try { log.debug("createSimple({})", atts); String docPath = null; InputStream is = null; for (Attachment att : atts) { if ("docPath".equals(att.getContentDisposition().getParameter("name"))) { docPath = att.getObject(String.class); } else if ("content".equals(att.getContentDisposition().getParameter("name"))) { is = att.getDataHandler().getInputStream(); } } DocumentModule dm = ModuleManager.getDocumentModule(); Document doc = new Document(); doc.setPath(docPath); Document newDocument = dm.create(null, doc, is); IOUtils.closeQuietly(is); log.debug("createSimple: {}", newDocument); return newDocument; } catch (Exception e) { throw new GenericException(e); } }
Example 5
Source File: DocumentService.java From document-management-system with GNU General Public License v2.0 | 5 votes |
@POST @Path("/checkin") @Consumes(MediaType.MULTIPART_FORM_DATA) // The "docId" and "content" parameters comes in the POST request body (encoded as XML or JSON). public Version checkin(List<Attachment> atts) throws GenericException { try { log.debug("checkin({})", atts); String docId = null; String comment = null; InputStream is = null; for (Attachment att : atts) { if ("docId".equals(att.getContentDisposition().getParameter("name"))) { docId = att.getObject(String.class); } else if ("comment".equals(att.getContentDisposition().getParameter("name"))) { comment = att.getObject(String.class); } else if ("content".equals(att.getContentDisposition().getParameter("name"))) { is = att.getDataHandler().getInputStream(); } } DocumentModule dm = ModuleManager.getDocumentModule(); Version version = dm.checkin(null, docId, is, comment); IOUtils.closeQuietly(is); log.debug("checkin: {}", version); return version; } catch (Exception e) { throw new GenericException(e); } }
Example 6
Source File: MailService.java From document-management-system with GNU General Public License v2.0 | 5 votes |
@POST @Path("/importEml") @Consumes(MediaType.MULTIPART_FORM_DATA) // The "dstId" and "content" parameters comes in the POST request body. public Mail importEml(List<Attachment> atts) throws RepositoryException, AccessDeniedException, PathNotFoundException, DatabaseException, IOException, AutomationException, UserQuotaExceededException, FileSizeExceededException, ExtensionException, UnsupportedMimeTypeException, ItemExistsException, VirusDetectedException, MessagingException { log.debug("importEml({})", atts); InputStream is = null; String dstPath = null; try { for (Attachment att : atts) { if ("dstId".equals(att.getContentDisposition().getParameter("name"))) { String dstId = att.getObject(String.class); if (PathUtils.isPath(dstId)) { dstPath = dstId; } else { dstPath = ModuleManager.getRepositoryModule().getNodePath(null, dstId); } } else if ("content".equals(att.getContentDisposition().getParameter("name"))) { is = att.getDataHandler().getInputStream(); } } Mail newMail = OKMMail.getInstance().importEml(dstPath, is); log.debug("importEml: {}", newMail); return newMail; } finally { IOUtils.closeQuietly(is); } }
Example 7
Source File: MailService.java From document-management-system with GNU General Public License v2.0 | 5 votes |
@POST @Path("/importMsg") @Consumes(MediaType.MULTIPART_FORM_DATA) // The "dstId" and "content" parameters comes in the POST request body. public Mail importMsg(List<Attachment> atts) throws RepositoryException, AccessDeniedException, PathNotFoundException, DatabaseException, IOException, AutomationException, UserQuotaExceededException, FileSizeExceededException, ExtensionException, UnsupportedMimeTypeException, ItemExistsException, VirusDetectedException, MessagingException { log.debug("importMsg({})", atts); InputStream is = null; String dstPath = null; try { for (Attachment att : atts) { if ("dstId".equals(att.getContentDisposition().getParameter("name"))) { String dstId = att.getObject(String.class); if (PathUtils.isPath(dstId)) { dstPath = dstId; } else { dstPath = ModuleManager.getRepositoryModule().getNodePath(null, dstId); } } else if ("content".equals(att.getContentDisposition().getParameter("name"))) { is = att.getDataHandler().getInputStream(); } } Mail newMail = OKMMail.getInstance().importMsg(dstPath, is); log.debug("importMsg: {}", newMail); return newMail; } finally { IOUtils.closeQuietly(is); } }
Example 8
Source File: MultipartStore.java From cxf with Apache License 2.0 | 5 votes |
@Path("/books/file/semicolon") @Consumes("multipart/form-data") @Produces("text/plain") @POST public String addBookFileNameSemicolon(@Multipart("a") Attachment att) { return att.getObject(String.class) + ", filename:" + att.getContentDisposition().getParameter("filename"); }
Example 9
Source File: RestDocumentService.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
@Override @POST @Path("/checkin") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Check-in an existing document", notes = "Performs a check-in (commit) operation of new content over an existing document. The document must be in checked-out status") @ApiImplicitParams({ @ApiImplicitParam(name = "docId", value = "The ID of an existing document to update", required = true, dataType = "integer", paramType = "form"), @ApiImplicitParam(name = "comment", value = "An optional comment", required = false, dataType = "string", paramType = "form"), @ApiImplicitParam(name = "release", value = "Indicates whether to create or not a new major release of the updated document", required = false, dataType = "string", paramType = "form", allowableValues = "true, false"), @ApiImplicitParam(name = "filename", value = "File name", required = true, dataType = "string", paramType = "form"), @ApiImplicitParam(name = "filedata", value = "File data", required = true, dataType = "file", paramType = "form") }) @ApiResponses(value = { @ApiResponse(code = 401, message = "Authentication failed"), @ApiResponse(code = 500, message = "Generic error, see the response message") }) public Response checkin(@ApiParam(hidden = true) List<Attachment> attachments) throws Exception { String sid = validateSession(); try { long docId = 0L; String comment = null; boolean release = false; String filename = null; DataHandler datah = null; for (Attachment att : attachments) { Map<String, String> params = att.getContentDisposition().getParameters(); if ("docId".equals(params.get("name"))) { docId = Long.parseLong(att.getObject(String.class)); } else if ("comment".equals(params.get("name"))) { comment = att.getObject(String.class); } else if ("release".equals(params.get("name"))) { release = Boolean.parseBoolean(att.getObject(String.class)); } else if ("filename".equals(params.get("name"))) { filename = att.getObject(String.class); } else if ("filedata".equals(params.get("name"))) { datah = att.getDataHandler(); } } super.checkin(sid, docId, comment, filename, release, datah); return Response.ok("file checked-in").build(); } catch (Throwable t) { log.error(t.getMessage(), t); return Response.status(500).entity(t.getMessage()).build(); } }
Example 10
Source File: RestDocumentService.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
@Override @POST @Path("/upload") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Uploads a document", notes = "Creates or updates an existing document, if used in update mode docId must be provided, when used in create mode folderId is required. Returns the ID of the created/updated document. <br/>Example: curl -u admin:admin -H ''Accept: application/json'' -X POST -F folderId=4 -F filename=newDoc.txt -F [email protected] http://localhost:8080/services/rest/document/upload") @ApiImplicitParams({ @ApiImplicitParam(name = "docId", value = "The ID of an existing document to update", required = false, dataType = "integer", paramType = "form"), @ApiImplicitParam(name = "folderId", value = "Folder ID where to place the document", required = false, dataType = "string", paramType = "form"), @ApiImplicitParam(name = "release", value = "Indicates whether to create or not a new major release of an updated document", required = false, dataType = "string", paramType = "form", allowableValues = "true, false"), @ApiImplicitParam(name = "filename", value = "File name", required = true, dataType = "string", paramType = "form"), @ApiImplicitParam(name = "language", value = "Language of the document (ISO 639-2)", required = false, dataType = "string", paramType = "form", defaultValue = "en"), @ApiImplicitParam(name = "filedata", value = "File data", required = true, dataType = "file", paramType = "form") }) @ApiResponses(value = { @ApiResponse(code = 401, message = "Authentication failed"), @ApiResponse(code = 500, message = "Generic error, see the response message") }) public Response upload(@ApiParam(hidden = true) List<Attachment> attachments) throws Exception { String sid = validateSession(); try { Long docId = null; Long folderId = null; boolean release = false; String filename = null; String language = null; DataHandler datah = null; for (Attachment att : attachments) { Map<String, String> params = att.getContentDisposition().getParameters(); // log.debug("keys: {}", params.keySet()); // log.debug("name: {}", params.get("name")); if ("docId".equals(params.get("name"))) { docId = Long.parseLong(att.getObject(String.class)); } else if ("folderId".equals(params.get("name"))) { folderId = Long.parseLong(att.getObject(String.class)); } else if ("release".equals(params.get("name"))) { release = Boolean.parseBoolean(att.getObject(String.class)); } else if ("filename".equals(params.get("name"))) { filename = att.getObject(String.class); } else if ("language".equals(params.get("name"))) { language = att.getObject(String.class); } else if ("filedata".equals(params.get("name"))) { datah = att.getDataHandler(); } } long documentId = super.upload(sid, docId, folderId, release, filename, language, datah); return Response.ok("" + documentId).build(); } catch (Throwable t) { log.error(t.getMessage(), t); return Response.status(500).entity(t.getMessage()).build(); } }
Example 11
Source File: RestDocumentService.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
@Override @POST @Path("/replaceFile") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @ApiOperation(value = "Replace the file of a version", notes = "Replaces the file associated to a given version.") @ApiImplicitParams({ @ApiImplicitParam(name = "docId", value = "The ID of an existing document to update", required = true, dataType = "integer", paramType = "form"), @ApiImplicitParam(name = "fileVersion", value = "The file version", required = false, dataType = "string", paramType = "form"), @ApiImplicitParam(name = "comment", value = "Comment", required = false, dataType = "string", paramType = "form"), @ApiImplicitParam(name = "filedata", value = "File data", required = true, dataType = "file", paramType = "form") }) @ApiResponses(value = { @ApiResponse(code = 401, message = "Authentication failed"), @ApiResponse(code = 500, message = "Generic error, see the response message") }) public Response replaceFile(List<Attachment> attachments) throws Exception { String sid = validateSession(); try { Long docId = null; String fileVersion = null; String comment = null; DataHandler datah = null; for (Attachment att : attachments) { Map<String, String> params = att.getContentDisposition().getParameters(); if ("docId".equals(params.get("name"))) { docId = Long.parseLong(att.getObject(String.class)); } else if ("fileVersion".equals(params.get("name"))) { fileVersion = att.getObject(String.class); } else if ("comment".equals(params.get("name"))) { comment = att.getObject(String.class); } else if ("filedata".equals(params.get("name"))) { datah = att.getDataHandler(); } } super.replaceFile(sid, docId, fileVersion, comment, datah); return Response.ok("" + docId).build(); } catch (Throwable t) { log.error(t.getMessage(), t); return Response.status(500).entity(t.getMessage()).build(); } }
Example 12
Source File: ConversionService.java From document-management-system with GNU General Public License v2.0 | 4 votes |
@POST @Path("/imageConvert") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_OCTET_STREAM) // The "mimeType" parameter comes in the POST request body (encoded as XML or JSON). public Response imageConvert(List<Attachment> atts) throws GenericException { log.debug("imageConvert({})", atts); String filename = null; String srcMimeTypeIn = null; String dstMimeType = null; String params = null; InputStream is = null; FileOutputStream fos = null; File input = null; File output = null; try { for (Attachment att : atts) { ContentDisposition contDisp = att.getContentDisposition(); if ("dstMimeType".equals(contDisp.getParameter("name"))) { dstMimeType = att.getObject(String.class); } else if ("params".equals(contDisp.getParameter("name"))) { params = att.getObject(String.class); } else if ("content".equals(contDisp.getParameter("name"))) { filename = contDisp.getParameter("filename"); srcMimeTypeIn = MimeTypeConfig.mimeTypes.getContentType(filename.toLowerCase()); is = att.getDataHandler().getInputStream(); } } input = FileUtils.createTempFileFromMime(srcMimeTypeIn); fos = new FileOutputStream(input); IOUtils.copy(is, fos); output = FileUtils.createTempFileFromMime(dstMimeType); ImageUtils.ImageMagickConvert(input, output, params); final FileInputStream fis = new FileInputStream(output); StreamingOutput stream = new StreamingOutput() { @Override public void write(OutputStream os) throws IOException, WebApplicationException { IOUtils.copy(fis, os); IOUtils.closeQuietly(fis); IOUtils.closeQuietly(os); } }; Response.ResponseBuilder response = Response.ok(stream); MimeType mt = MimeTypeDAO.findByName(dstMimeType); String convertedFile = FileUtils.getFileName(filename) + "." + mt.getExtensions().iterator().next(); response.header("Content-Disposition", "attachment; filename=\"" + convertedFile + "\""); log.debug("imageConvert: [BINARY]"); return response.build(); } catch (Exception e) { throw new GenericException(e); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(fos); FileUtils.deleteQuietly(input); FileUtils.deleteQuietly(output); } }