正 文

通过 SOAP 和 HTTP 发送安全/非安全附件


www.7dspace.com  更新日期:2006-2-13 22:58:35  七度空间


      业务文档中的合作伙伴 ID

      此方法更适合 B2B 事务。准备附件时,您需要准备 MimeMessage,并插入在第一个 MimeMessage 中插入自定义 Header 的 MimeMultiparts,此自定义 Header 将清楚地说明其内容(应用程序/二进制数据、应用程序/八进制流、应用程序/pkcs7 签名、应用程序/包封数据等等)和合作伙伴的 ID 及其他内容的相关信息。您还需要准备具有以上 MimeMessage 的 javax.activation.DataHandler 对象,然后通过 SOAP/HTTP 发送您创建的 DataHandler。

清单 5 显示了需要对客户端进行的处理:

清单 5. 客户端处理程序

static void sendSignedDocument(AttachmentTip tip,String fileName)
     throws java.rmi.RemoteException
{
     try{
       byte[] crlf=new byte[]{13,10};
       ByteArrayOutputStream baos=new ByteArrayOutputStream();
       baos.write("Content-Type: ".getBytes());
       baos.write("application/pkcs7-signature".getBytes());
       baos.write(crlf);
       baos.write(crlf);
       byte[] ba=baos.toByteArray();

       ByteArrayInputStream contentInputs = new ByteArrayInputStream(ba);
       MimeMessage m_mimeMessage = new MimeMessage(null, contentInputs);

       m_mimeMessage.removeHeader("Content-Type");
       MimeMultipart m_mimeMultipart = new MimeMultipart("signed");
       ContentType ct = new ContentType(m_mimeMultipart.getContentType());
       ct.setParameter("protocol", "application/pkcs7-signature");
       ct.setParameter("micalg", "sha1");
//     // add the text
       InternetHeaders ih=new InternetHeaders();
//
       m_mimeMessage.setHeader("Content-Type",ct.toString());
       m_mimeMessage.setHeader("Sender-Id","123456789");
       m_mimeMessage.setHeader("Receiver-Id","987654321");
//
       byte[] sigByteArray =
         generateSignature(null,"This is the Temp Data".getBytes());
       MimeBodyPart mp = null;
       mp=new MimeBodyPart(ih, encode(sigByteArray,"binary"));  //"This
         is the Temp Data".getBytes());
       m_mimeMultipart.addBodyPart(mp);

       ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
       m_mimeMessage.writeTo(byteArray);
       m_mimeMultipart.writeTo(byteArray);

       MimeBodyPart part = (MimeBodyPart)m_mimeMultipart.getBodyPart(0);
       Object partobj = part.getContent();

       InputStream is = part.getRawInputStream(); //getContentStream();
       byte[] isData = new byte[is.available()];
       is.read(isData);
       is.close();
       java.io.FileOutputStream fos1 =
         new java.io.FileOutputStream("c:\\tempout2.txt");
       fos1.write(isData);
       fos1.close();
       java.io.FileOutputStream fos =
         new java.io.FileOutputStream("c:\\tempout.txt");
       fos.write(byteArray.toByteArray());
       fos.close();
       FileDataSource fds1 = new FileDataSource("c:\\tempout.txt");
       DataHandler dh0 = new DataHandler(fds1);
       System.out.println("dh0.getContentType() "+dh0.getContentType());
       dh0.getContentType();

       FileDataSource fds = new FileDataSource(fileName);
       DataHandler dh = new DataHandler(fds);
       System.out.println("dh.getContentType() "+dh.getContentType());

       tip.sendSignedDocument(dh0);

     }catch(Exception ex){
       ex.printStackTrace();
     }
}

6页,页码:[1] [2] [3] [4] [5] [6] 

上一篇:DVD备份之王花落谁家 Divx6 VS RatDVD
下一篇:使用AJAX调用SOAP Web服务:构建Web服务客户机
标题:通过 SOAP 和 HTTP 发送安全/非安全附件 作者:Vikas Arora 来源:developerWorks 中国
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