Java 类javax.activation.URLDataSource 实例源码

项目:jbossws-cxf    文件:JBWS3250TestCase.java   
@Test
@RunAsClient
public void testMtomSawpFile() throws Exception
{
   URL wsdlURL = new URL(baseURL + "?wsdl");
   QName serviceName = new QName("http://ws.jboss.org/jbws3250", "TestEndpointService");
   Endpoint port = Service.create(wsdlURL, serviceName).getPort(Endpoint.class);
   SOAPBinding binding =(SOAPBinding)((BindingProvider)port).getBinding();
   binding.setMTOMEnabled(true);
   URL url = JBossWSTestHelper.getResourceURL("jaxws/jbws3250/wsf.png");
   URLDataSource urlDatasource = new URLDataSource(url);
   javax.activation.DataHandler dh = new DataHandler(urlDatasource);
   MTOMRequest request = new MTOMRequest();
   request.setContent(dh);
   request.setId("largeSize_mtom_request");
   MTOMResponse mtomResponse = port.echo(request);
   Assert.assertEquals("Response for requestID:largeSize_mtom_request", mtomResponse.getResponse());
   byte[] responseBytes = IOUtils.convertToBytes(mtomResponse.getContent());
   Assert.assertTrue(responseBytes.length > 65536);
}
项目:spring-ws-mtom-example    文件:JaxWsClient.java   
/**
 * Sends the test content file to the WebService
 */
public void storeContent() throws Exception {
    ContentStoreHttpPortService contentStoreService = new ContentStoreHttpPortService();
    ContentStoreHttpPort contentStorePort = contentStoreService.getContentStoreHttpPortSoap11();
    SOAPBinding binding = (SOAPBinding) ((BindingProvider) contentStorePort).getBinding();
    binding.setMTOMEnabled(true);

    StoreContentRequest request = objectFactory.createStoreContentRequest();
    request.setName(ClientUtil.TEST_CONTENT_NAME);

    DataHandler dataHandler = new DataHandler(new URLDataSource(ClientUtil.TEST_CONTENT_URL));
    request.setContent(dataHandler);

    StopWatch stopWatch = new StopWatch(this.getClass().getSimpleName());

    stopWatch.start("store");
    StoreContentResponse response = contentStorePort.storeContent(request);
    stopWatch.stop();

    System.out.println(stopWatch.prettyPrint());
}
项目:geokettle-2.0    文件:Mail.java   
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());
       // add the part with the file in the BodyPart();
       data.parts.addBodyPart(files);
       if(log.isDetailed()) log.logDetailed(toString(), Messages.getString("Mail.Log.AttachedFile",fds.getName()));

}
项目:read-open-source-code    文件:Mail.java   
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()));

}
项目:kettle-4.4.0-stable    文件:Mail.java   
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()));

}
项目:kettle-trunk    文件:Mail.java   
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()));

}
项目:pentaho-kettle    文件:Mail.java   
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() ) );
  }

}
项目:Camel    文件:BodyAndHeaderConvertTest.java   
@Override
protected void setUp() throws Exception {
    super.setUp();
    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://camel.apache.org/message.html"))));
}
项目:spring-ws-mtom-example    文件:SaajMtomClient.java   
/**
 * Sends the test content file to the WebService
 */
