1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/packaging/mime/internet/MimePullMultipart.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,121 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.messaging.saaj.packaging.mime.internet; 1.30 + 1.31 +import com.sun.xml.internal.messaging.saaj.packaging.mime.MessagingException; 1.32 +import com.sun.xml.internal.messaging.saaj.soap.AttachmentPartImpl; 1.33 +import java.io.IOException; 1.34 +import java.io.InputStream; 1.35 +import java.util.List; 1.36 +import javax.activation.DataSource; 1.37 +import javax.xml.soap.AttachmentPart; 1.38 +import com.sun.xml.internal.org.jvnet.mimepull.MIMEConfig; 1.39 +import com.sun.xml.internal.org.jvnet.mimepull.MIMEMessage; 1.40 +import com.sun.xml.internal.org.jvnet.mimepull.MIMEPart; 1.41 + 1.42 +/** 1.43 + * 1.44 + * @author Kumar 1.45 + */ 1.46 +public class MimePullMultipart extends MimeMultipart { 1.47 + 1.48 + private InputStream in = null; 1.49 + private String boundary = null; 1.50 + private MIMEMessage mm = null; 1.51 + private DataSource dataSource = null; 1.52 + private ContentType contType = null; 1.53 + private String startParam = null; 1.54 + private MIMEPart soapPart = null; 1.55 + 1.56 + public MimePullMultipart(DataSource ds, ContentType ct) 1.57 + throws MessagingException { 1.58 + parsed = false; 1.59 + if (ct==null) 1.60 + contType = new ContentType(ds.getContentType()); 1.61 + else 1.62 + contType = ct; 1.63 + 1.64 + dataSource = ds; 1.65 + boundary = contType.getParameter("boundary"); 1.66 + } 1.67 + 1.68 + public MIMEPart readAndReturnSOAPPart() throws MessagingException { 1.69 + if (soapPart != null) { 1.70 + throw new MessagingException("Inputstream from datasource was already consumed"); 1.71 + } 1.72 + readSOAPPart(); 1.73 + return soapPart; 1.74 + 1.75 + } 1.76 + 1.77 + protected void readSOAPPart() throws MessagingException { 1.78 + try { 1.79 + if (soapPart != null) { 1.80 + return; 1.81 + } 1.82 + in = dataSource.getInputStream(); 1.83 + MIMEConfig config = new MIMEConfig(); //use defaults 1.84 + mm = new MIMEMessage(in, boundary, config); 1.85 + String st = contType.getParameter("start"); 1.86 + if(startParam == null) { 1.87 + soapPart = mm.getPart(0); 1.88 + } else { 1.89 + // Strip <...> from root part's Content-I 1.90 + if (st != null && st.length() > 2 && st.charAt(0) == '<' && st.charAt(st.length()-1) == '>') { 1.91 + st = st.substring(1, st.length()-1); 1.92 + } 1.93 + startParam = st; 1.94 + soapPart = mm.getPart(startParam); 1.95 + 1.96 + } 1.97 + } catch (IOException ex) { 1.98 + throw new MessagingException("No inputstream from datasource", ex); 1.99 + } 1.100 + } 1.101 + 1.102 + public void parseAll() throws MessagingException { 1.103 + if (parsed) { 1.104 + return; 1.105 + } 1.106 + if (soapPart == null) { 1.107 + readSOAPPart(); 1.108 + } 1.109 + 1.110 + List<MIMEPart> prts = mm.getAttachments(); 1.111 + for(MIMEPart part : prts) { 1.112 + if (part != soapPart) { 1.113 + AttachmentPart attach = new AttachmentPartImpl(part); 1.114 + this.addBodyPart(new MimeBodyPart(part)); 1.115 + } 1.116 + } 1.117 + parsed = true; 1.118 + } 1.119 + 1.120 + protected void parse() throws MessagingException { 1.121 + parseAll(); 1.122 + } 1.123 + 1.124 +}