Package javax.activation

Examples of javax.activation.FileDataSource


        OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
        OMElement request = factory.createOMElement("request", ns);
        OMElement image = factory.createOMElement("image", ns);

        System.out.println("Sending file : " + fileName + " as MTOM");
        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);
View Full Code Here


        // The following is just wrong. Even if the DataHandler has a stream, we should still
        // 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();
View Full Code Here

    BodyPart mainBody = new MimeBodyPart();
    mainBody.setContent(content, "text/html;charset=gbk");
    multipart.addBodyPart(mainBody);
    for (Entry<String, String> e : mailAttachment.entrySet()) {
      BodyPart bodyPart = new MimeBodyPart();
      bodyPart.setDataHandler(new DataHandler(new FileDataSource(e
          .getKey())));
      bodyPart.setFileName(e.getValue());
      bodyPart.setHeader("Content-ID", e.getValue());
      multipart.addBodyPart(bodyPart);
    }
View Full Code Here

    BodyPart mainBody = new MimeBodyPart();
    mainBody.setContent(content, "text/html;charset=gbk");
    multipart.addBodyPart(mainBody);
    for (Entry<String, String> e : mailAttachment.entrySet()) {
      BodyPart bodyPart = new MimeBodyPart();
      bodyPart.setDataHandler(new DataHandler(new FileDataSource(e
          .getKey())));
      bodyPart.setFileName(e.getValue());
      bodyPart.setHeader("Content-ID", e.getValue());
      multipart.addBodyPart(bodyPart);
    }
View Full Code Here

    OMNamespace namespace = fac.createOMNamespace(applicationNamespaceName,"ns1");
    OMElement pingElem = fac.createOMElement(MTOMPing, namespace);
    OMElement attachmentElem = fac.createOMElement("Attachment", namespace);
   
      String imageName = "test-resources" + File.separator + "mtom-image.jpg";
      FileDataSource dataSource;
    try {
      dataSource = new FileDataSource (new File (imageName));
    } catch (Exception e) {
      throw new AxisFault (e);
    }
   
      DataHandler dataHandler = new DataHandler(dataSource);
View Full Code Here

    public void testEmbedDataSource() throws Exception
    {
        File tmpFile = File.createTempFile("testEmbedDataSource", "txt");
        tmpFile.deleteOnExit();
        FileDataSource dataSource = new FileDataSource(tmpFile);

        // does embedding a datasource without a name fail?
        try
        {
            this.email.embed(dataSource, "");
            fail("embedding with an empty string for a name should fail");
        }
        catch (EmailException e)
        {
            // expected
        }

        // properly embed the datasource
        String cid = this.email.embed(dataSource, "testname");

        // does embedding the same datasource under the same name return
        // the original cid?
        String sameCid = this.email.embed(dataSource, "testname");
        assertEquals("didn't get same CID for embedding same datasource twice",
                cid, sameCid);

        // does embedding another datasource under the same name fail?
        File anotherFile = File.createTempFile("testEmbedDataSource2", "txt");
        anotherFile.deleteOnExit();
        FileDataSource anotherDS = new FileDataSource(anotherFile);
        try
        {
            this.email.embed(anotherDS, "testname");
        }
        catch (EmailException e)
View Full Code Here

        // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
        Exchange exchange = endpoint.createExchange();
        Message in = exchange.getIn();
        in.setBody("<html><body><h1>Hello</h1>World</body></html>");
        in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));

        // create a producer that can produce the exchange (= send the mail)
        Producer producer = endpoint.createProducer();
        // start the producer
        producer.start();
View Full Code Here

        // create the exchange with the mail message that is multipart with a file and a Hello World text/plain message.
        Exchange exchange = endpoint.createExchange();
        Message in = exchange.getIn();
        in.setBody("Hello World");
        in.addAttachment("logo.jpeg", new DataHandler(new FileDataSource("src/test/data/logo.jpeg")));

        // create a producer that can produce the exchange (= send the mail)
        Producer producer = endpoint.createProducer();
        // start the producer
        producer.start();
View Full Code Here

        mixed.addBodyPart(htmlPart);

        DataSource ds;
        try {
            File f = new File(getClass().getResource("/log4j.properties").toURI());
            ds = new FileDataSource(f);
        } catch (URISyntaxException ex) {
            ds = new URLDataSource(getClass().getResource("/log4j.properties"));
        }
        DataHandler dh = new DataHandler(ds);
View Full Code Here

        template.send("direct:begin", new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
                Message m = exchange.getIn();
                m.setBody("Hello World");
                m.addAttachment("log4j", new DataHandler(new FileDataSource("src/test/resources/log4j.properties")));
                m.addAttachment("jndi-example", new DataHandler(new FileDataSource("src/test/resources/jndi-example.properties")));
            }
        });

        assertMockEndpointsSatisfied();
        Map<String, DataHandler> attachments = mock.getExchanges().get(0).getIn().getAttachments();
View Full Code Here

TOP

Related Classes of javax.activation.FileDataSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.