Examples of DataHandler


Examples of javax.activation.DataHandler

    {
        JavaMailAttachments atts = new JavaMailAttachments();
        Attachments recvd = context.getInMessage().getAttachments();
       
        Attachment att = (Attachment) context.getInMessage().getAttachments().getParts().next();
        DataHandler handler = new DataHandler(att.getDataHandler().getDataSource());
        att = new SimpleAttachment("test.jpg", handler);
       
        atts.addPart(att);
        context.getOutMessage().setAttachments(atts);
       
View Full Code Here

Examples of javax.activation.DataHandler

        Client client = ((XFireProxy) Proxy.getInvocationHandler(picClient)).getClient();
        client.setProperty(SoapConstants.MTOM_ENABLED, "true");
       
        EchoPicture req = new EchoPicture();
        FileDataSource source = new FileDataSource(getTestFile("src/test-resources/xfire.jpg"));
        req.setImage(new DataHandler(source));
       
        EchoPictureResponse res = picClient.EchoPicture(req);
        assertNotNull(res.getImage());
    }
View Full Code Here

Examples of javax.activation.DataHandler

            Assert.fail(e.getMessage());
            e.printStackTrace();
        }
       
        FileDataSource source = new FileDataSource(getTestFile("src/test-resources/xfire.jpg"));
        response.setImage(new DataHandler(source));
       
        return response;
    }
View Full Code Here

Examples of javax.activation.DataHandler

            msg.setFrom();
        }
        msg.setRecipients( javax.mail.Message.RecipientType.TO, to );
        msg.setSubject( subject );

        msg.setDataHandler( new DataHandler( body, mimeType ) );

        //msg.setHeader( "X-Mailer", "JavaMailer" );
        msg.setSentDate( new Date(  ) );

        Transport.send( msg );
View Full Code Here

Examples of javax.activation.DataHandler

        if (sSrc.startsWith("www."))
          sSrc = "http://" + sSrc;

        if (sSrc.startsWith("http://") || sSrc.startsWith("https://")) {
          oImgBodyPart.setDataHandler(new DataHandler(new URL(Hosts.resolve(sSrc))));
        }
        else {
          oImgBodyPart.setDataHandler(new DataHandler(new FileDataSource((sBasePath==null ? "" : sBasePath)+sSrc)));
        }

        oImgBodyPart.setDisposition("inline");
        oImgBodyPart.setHeader("Content-ID", sCid);
        oImgBodyPart.setFileName(sCid);

        // Add image to multi-part
        if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/related).addBodyPart("+sCid+")");
        oHtmlRelated.addBodyPart(oImgBodyPart);
      } // wend

      // Set html text alternative part (html text + inline images)
      MimeBodyPart oTextHtmlRelated = new MimeBodyPart();
      oTextHtmlRelated.setContent(oHtmlRelated);
      if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/alternative).addBodyPart(multipart/related)");
      oTextHtmlAlt.addBodyPart(oTextHtmlRelated);
    }

    // ************************************************************************
    // Create message to be sent and add main text body to it

    if (aAttachmentsPath==null) {
      oSentMessage.setContent(oTextHtmlAlt);
    } else {
      MimeBodyPart oMixedPart = new MimeBodyPart();
      oMixedPart.setContent(oTextHtmlAlt);
      oSentMsgParts.addBodyPart(oMixedPart);
    }

  } else { // (sContentType=="plain")

    // *************************************************
    // If this is a plain text message just add the text

    if (aAttachmentsPath==null) {
      oSentMessage.setText(sTextBody, sCharEnc);
    } else {
      oMsgPlainText.setDisposition("inline");
      oMsgPlainText.setText(sTextBody, sCharEnc, "plain");
      //oMsgPlainText.setContent(sTextBody, "text/plain; charset="+sCharEnc);
      if (DebugFile.trace) DebugFile.writeln("MimeBodyPart(multipart/mixed).addBodyPart(text/plain)");
      oSentMsgParts.addBodyPart(oMsgPlainText);
    }
  }
  // fi (sContentType=="html")

  // ************************************************************************
  // Add attachments to message to be sent

  if (aAttachmentsPath!=null) {
    final int nAttachments = aAttachmentsPath.length;

    FileSystem oFS = new FileSystem();
    for (int p=0; p<nAttachments; p++) {
      String sFilePath = aAttachmentsPath[p];
      if (sBasePath!=null) {
        if (!sFilePath.startsWith(sBasePath))
          sFilePath = sBasePath + sFilePath;
      }
      File oFile = new File(sFilePath);
     
      MimeBodyPart oAttachment = new MimeBodyPart();
      oAttachment.setDisposition("attachment");
      oAttachment.setFileName(oFile.getName());
      oAttachment.setHeader("Content-Transfer-Encoding", "base64");

      ByteArrayDataSource oDataSrc;
      try {
        oDataSrc = new ByteArrayDataSource(oFS.readfilebin(sFilePath), "application/octet-stream");
      } catch (com.enterprisedt.net.ftp.FTPException ftpe) {
      throw new IOException(ftpe.getMessage());
      }
      oAttachment.setDataHandler(new DataHandler(oDataSrc));
      oSentMsgParts.addBodyPart(oAttachment);
    } // next
    oSentMessage.setContent(oSentMsgParts);
  } // fi (iDraftParts>0)

