List of usage examples for javax.activation DataHandler DataHandler
public DataHandler(URL url)
DataHandler
instance referencing a URL. From source file:de.extra.extraClientLight.helper.BuildExtraTransport.java
/** * Stellt den Body mit Nutzdaten zusammen * /*from w ww .j a v a 2s .co m*/ * @param nutzdaten * Nutzdatenobjekt als Stream * @return TransportRequestBodyType * @throws IOException */ private static TransportRequestBodyType buildBody(InputStream nutzdaten) throws IOException { TransportRequestBodyType requestBody = new TransportRequestBodyType(); DataType data = new DataType(); Base64CharSequenceType payload = new Base64CharSequenceType(); DataSource ds = new ByteArrayDataSource(IOUtils.toByteArray(nutzdaten), "application"); DataHandler dataHandler = new DataHandler(ds); payload.setValue(dataHandler); data.setBase64CharSequence(payload); requestBody.setData(data); return requestBody; }
From source file:org.wso2.appserver.integration.common.utils.SqlDataSourceUtil.java
public DataHandler createArtifact(String dbsFilePath) throws XMLStreamException, IOException, XPathExpressionException { if (automationContext == null) { init();/* w w w. ja v a 2 s . c om*/ } Assert.assertNotNull(jdbcUrl, "Initialize jdbcUrl"); try { OMElement dbsFile = AXIOMUtil.stringToOM(FileManager.readFile(dbsFilePath)); OMElement dbsConfig = dbsFile.getFirstChildWithName(new QName("config")); Iterator configElement1 = dbsConfig.getChildElements(); while (configElement1.hasNext()) { OMElement property = (OMElement) configElement1.next(); String value = property.getAttributeValue(new QName("name")); if ("org.wso2.ws.dataservice.protocol".equals(value)) { property.setText(jdbcUrl); } else if ("org.wso2.ws.dataservice.driver".equals(value)) { property.setText(jdbcDriver); } else if ("org.wso2.ws.dataservice.user".equals(value)) { property.setText(databaseUser); } else if ("org.wso2.ws.dataservice.password".equals(value)) { property.setText(databasePassword); } } log.debug(dbsFile); ByteArrayDataSource dbs = new ByteArrayDataSource(dbsFile.toString().getBytes()); return new DataHandler(dbs); } catch (XMLStreamException e) { log.error("XMLStreamException when Reading Service File", e); throw new XMLStreamException("XMLStreamException when Reading Service File", e); } catch (IOException e) { log.error("IOException when Reading Service File", e); throw new IOException("IOException when Reading Service File", e); } }
From source file:cz.zcu.kiv.eegdatabase.webservices.semantic.SemanticServiceImpl.java
/** * Generates an ontology document from POJO objects. * This method transforms the Jena's output using Owl-Api. * * @param syntaxType - syntax (rdf,owl,ttl) * @return//from www .jav a 2 s . com * @throws WebServiceException * @throws IOException * @throws OWLOntologyStorageException * @throws OWLOntologyCreationException */ public DataHandler getOntologyOwlApi(String syntaxType) throws SOAPException { InputStream is = null; byte[] bytes = null; ByteArrayDataSource owl = null; ByteArrayOutputStream os = new ByteArrayOutputStream(); try { int i; is = simpleSemanticFactory.getOntologyOwlApi(syntaxType); while ((i = is.read()) > -1) { os.write(i); } } catch (OWLOntologyCreationException e) { log.error(e); throw new SOAPException(e); } catch (OWLOntologyStorageException e) { log.error(e); throw new SOAPException(e); } catch (IOException e) { log.error(e); throw new SOAPException(e); } owl = new ByteArrayDataSource(os.toByteArray(), "fileBinaryStream"); return new DataHandler(owl); }
From source file:de.extra_standard.namespace.webservice.ExtraServiceImpl.java
@Override @WebMethod(action = "http://www.extra-standard.de/namespace/webservice/execute") @WebResult(name = "Transport", targetNamespace = "http://www.extra-standard.de/namespace/response/1", partName = "response") public ResponseTransport execute( @WebParam(name = "Transport", targetNamespace = "http://www.extra-standard.de/namespace/request/1", partName = "request") final de.drv.dsrv.extrastandard.namespace.request.RequestTransport request) throws ExtraFault { try {/*from www . j a va 2 s. c o m*/ logger.info("receive Extra ResponseTransport"); final Base64CharSequenceType base64CharSequence = request.getTransportBody().getData() .getBase64CharSequence(); final DataHandler dataHandler = base64CharSequence.getValue(); final InputStream inputStream = dataHandler.getInputStream(); final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); final String dateSuffix = sdf.format(new Date(System.currentTimeMillis())); final String dataHandlerName = dataHandler.getName(); logger.info("Receiving File : " + dataHandlerName); final File receivedFile = new File(outputDirectory, dataHandlerName + "_" + dateSuffix); final FileOutputStream fileOutputStream = new FileOutputStream(receivedFile); IOUtils.copyLarge(inputStream, fileOutputStream); logger.info("Input file is stored under " + receivedFile.getAbsolutePath()); logger.info("ChecksumCRC32 " + FileUtils.checksumCRC32(receivedFile)); logger.info("Filesize: " + FileUtils.sizeOf(receivedFile)); } catch (final IOException e) { logger.error("IOException in Server:", e); } // TODO TestTransport erzeugen!! final ResponseTransport responseTransport = new ResponseTransport(); final ResponseTransportBody responseTransportBody = new ResponseTransportBody(); final DataType dataType = new DataType(); final Base64CharSequenceType base64CharSequenceType = new Base64CharSequenceType(); final DataSource ds = new FileDataSource(testDataFile); final DataHandler dataHandler = new DataHandler(ds); base64CharSequenceType.setValue(dataHandler); dataType.setBase64CharSequence(base64CharSequenceType); responseTransportBody.setData(dataType); responseTransport.setTransportBody(responseTransportBody); return responseTransport; }
From source file:ebay.dts.client.FileTransferActions.java
public UploadFileResponse uploadFile2(String xmlFile, String jobId, String fileReferenceId) throws EbayConnectorException { String callName = "uploadFile"; UploadFileResponse response = null;//w w w .j av a 2s . c om File fileToUpload = null; try { String compressedFileName = compressFileToGzip(xmlFile); if (compressedFileName == null) { logger.error("Failed to compress your XML file into gzip file. Aborted."); return null; } FileTransferServicePort port = call.setFTSMessageContext(callName); UploadFileRequest request = new UploadFileRequest(); FileAttachment attachment = new FileAttachment(); fileToUpload = new File(compressedFileName); DataHandler dh = new DataHandler(new FileDataSource(fileToUpload)); attachment.setData(dh); attachment.setSize(fileToUpload.length()); String fileFormat = "gzip"; request.setFileFormat(fileFormat); /* * For instance, the Bulk Data Exchange Service uses a job ID as a * primary identifier, so, if you're using the Bulk Data Exchange * Service, enter the job ID as the taskReferenceId. */ request.setTaskReferenceId(jobId); request.setFileReferenceId(fileReferenceId); request.setFileAttachment(attachment); // request. if (port != null && request != null) { response = port.uploadFile(request); } return response; } catch (Exception e) { logger.error(e.getMessage()); throw new EbayConnectorException(e.getMessage(), e); } finally { if (fileToUpload != null && fileToUpload.exists()) { fileToUpload.delete(); } } }
From source file:com.googlecode.psiprobe.tools.Mailer.java
private static MimeBodyPart createAttachmentPart(DataSource attachment) throws MessagingException { MimeBodyPart attachmentPart = new MimeBodyPart(); attachmentPart.setDataHandler(new DataHandler(attachment)); attachmentPart.setDisposition(MimeBodyPart.ATTACHMENT); attachmentPart.setFileName(attachment.getName()); return attachmentPart; }
From source file:com.consol.citrus.ws.message.SoapAttachment.java
@Override public DataHandler getDataHandler() { if (dataHandler == null) { if (StringUtils.hasText(contentResourcePath)) { dataHandler = new DataHandler(new FileResourceDataSource(contentType, contentResourcePath)); } else {//from w w w. j av a2 s . c om dataHandler = new DataHandler(new ContentDataSource(contentType, content, charsetName, contentId)); } } return dataHandler; }
From source file:ee.cyber.licensing.service.MailService.java
public void generateAndSendMail(MailBody mailbody, int licenseId, int fileId) throws MessagingException, IOException, SQLException { License license = licenseRepository.findById(licenseId); List<Contact> contacts = contactRepository.findAll(license.getCustomer()); List<String> receivers = getReceivers(mailbody, contacts); logger.info("1st ===> setup Mail Server Properties"); Properties mailServerProperties = getProperties(); final String email = mailServerProperties.getProperty("fromEmail"); final String password = mailServerProperties.getProperty("password"); final String host = mailServerProperties.getProperty("mail.smtp.host"); logger.info("2nd ===> create Authenticator object to pass in Session.getInstance argument"); Authenticator authentication = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(email, password); }//from w ww . j ava 2 s.c o m }; logger.info("Mail Server Properties have been setup successfully"); logger.info("3rd ===> get Mail Session.."); Session getMailSession = Session.getInstance(mailServerProperties, authentication); logger.info("4th ===> generateAndSendEmail() starts"); MimeMessage mailMessage = new MimeMessage(getMailSession); mailMessage.addHeader("Content-type", "text/html; charset=UTF-8"); mailMessage.addHeader("format", "flowed"); mailMessage.addHeader("Content-Transfer-Encoding", "8bit"); mailMessage.setFrom(new InternetAddress(email, "License dude")); //mailMessage.setReplyTo(InternetAddress.parse(email, false)); mailMessage.setSubject(mailbody.getSubject()); //String emailBody = body + "<br><br> Regards, <br>Cybernetica team"; mailMessage.setSentDate(new Date()); for (String receiver : receivers) { mailMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(receiver)); } if (fileId != 0) { MailAttachment file = fileRepository.findById(fileId); if (file != null) { String fileName = file.getFileName(); byte[] fileData = file.getData_b(); if (fileName != null) { // Create a multipart message for attachment Multipart multipart = new MimeMultipart(); // Body part BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setContent(mailbody.getBody(), "text/html"); multipart.addBodyPart(messageBodyPart); //Attachment part messageBodyPart = new MimeBodyPart(); ByteArrayDataSource source = new ByteArrayDataSource(fileData, "application/octet-stream"); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(fileName); multipart.addBodyPart(messageBodyPart); mailMessage.setContent(multipart); } } } else { mailMessage.setContent(mailbody.getBody(), "text/html"); } logger.info("5th ===> Get Session"); sendMail(email, password, host, getMailSession, mailMessage); }
From source file:org.openiam.idm.srvc.msg.service.MailSenderClient.java
public void send(Message msg) { Properties properties = System.getProperties(); properties.setProperty("mail.smtp.host", host); properties.setProperty("mail.transport.protocol", "smtp"); if (username != null && !username.isEmpty()) { properties.setProperty("mail.user", username); properties.setProperty("mail.password", password); }/*from w w w .jav a 2 s .co m*/ if (port != null && !port.isEmpty()) { properties.setProperty("mail.smtp.port", port); } Session session = Session.getDefaultInstance(properties); MimeMessage message = new MimeMessage(session); try { message.setFrom(msg.getFrom()); if (msg.getTo().size() > 1) { List<InternetAddress> addresses = msg.getTo(); message.addRecipients(TO, addresses.toArray(new Address[addresses.size()])); } else { message.addRecipient(TO, msg.getTo().get(0)); } if (msg.getBcc() != null && msg.getBcc().size() != 0) { if (msg.getTo().size() > 1) { List<InternetAddress> addresses = msg.getBcc(); message.addRecipients(BCC, addresses.toArray(new Address[addresses.size()])); } else { message.addRecipient(TO, msg.getBcc().get(0)); } } if (msg.getCc() != null && msg.getCc().size() > 0) { if (msg.getCc().size() > 1) { List<InternetAddress> addresses = msg.getCc(); message.addRecipients(CC, addresses.toArray(new Address[addresses.size()])); } else { message.addRecipient(CC, msg.getCc().get(0)); } } message.setSubject(msg.getSubject(), "UTF-8"); MimeBodyPart mbp1 = new MimeBodyPart(); // create the Multipart and add its parts to it Multipart mp = new MimeMultipart(); if (msg.getBodyType() == Message.BodyType.HTML_TEXT) { mbp1.setContent(msg.getBody(), "text/html"); } else { mbp1.setText(msg.getBody(), "UTF-8"); } if (port != null && !port.isEmpty()) { properties.setProperty("mail.smtp.port", port); } mp.addBodyPart(mbp1); if (msg.getAttachments().size() > 0) { for (String fileName : msg.getAttachments()) { // create the second message part MimeBodyPart mbpFile = new MimeBodyPart(); // attach the file to the message FileDataSource fds = new FileDataSource(fileName); mbpFile.setDataHandler(new DataHandler(fds)); mbpFile.setFileName(fds.getName()); mp.addBodyPart(mbpFile); } } // add the Multipart to the message message.setContent(mp); if (username != null && !username.isEmpty()) { properties.setProperty("mail.user", username); properties.setProperty("mail.password", password); properties.put("mail.smtp.auth", auth); properties.put("mail.smtp.starttls.enable", starttls); Transport mailTransport = session.getTransport(); mailTransport.connect(host, username, password); mailTransport.sendMessage(message, message.getAllRecipients()); } else { Transport.send(message); log.debug("Message successfully sent."); } } catch (Throwable e) { log.error("Exception while sending mail", e); } }
From source file:org.jasig.portlet.blackboardvcportlet.dao.ws.impl.MultimediaWSDaoTestBase.java
@Test public void createSessionMultimediaTest() throws Exception { InputStream is = new ByteArrayInputStream("TEST2".getBytes()); ByteArrayDataSource rawData = new ByteArrayDataSource(is, "video/mpeg"); DataHandler dataHandler = new DataHandler(rawData); BlackboardMultimediaResponse createSessionMultimedia = dao.createSessionMultimedia(session.getSessionId(), user.getEmail(), "test.mpeg", "aliens", dataHandler); multimedias.add(createSessionMultimedia.getMultimediaId()); List<BlackboardMultimediaResponse> repositoryMultimedias = dao .getSessionMultimedias(session.getSessionId()); assertNotNull(repositoryMultimedias); assertTrue(repositoryMultimedias.size() == 1); }