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/soap/AttachmentPartImpl.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,611 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, 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.soap; 1.30 + 1.31 +import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl; 1.32 + 1.33 +import com.sun.xml.internal.messaging.saaj.packaging.mime.util.ASCIIUtility; 1.34 + 1.35 +import com.sun.xml.internal.messaging.saaj.packaging.mime.Header; 1.36 +import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimePartDataSource; 1.37 +import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.InternetHeaders; 1.38 +import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeBodyPart; 1.39 +import com.sun.xml.internal.messaging.saaj.packaging.mime.internet.MimeUtility; 1.40 +import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; 1.41 +import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants; 1.42 + 1.43 +import java.io.IOException; 1.44 +import java.io.InputStream; 1.45 +import java.io.ByteArrayOutputStream; 1.46 +import java.io.ByteArrayInputStream; 1.47 +import java.io.OutputStream; 1.48 +import java.util.Iterator; 1.49 +import java.util.List; 1.50 +import java.util.logging.Level; 1.51 +import java.util.logging.Logger; 1.52 + 1.53 +import javax.activation.*; 1.54 +import javax.xml.soap.*; 1.55 +import com.sun.xml.internal.org.jvnet.mimepull.MIMEPart; 1.56 + 1.57 +/** 1.58 + * Implementation of attachments. 1.59 + * 1.60 + * @author Anil Vijendran (akv@eng.sun.com) 1.61 + */ 1.62 +public class AttachmentPartImpl extends AttachmentPart { 1.63 + 1.64 + protected static final Logger log = 1.65 + Logger.getLogger(LogDomainConstants.SOAP_DOMAIN, 1.66 + "com.sun.xml.internal.messaging.saaj.soap.LocalStrings"); 1.67 + 1.68 + static { 1.69 + try { 1.70 + CommandMap map = CommandMap.getDefaultCommandMap(); 1.71 + if (map instanceof MailcapCommandMap) { 1.72 + MailcapCommandMap mailMap = (MailcapCommandMap) map; 1.73 + String hndlrStr = ";;x-java-content-handler="; 1.74 + mailMap.addMailcap( 1.75 + "text/xml" 1.76 + + hndlrStr 1.77 + + "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler"); 1.78 + mailMap.addMailcap( 1.79 + "application/xml" 1.80 + + hndlrStr 1.81 + + "com.sun.xml.internal.messaging.saaj.soap.XmlDataContentHandler"); 1.82 + mailMap.addMailcap( 1.83 + "application/fastinfoset" 1.84 + + hndlrStr 1.85 + + "com.sun.xml.internal.messaging.saaj.soap.FastInfosetDataContentHandler"); 1.86 + /* Image DataContentHandler handles all image types 1.87 + mailMap.addMailcap( 1.88 + "image/jpeg" 1.89 + + hndlrStr 1.90 + + "com.sun.xml.internal.messaging.saaj.soap.JpegDataContentHandler"); 1.91 + mailMap.addMailcap( 1.92 + "image/gif" 1.93 + + hndlrStr 1.94 + + "com.sun.xml.internal.messaging.saaj.soap.GifDataContentHandler"); */ 1.95 + /*mailMap.addMailcap( 1.96 + "multipart/*" 1.97 + + hndlrStr 1.98 + + "com.sun.xml.internal.messaging.saaj.soap.MultipartDataContentHandler");*/ 1.99 + mailMap.addMailcap( 1.100 + "image/*" 1.101 + + hndlrStr 1.102 + + "com.sun.xml.internal.messaging.saaj.soap.ImageDataContentHandler"); 1.103 + mailMap.addMailcap( 1.104 + "text/plain" 1.105 + + hndlrStr 1.106 + + "com.sun.xml.internal.messaging.saaj.soap.StringDataContentHandler"); 1.107 + } else { 1.108 + throw new SOAPExceptionImpl("Default CommandMap is not a MailcapCommandMap"); 1.109 + } 1.110 + } catch (Throwable t) { 1.111 + log.log( 1.112 + Level.SEVERE, 1.113 + "SAAJ0508.soap.cannot.register.handlers", 1.114 + t); 1.115 + if (t instanceof RuntimeException) { 1.116 + throw (RuntimeException) t; 1.117 + } else { 1.118 + throw new RuntimeException(t.getLocalizedMessage()); 1.119 + } 1.120 + } 1.121 + }; 1.122 + 1.123 + private final MimeHeaders headers; 1.124 + private MimeBodyPart rawContent = null; 1.125 + private DataHandler dataHandler = null; 1.126 + 1.127 + //alternate impl that uses a MIMEPart 1.128 + private MIMEPart mimePart = null; 1.129 + 1.130 + public AttachmentPartImpl() { 1.131 + headers = new MimeHeaders(); 1.132 + } 1.133 + 1.134 + public AttachmentPartImpl(MIMEPart part) { 1.135 + headers = new MimeHeaders(); 1.136 + mimePart = part; 1.137 + List<? extends com.sun.xml.internal.org.jvnet.mimepull.Header> hdrs = part.getAllHeaders(); 1.138 + for (com.sun.xml.internal.org.jvnet.mimepull.Header hd : hdrs) { 1.139 + headers.addHeader(hd.getName(), hd.getValue()); 1.140 + } 1.141 + } 1.142 + 1.143 + public int getSize() throws SOAPException { 1.144 + byte[] bytes; 1.145 + if (mimePart != null) { 1.146 + try { 1.147 + return mimePart.read().available(); 1.148 + } catch (IOException e) { 1.149 + return -1; 1.150 + } 1.151 + } 1.152 + if ((rawContent == null) && (dataHandler == null)) 1.153 + return 0; 1.154 + 1.155 + if (rawContent != null) { 1.156 + try { 1.157 + return rawContent.getSize(); 1.158 + } catch (Exception ex) { 1.159 + log.log( 1.160 + Level.SEVERE, 1.161 + "SAAJ0573.soap.attachment.getrawbytes.ioexception", 1.162 + new String[] { ex.getLocalizedMessage()}); 1.163 + throw new SOAPExceptionImpl("Raw InputStream Error: " + ex); 1.164 + } 1.165 + } else { 1.166 + ByteOutputStream bout = new ByteOutputStream(); 1.167 + try { 1.168 + dataHandler.writeTo(bout); 1.169 + } catch (IOException ex) { 1.170 + log.log( 1.171 + Level.SEVERE, 1.172 + "SAAJ0501.soap.data.handler.err", 1.173 + new String[] { ex.getLocalizedMessage()}); 1.174 + throw new SOAPExceptionImpl("Data handler error: " + ex); 1.175 + } 1.176 + return bout.size(); 1.177 + } 1.178 + } 1.179 + 1.180 + public void clearContent() { 1.181 + if (mimePart != null) { 1.182 + mimePart.close(); 1.183 + mimePart = null; 1.184 + } 1.185 + dataHandler = null; 1.186 + rawContent = null; 1.187 + } 1.188 + 1.189 + public Object getContent() throws SOAPException { 1.190 + try { 1.191 + if (mimePart != null) { 1.192 + //return an inputstream 1.193 + return mimePart.read(); 1.194 + } 1.195 + if (dataHandler != null) { 1.196 + return getDataHandler().getContent(); 1.197 + } else if (rawContent != null) { 1.198 + return rawContent.getContent(); 1.199 + } else { 1.200 + log.severe("SAAJ0572.soap.no.content.for.attachment"); 1.201 + throw new SOAPExceptionImpl("No data handler/content associated with this attachment"); 1.202 + } 1.203 + } catch (Exception ex) { 1.204 + log.log(Level.SEVERE, "SAAJ0575.soap.attachment.getcontent.exception", ex); 1.205 + throw new SOAPExceptionImpl(ex.getLocalizedMessage()); 1.206 + } 1.207 + } 1.208 + 1.209 + public void setContent(Object object, String contentType) 1.210 + throws IllegalArgumentException { 1.211 + if (mimePart != null) { 1.212 + mimePart.close(); 1.213 + mimePart = null; 1.214 + } 1.215 + DataHandler dh = new DataHandler(object, contentType); 1.216 + 1.217 + setDataHandler(dh); 1.218 + } 1.219 + 1.220 + 1.221 + public DataHandler getDataHandler() throws SOAPException { 1.222 + if (mimePart != null) { 1.223 + //return an inputstream 1.224 + return new DataHandler(new DataSource() { 1.225 + 1.226 + public InputStream getInputStream() throws IOException { 1.227 + return mimePart.read(); 1.228 + } 1.229 + 1.230 + public OutputStream getOutputStream() throws IOException { 1.231 + throw new UnsupportedOperationException("getOutputStream cannot be supported : You have enabled LazyAttachments Option"); 1.232 + } 1.233 + 1.234 + public String getContentType() { 1.235 + return mimePart.getContentType(); 1.236 + } 1.237 + 1.238 + public String getName() { 1.239 + return "MIMEPart Wrapper DataSource"; 1.240 + } 1.241 + }); 1.242 + } 1.243 + if (dataHandler == null) { 1.244 + if (rawContent != null) { 1.245 + return new DataHandler(new MimePartDataSource(rawContent)); 1.246 + } 1.247 + log.severe("SAAJ0502.soap.no.handler.for.attachment"); 1.248 + throw new SOAPExceptionImpl("No data handler associated with this attachment"); 1.249 + } 1.250 + return dataHandler; 1.251 + } 1.252 + 1.253 + public void setDataHandler(DataHandler dataHandler) 1.254 + throws IllegalArgumentException { 1.255 + if (mimePart != null) { 1.256 + mimePart.close(); 1.257 + mimePart = null; 1.258 + } 1.259 + if (dataHandler == null) { 1.260 + log.severe("SAAJ0503.soap.no.null.to.dataHandler"); 1.261 + throw new IllegalArgumentException("Null dataHandler argument to setDataHandler"); 1.262 + } 1.263 + this.dataHandler = dataHandler; 1.264 + rawContent = null; 1.265 + 1.266 + log.log( 1.267 + Level.FINE, 1.268 + "SAAJ0580.soap.set.Content-Type", 1.269 + new String[] { dataHandler.getContentType()}); 1.270 + setMimeHeader("Content-Type", dataHandler.getContentType()); 1.271 + } 1.272 + 1.273 + public void removeAllMimeHeaders() { 1.274 + headers.removeAllHeaders(); 1.275 + } 1.276 + 1.277 + public void removeMimeHeader(String header) { 1.278 + headers.removeHeader(header); 1.279 + } 1.280 + 1.281 + public String[] getMimeHeader(String name) { 1.282 + return headers.getHeader(name); 1.283 + } 1.284 + 1.285 + public void setMimeHeader(String name, String value) { 1.286 + headers.setHeader(name, value); 1.287 + } 1.288 + 1.289 + public void addMimeHeader(String name, String value) { 1.290 + headers.addHeader(name, value); 1.291 + } 1.292 + 1.293 + public Iterator getAllMimeHeaders() { 1.294 + return headers.getAllHeaders(); 1.295 + } 1.296 + 1.297 + public Iterator getMatchingMimeHeaders(String[] names) { 1.298 + return headers.getMatchingHeaders(names); 1.299 + } 1.300 + 1.301 + public Iterator getNonMatchingMimeHeaders(String[] names) { 1.302 + return headers.getNonMatchingHeaders(names); 1.303 + } 1.304 + 1.305 + boolean hasAllHeaders(MimeHeaders hdrs) { 1.306 + if (hdrs != null) { 1.307 + Iterator i = hdrs.getAllHeaders(); 1.308 + while (i.hasNext()) { 1.309 + MimeHeader hdr = (MimeHeader) i.next(); 1.310 + String[] values = headers.getHeader(hdr.getName()); 1.311 + boolean found = false; 1.312 + 1.313 + if (values != null) { 1.314 + for (int j = 0; j < values.length; j++) 1.315 + if (hdr.getValue().equalsIgnoreCase(values[j])) { 1.316 + found = true; 1.317 + break; 1.318 + } 1.319 + } 1.320 + 1.321 + if (!found) { 1.322 + return false; 1.323 + } 1.324 + } 1.325 + } 1.326 + return true; 1.327 + } 1.328 + 1.329 + MimeBodyPart getMimePart() throws SOAPException { 1.330 + try { 1.331 + if (this.mimePart != null) { 1.332 + return new MimeBodyPart(mimePart); 1.333 + } 1.334 + if (rawContent != null) { 1.335 + copyMimeHeaders(headers, rawContent); 1.336 + return rawContent; 1.337 + } 1.338 + 1.339 + MimeBodyPart envelope = new MimeBodyPart(); 1.340 + 1.341 + envelope.setDataHandler(dataHandler); 1.342 + copyMimeHeaders(headers, envelope); 1.343 + 1.344 + return envelope; 1.345 + } catch (Exception ex) { 1.346 + log.severe("SAAJ0504.soap.cannot.externalize.attachment"); 1.347 + throw new SOAPExceptionImpl("Unable to externalize attachment", ex); 1.348 + } 1.349 + } 1.350 + 1.351 + public static void copyMimeHeaders(MimeHeaders headers, MimeBodyPart mbp) 1.352 + throws SOAPException { 1.353 + 1.354 + Iterator i = headers.getAllHeaders(); 1.355 + 1.356 + while (i.hasNext()) 1.357 + try { 1.358 + MimeHeader mh = (MimeHeader) i.next(); 1.359 + 1.360 + mbp.setHeader(mh.getName(), mh.getValue()); 1.361 + } catch (Exception ex) { 1.362 + log.severe("SAAJ0505.soap.cannot.copy.mime.hdr"); 1.363 + throw new SOAPExceptionImpl("Unable to copy MIME header", ex); 1.364 + } 1.365 + } 1.366 + 1.367 + public static void copyMimeHeaders(MimeBodyPart mbp, AttachmentPartImpl ap) 1.368 + throws SOAPException { 1.369 + try { 1.370 + List hdr = mbp.getAllHeaders(); 1.371 + int sz = hdr.size(); 1.372 + for( int i=0; i<sz; i++ ) { 1.373 + Header h = (Header)hdr.get(i); 1.374 + if(h.getName().equalsIgnoreCase("Content-Type")) 1.375 + continue; // skip 1.376 + ap.addMimeHeader(h.getName(), h.getValue()); 1.377 + } 1.378 + } catch (Exception ex) { 1.379 + log.severe("SAAJ0506.soap.cannot.copy.mime.hdrs.into.attachment"); 1.380 + throw new SOAPExceptionImpl( 1.381 + "Unable to copy MIME headers into attachment", 1.382 + ex); 1.383 + } 1.384 + } 1.385 + 1.386 + public void setBase64Content(InputStream content, String contentType) 1.387 + throws SOAPException { 1.388 + 1.389 + if (mimePart != null) { 1.390 + mimePart.close(); 1.391 + mimePart = null; 1.392 + } 1.393 + dataHandler = null; 1.394 + InputStream decoded = null; 1.395 + try { 1.396 + decoded = MimeUtility.decode(content, "base64"); 1.397 + InternetHeaders hdrs = new InternetHeaders(); 1.398 + hdrs.setHeader("Content-Type", contentType); 1.399 + //TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart 1.400 + // Ctor with inputStream causes problems based on the InputStream 1.401 + // has markSupported()==true 1.402 + ByteOutputStream bos = new ByteOutputStream(); 1.403 + bos.write(decoded); 1.404 + rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount()); 1.405 + setMimeHeader("Content-Type", contentType); 1.406 + } catch (Exception e) { 1.407 + log.log(Level.SEVERE, "SAAJ0578.soap.attachment.setbase64content.exception", e); 1.408 + throw new SOAPExceptionImpl(e.getLocalizedMessage()); 1.409 + } finally { 1.410 + try { 1.411 + decoded.close(); 1.412 + } catch (IOException ex) { 1.413 + throw new SOAPException(ex); 1.414 + } 1.415 + } 1.416 + } 1.417 + 1.418 + public InputStream getBase64Content() throws SOAPException { 1.419 + InputStream stream; 1.420 + if (mimePart != null) { 1.421 + stream = mimePart.read(); 1.422 + } else if (rawContent != null) { 1.423 + try { 1.424 + stream = rawContent.getInputStream(); 1.425 + } catch (Exception e) { 1.426 + log.log(Level.SEVERE,"SAAJ0579.soap.attachment.getbase64content.exception", e); 1.427 + throw new SOAPExceptionImpl(e.getLocalizedMessage()); 1.428 + } 1.429 + } else if (dataHandler != null) { 1.430 + try { 1.431 + stream = dataHandler.getInputStream(); 1.432 + } catch (IOException e) { 1.433 + log.severe("SAAJ0574.soap.attachment.datahandler.ioexception"); 1.434 + throw new SOAPExceptionImpl("DataHandler error" + e); 1.435 + } 1.436 + } else { 1.437 + log.severe("SAAJ0572.soap.no.content.for.attachment"); 1.438 + throw new SOAPExceptionImpl("No data handler/content associated with this attachment"); 1.439 + } 1.440 + 1.441 + //TODO: Write a BASE64EncoderInputStream instead, 1.442 + // this code below is inefficient 1.443 + // where we are trying to read the whole attachment first 1.444 + int len; 1.445 + int size = 1024; 1.446 + byte [] buf; 1.447 + if (stream != null) { 1.448 + try { 1.449 + ByteArrayOutputStream bos = new ByteArrayOutputStream(size); 1.450 + //TODO: try and optimize this on the same lines as 1.451 + // ByteOutputStream : to eliminate the temp buffer here 1.452 + OutputStream ret = MimeUtility.encode(bos, "base64"); 1.453 + buf = new byte[size]; 1.454 + while ((len = stream.read(buf, 0, size)) != -1) { 1.455 + ret.write(buf, 0, len); 1.456 + } 1.457 + ret.flush(); 1.458 + buf = bos.toByteArray(); 1.459 + return new ByteArrayInputStream(buf); 1.460 + } catch (Exception e) { 1.461 + // throw new SOAPException 1.462 + log.log(Level.SEVERE,"SAAJ0579.soap.attachment.getbase64content.exception", e); 1.463 + throw new SOAPExceptionImpl(e.getLocalizedMessage()); 1.464 + } finally { 1.465 + try { 1.466 + stream.close(); 1.467 + } catch (IOException ex) { 1.468 + //close the stream 1.469 + } 1.470 + } 1.471 + } else { 1.472 + //throw new SOAPException 1.473 + log.log(Level.SEVERE,"SAAJ0572.soap.no.content.for.attachment"); 1.474 + throw new SOAPExceptionImpl("No data handler/content associated with this attachment"); 1.475 + } 1.476 + } 1.477 + 1.478 + public void setRawContent(InputStream content, String contentType) 1.479 + throws SOAPException { 1.480 + if (mimePart != null) { 1.481 + mimePart.close(); 1.482 + mimePart = null; 1.483 + } 1.484 + dataHandler = null; 1.485 + try { 1.486 + InternetHeaders hdrs = new InternetHeaders(); 1.487 + hdrs.setHeader("Content-Type", contentType); 1.488 + //TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart 1.489 + // Ctor with inputStream causes problems based on whether the InputStream has 1.490 + // markSupported()==true or false 1.491 + ByteOutputStream bos = new ByteOutputStream(); 1.492 + bos.write(content); 1.493 + rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount()); 1.494 + setMimeHeader("Content-Type", contentType); 1.495 + } catch (Exception e) { 1.496 + log.log(Level.SEVERE, "SAAJ0576.soap.attachment.setrawcontent.exception", e); 1.497 + throw new SOAPExceptionImpl(e.getLocalizedMessage()); 1.498 + } finally { 1.499 + try { 1.500 + content.close(); 1.501 + } catch (IOException ex) { 1.502 + throw new SOAPException(ex); 1.503 + } 1.504 + } 1.505 + } 1.506 + 1.507 + /* 1.508 + public void setRawContentBytes(byte[] content, String contentType) 1.509 + throws SOAPException { 1.510 + if (content == null) { 1.511 + throw new SOAPExceptionImpl("Null content passed to setRawContentBytes"); 1.512 + } 1.513 + dataHandler = null; 1.514 + try { 1.515 + InternetHeaders hdrs = new InternetHeaders(); 1.516 + hdrs.setHeader("Content-Type", contentType); 1.517 + rawContent = new MimeBodyPart(hdrs, content, content.length); 1.518 + setMimeHeader("Content-Type", contentType); 1.519 + } catch (Exception e) { 1.520 + log.log(Level.SEVERE, "SAAJ0576.soap.attachment.setrawcontent.exception", e); 1.521 + throw new SOAPExceptionImpl(e.getLocalizedMessage()); 1.522 + } 1.523 + } */ 1.524 + 1.525 + public void setRawContentBytes( 1.526 + byte[] content, int off, int len, String contentType) 1.527 + throws SOAPException { 1.528 + if (mimePart != null) { 1.529 + mimePart.close(); 1.530 + mimePart = null; 1.531 + } 1.532 + if (content == null) { 1.533 + throw new SOAPExceptionImpl("Null content passed to setRawContentBytes"); 1.534 + } 1.535 + dataHandler = null; 1.536 + try { 1.537 + InternetHeaders hdrs = new InternetHeaders(); 1.538 + hdrs.setHeader("Content-Type", contentType); 1.539 + rawContent = new MimeBodyPart(hdrs, content, off, len); 1.540 + setMimeHeader("Content-Type", contentType); 1.541 + } catch (Exception e) { 1.542 + log.log(Level.SEVERE, 1.543 + "SAAJ0576.soap.attachment.setrawcontent.exception", e); 1.544 + throw new SOAPExceptionImpl(e.getLocalizedMessage()); 1.545 + } 1.546 + } 1.547 + 1.548 + public InputStream getRawContent() throws SOAPException { 1.549 + if (mimePart != null) { 1.550 + return mimePart.read(); 1.551 + } 1.552 + if (rawContent != null) { 1.553 + try { 1.554 + return rawContent.getInputStream(); 1.555 + } catch (Exception e) { 1.556 + log.log(Level.SEVERE,"SAAJ0577.soap.attachment.getrawcontent.exception", e); 1.557 + throw new SOAPExceptionImpl(e.getLocalizedMessage()); 1.558 + } 1.559 + } else if (dataHandler != null) { 1.560 + try { 1.561 + return dataHandler.getInputStream(); 1.562 + } catch (IOException e) { 1.563 + log.severe("SAAJ0574.soap.attachment.datahandler.ioexception"); 1.564 + throw new SOAPExceptionImpl("DataHandler error" + e); 1.565 + } 1.566 + } else { 1.567 + log.severe("SAAJ0572.soap.no.content.for.attachment"); 1.568 + throw new SOAPExceptionImpl("No data handler/content associated with this attachment"); 1.569 + } 1.570 + } 1.571 + 1.572 + public byte[] getRawContentBytes() throws SOAPException { 1.573 + InputStream ret; 1.574 + if (mimePart != null) { 1.575 + try { 1.576 + ret = mimePart.read(); 1.577 + return ASCIIUtility.getBytes(ret); 1.578 + } catch (IOException ex) { 1.579 + log.log(Level.SEVERE,"SAAJ0577.soap.attachment.getrawcontent.exception", ex); 1.580 + throw new SOAPExceptionImpl(ex); 1.581 + } 1.582 + } 1.583 + if (rawContent != null) { 1.584 + try { 1.585 + ret = rawContent.getInputStream(); 1.586 + return ASCIIUtility.getBytes(ret); 1.587 + } catch (Exception e) { 1.588 + log.log(Level.SEVERE,"SAAJ0577.soap.attachment.getrawcontent.exception", e); 1.589 + throw new SOAPExceptionImpl(e); 1.590 + } 1.591 + } else if (dataHandler != null) { 1.592 + try { 1.593 + ret = dataHandler.getInputStream(); 1.594 + return ASCIIUtility.getBytes(ret); 1.595 + } catch (IOException e) { 1.596 + log.severe("SAAJ0574.soap.attachment.datahandler.ioexception"); 1.597 + throw new SOAPExceptionImpl("DataHandler error" + e); 1.598 + } 1.599 + } else { 1.600 + log.severe("SAAJ0572.soap.no.content.for.attachment"); 1.601 + throw new SOAPExceptionImpl("No data handler/content associated with this attachment"); 1.602 + } 1.603 + } 1.604 + 1.605 + // attachments are equal if they are the same reference 1.606 + public boolean equals(Object o) { 1.607 + return (this == o); 1.608 + } 1.609 + 1.610 + public MimeHeaders getMimeHeaders() { 1.611 + return headers; 1.612 + } 1.613 + 1.614 +}