View Full Code Here

Examples of javax.activation.DataHandler

            // Set the Subject
            tMsg.setSubject(aSubject, mCodeSet);

            // Set the message Body in a dirrerent way (HTML or plain text)
            if (aIsHtml) {
                DataHandler tDh = new DataHandler(aMessage, "text/html");
                tMsg.setDataHandler(tDh);
            } else {
                tMsg.setText(aMessage, mCodeSet);
            }
View Full Code Here

Examples of javax.activation.DataHandler

         // MimeBodyPart mbp1 = new MimeBodyPart(attachment);
         MimeBodyPart mbp1 = new MimeBodyPart(); // "application/x-any"
         // "application/xmlBlaster-xbformat"
         DataSource ds = new ByteArrayDataSource(attachment,
               "application/xmlBlaster-xbformat");
         mbp1.setDataHandler(new DataHandler(ds));
         mbp1.setFileName(attachmentName);
         // mbp1.getContentType(); "application/octet-stream"

         // create the Multipart and add its parts to it
         Multipart mp = new MimeMultipart();
View Full Code Here

Examples of javax.activation.DataHandler

               else {
                  // "application/xmlBlaster-xbformat"
                  DataSource ds = new ByteArrayDataSource(
                        content,
                        holder[i].getContentType());
                  mbp.setDataHandler(new DataHandler(ds));
               }
               multi.addBodyPart(mbp);
            }
  
            // add the Multipart to the message
View Full Code Here

Examples of javax.activation.DataHandler

          String sContentType = oRSet.getString(7);
          if (DebugFile.trace) DebugFile.writeln("new ByteArrayDataSource("+sFilePath+", "+sContentType+")");
          ByteArrayDataSource baDataSrc = new ByteArrayDataSource(byData, sContentType);

          oMimeBody = new MimeBodyPart();
          oMimeBody.setDataHandler(new DataHandler(baDataSrc));
        }
        else if (id_disposition.equals("pointer")) {
          if (DebugFile.trace) DebugFile.writeln("content disposition is pointer");
          lPos = oRSet.getBigDecimal(3).longValue();
          sFilePath = oRSet.getString(4);
View Full Code Here

Examples of javax.activation.DataHandler

    String sRetVal;

    URL oUrl = new URL(sFilePath);
   
    ByteArrayOutputStream oStrm = new ByteArrayOutputStream();
    DataHandler oHndlr = new DataHandler(oUrl);
    oHndlr.writeTo(oStrm);
    sRetVal = oStrm.toString(sEncoding);
    oStrm.close();

    return sRetVal;
  } // readfilestr
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.