/** * Create a <code>DataHandler</code> instance referencing a URL. * The DataHandler internally creates a <code>URLDataSource</code> * instance to represent the URL. * * @param url a URL object */ public DataHandler(URL url) { dataSource = new URLDataSource(url); oldFactory = factory; // keep track of the factory }
public JAXBElement<DataHandler> standardClassDataHandler() { DataSource dataSource = new URLDataSource(getClass().getResource("spring-ws.png")); DataHandler dataHandler = new DataHandler(dataSource); return new JAXBElement<>(NAME, DataHandler.class, dataHandler); }
private void addAttachedFilePart( FileObject file ) throws Exception { // create a data source MimeBodyPart files = new MimeBodyPart(); // create a data source URLDataSource fds = new URLDataSource( file.getURL() ); // get a data Handler to manipulate this file type; files.setDataHandler( new DataHandler( fds ) ); // include the file in the data source files.setFileName( file.getName().getBaseName() ); // insist on base64 to preserve line endings files.addHeader( "Content-Transfer-Encoding", "base64" ); // add the part with the file in the BodyPart(); data.parts.addBodyPart( files ); if ( isDetailed() ) { logDetailed( BaseMessages.getString( PKG, "Mail.Log.AttachedFile", fds.getName() ) ); } }
/** * Create a <code>DataHandler</code> instance referencing a URL. * The DataHandler internally creates a <code>URLDataSource</code> * instance to represent the URL. * * @param url a URL object */ public DataHandler(URL url) { dataSource = new URLDataSource(url); oldFactory = factory; // keep track of the factory }
URLDataSource fds = new URLDataSource( file.getURL() ); URLDataSource fds = new URLDataSource( imageFile.getURL() ); messageBodyPart.setDataHandler( new DataHandler( fds ) );
DataHandler handler = new DataHandler( new URLDataSource( Service.class.getResource("coffee.jpg"))); message.addAttachment("picture", handler);
@Override protected void render(Part mailPart, String fileName) { DataSource ds = new URLDataSource(url); if (fileName == null) { fileName = url.getPath(); } render(mailPart, fileName, ds); } }
@Override protected void render(Part mailPart, String fileName) { DataSource ds = new URLDataSource(url); if (fileName == null) { fileName = url.getPath(); } render(mailPart, fileName, ds); } }
@Endpoint public class Service{ private SaajSoapMessageFactory saajMessageFactory; // dependency inject this @PayloadRoot(namespace = "http://foo.com/coffee", localPart = "order") @ResponsePayload public Coffee getCoffee(@RequestPayload Order order, MessageContext context){ DataHandler handler = new DataHandler( new URLDataSource( Service.class.getResource("coffee.jpg"))); SaajSoapMessage message = saajMessageFactory.createWebServiceMessage(); message.addAttachment("picture", handler); context.setResponse(message); return new Coffee("Hot Joe"); } public void setSaajMessageFactory(SaajMessageFactory saajMessageFactory){ this.saajMessageFactory = saajMessageFactory; } public SaajMessageFactory getSaajMessageFactory(){ return saajMessageFactory; } }
@Override protected void render(Part mailPart, String fileName) { ResourceLoader resourceLoader = containingContent.getResourceLoader(); if (resourceLoader == null) { throw new MailBuilderException("Could not find resource \"" + resourceName + "\": no resourceLoader specified"); } Resource resource = resourceLoader.getResource(resourceName); if (!resource.exists()) { throw new MailBuilderException("Could not find resource \"" + resourceName + "\""); } DataSource ds; try { ds = new URLDataSource(resource.getURL()); } catch (IOException e) { ds = new ResourceDataSource(resource); } if (fileName == null) { fileName = resourceName; } render(mailPart, fileName, ds); } }
@Override protected void render(Part mailPart, String fileName) { ResourceLoader resourceLoader = containingContent.getResourceLoader(); if (resourceLoader == null) { throw new MailBuilderException("Could not find resource \"" + resourceName + "\": no resourceLoader specified"); } Resource resource = resourceLoader.getResource(resourceName); if (!resource.exists()) { throw new MailBuilderException("Could not find resource \"" + resourceName + "\""); } DataSource ds; try { ds = new URLDataSource(resource.getURL()); } catch (IOException e) { ds = new ResourceDataSource(resource); } if (fileName == null) { fileName = resourceName; } render(mailPart, fileName, ds); } }
private void renderInlineResource(Multipart multipart, InlineResource inlineResource, Set<String> fileNames) throws MessagingException { assertNotNull(resourceLoader, "no resourceLoader"); String resourceName = inlineResource.getResourceName(); Resource resource = resourceLoader.getResource(resourceName); if (!resource.exists()) { throw new MailBuilderException("Could not find resource \"" + resourceName + "\""); } DataSource ds; try { ds = new URLDataSource(resource.getURL()); } catch (IOException e) { ds = new ResourceDataSource(resource); } MimeBodyPart bodyPart = new MimeBodyPart(); bodyPart.setDataHandler(new DataHandler(ds)); bodyPart.setHeader(CONTENT_ID, "<" + inlineResource.getContentId() + ">"); bodyPart.setFileName(inlineResource.getUniqueFilename(fileNames)); bodyPart.setDisposition("inline"); multipart.addBodyPart(bodyPart); }
/** {@inheritDoc} */ @Override public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException { DataSource result = null; try { if (!isCid(resourceLocation)) { final URL url = createUrl(resourceLocation); result = new URLDataSource(url); result.getInputStream(); } return result; } catch (final IOException e) { if (isLenient) { return null; } throw e; } }
private void renderInlineResource(Multipart multipart, InlineResource inlineResource, Set<String> fileNames) throws MessagingException { assertNotNull(resourceLoader, "no resourceLoader"); String resourceName = inlineResource.getResourceName(); Resource resource = resourceLoader.getResource(resourceName); if (!resource.exists()) { throw new MailBuilderException("Could not find resource \"" + resourceName + "\""); } DataSource ds; try { ds = new URLDataSource(resource.getURL()); } catch (IOException e) { ds = new ResourceDataSource(resource); } MimeBodyPart bodyPart = new MimeBodyPart(); bodyPart.setDataHandler(new DataHandler(ds)); bodyPart.setHeader(CONTENT_ID, "<" + inlineResource.getContentId() + ">"); bodyPart.setFileName(inlineResource.getUniqueFilename(fileNames)); bodyPart.setDisposition("inline"); multipart.addBodyPart(bodyPart); }
return embed(new URLDataSource(url), name);
return attach(new URLDataSource(url), name, description, disposition);
/** * Create a <code>DataHandler</code> instance referencing a URL. * The DataHandler internally creates a <code>URLDataSource</code> * instance to represent the URL. * * @param url a URL object */ public DataHandler(URL url) { dataSource = new URLDataSource(url); oldFactory = factory; // keep track of the factory }
URLDataSource fds = new URLDataSource( image.getURL() ); imagePart.setDataHandler( new DataHandler( fds ) );
String fileName = "WEB-INF/resources/images/logomailtemplate.png"; ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = this.getClass().getClassLoader(); } DataSource ds = new FileDataSource(new File(classLoader.getResource(fileName).toURI())); //OR DataSource ds = new URLDataSource(classLoader.getResource(fileName));
@Override public PatchId addArchive(URL fileUrl) throws IOException { lock.tryLock(); try { PatchId patchId = PatchId.fromURL(fileUrl); DataHandler dataHandler = new DataHandler(new URLDataSource(fileUrl)); PatchMetadata metadata = new PatchMetadataBuilder().patchId(patchId).build(); return addArchive(metadata, dataHandler, false); } finally { lock.unlock(); } }