public void storeContent() {
    StoreContentRequest storeContentRequest = objectFactory.createStoreContentRequest();
    storeContentRequest.setName(ClientUtil.TEST_CONTENT_NAME);
    storeContentRequest.setContent(new DataHandler(new URLDataSource(ClientUtil.TEST_CONTENT_URL)));
    stopWatch.start("store");
    getWebServiceTemplate().marshalSendAndReceive(storeContentRequest);
    stopWatch.stop();
    System.out.println(stopWatch.prettyPrint());
}
项目:spring-boot-cxf-integration-example    文件:SampleIntegrationApplicationTest.java   
@Test
public void test() throws Exception {
    String message = client.storeContent("test", new DataHandler(new URLDataSource(TEST_CONTENT_URL)));
    System.out.println("Server message: " + message);
    assertEquals("Content successfully stored", message);

    DataHandler dh = client.loadContent("test");
    assertNotNull(dh);
    File tempFile = new File(System.getProperty("java.io.tmpdir"), "spring_mtom_jaxws_tmp.bin");
    tempFile.deleteOnExit();
    long size = saveContentToFile(dh, tempFile);
    assertTrue(size > 0);
    assertTrue(tempFile.length()>0);
}
项目:jruby-cxf    文件:AttachmentUtil.java   
public static Attachment getAttachment(String id, Collection<Attachment> attachments) {
    if (id == null) {
        throw new DatabindingException("Cannot get attachment: null id");
    }
    int i = id.indexOf("cid:");
    if (i != -1) {
        id = id.substring(4).trim();
    }

    if (attachments == null) {
        return null;
    }

    for (Iterator<Attachment> iter = attachments.iterator(); iter.hasNext();) {
        Attachment a = iter.next();
        if (a.getId().equals(id)) {
            return a;
        }
    }

    // Try loading the URL remotely
    try {
        URLDataSource source = new URLDataSource(new URL(id));
        return new AttachmentImpl(id, new DataHandler(source));
    } catch (MalformedURLException e) {
        return null;
    }
}
项目:smart-security-camera    文件:SesSendNotificationHandler.java   
@Override
public Parameters handleRequest(Parameters parameters, Context context) {

    context.getLogger().log("Input Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");

    try {

        // Create an empty Mime message and start populating it
        Session session = Session.getDefaultInstance(new Properties());
        MimeMessage message = new MimeMessage(session);
        message.setSubject(EMAIL_SUBJECT, "UTF-8");
        message.setFrom(new InternetAddress(System.getenv("EMAIL_FROM")));
        message.setReplyTo(new Address[] { new InternetAddress(System.getenv("EMAIL_FROM")) });
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(System.getenv("EMAIL_RECIPIENT")));

        MimeBodyPart wrap = new MimeBodyPart();
        MimeMultipart cover = new MimeMultipart("alternative");
        MimeBodyPart html = new MimeBodyPart();
        cover.addBodyPart(html);
        wrap.setContent(cover);
        MimeMultipart content = new MimeMultipart("related");
        message.setContent(content);
        content.addBodyPart(wrap);

        // Create an S3 URL reference to the snapshot that will be attached to this email
        URL attachmentURL = createSignedURL(parameters.getS3Bucket(), parameters.getS3Key());

        StringBuilder sb = new StringBuilder();
        String id = UUID.randomUUID().toString();
        sb.append("<img src=\"cid:");
        sb.append(id);
        sb.append("\" alt=\"ATTACHMENT\"/>\n");

        // Add the attachment as a part of the message body
        MimeBodyPart attachment = new MimeBodyPart();
        DataSource fds = new URLDataSource(attachmentURL);
        attachment.setDataHandler(new DataHandler(fds));

        attachment.setContentID("<" + id + ">");
        attachment.setDisposition(BodyPart.ATTACHMENT);

        attachment.setFileName(fds.getName());
        content.addBodyPart(attachment);

        // Pretty print the Rekognition Labels as part of the Emails HTML content
        String prettyPrintLabels = parameters.getRekognitionLabels().toString();
        prettyPrintLabels = prettyPrintLabels.replace("{", "").replace("}", "");
        prettyPrintLabels = prettyPrintLabels.replace(",", "<br>");            
        html.setContent("<html><body><h2>Uploaded Filename : " + parameters.getS3Key().replace("upload/", "") + 
                        "</h2><p><b>Detected Labels/Confidence</b><br><br>" + prettyPrintLabels + "</p>"+sb+"</body></html>", "text/html");

        // Convert the JavaMail message into a raw email request for sending via SES
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        message.writeTo(outputStream);
        RawMessage rawMessage = new RawMessage(ByteBuffer.wrap(outputStream.toByteArray()));
        SendRawEmailRequest rawEmailRequest = new SendRawEmailRequest(rawMessage);

        // Send the email using the AWS SES Service
        AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.defaultClient();
        client.sendRawEmail(rawEmailRequest);

    } catch (MessagingException | IOException e) {
        // Convert Checked Exceptions to RuntimeExceptions to ensure that
        // they get picked up by the Step Function infrastructure
        throw new AmazonServiceException("Error in ["+context.getFunctionName()+"]", e);
    }

    context.getLogger().log("Output Function [" + context.getFunctionName() + "], Parameters [" + parameters + "]");

    return parameters;
}
项目:spring4-understanding    文件:StandardClasses.java   
public JAXBElement<DataHandler> standardClassDataHandler() {
    DataSource dataSource = new URLDataSource(getClass().getResource("spring-ws.png"));
    DataHandler dataHandler = new DataHandler(dataSource);
    return new JAXBElement<DataHandler>(NAME, DataHandler.class, dataHandler);
}
项目:serianalyzer    文件:SerianalyzerInput.java   
/**
 * 
 * @param u
 * @throws IOException
 */
