当前位置: 首页>>代码示例>>Java>>正文


Java MimeBodyPart.getHeader方法代码示例

本文整理汇总了Java中javax.mail.internet.MimeBodyPart.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java MimeBodyPart.getHeader方法的具体用法?Java MimeBodyPart.getHeader怎么用?Java MimeBodyPart.getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.mail.internet.MimeBodyPart的用法示例。


在下文中一共展示了MimeBodyPart.getHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: appendPart

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
private void appendPart( StringBuffer sb, MimeBodyPart mbp ) throws IOException, MessagingException {
    String[] disposition = mbp.getHeader( "Content-Disposition" );
    String name = getHeaderAttribute( disposition[0], "name" );
    if (mbp.getFileName() == null) {
        appendFieldValue( name, sb, mbp );
    } else {
        sb.append( mbp.getContentType() ).append( ':' );
        appendFileSpecs( name, sb, mbp );
    }
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:11,代码来源:FileUploadTest.java

示例2: testCompressAS2Message

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
@Test
public void testCompressAS2Message() throws Exception{
	InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
	ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));
	partnershipDVO.setIsOutboundCompressRequired(true);
	String mid = RANDOM.toString();
	
	AS2Message as2Msg = TARGET.storeOutgoingMessage(
			mid, //MessageID
			"xml", 
			partnershipDVO,
			new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
	
	SMIMECompressed compressed = new SMIMECompressed(as2Msg.getBodyPart());
	MimeBodyPart decompressedPart = SMIMEUtil.toMimeBodyPart(compressed.getContent(new ZlibExpanderProvider()));

	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	IOHandler.pipe( decompressedPart.getDataHandler().getInputStream(), baos);
	byte[] decrptedBA = baos.toByteArray();
	byte[] original = IOHandler.readBytes(FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG));
	
	Assert.assertTrue(Arrays.equals(decrptedBA, original));		
	//TODO
   String filenameHdr = decompressedPart.getHeader("Content-Disposition")[0];
   Assert.assertEquals("Filename value lost in BodyPart Header", 
		   MOCK_AS2_MSG, getFileName(filenameHdr));
   
   
   // Verify MIC Value
      ByteArrayOutputStream contentBAOS = new ByteArrayOutputStream();
      decompressedPart.writeTo(contentBAOS);
      byte[] content = (contentBAOS.toByteArray());
      String mic = calculateMIC(content);
      Assert.assertEquals( "MIC Value is not valid.",
   		   mic, getStoredMessage(mid).getMicValue());
     
}
 
开发者ID:cecid,项目名称:hermes,代码行数:38,代码来源:OutgoingMessageProcessorTest.java

示例3: testSignedAS2Message

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
@Test
public void testSignedAS2Message() throws Exception{
	InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
	ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));

	partnershipDVO.setIsOutboundSignRequired(true);
	String mid = RANDOM.toString();
	
	AS2Message as2Msg = TARGET.storeOutgoingMessage(
			mid, //MessageID
			"xml", 
			partnershipDVO,
			new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
	
	//Verify As2Signing Message
	try{
		SMIMESigned signed = new SMIMESigned((MimeMultipart)as2Msg.getBodyPart().getContent());
		SignerInformationStore  signers = signed.getSignerInfos();
		Iterator signerInfos = signers.getSigners().iterator();
		while (signerInfos.hasNext()) {
			SignerInformation   signerInfo = (SignerInformation)signerInfos.next();

			SignerInformationVerifier verifier =
			    new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(),
							       new DefaultSignatureAlgorithmIdentifierFinder(),
							       new DefaultDigestAlgorithmIdentifierFinder(), 
							       new BcDigestCalculatorProvider())
			    .build(new JcaX509CertificateHolder(partnershipDVO.getEffectiveVerifyCertificate()));
			
			if (!signerInfo.verify(verifier)) {
				Assert.fail("Signature Verfifcation Failed");
			}
		}
		
		//Assert the filename value
		MimeBodyPart signedPart = signed.getContent();
        String filenameHdr = signedPart.getHeader("Content-Disposition")[0];
        Assert.assertEquals("Lost Filename Header Information", MOCK_AS2_MSG, getFileName(filenameHdr));
        
        
        // Verify MIC Value
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        signedPart.writeTo(baos);
           byte[] content = (baos.toByteArray());
           String mic = calculateMIC(content);
           
           MessageDVO msgDVO = getStoredMessage(mid);
           Assert.assertEquals("MIC Value is not valid.", mic, msgDVO.getMicValue());
        
	}catch(Exception exp){
		Assert.fail("Signature Verfifcation Failed");
	}
       Assert.assertTrue(true);
	}
 
