當前位置: 首頁>>代碼示例>>Java>>正文


Java MimeMultipart.writeTo方法代碼示例

本文整理匯總了Java中javax.mail.internet.MimeMultipart.writeTo方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeMultipart.writeTo方法的具體用法?Java MimeMultipart.writeTo怎麽用?Java MimeMultipart.writeTo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.mail.internet.MimeMultipart的用法示例。


在下文中一共展示了MimeMultipart.writeTo方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: multipart

import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
/**
 * Encodes multipart/form-data where the body content must be an instance of the {@link MultipartContent} class. Individual parts will be
 * encoded using the encoders available to the {@link ChainedHttpConfig} object.
 *
 * @param config the chained configuration object
 * @param ts     the server adapter
 */
public static void multipart(final ChainedHttpConfig config, final ToServer ts) {
    try {
        final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest();

        final Object body = request.actualBody();
        if (!(body instanceof MultipartContent)) {
            throw new IllegalArgumentException("Multipart body content must be MultipartContent.");
        }

        final String contentType = request.actualContentType();
        if (!(contentType.equals(MULTIPART_FORMDATA.getAt(0)) || contentType.equals(MULTIPART_MIXED.getAt(0)))) {
            throw new IllegalArgumentException("Multipart body content must be multipart/form-data.");
        }

        final MimeMultipart mimeMultipart = new MimeMultipart();

        for (final MultipartContent.MultipartPart mpe : ((MultipartContent) body).parts()) {
            mimeMultipart.addBodyPart(part(config, mpe));
        }

        request.setContentType(mimeMultipart.getContentType());

        final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
        mimeMultipart.writeTo(bytesOut);

        ts.toServer(new ByteArrayInputStream(bytesOut.toByteArray()));

    } catch (IOException | MessagingException ioe) {
        ioe.printStackTrace();
    }
}
 
開發者ID:http-builder-ng,項目名稱:http-builder-ng,代碼行數:39,代碼來源:CoreEncoders.java

示例2: signMessage

import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
private MimeBodyPart signMessage(MimeBodyPart bodyPart) throws Exception{
	X509Certificate cert = partnershipDVO.getVerifyX509Certificate();
	
	/* Create the SMIMESignedGenerator */
       SMIMECapabilityVector capabilities = new SMIMECapabilityVector();
       capabilities.addCapability(SMIMECapability.dES_EDE3_CBC);
       capabilities.addCapability(SMIMECapability.rC2_CBC, 128);
       capabilities.addCapability(SMIMECapability.dES_CBC);

       ASN1EncodableVector attributes = new ASN1EncodableVector();
       attributes.add(new SMIMEEncryptionKeyPreferenceAttribute(
           new IssuerAndSerialNumber(new X509Name(cert.getIssuerDN().getName()), cert.getSerialNumber()))
       );
       attributes.add(new SMIMECapabilitiesAttribute(capabilities));

       SMIMESignedGenerator signer = new SMIMESignedGenerator();
       signer.setContentTransferEncoding("base64");
signer.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder().setProvider(SECURITY_PROVIDER)
			      .setSignedAttributeGenerator(new AttributeTable(attributes))
			      .build("SHA1withRSA",
				     keyMan.getPrivateKey(),
				     partnershipDVO.getVerifyX509Certificate()));

       // Add the list of certs to the generator
       ArrayList certList = new ArrayList();
       certList.add(cert);
       CertStore certs = CertStore.getInstance("Collection",
               new CollectionCertStoreParameters(certList), "BC");
signer.addCertificates(new JcaCertStore(certList));

       // Sign body part
MimeMultipart mm = signer.generate(bodyPart);

       InternetHeaders headers = new InternetHeaders();
       boolean isContentTypeFolded = new Boolean(System.getProperty("mail.mime.foldtext","true")).booleanValue();
       headers.setHeader("Content-Type", isContentTypeFolded? mm.getContentType():mm.getContentType().replaceAll("\\s", " "));
       ByteArrayOutputStream baos = new ByteArrayOutputStream();
       mm.writeTo(baos);  
       MimeBodyPart signedPart = new MimeBodyPart(headers, baos.toByteArray());
       
       return signedPart;
}
 
開發者ID:cecid,項目名稱:hermes,代碼行數:43,代碼來源:IncomingMessageProcessorTest.java

示例3: sign

import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
public void sign(X509Certificate cert, PrivateKey privateKey, String digestAlg) throws SFRMException {
      try {
      	
          /* Create the SMIMESignedGenerator */
          SMIMECapabilityVector capabilities = new SMIMECapabilityVector();
          capabilities.addCapability(SMIMECapability.dES_EDE3_CBC);
          capabilities.addCapability(SMIMECapability.rC2_CBC, 128);
          capabilities.addCapability(SMIMECapability.dES_CBC);
                      
          SMIMESignedGenerator signer = new SMIMESignedGenerator();
          
          signer.setContentTransferEncoding("binary");

   String signerDigestAlg = "";
   
   if (digestAlg.equalsIgnoreCase(ALG_SIGN_MD5))
signerDigestAlg = "MD5withRSA";
   else if (digestAlg.equalsIgnoreCase(ALG_SIGN_SHA1))
signerDigestAlg = "SHA1withRSA";
   else
throw new SFRMException("Encryption algorihtm error - " + digestAlg);

   signer.addSignerInfoGenerator(new JcaSimpleSignerInfoGeneratorBuilder()
    .setProvider(SECURITY_PROVIDER)
    .build(signerDigestAlg, privateKey, cert));

          /* Add the list of certs to the generator */
          ArrayList<X509Certificate> certList = new ArrayList<X509Certificate>();
          certList.add(cert);
          CertStore certs = CertStore.getInstance("Collection",
                  new CollectionCertStoreParameters(certList), "BC");
          // signer.addCertificatesAndCRLs(certs);
   signer.addCertificates(new JcaCertStore(certList));

          /* Sign the body part */
          MimeMultipart mm = signer.generate(bodyPart);

          InternetHeaders headers = new InternetHeaders();
          headers.setHeader("Content-Type", mm.getContentType());
          
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          mm.writeTo(baos);
         
          this.bodyPart = new MimeBodyPart(headers, baos.toByteArray());
          
          this.setIsSigned(true);
          
      } catch (org.bouncycastle.mail.smime.SMIMEException ex) {
          throw new SFRMException("Unable to sign body part", ex.getUnderlyingException());
      } catch (Exception e) {
          throw new SFRMException("Unable to sign body part", e);
      }
  }
 
開發者ID:cecid,項目名稱:hermes,代碼行數:54,代碼來源:SFRMMessage.java


注:本文中的javax.mail.internet.MimeMultipart.writeTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。