public void index ( URL u ) throws IOException {
    try ( InputStream openStream = u.openStream() ) {
        index(new URLDataSource(u));
    }
}
项目:pumpernickel    文件:ZipIterator.java   
public ZipIterator(URL url) throws Exception {
    this(new URLDataSource(url));
}
项目:jbossws-cxf    文件:MultipartContentTypeTestCase.java   
private DataHandler getResource(final String resource) throws Exception {
   URL imageUrl = getResourceURL(resource);
   return new DataHandler(new URLDataSource(imageUrl));
}
项目:Lucee4    文件:HtmlEmailImpl.java   
/**
 * Embeds an URL in the HTML.
 *
 * <p>This method allows to embed a file located by an URL into
 * the mail body.  It allows, for instance, to add inline images
 * to the email.  Inline files may be referenced with a
 * <code>cid:xxxxxx</code> URL, where xxxxxx is the Content-ID
 * returned by the embed function.
 *
 * <p>Example of use:<br><code><pre>
 * HtmlEmail he = new HtmlEmail();
 * he.setHtmlMsg("&lt;html&gt;&lt;img src=cid:" +
 *  embed("file:/my/image.gif","image.gif") +
 *  "&gt;&lt;/html&gt;");
 * // code to set the others email fields (not shown)
 * </pre></code>
 *
 * @param url The URL of the file.
 * @param cid A String with the Content-ID of the file.
 * @param name The name that will be set in the filename header
 * field.
 * @throws EmailException when URL supplied is invalid
 *  also see javax.mail.internet.MimeBodyPart for definitions
 *
 */
public void embed(URL url, String cid, String name) throws EmailException {
    // verify that the URL is valid
    try {
        InputStream is = url.openStream();
        is.close();
    }
    catch (IOException e) {
        throw new EmailException("Invalid URL");
    }

    MimeBodyPart mbp = new MimeBodyPart();

    try {
        mbp.setDataHandler(new DataHandler(new URLDataSource(url)));
        mbp.setFileName(name);
        mbp.setDisposition("inline");
        mbp.addHeader("Content-ID", "<" + cid + ">");
        this.inlineImages.add(mbp);
    }
    catch (MessagingException me) {
        throw new EmailException(me);
    }
}
项目:Lucee    文件:HtmlEmailImpl.java   
/**
 * Embeds an URL in the HTML.
 *
 * <p>This method allows to embed a file located by an URL into
 * the mail body.  It allows, for instance, to add inline images
 * to the email.  Inline files may be referenced with a
 * <code>cid:xxxxxx</code> URL, where xxxxxx is the Content-ID
 * returned by the embed function.
 *
 * <p>Example of use:<br><code><pre>
 * HtmlEmail he = new HtmlEmail();
 * he.setHtmlMsg("&lt;html&gt;&lt;img src=cid:" +
 *  embed("file:/my/image.gif","image.gif") +
 *  "&gt;&lt;/html&gt;");
 * // code to set the others email fields (not shown)
 * </pre></code>
 *
 * @param url The URL of the file.
 * @param cid A String with the Content-ID of the file.
 * @param name The name that will be set in the filename header
 * field.
 * @throws EmailException when URL supplied is invalid
 *  also see javax.mail.internet.MimeBodyPart for definitions
 *
 */
public void embed(URL url, String cid, String name) throws EmailException {
    // verify that the URL is valid
    try {
        InputStream is = url.openStream();
        is.close();
    }
    catch (IOException e) {
        throw new EmailException("Invalid URL");
    }

    MimeBodyPart mbp = new MimeBodyPart();

    try {
        mbp.setDataHandler(new DataHandler(new URLDataSource(url)));
        mbp.setFileName(name);
        mbp.setDisposition("inline");
        mbp.addHeader("Content-ID", "<" + cid + ">");
        this.inlineImages.add(mbp);
    }
    catch (MessagingException me) {
        throw new EmailException(me);
    }
}
项目:class-guard    文件:StandardClasses.java   
public JAXBElement<DataHandler> standardClassDataHandler() {
    DataSource dataSource = new URLDataSource(getClass().getResource("spring-ws.png"));
    DataHandler dataHandler = new DataHandler(dataSource);
    return new JAXBElement<DataHandler>(NAME, DataHandler.class, dataHandler);
}
项目:wso2-axis2    文件:TestUtils.java   
public static DataSource getTestFileAsDataSource(String name) {
    return new URLDataSource(TestUtils.class.getClassLoader().getResource(name));
}
项目:easy-mail    文件:URLHtmlContentProvider.java   
@Override
public DataSource getImageDataSource(final String relativeUrl) throws MalformedURLException {
    return new URLDataSource(new URL(resource, relativeUrl));
}