开发者ID:cecid,项目名称:hermes,代码行数:55,代码来源:OutgoingMessageProcessorTest.java

示例4: testEncrytedAS2Message

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
@Test
public void testEncrytedAS2Message() throws Exception{
    InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
    ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));
    String mid = RANDOM.toString();
    
    partnershipDVO.setIsOutboundEncryptRequired(true);
    AS2Message as2Msg = TARGET.storeOutgoingMessage(
						    mid, //MessageID
						    "xml", 
						    partnershipDVO,
						    new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
	
	
    // Decrypt Message
    SMIMEEnveloped crypted = new SMIMEEnveloped(as2Msg.getBodyPart());
    
    // RecipientId recId = new RecipientId();
    RecipientId recId = new JceKeyTransRecipientId(partnershipDVO.getEncryptX509Certificate());

    RecipientInformationStore  recipientsInfo = crypted.getRecipientInfos();	
    RecipientInformation       recipientInfo = recipientsInfo.get(recId);

    KeyStoreManager keyMan = (KeyStoreManager)TARGET.getSystemModule().getComponent("keystore-manager");

    JceKeyTransEnvelopedRecipient recipient = new JceKeyTransEnvelopedRecipient(keyMan.getPrivateKey());	
    recipient.setProvider(SECURITY_PROVIDER);							
    
    MimeBodyPart  decrpted = SMIMEUtil.toMimeBodyPart(recipientInfo.getContent(recipient));
       
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    IOHandler.pipe( decrpted.getDataHandler().getInputStream(), baos);
    byte[] decrptedBA = baos.toByteArray();
    byte[] originalBA = IOHandler.readBytes(FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG));
       
    Assert.assertTrue(Arrays.equals(decrptedBA, originalBA));
       
    //Assert the filename
    String filenameHdr = decrpted.getHeader("Content-Disposition")[0];
    Assert.assertEquals("Filename value lost in BodyPartHeader",
			MOCK_AS2_MSG, getFileName(filenameHdr));

    //Verify MIC
    ByteArrayOutputStream contentStream = new ByteArrayOutputStream();
    decrpted.writeTo(contentStream);
    byte[] content = (contentStream.toByteArray());
    String mic = calculateMIC(content);
    Assert.assertEquals( "MIC Value is not valid.", mic, getStoredMessage(mid).getMicValue());
}
 
开发者ID:cecid,项目名称:hermes,代码行数:50,代码来源:OutgoingMessageProcessorTest.java

示例5: testSignedEncryptedAS2Message

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
@Test
public void testSignedEncryptedAS2Message() throws Exception {
    InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
    ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));
	
    // Prepare Data
    String mid = RANDOM.toString();
    partnershipDVO.setIsOutboundEncryptRequired(true);
    partnershipDVO.setIsOutboundSignRequired(true);
    //Encrypt message
    AS2Message as2Msg = TARGET.storeOutgoingMessage(
						    mid, //MessageID
						    "xml", 
						    partnershipDVO,
						    new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
	
    // Decrypt Message
    SMIMEEnveloped crypted = new SMIMEEnveloped(as2Msg.getBodyPart());

    RecipientId recId = new JceKeyTransRecipientId(partnershipDVO.getEncryptX509Certificate());
    
    RecipientInformationStore  recipientsInfo = crypted.getRecipientInfos();	
    RecipientInformation       recipientInfo = recipientsInfo.get(recId);

    KeyStoreManager keyMan = (KeyStoreManager)TARGET.getSystemModule().getComponent("keystore-manager");

    JceKeyTransEnvelopedRecipient recipient = new JceKeyTransEnvelopedRecipient(keyMan.getPrivateKey());	
    recipient.setProvider(SECURITY_PROVIDER);							
    
    MimeBodyPart  decrpted = SMIMEUtil.toMimeBodyPart(recipientInfo.getContent(recipient));
	
    //Verify Signature
    try{
	SMIMESigned signed = new SMIMESigned((MimeMultipart)decrpted.getContent());
	SignerInformationStore  signers = signed.getSignerInfos();
	Iterator signerInfos = signers.getSigners().iterator();

	while (signerInfos.hasNext()) {
	    SignerInformation   signerInfo = (SignerInformation)signerInfos.next();

	    SignerInformationVerifier verifier =
		new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(),
						   new DefaultSignatureAlgorithmIdentifierFinder(),
						   new DefaultDigestAlgorithmIdentifierFinder(), 
						   new BcDigestCalculatorProvider())
		.build(new JcaX509CertificateHolder(partnershipDVO.getEffectiveVerifyCertificate()));
	    if (!signerInfo.verify(verifier)) {
		Assert.fail("Signature Verfifcation Failed");
	    }
	}

	
		
	//Assert the filename value
	MimeBodyPart signedPart = signed.getContent();
        String filenameHdr = signedPart.getHeader("Content-Disposition")[0];
        Assert.assertEquals("Lost Filename Header Information", MOCK_AS2_MSG, getFileName(filenameHdr));
        
        
        // Verify MIC Value
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        signedPart.writeTo(baos);
	byte[] content = (baos.toByteArray());
	String mic = calculateMIC(content);
           
	MessageDVO msgDVO = getStoredMessage(mid);
	Assert.assertEquals("MIC Value is not valid.", mic, msgDVO.getMicValue());
        
    }catch(Exception exp){
	Assert.fail("Signature Verfifcation Failed");
    }
    Assert.assertTrue(true);
}
 
