javax.activation.FileDataSource Java Examples
The following examples show how to use
javax.activation.FileDataSource.
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: Jaxb2UnmarshallerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void marshalAttachments() throws Exception { unmarshaller = new Jaxb2Marshaller(); unmarshaller.setClassesToBeBound(BinaryObject.class); unmarshaller.setMtomEnabled(true); unmarshaller.afterPropertiesSet(); MimeContainer mimeContainer = mock(MimeContainer.class); Resource logo = new ClassPathResource("spring-ws.png", getClass()); DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile())); given(mimeContainer.isXopPackage()).willReturn(true); given(mimeContainer.getAttachment("<6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws>")).willReturn(dataHandler); given(mimeContainer.getAttachment("<99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws>")).willReturn(dataHandler); given(mimeContainer.getAttachment("[email protected]")).willReturn(dataHandler); String content = "<binaryObject xmlns='http://springframework.org/spring-ws'>" + "<bytes>" + "<xop:Include href='cid:6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" + "</bytes>" + "<dataHandler>" + "<xop:Include href='cid:99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" + "</dataHandler>" + "<swaDataHandler>[email protected]</swaDataHandler>" + "</binaryObject>"; StringReader reader = new StringReader(content); Object result = unmarshaller.unmarshal(new StreamSource(reader), mimeContainer); assertTrue("Result is not a BinaryObject", result instanceof BinaryObject); BinaryObject object = (BinaryObject) result; assertNotNull("bytes property not set", object.getBytes()); assertTrue("bytes property not set", object.getBytes().length > 0); assertNotNull("datahandler property not set", object.getSwaDataHandler()); }
Example #2
Source File: AccessStructure.java From jplag with GNU General Public License v3.0 | 6 votes |
/** * @return A MimeMultipart object containing the zipped result files */ public MimeMultipart getResult() { File file = new File(JPLAG_RESULTS_DIRECTORY + File.separator + submissionID + getUsername() + ".zip"); MimeMultipart mmp = new MimeMultipart(); FileDataSource fds1 = new FileDataSource(file); MimetypesFileTypeMap mftp = new MimetypesFileTypeMap(); mftp.addMimeTypes("multipart/zip zip ZIP"); fds1.setFileTypeMap(mftp); MimeBodyPart mbp = new MimeBodyPart(); try { mbp.setDataHandler(new DataHandler(fds1)); mbp.setFileName(file.getName()); mmp.addBodyPart(mbp); } catch (MessagingException me) { me.printStackTrace(); } return mmp; }
Example #3
Source File: OnyxReporterWebserviceManager.java From olat with Apache License 2.0 | 6 votes |
/** * For every result xml file found in the survey folder a dummy student is created. * * @param nodeId * @return */ private List<Student> getAnonymizedStudentsWithResultsForSurvey(final String nodeId) { final List<Student> serviceStudents = new ArrayList<Student>(); final File directory = new File(this.surveyFolderPath); if (directory.exists()) { final String[] allXmls = directory.list(new myFilenameFilter(nodeId)); if (allXmls != null && allXmls.length > 0) { int id = 0; for (final String xmlFileName : allXmls) { final File xmlFile = new File(this.surveyFolderPath + xmlFileName); final Student serviceStudent = new Student(); serviceStudent.setResultFile(new DataHandler(new FileDataSource(xmlFile))); serviceStudent.setStudentId("st" + id); serviceStudents.add(serviceStudent); id++; } } } return serviceStudents; }
Example #4
Source File: OnyxReporterWebserviceManager.java From olat with Apache License 2.0 | 6 votes |
/** * Delivers a map with all possible outcome-variables of this onyx test. * * @param node The course node with the Onyx test. * @return A map with all outcome-variables with name as key and type as value. */ public Map<String, String> getOutcomes(final AssessableCourseNode node) throws RemoteException { final Map<String, String> outcomes = new HashMap<String, String>(); final OnyxReporterStub stub = client.getOnyxReporterStub(); final File onyxTestZip = getCP(node.getReferencedRepositoryEntry()); // Get outcomes final ContentPackage cp = new ContentPackage(); cp.setContentPackage(new DataHandler(new FileDataSource(onyxTestZip))); final ResultVariableCandidatesInput resultVariableCandidatesInput = new ResultVariableCandidatesInput(); resultVariableCandidatesInput.setResultVariableCandidatesInput(cp); final ResultVariableCandidatesResponse response = stub.resultVariableCandidates(resultVariableCandidatesInput); final PostGetParams[] params = response.getResultVariableCandidatesResponse().getReturnValues(); for (final PostGetParams param : params) { outcomes.put(param.getParamName(), param.getParamValue()); } return outcomes; }
Example #5
Source File: Jaxb2MarshallerTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void marshalAttachments() throws Exception { marshaller = new Jaxb2Marshaller(); marshaller.setClassesToBeBound(BinaryObject.class); marshaller.setMtomEnabled(true); marshaller.afterPropertiesSet(); MimeContainer mimeContainer = mock(MimeContainer.class); Resource logo = new ClassPathResource("spring-ws.png", getClass()); DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile())); given(mimeContainer.convertToXopPackage()).willReturn(true); byte[] bytes = FileCopyUtils.copyToByteArray(logo.getInputStream()); BinaryObject object = new BinaryObject(bytes, dataHandler); StringWriter writer = new StringWriter(); marshaller.marshal(object, new StreamResult(writer), mimeContainer); assertTrue("No XML written", writer.toString().length() > 0); verify(mimeContainer, times(3)).addAttachment(isA(String.class), isA(DataHandler.class)); }
Example #6
Source File: MTOMSecurityTest.java From cxf with Apache License 2.0 | 6 votes |
@org.junit.Test public void testSymmetricBinaryBytesInAttachment() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = MTOMSecurityTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = MTOMSecurityTest.class.getResource("DoubleItMtom.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItSymmetricBinaryPort"); DoubleItMtomPortType port = service.getPort(portQName, DoubleItMtomPortType.class); updateAddressPort(port, PORT); DataSource source = new FileDataSource(new File("src/test/resources/java.jpg")); DoubleIt4 doubleIt = new DoubleIt4(); doubleIt.setNumberToDouble(25); assertEquals(50, port.doubleIt4(25, new DataHandler(source))); ((java.io.Closeable)port).close(); bus.shutdown(true); }
Example #7
Source File: SoapDocumentServiceTest.java From document-management-software with GNU Lesser General Public License v3.0 | 6 votes |
@Test public void testCheckin() throws Exception { docService.checkout("", 1); Document doc = docDao.findById(1); Assert.assertNotNull(doc); docDao.initialize(doc); Assert.assertEquals(Document.DOC_CHECKED_OUT, doc.getStatus()); File file = new File("pom.xml"); docService.checkin("", 1, "comment", "pom.xml", true, new DataHandler(new FileDataSource(file))); doc = docDao.findById(1); Assert.assertNotNull(doc); docDao.initialize(doc); // Assert.assertEquals(AbstractDocument.INDEX_TO_INDEX, // doc.getIndexed()); Assert.assertEquals(0, doc.getSigned()); Assert.assertEquals(Document.DOC_UNLOCKED, doc.getStatus()); }
Example #8
Source File: MailSenderUtil.java From DrivingAgency with MIT License | 6 votes |
public void sendAttachmentMail(String to, String subject, String content, File file){ MimeMessage mimeMessage = mailSender.createMimeMessage(); try { MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true); helper.setFrom(from); helper.setTo(to); helper.setSubject(subject); helper.setText(content, true); FileDataSource fileDataSource=new FileDataSource(file); helper.addAttachment("Student.xls",fileDataSource); //helper.addAttachment("test"+fileName, file); mailSender.send(mimeMessage); log.info("带附件的邮件已经发送。"); } catch (MessagingException e) { log.error("发送带附件的邮件时发⽣异常!", e); } }
Example #9
Source File: OnyxReporterWebserviceManager.java From olat with Apache License 2.0 | 6 votes |
/** * For every result xml file found in the survey folder a dummy student is created. * * @param nodeId * @return */ private List<Student> getAnonymizedStudentsWithResultsForSurvey(final String nodeId) { final List<Student> serviceStudents = new ArrayList<Student>(); final File directory = new File(this.surveyFolderPath); if (directory.exists()) { final String[] allXmls = directory.list(new myFilenameFilter(nodeId)); if (allXmls != null && allXmls.length > 0) { int id = 0; for (final String xmlFileName : allXmls) { final File xmlFile = new File(this.surveyFolderPath + xmlFileName); final Student serviceStudent = new Student(); serviceStudent.setResultFile(new DataHandler(new FileDataSource(xmlFile))); serviceStudent.setStudentId("st" + id); serviceStudents.add(serviceStudent); id++; } } } return serviceStudents; }
Example #10
Source File: BuildMail.java From fastdfs-zyc with GNU General Public License v2.0 | 6 votes |
/** * @param name * String * @param pass * String */ public boolean addFileAffix(String filename) { System.out.println("增加邮件附件:" + filename); try { BodyPart bp = new MimeBodyPart(); FileDataSource fileds = new FileDataSource(filename); bp.setDataHandler(new DataHandler(fileds)); bp.setFileName(fileds.getName()); mp.addBodyPart(bp); return true; } catch (Exception e) { System.err.println("增加邮件附件:" + filename + "发生错误!" + e); return false; } }
Example #11
Source File: MimePackage.java From ats-framework with Apache License 2.0 | 6 votes |
/** * Add the specified file as an attachment * * @param fileName * name of the file * @throws PackageException * on error */ @PublicAtsApi public void addAttachment( String fileName ) throws PackageException { try { // add attachment to multipart content MimeBodyPart attPart = new MimeBodyPart(); FileDataSource ds = new FileDataSource(fileName); attPart.setDataHandler(new DataHandler(ds)); attPart.setDisposition(MimeBodyPart.ATTACHMENT); attPart.setFileName(ds.getName()); addPart(attPart, PART_POSITION_LAST); } catch (MessagingException me) { throw new PackageException(me); } }
Example #12
Source File: EmailTest.java From javautils with Apache License 2.0 | 6 votes |
@Test public void test(){ Properties props = new Properties(); props.put("mail.transport.protocol", "smtp"); props.put("mail.smtp.auth", "true"); props.put("mail.host", "smtp.163.com"); String sender = "*********@163.com"; String receiver = "*********@qq.com"; String title = "你好、Hello Mail"; String content = "Hello World!!!"; String username = "*********@163.com"; String password = "*********"; List<DataSource> attachments = new ArrayList<>(); DataSource dataSource1 = new FileDataSource("src/main/resources/image/你好.txt"); DataSource dataSource2 = new FileDataSource("src/main/resources/image/code.png"); attachments.add(dataSource1); attachments.add(dataSource2); // Email email = new Email(props, sender, username, password, receiver, title, content, attachments); // EmailUtil.sendEmail(email); }
Example #13
Source File: Jaxb2MarshallerTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void marshalAttachments() throws Exception { marshaller = new Jaxb2Marshaller(); marshaller.setClassesToBeBound(BinaryObject.class); marshaller.setMtomEnabled(true); marshaller.afterPropertiesSet(); MimeContainer mimeContainer = mock(MimeContainer.class); Resource logo = new ClassPathResource("spring-ws.png", getClass()); DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile())); given(mimeContainer.convertToXopPackage()).willReturn(true); byte[] bytes = FileCopyUtils.copyToByteArray(logo.getInputStream()); BinaryObject object = new BinaryObject(bytes, dataHandler); StringWriter writer = new StringWriter(); marshaller.marshal(object, new StreamResult(writer), mimeContainer); assertTrue("No XML written", writer.toString().length() > 0); verify(mimeContainer, times(3)).addAttachment(isA(String.class), isA(DataHandler.class)); }
Example #14
Source File: MultiPartEmailTest.java From commons-email with Apache License 2.0 | 6 votes |
@Test public void testAttachFileLocking() throws Exception { // ==================================================================== // EMAIL-120: attaching a FileDataSource may result in a locked file // resource on windows systems // ==================================================================== final File tmpFile = File.createTempFile("attachment", ".eml"); this.email.attach( new FileDataSource(tmpFile), "Test Attachment", "Test Attachment Desc"); assertTrue(tmpFile.delete()); }
Example #15
Source File: DataMapperIntegrationTest.java From product-ei with Apache License 2.0 | 6 votes |
protected void uploadResourcesToGovernanceRegistry(String registryRoot, String artifactRoot, String dmConfig, String inSchema, String outSchema) throws Exception { resourceAdminServiceClient.addCollection("/_system/governance/", registryRoot, "", ""); resourceAdminServiceClient.addResource("/_system/governance/" + registryRoot + dmConfig, "text/plain", "", new DataHandler(new FileDataSource( new File(getClass().getResource(artifactRoot + dmConfig).getPath())))); resourceAdminServiceClient.addResource("/_system/governance/" + registryRoot + inSchema, "", "", new DataHandler(new FileDataSource( new File(getClass().getResource(artifactRoot + inSchema).getPath())))); resourceAdminServiceClient.addResource("/_system/governance/" + registryRoot + outSchema, "", "", new DataHandler(new FileDataSource( new File(getClass().getResource(artifactRoot + outSchema).getPath())))); }
Example #16
Source File: PayloadFactoryWithDynamicKeyTestCase.java From product-ei with Apache License 2.0 | 6 votes |
private void uploadResourcesToConfigRegistry() throws Exception { ResourceAdminServiceClient resourceAdminServiceStub = new ResourceAdminServiceClient(contextUrls.getBackEndUrl(), context.getContextTenant().getContextUser().getUserName(), context.getContextTenant().getContextUser().getPassword()); resourceAdminServiceStub.addCollection("/_system/config/", "payloadFactory", "", "Contains test files for payload factory mediator"); resourceAdminServiceStub.addResource( "/_system/config/payloadFactory/payload-in.xml", "application/xml", "payload format", new DataHandler(new FileDataSource( new File(getESBResourceLocation() + File.separator + "mediatorconfig" + File.separator + "payload" + File.separator + "factory" + File.separator + "payload-in.xml")))); }
Example #17
Source File: ESBJAVA4565TestCase.java From product-ei with Apache License 2.0 | 6 votes |
@BeforeClass(alwaysRun = true) protected void init() throws Exception { super.init(); verifySequenceExistence("ESBJAVA4565TestSequence"); resourceAdminServiceStub = new ResourceAdminServiceClient(contextUrls.getBackEndUrl(), getSessionCookie()); String ftpXmlPath = Paths.get(getESBResourceLocation(), "registry", "ftp.xml").toString(); resourceAdminServiceStub.addResource(REGISTRY_ARTIFACT, "application/xml", "FTP Test account details", new DataHandler(new FileDataSource(new File(ftpXmlPath)))); OMElement task = AXIOMUtil.stringToOM("<task:task xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"\n" + " name=\"TestTask\"\n" + " class=\"org.apache.synapse.startup.tasks.MessageInjector\" group=\"synapse.simple.quartz\">\n" + " <task:trigger interval=\"10\"/>\n" + " <task:property name=\"format\" value=\"get\"/>\n" + " <task:property name=\"sequenceName\" value=\"ESBJAVA4565TestSequence\"/>\n" + " <task:property name=\"injectTo\" value=\"sequence\"/>\n" + " <task:property name=\"message\"><empty/></task:property>\n" + "</task:task>"); this.addScheduledTask(task); }
Example #18
Source File: SOAPClient.java From product-ei with Apache License 2.0 | 6 votes |
/** * Sends a SOAP message with MTOM attachment and returns response as a OMElement. * * @param fileName name of file to be sent as an attachment * @param targetEPR service url * @param soapAction SOAP Action to set. Specify with "urn:" * @return OMElement response from BE service * @throws AxisFault in case of an invocation failure */ public OMElement sendSOAPMessageWithAttachment(String fileName, String targetEPR, String soapAction) throws AxisFault { OMFactory factory = OMAbstractFactory.getOMFactory(); OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0"); OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns); OMElement request = factory.createOMElement("request", ns); OMElement image = factory.createOMElement("image", ns); FileDataSource fileDataSource = new FileDataSource(new File(fileName)); DataHandler dataHandler = new DataHandler(fileDataSource); OMText textData = factory.createOMText(dataHandler, true); image.addChild(textData); request.addChild(image); payload.addChild(request); ServiceClient serviceClient = new ServiceClient(); Options options = new Options(); options.setTo(new EndpointReference(targetEPR)); options.setAction(soapAction); options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE); options.setCallTransportCleanup(true); serviceClient.setOptions(options); return serviceClient.sendReceive(payload); }
Example #19
Source File: Jaxb2MarshallerTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void marshalAttachments() throws Exception { marshaller = new Jaxb2Marshaller(); marshaller.setClassesToBeBound(BinaryObject.class); marshaller.setMtomEnabled(true); marshaller.afterPropertiesSet(); MimeContainer mimeContainer = mock(MimeContainer.class); Resource logo = new ClassPathResource("spring-ws.png", getClass()); DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile())); given(mimeContainer.convertToXopPackage()).willReturn(true); byte[] bytes = FileCopyUtils.copyToByteArray(logo.getInputStream()); BinaryObject object = new BinaryObject(bytes, dataHandler); StringWriter writer = new StringWriter(); marshaller.marshal(object, new StreamResult(writer), mimeContainer); assertTrue("No XML written", writer.toString().length() > 0); verify(mimeContainer, times(3)).addAttachment(isA(String.class), isA(DataHandler.class)); }
Example #20
Source File: BPELDeployer.java From carbon-identity with Apache License 2.0 | 6 votes |
private void deployArtifacts() throws RemoteException { String bpelArchiveName = processName + BPELDeployer.Constants.ZIP_EXT; String archiveHome = System.getProperty(BPELDeployer.Constants.TEMP_DIR_PROPERTY) + File.separator; DataSource bpelDataSource = new FileDataSource(archiveHome + bpelArchiveName); WorkflowDeployerClient workflowDeployerClient; if (bpsProfile.getProfileName().equals(WFImplConstant.DEFAULT_BPS_PROFILE_NAME)) { workflowDeployerClient = new WorkflowDeployerClient(bpsProfile.getManagerHostURL(), bpsProfile.getUsername()); } else { workflowDeployerClient = new WorkflowDeployerClient(bpsProfile.getManagerHostURL(), bpsProfile.getUsername(), bpsProfile.getPassword()); } workflowDeployerClient.uploadBPEL(getBPELUploadedFileItem(new DataHandler(bpelDataSource), bpelArchiveName, BPELDeployer.Constants.ZIP_TYPE)); String htArchiveName = htName + BPELDeployer.Constants.ZIP_EXT; DataSource htDataSource = new FileDataSource(archiveHome + htArchiveName); workflowDeployerClient.uploadHumanTask(getHTUploadedFileItem(new DataHandler(htDataSource), htArchiveName, BPELDeployer.Constants.ZIP_TYPE)); }
Example #21
Source File: MTOMSecurityTest.java From cxf with Apache License 2.0 | 6 votes |
@org.junit.Test public void testSignedMTOMAction() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = MTOMSecurityTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = MTOMSecurityTest.class.getResource("DoubleItMtom.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItSignedMTOMActionPort"); DoubleItMtomPortType port = service.getPort(portQName, DoubleItMtomPortType.class); updateAddressPort(port, PORT); DataSource source = new FileDataSource(new File("src/test/resources/java.jpg")); DoubleIt4 doubleIt = new DoubleIt4(); doubleIt.setNumberToDouble(25); assertEquals(50, port.doubleIt4(25, new DataHandler(source))); ((java.io.Closeable)port).close(); bus.shutdown(true); }
Example #22
Source File: TestUtil.java From DKIM-for-JavaMail with Apache License 2.0 | 6 votes |
public static void addFileAttachment(Multipart mp, Object filename) throws MessagingException { if (filename==null) return; File f = new File((String) filename); if (!f.exists() || !f.canRead()) { msgAndExit("Cannot read attachment file "+filename+", sending stops"); } MimeBodyPart mbp_file = new MimeBodyPart(); FileDataSource fds = new FileDataSource(f); mbp_file.setDataHandler(new DataHandler(fds)); mbp_file.setFileName(f.getName()); mp.addBodyPart(mbp_file); }
Example #23
Source File: ESBJAVA4909MultipartRelatedTestCase.java From micro-integrator with Apache License 2.0 | 6 votes |
public void sendUsingMTOM(String fileName, String targetEPR) throws IOException { final String EXPECTED = "<m0:uploadFileUsingMTOMResponse xmlns:m0=\"http://services.samples\"><m0:response>" + "<m0:image>PHByb3h5PkFCQzwvcHJveHk+</m0:image></m0:response></m0:uploadFileUsingMTOMResponse>"; OMFactory factory = OMAbstractFactory.getOMFactory(); OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0"); OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns); OMElement request = factory.createOMElement("request", ns); OMElement image = factory.createOMElement("image", ns); FileDataSource fileDataSource = new FileDataSource(new File(fileName)); DataHandler dataHandler = new DataHandler(fileDataSource); OMText textData = factory.createOMText(dataHandler, true); image.addChild(textData); request.addChild(image); payload.addChild(request); ServiceClient serviceClient = new ServiceClient(); Options options = new Options(); options.setTo(new EndpointReference(targetEPR)); options.setAction("urn:uploadFileUsingMTOM"); options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE); options.setCallTransportCleanup(true); serviceClient.setOptions(options); OMElement response = serviceClient.sendReceive(payload); Assert.assertTrue(response.toString().contains(EXPECTED), "Attachment is missing in the response"); }
Example #24
Source File: ESBIntegrationTest.java From product-ei with Apache License 2.0 | 5 votes |
protected void uploadConnector(String repoLocation, String strFileName) throws MalformedURLException, RemoteException { List<LibraryFileItem> uploadLibraryInfoList = new ArrayList<LibraryFileItem>(); LibraryFileItem uploadedFileItem = new LibraryFileItem(); uploadedFileItem.setDataHandler(new DataHandler(new FileDataSource(new File(repoLocation + File.separator + strFileName)))); uploadedFileItem.setFileName(strFileName); uploadedFileItem.setFileType("zip"); uploadLibraryInfoList.add(uploadedFileItem); LibraryFileItem[] uploadServiceTypes = new LibraryFileItem[uploadLibraryInfoList.size()]; uploadServiceTypes = uploadLibraryInfoList.toArray(uploadServiceTypes); esbUtils.uploadConnector(contextUrls.getBackEndUrl(),sessionCookie,uploadServiceTypes); }
Example #25
Source File: RestWorkbench.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
private static void createDocument02() throws Exception { File xxxx = new File("C:\\tmp\\InvoiceProcessing02-dashboard.png"); WSDocument document = new WSDocument(); document.setFolderId(04L); document.setFileName(xxxx.getName()); DataSource fds = new FileDataSource(xxxx); DataHandler handler = new DataHandler(fds); WSDocument created = docClient.create(document, handler); System.out.println(created.getId()); }
Example #26
Source File: Jaxb2UnmarshallerTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void marshalAttachments() throws Exception { unmarshaller = new Jaxb2Marshaller(); unmarshaller.setClassesToBeBound(BinaryObject.class); unmarshaller.setMtomEnabled(true); unmarshaller.afterPropertiesSet(); MimeContainer mimeContainer = mock(MimeContainer.class); Resource logo = new ClassPathResource("spring-ws.png", getClass()); DataHandler dataHandler = new DataHandler(new FileDataSource(logo.getFile())); given(mimeContainer.isXopPackage()).willReturn(true); given(mimeContainer.getAttachment("<6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws>")).willReturn(dataHandler); given(mimeContainer.getAttachment("<99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws>")).willReturn(dataHandler); given(mimeContainer.getAttachment("[email protected]")).willReturn(dataHandler); String content = "<binaryObject xmlns='http://springframework.org/spring-ws'>" + "<bytes>" + "<xop:Include href='cid:6b76528d-7a9c-4def-8e13-095ab89e9bb7@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" + "</bytes>" + "<dataHandler>" + "<xop:Include href='cid:99bd1592-0521-41a2-9688-a8bfb40192fb@http://springframework.org/spring-ws' xmlns:xop='http://www.w3.org/2004/08/xop/include'/>" + "</dataHandler>" + "<swaDataHandler>[email protected]</swaDataHandler>" + "</binaryObject>"; StringReader reader = new StringReader(content); Object result = unmarshaller.unmarshal(new StreamSource(reader), mimeContainer); assertTrue("Result is not a BinaryObject", result instanceof BinaryObject); BinaryObject object = (BinaryObject) result; assertNotNull("bytes property not set", object.getBytes()); assertTrue("bytes property not set", object.getBytes().length > 0); assertNotNull("datahandler property not set", object.getSwaDataHandler()); }
Example #27
Source File: BPMNUploaderClient.java From product-ei with Apache License 2.0 | 5 votes |
private void deployPackage(String packageName, String resourceDir, BPMNUploaderServiceStub bpmnUploaderServiceStub) throws RemoteException, InterruptedException { String sampleArchiveName = packageName + ".bar"; log.info(resourceDir + File.separator + sampleArchiveName); DataSource BPMNDataSource = new FileDataSource(resourceDir + File.separator + sampleArchiveName); UploadedFileItem[] uploadedFileItems = new UploadedFileItem[1]; uploadedFileItems[0] = getUploadedFileItem(new DataHandler(BPMNDataSource), sampleArchiveName, "bar"); log.info("Deploying " + sampleArchiveName); bpmnUploaderServiceStub.uploadService(uploadedFileItems); }
Example #28
Source File: SoapDocumentServiceTest.java From document-management-software with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testCreate() throws Exception { WSDocument wsDoc = new WSDocument(); wsDoc.setId(0L); wsDoc.setFolderId(4L); wsDoc.setTemplateId(-1L); wsDoc.setFileName("document test.txt"); wsDoc.setCustomId("yyyyyyyy"); File file = new File("pom.xml"); wsDoc.setComment("comment"); WSAttribute att = new WSAttribute(); att.setName("coverage"); att.setStringValue("coverage-val"); wsDoc.addAttribute(att); docService.create("xxxx", wsDoc, new DataHandler(new FileDataSource(file))); System.out.println(wsDoc.getFileName()); Document doc = docDao.findByFileNameAndParentFolderId(wsDoc.getFolderId(), wsDoc.getFileName(), null, 1L, null) .get(0); System.out.println(doc.getFileName()); Assert.assertNotNull(doc); docDao.initialize(doc); Assert.assertEquals("document test.txt", doc.getFileName()); Assert.assertEquals("coverage-val", doc.getValue("coverage")); wsDoc = docService.getDocument("xxxx", doc.getId()); Assert.assertEquals("document test.txt", wsDoc.getFileName()); Assert.assertEquals("coverage-val", wsDoc.getAttribute("coverage").getStringValue()); }
Example #29
Source File: SignupEmailFacadeImpl.java From sakai with Educational Community License v2.0 | 5 votes |
/** * Helper to create an ICS calendar from a list of vevents, then turn it into an attachment * @param vevents list of vevents * @param method the ITIP method for the calendar, e.g. "REQUEST" * @return */ private Attachment formatICSAttachment(List<VEvent> vevents, String method) { String path = calendarHelper.createCalendarFile(vevents, method); // It's possible that ICS creation failed if (StringUtils.isBlank(path)) { return null; } // Explicitly define the Content-Type and Content-Diposition headers so the invitation appears inline String filename = StringUtils.substringAfterLast(path, File.separator); String type = String.format("text/calendar; charset=\"utf-8\"; method=%s; name=signup-invite.ics", method); File file = new File(path); DataSource dataSource = new Attachment.RenamedDataSource(new FileDataSource(file), filename); return new Attachment(dataSource, type, Attachment.ContentDisposition.INLINE); }
Example #30
Source File: MailSender.java From EserKnife with Apache License 2.0 | 5 votes |
private static void addAttachFile(MailInfo mailInfo, Multipart multiPart) throws MessagingException, UnsupportedEncodingException { BodyPart bodyPart; if(mailInfo.getAttachFileNames() != null && mailInfo.getAttachFileNames().length != 0){ for(String attachFile : mailInfo.getAttachFileNames()){ bodyPart=new MimeBodyPart(); FileDataSource fds=new FileDataSource(attachFile); //得到数据源 bodyPart.setDataHandler(new DataHandler(fds)); //得到附件本身并放入BodyPart bodyPart.setFileName(MimeUtility.encodeText(fds.getName())); //得到文件名并编码(防止中文文件名乱码)同样放入BodyPart multiPart.addBodyPart(bodyPart); } } }