Search in sources :

Example 46 with FileDataSource

use of javax.activation.FileDataSource in project webservices-axiom by apache.

the class TextHelperTest method test_fromOMText.

/**
     * Test the OMText -> StringBuffer code
     * @throws Exception
     */
public void test_fromOMText() throws Exception {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    FileDataSource fds = new FileDataSource(file);
    DataHandler dh = new DataHandler(fds);
    OMText omText = factory.createOMText(dh, true);
    StringBuffer buffer = new StringBuffer();
    TextHelper.toStringBuffer(omText, buffer);
    assertTrue(buffer.length() > SIZE);
    String text = buffer.toString();
    assertTrue(text.length() == EXPECTED_BASE64_SIZE);
    assertTrue(text.startsWith(EXPECTED_STARTS_WITH));
}
Also used : OMFactory(org.apache.axiom.om.OMFactory) FileDataSource(javax.activation.FileDataSource) OMText(org.apache.axiom.om.OMText) DataHandler(javax.activation.DataHandler)

Example 47 with FileDataSource

use of javax.activation.FileDataSource in project webservices-axiom by apache.

the class BufferUtilsTest method testDataSourceBackedDataHandlerExceedLimit.

public void testDataSourceBackedDataHandlerExceedLimit() throws IOException {
    File file = File.createTempFile("bufferUtils", "tst");
    file.deleteOnExit();
    try {
        RandomAccessFile raf = new RandomAccessFile(file, "rw");
        try {
            raf.setLength(5000);
        } finally {
            raf.close();
        }
        FileDataSource fds = new FileDataSource(file);
        DataHandler dh = new DataHandler(fds);
        int unsupported = BufferUtils.doesDataHandlerExceedLimit(dh, 0);
        assertEquals(-1, unsupported);
        int doesExceed = BufferUtils.doesDataHandlerExceedLimit(dh, 1000);
        assertEquals(1, doesExceed);
        int doesNotExceed = BufferUtils.doesDataHandlerExceedLimit(dh, 100000);
        assertEquals(0, doesNotExceed);
    } finally {
        file.delete();
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) FileDataSource(javax.activation.FileDataSource) DataHandler(javax.activation.DataHandler) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 48 with FileDataSource

use of javax.activation.FileDataSource in project cxf by apache.

the class AttachmentUtil method createMtomAttachmentFromDH.

public static Attachment createMtomAttachmentFromDH(boolean isXop, DataHandler handler, String elementNS, int threshold) {
    if (!isXop) {
        return null;
    }
    // apply the threshold.
    try {
        DataSource ds = handler.getDataSource();
        if (ds instanceof FileDataSource) {
            FileDataSource fds = (FileDataSource) ds;
            File file = fds.getFile();
            if (file.length() < threshold) {
                return null;
            }
        } else if (ds.getClass().getName().endsWith("ObjectDataSource")) {
            Object o = handler.getContent();
            if (o instanceof String && ((String) o).length() < threshold) {
                return null;
            } else if (o instanceof byte[] && ((byte[]) o).length < threshold) {
                return null;
            }
        }
    } catch (IOException e1) {
    // ignore, just do the normal attachment thing
    }
    String id;
    try {
        id = AttachmentUtil.createContentID(elementNS);
    } catch (UnsupportedEncodingException e) {
        throw new Fault(e);
    }
    AttachmentImpl att = new AttachmentImpl(id, handler);
    if (!StringUtils.isEmpty(handler.getName())) {
        // set Content-Disposition attachment header if filename isn't null
        String file = handler.getName();
        File f = new File(file);
        if (f.exists() && f.isFile()) {
            file = f.getName();
        }
        att.setHeader("Content-Disposition", "attachment;name=\"" + file + "\"");
    }
    att.setXOP(isXop);
    return att;
}
Also used : FileDataSource(javax.activation.FileDataSource) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Fault(org.apache.cxf.interceptor.Fault) IOException(java.io.IOException) File(java.io.File) FileDataSource(javax.activation.FileDataSource) URLDataSource(javax.activation.URLDataSource) DataSource(javax.activation.DataSource)

Example 49 with FileDataSource

use of javax.activation.FileDataSource in project cxf by apache.

the class MTOMSecurityTest method testSymmetricBinaryBytesInAttachment.

@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);
    port.doubleIt4(25, new DataHandler(source));
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) DoubleItMtomPortType(org.example.contract.doubleit.DoubleItMtomPortType) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DataHandler(javax.activation.DataHandler) URL(java.net.URL) FileDataSource(javax.activation.FileDataSource) DataSource(javax.activation.DataSource) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) FileDataSource(javax.activation.FileDataSource) DoubleIt4(org.example.schema.doubleit.DoubleIt4) File(java.io.File)

Example 50 with FileDataSource

use of javax.activation.FileDataSource in project cxf by apache.

the class MTOMSecurityTest method testSignedMTOMAction.

// Sign an attachment without inlining
@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);
    port.doubleIt4(25, new DataHandler(source));
    ((java.io.Closeable) port).close();
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) DoubleItMtomPortType(org.example.contract.doubleit.DoubleItMtomPortType) QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) DataHandler(javax.activation.DataHandler) URL(java.net.URL) FileDataSource(javax.activation.FileDataSource) DataSource(javax.activation.DataSource) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) FileDataSource(javax.activation.FileDataSource) DoubleIt4(org.example.schema.doubleit.DoubleIt4) File(java.io.File)

Aggregations

FileDataSource (javax.activation.FileDataSource)55 DataHandler (javax.activation.DataHandler)46 File (java.io.File)22 DataSource (javax.activation.DataSource)18 Exchange (org.apache.camel.Exchange)18 MimeBodyPart (javax.mail.internet.MimeBodyPart)17 Test (org.junit.Test)16 Message (org.apache.camel.Message)15 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)12 MimeMultipart (javax.mail.internet.MimeMultipart)11 BodyPart (javax.mail.BodyPart)9 MimeMessage (javax.mail.internet.MimeMessage)8 Producer (org.apache.camel.Producer)7 URL (java.net.URL)6 MessagingException (javax.mail.MessagingException)6 Multipart (javax.mail.Multipart)6 InternetAddress (javax.mail.internet.InternetAddress)6 Endpoint (org.apache.camel.Endpoint)6 Processor (org.apache.camel.Processor)6 QName (javax.xml.namespace.QName)5