Search in sources :

Example 31 with DataHandler

use of javax.activation.DataHandler in project camel by apache.

the class SoapResponseAttachmentTest method consumeStockQuoteWebserviceWithSoapResponseAttachment.

/**
     * This tests if attachments, returned by a spring-ws request, are populated into the exchange. 
     * The SOAP attachments are populated by the SoapAttachmentResponseProcessor. 
     * Which adds 2 response attachments.
     * Note: 'allowResponseAttachmentOverride=true' must be set!
     *
     * @throws Exception
     */
@Test()
public void consumeStockQuoteWebserviceWithSoapResponseAttachment() throws Exception {
    Exchange result = template.request("direct:stockQuoteWebservice", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().setBody(xmlRequestForGoogleStockQuote);
            exchange.getIn().setHeader(SpringWebserviceConstants.SPRING_WS_SOAP_HEADER, soapHeader);
            exchange.getIn().addAttachment("requestAttachment1.txt", new DataHandler("hello attachment!", "text/plain"));
        }
    });
    assertNotNull(result);
    assertNotNull(result.getOut().getAttachment("requestAttachment1.txt"));
    assertNotNull(result.getOut().getAttachment("responseAttachment1.txt"));
    assertNotNull(result.getOut().getAttachment("responseAttachment2.xml"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DataHandler(javax.activation.DataHandler) Test(org.junit.Test)

Example 32 with DataHandler

use of javax.activation.DataHandler in project camel by apache.

the class VelocityTest method testVelocityLetter.

@Test
public void testVelocityLetter() throws Exception {
    final DataHandler dataHandler = new DataHandler("my attachment", "text/plain");
    Exchange exchange = template.request("direct:a", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().addAttachment("item", dataHandler);
            exchange.getIn().setBody("Monday");
            exchange.getIn().setHeader("name", "Christian");
            exchange.setProperty("item", "7");
        }
    });
    assertEquals("Dear Christian. You ordered item 7 on Monday.", exchange.getOut().getBody());
    assertEquals("Christian", exchange.getOut().getHeader("name"));
    assertSame(dataHandler, exchange.getOut().getAttachment("item"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DataHandler(javax.activation.DataHandler) Test(org.junit.Test)

Example 33 with DataHandler

use of javax.activation.DataHandler in project camel by apache.

the class VelocityMethodInvokationTest method testVelocityLetter.

@Test
public void testVelocityLetter() throws Exception {
    final DataHandler dataHandler = new DataHandler("my attachment", "text/plain");
    Exchange exchange = template.request("direct:a", new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            exchange.getIn().addAttachment("item", dataHandler);
            exchange.getIn().setBody("Monday & Tuesday");
            exchange.getIn().setHeader("name", "Christian");
            exchange.setProperty("item", "7");
        }
    });
    assertEquals("Dear Christian. You ordered item 7 on Monday & Tuesday.", exchange.getOut().getBody());
    assertEquals("Christian", exchange.getOut().getHeader("name"));
    assertSame(dataHandler, exchange.getOut().getAttachment("item"));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) DataHandler(javax.activation.DataHandler) Test(org.junit.Test)

Example 34 with DataHandler

use of javax.activation.DataHandler in project nhin-d by DirectProject.

the class DirectDocuments method toProvideAndRegisterDocumentSetRequestType.

public ProvideAndRegisterDocumentSetRequestType toProvideAndRegisterDocumentSetRequestType() throws IOException {
    ProvideAndRegisterDocumentSetRequestType request = new ProvideAndRegisterDocumentSetRequestType();
    request.setSubmitObjectsRequest(this.getSubmitObjectsRequest());
    for (DirectDocument2 document : documents) {
        if (document.getData() != null) {
            DataSource source = new ByteArrayDataSource(document.getData(), document.getMetadata().getMimeType());
            DataHandler dhnew = new DataHandler(source);
            Document pdoc = new Document();
            pdoc.setValue(dhnew);
            String id = document.getMetadata().getId();
            pdoc.setId(id);
            request.getDocument().add(pdoc);
        }
    }
    return request;
}
Also used : DataHandler(javax.activation.DataHandler) Document(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource)

Example 35 with DataHandler

use of javax.activation.DataHandler in project nhin-d by DirectProject.

the class DefaultXdmXdsTransformer method transform.

/*
     * (non-Javadoc)
     * 
     * @see org.nhindirect.transform.XdmXdsTransformer#transform(java.io.File)
     */
@Override
public ProvideAndRegisterDocumentSetRequestType transform(File file) throws TransformationException {
    LOGGER.trace("Begin transformation of XDM to XDS (file)");
    String docId = null;
    ZipFile zipFile = null;
    String docName = getDocName(file);
    if (docName != null) {
        XDM_FILENAME_DATA = docName;
    }
    ProvideAndRegisterDocumentSetRequestType prsr = new ProvideAndRegisterDocumentSetRequestType();
    try {
        zipFile = new ZipFile(file, ZipFile.OPEN_READ);
        Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
        ZipEntry zipEntry = null;
        // load the ZIP archive into memory
        while (zipEntries.hasMoreElements()) {
            zipEntry = zipEntries.nextElement();
            String zname = zipEntry.getName();
            LOGGER.trace("Processing a ZipEntry " + zname);
            if (!zipEntry.isDirectory()) {
                String subsetDirspec = getSubmissionSetDirspec(zipEntry.getName());
                // Read metadata
                if (matchName(zname, subsetDirspec, XDM_FILENAME_METADATA)) {
                    ByteArrayOutputStream byteArrayOutputStream = readData(zipFile, zipEntry);
                    SubmitObjectsRequest submitObjectRequest = (SubmitObjectsRequest) XmlUtils.unmarshal(byteArrayOutputStream.toString(), oasis.names.tc.ebxml_regrep.xsd.lcm._3.ObjectFactory.class);
                    prsr.setSubmitObjectsRequest(submitObjectRequest);
                    docId = getDocId(submitObjectRequest);
                } else // Read data
                if (matchName(zname, subsetDirspec, XDM_FILENAME_DATA)) {
                    ByteArrayOutputStream byteArrayOutputStream = readData(zipFile, zipEntry);
                    DataSource source = new ByteArrayDataSource(byteArrayOutputStream.toByteArray(), MimeType.APPLICATION_XML + "; charset=UTF-8");
                    DataHandler dhnew = new DataHandler(source);
                    Document pdoc = new Document();
                    pdoc.setValue(dhnew);
                    pdoc.setId(docId);
                    List<Document> docs = prsr.getDocument();
                    docs.add(pdoc);
                }
            }
            if (!prsr.getDocument().isEmpty()) {
                ((Document) prsr.getDocument().get(0)).setId(zname);
            }
        }
        zipFile.close();
    } catch (Exception e) {
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unable to complete transformation.", e);
        }
        throw new TransformationException("Unable to complete transformation.", e);
    }
    return prsr;
}
Also used : TransformationException(org.nhindirect.xd.transform.exception.TransformationException) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataHandler(javax.activation.DataHandler) Document(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType.Document) SubmitObjectsRequest(oasis.names.tc.ebxml_regrep.xsd.lcm._3.SubmitObjectsRequest) TransformationException(org.nhindirect.xd.transform.exception.TransformationException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) DataSource(javax.activation.DataSource) ZipFile(java.util.zip.ZipFile) List(java.util.List) ByteArrayDataSource(javax.mail.util.ByteArrayDataSource) ProvideAndRegisterDocumentSetRequestType(ihe.iti.xds_b._2007.ProvideAndRegisterDocumentSetRequestType)

Aggregations

DataHandler (javax.activation.DataHandler)180 Exchange (org.apache.camel.Exchange)39 MimeBodyPart (javax.mail.internet.MimeBodyPart)38 FileDataSource (javax.activation.FileDataSource)33 Test (org.junit.Test)33 DataSource (javax.activation.DataSource)32 ByteArrayDataSource (javax.mail.util.ByteArrayDataSource)29 IOException (java.io.IOException)27 ByteArrayOutputStream (java.io.ByteArrayOutputStream)25 InputStream (java.io.InputStream)25 MessagingException (javax.mail.MessagingException)25 MimeMultipart (javax.mail.internet.MimeMultipart)25 MimeMessage (javax.mail.internet.MimeMessage)23 ByteArrayInputStream (java.io.ByteArrayInputStream)22 Message (org.apache.camel.Message)21 OMElement (org.apache.axiom.om.OMElement)17 Processor (org.apache.camel.Processor)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)14 File (java.io.File)13 PipedInputStream (java.io.PipedInputStream)13