Package javax.activation

Examples of javax.activation.URLDataSource


    {
        // ====================================================================
        // Test Success - URL
        // ====================================================================
        this.email.attach(
            new URLDataSource(new URL(this.strTestURL)),
            "Test Attachment",
            "Test Attachment Desc");

        // ====================================================================
        // Test Exceptions
        // ====================================================================
        // null datasource
        try
        {
            URLDataSource urlDs = null;
            this.email.attach(urlDs, "Test Attachment", "Test Attachment Desc");
            fail("Should have thrown an exception");
        }
        catch (EmailException e)
        {
            assertTrue(true);
        }

        // invalid datasource
        try
        {
            URLDataSource urlDs = new URLDataSource(new URL("http://example.invalid/"));
            this.email.attach(urlDs, "Test Attachment", "Test Attachment Desc");
            fail("Should have thrown an exception");
        }
        catch (EmailException e)
        {
View Full Code Here


        exchange = new DefaultExchange(new DefaultCamelContext());
        exchange.setProperty("foo", 1234);
        Message message = exchange.getIn();
        message.setBody("<hello>world!</hello>");
        message.setHeader("bar", 567);
        message.addAttachment("att", new DataHandler(new URLDataSource(new URL("http://activemq.apache.org/camel/message.html"))));
    }
View Full Code Here

        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);

        BodyPart attachmentBodyPart;
        // Create another body part
View Full Code Here

    DataHandler dh = null;
    if (src == null) {
      dh = (DataHandler)DataHandlerUtils.getDataHandlerFromText(
        getText(), (type != null) ? type.toString() : null);
    } else {
      dh = new DataHandler(new URLDataSource(src));
    }
    return dh;
  }
View Full Code Here

        try
        {
            if (!isCid(resourceLocation))
            {
                final URL url = createUrl(resourceLocation);
                result = new URLDataSource(url);
                result.getInputStream();
            }

            return result;
        }
View Full Code Here

        // check if a URLDataSource for this name has already been attached;
        // if so, return the cached CID value.
        if (inlineEmbeds.containsKey(name))
        {
            final InlineImage ii = inlineEmbeds.get(name);
            final URLDataSource urlDataSource = (URLDataSource) ii.getDataSource();
            // make sure the supplied URL points to the same thing
            // as the one already associated with this name.
            // NOTE: Comparing URLs with URL.equals() is a blocking operation
            // in the case of a network failure therefore we use
            // url.toExternalForm().equals() here.
            if (url.toExternalForm().equals(urlDataSource.getURL().toExternalForm()))
            {
                return ii.getCid();
            }
            else
            {
                throw new EmailException("embedded name '" + name
                    + "' is already bound to URL " + urlDataSource.getURL()
                    + "; existing names cannot be rebound");
            }
        }

        // verify that the URL is valid
        InputStream is = null;
        try
        {
            is = url.openStream();
        }
        catch (final IOException e)
        {
            throw new EmailException("Invalid URL", e);
        }
        finally
        {
            try
            {
                if (is != null)
                {
                    is.close();
                }
            }
            catch (final IOException ioe) // NOPMD
            { /* sigh */ }
        }

        return embed(new URLDataSource(url), name);
    }
View Full Code Here

       catch (final IOException e)
       {
           throw new EmailException("Invalid URL set:" + url, e);
       }

       return attach(new URLDataSource(url), name, description, disposition);
    }
View Full Code Here

    {
        // ====================================================================
        // Test Success - URL
        // ====================================================================
        this.email.attach(
            new URLDataSource(new URL(this.strTestURL)),
            "Test Attachment",
            "Test Attachment Desc");

        // ====================================================================
        // Test Exceptions
        // ====================================================================
        // null datasource
        try
        {
            final URLDataSource urlDs = null;
            this.email.attach(urlDs, "Test Attachment", "Test Attachment Desc");
            fail("Should have thrown an exception");
        }
        catch (final EmailException e)
        {
            assertTrue(true);
        }

        // invalid datasource
        try
        {
            final URLDataSource urlDs = new URLDataSource(createInvalidURL());
            this.email.attach(urlDs, "Test Attachment", "Test Attachment Desc");
            fail("Should have thrown an exception");
        }
        catch (final EmailException e)
        {
View Full Code Here

        return email;
    }

    protected String getFromUrl(final URL url) throws Exception {

        final URLDataSource dataSource = new URLDataSource(url);
        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOUtils.copy(dataSource.getInputStream(), baos);
        return new String(baos.toByteArray(), "UTF-8");
    }
View Full Code Here

        TestHandlerXMLBinding handler = new TestHandlerXMLBinding();
        addHandlersProgrammatically(disp, handler);

        URL is = getClass().getResource("/messages/XML_GreetMeDocLiteralReq.xml");
        DataSource ds = new URLDataSource(is);

        try {
            disp.invoke(ds);
            fail("Did not get expected exception");
        } catch (HTTPException e) {
View Full Code Here

TOP

Related Classes of javax.activation.URLDataSource

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.