开发者ID:cecid,项目名称:hermes,代码行数:74,代码来源:OutgoingMessageProcessorTest.java

示例6: testSignedCommpressMessage

import javax.mail.internet.MimeBodyPart; //导入方法依赖的package包/类
@Test
public void testSignedCommpressMessage() throws Exception{
	InputStream ins = FIXTURE_LOADER.getResourceAsStream(MOCK_AS2_MSG);
	ByteArrayInputStream bIns = new ByteArrayInputStream(IOHandler.readBytes(ins));
	
	// Prepare Data
	String mid = RANDOM.toString();
	partnershipDVO.setIsOutboundSignRequired(true);
	partnershipDVO.setIsOutboundCompressRequired(true);
	//Process message
	AS2Message as2Msg = TARGET.storeOutgoingMessage(
			mid, //MessageID
			"xml", 
			partnershipDVO,
			new InputStreamDataSource(bIns, "xml", MOCK_AS2_MSG));
       
       try{
       	//Verify Message Signature
		SMIMESigned signed = new SMIMESigned((MimeMultipart)as2Msg.getBodyPart().getContent());
		SignerInformationStore  signers = signed.getSignerInfos();
		Iterator signerInfos = signers.getSigners().iterator();
		while (signerInfos.hasNext()) {
			SignerInformation   signerInfo = (SignerInformation)signerInfos.next();

			SignerInformationVerifier verifier =
			    new BcRSASignerInfoVerifierBuilder(new DefaultCMSSignatureAlgorithmNameGenerator(),
							       new DefaultSignatureAlgorithmIdentifierFinder(),
							       new DefaultDigestAlgorithmIdentifierFinder(), 
							       new BcDigestCalculatorProvider())
			    .build(new JcaX509CertificateHolder(partnershipDVO.getEffectiveVerifyCertificate()));
			
			if (!signerInfo.verify(verifier)) {
				Assert.fail("Signature Verfifcation Failed");
			}
		}
		
		// Verify MIC Value
		MimeBodyPart signedPart = signed.getContent();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        signedPart.writeTo(baos);
        byte[] content = (baos.toByteArray());
        String mic = calculateMIC(content);
        MessageDVO msgDVO = getStoredMessage(mid);
        Assert.assertEquals("MIC Value is not valid.", mic, msgDVO.getMicValue());
		
		//Decompress Message
		SMIMECompressed compressed = new SMIMECompressed(signedPart);
		MimeBodyPart decompressedPart = SMIMEUtil.toMimeBodyPart(compressed.getContent(new ZlibExpanderProvider()));
		
		//Assert the filename value
        String filenameHdr = decompressedPart.getHeader("Content-Disposition")[0];
        Assert.assertEquals("Lost Filename Header Information", MOCK_AS2_MSG, getFileName(filenameHdr));
        
	}catch(Exception exp){
		Assert.fail("Signature Verfifcation Failed");
	}
	
}
 
开发者ID:cecid,项目名称:hermes,代码行数:59,代码来源:OutgoingMessageProcessorTest.java


注:本文中的javax.mail.internet.MimeBodyPart.getHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。