use of javax.activation.DataHandler in project quickstarts by jboss-switchyard.
the class InternalResponseProcessor method process.
@Override
public void process(Exchange exchange) throws Exception {
String newFileName = "internal-resized-switchyard.jpeg";
Image input = exchange.getIn().getBody(Image.class);
exchange.getOut().addAttachment(newFileName, new DataHandler(input, "image/jpeg"));
exchange.getOut().setBody(newFileName);
}
use of javax.activation.DataHandler in project orientdb by orientechnologies.
the class OMailPlugin method addAttachment.
/**
* Adds a file as an attachment to the email's content
*
* @param multipart
* @param filePath
* @throws MessagingException
*/
private void addAttachment(final Multipart multipart, final String filePath) throws MessagingException {
MimeBodyPart attachPart = new MimeBodyPart();
DataSource source = new FileDataSource(filePath);
attachPart.setDataHandler(new DataHandler(source));
attachPart.setFileName(new File(filePath).getName());
multipart.addBodyPart(attachPart);
}
use of javax.activation.DataHandler in project spring-framework by spring-projects.
the class MimeMessageHelper method addInline.
/**
* Add an inline element to the MimeMessage, taking the content from a
* {@code javax.activation.DataSource}.
* <p>Note that the InputStream returned by the DataSource implementation
* needs to be a <i>fresh one on each call</i>, as JavaMail will invoke
* {@code getInputStream()} multiple times.
* <p><b>NOTE:</b> Invoke {@code addInline} <i>after</i> {@link #setText};
* else, mail readers might not be able to resolve inline references correctly.
* @param contentId the content ID to use. Will end up as "Content-ID" header
* in the body part, surrounded by angle brackets: e.g. "myId" -> "<myId>".
* Can be referenced in HTML source via src="cid:myId" expressions.
* @param dataSource the {@code javax.activation.DataSource} to take
* the content from, determining the InputStream and the content type
* @throws MessagingException in case of errors
* @see #addInline(String, java.io.File)
* @see #addInline(String, org.springframework.core.io.Resource)
*/
public void addInline(String contentId, DataSource dataSource) throws MessagingException {
Assert.notNull(contentId, "Content ID must not be null");
Assert.notNull(dataSource, "DataSource must not be null");
MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setDisposition(MimeBodyPart.INLINE);
// We're using setHeader here to remain compatible with JavaMail 1.2,
// rather than JavaMail 1.3's setContentID.
mimeBodyPart.setHeader(HEADER_CONTENT_ID, "<" + contentId + ">");
mimeBodyPart.setDataHandler(new DataHandler(dataSource));
getMimeMultipart().addBodyPart(mimeBodyPart);
}
use of javax.activation.DataHandler in project spring-framework by spring-projects.
the class Jaxb2MarshallerTests method marshalAttachments.
@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));
}
use of javax.activation.DataHandler in project camel by apache.
the class BasicMessageFilterTest method producerWithAttachment.
@Test
public void producerWithAttachment() throws Exception {
exchange.getIn().addAttachment("testAttachment", new DataHandler(this.getClass().getResource("/sampleAttachment.txt")));
filter.filterProducer(exchange, message);
Assertions.assertThat(message.getAttachments()).isNotNull().isNotEmpty();
Assertions.assertThat(message.getAttachment("testAttachment")).isNotNull();
}
Aggregations