src/share/jaxws_classes/com/sun/xml/internal/ws/encoding/MimeCodec.java

Print this page
rev 472 : 8036030: Update JAX-WS RI integration to latest version
   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 101         this.features = f;
 102     }
 103 
 104     public String getMimeType() {
 105         return MULTIPART_RELATED_MIME_TYPE;
 106     }
 107 
 108     protected Codec getMimeRootCodec(Packet packet) {
 109         return mimeRootCodec;
 110     }
 111 
 112     // TODO: preencode String literals to byte[] so that they don't have to
 113     // go through char[]->byte[] conversion at runtime.
 114     public ContentType encode(Packet packet, OutputStream out) throws IOException {
 115         Message msg = packet.getMessage();
 116         if (msg == null) {
 117             return null;
 118         }
 119         ContentTypeImpl ctImpl = (ContentTypeImpl)getStaticContentType(packet);
 120         String boundary = ctImpl.getBoundary();

 121         boolean hasAttachments = (boundary != null);
 122         Codec rootCodec = getMimeRootCodec(packet);
 123         if (hasAttachments) {
 124             writeln("--"+boundary, out);
 125             ContentType ct = rootCodec.getStaticContentType(packet);
 126             String ctStr = (ct != null) ? ct.getContentType() : rootCodec.getMimeType();

 127             writeln("Content-Type: " + ctStr, out);
 128             writeln(out);
 129         }
 130         ContentType primaryCt = rootCodec.encode(packet, out);
 131 
 132         if (hasAttachments) {
 133             writeln(out);
 134             // Encode all the attchments
 135             for (Attachment att : msg.getAttachments()) {
 136                 writeln("--"+boundary, out);
 137                 //SAAJ's AttachmentPart.getContentId() returns content id already enclosed with
 138                 //angle brackets. For now put angle bracket only if its not there
 139                 String cid = att.getContentId();
 140                 if(cid != null && cid.length() >0 && cid.charAt(0) != '<')
 141                     cid = '<' + cid + '>';
 142                 writeln("Content-Id:" + cid, out);
 143                 writeln("Content-Type: " + att.getContentType(), out);
 144                 writeCustomMimeHeaders(att, out);
 145                 writeln("Content-Transfer-Encoding: binary", out);
 146                 writeln(out);                    // write \r\n


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 101         this.features = f;
 102     }
 103 
 104     public String getMimeType() {
 105         return MULTIPART_RELATED_MIME_TYPE;
 106     }
 107 
 108     protected Codec getMimeRootCodec(Packet packet) {
 109         return mimeRootCodec;
 110     }
 111 
 112     // TODO: preencode String literals to byte[] so that they don't have to
 113     // go through char[]->byte[] conversion at runtime.
 114     public ContentType encode(Packet packet, OutputStream out) throws IOException {
 115         Message msg = packet.getMessage();
 116         if (msg == null) {
 117             return null;
 118         }
 119         ContentTypeImpl ctImpl = (ContentTypeImpl)getStaticContentType(packet);
 120         String boundary = ctImpl.getBoundary();
 121         String rootId = ctImpl.getRootId();
 122         boolean hasAttachments = (boundary != null);
 123         Codec rootCodec = getMimeRootCodec(packet);
 124         if (hasAttachments) {
 125             writeln("--"+boundary, out);
 126             ContentType ct = rootCodec.getStaticContentType(packet);
 127             String ctStr = (ct != null) ? ct.getContentType() : rootCodec.getMimeType();
 128             if (rootId != null) writeln("Content-ID: " + rootId, out);
 129             writeln("Content-Type: " + ctStr, out);
 130             writeln(out);
 131         }
 132         ContentType primaryCt = rootCodec.encode(packet, out);
 133 
 134         if (hasAttachments) {
 135             writeln(out);
 136             // Encode all the attchments
 137             for (Attachment att : msg.getAttachments()) {
 138                 writeln("--"+boundary, out);
 139                 //SAAJ's AttachmentPart.getContentId() returns content id already enclosed with
 140                 //angle brackets. For now put angle bracket only if its not there
 141                 String cid = att.getContentId();
 142                 if(cid != null && cid.length() >0 && cid.charAt(0) != '<')
 143                     cid = '<' + cid + '>';
 144                 writeln("Content-Id:" + cid, out);
 145                 writeln("Content-Type: " + att.getContentType(), out);
 146                 writeCustomMimeHeaders(att, out);
 147                 writeln("Content-Transfer-Encoding: binary", out);
 148                 writeln(out);                    // write \r\n