1 /*
2 * Copyright (c) 1997, 2010, 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
243 }
244 log.severe("SAAJ0502.soap.no.handler.for.attachment");
245 throw new SOAPExceptionImpl("No data handler associated with this attachment");
246 }
247 return dataHandler;
248 }
249
250 public void setDataHandler(DataHandler dataHandler)
251 throws IllegalArgumentException {
252 if (mimePart != null) {
253 mimePart.close();
254 mimePart = null;
255 }
256 if (dataHandler == null) {
257 log.severe("SAAJ0503.soap.no.null.to.dataHandler");
258 throw new IllegalArgumentException("Null dataHandler argument to setDataHandler");
259 }
260 this.dataHandler = dataHandler;
261 rawContent = null;
262
263 log.log(
264 Level.FINE,
265 "SAAJ0580.soap.set.Content-Type",
266 new String[] { dataHandler.getContentType()});
267 setMimeHeader("Content-Type", dataHandler.getContentType());
268 }
269
270 public void removeAllMimeHeaders() {
271 headers.removeAllHeaders();
272 }
273
274 public void removeMimeHeader(String header) {
275 headers.removeHeader(header);
276 }
277
278 public String[] getMimeHeader(String name) {
279 return headers.getHeader(name);
280 }
281
282 public void setMimeHeader(String name, String value) {
283 headers.setHeader(name, value);
284 }
285
286 public void addMimeHeader(String name, String value) {
585 log.log(Level.SEVERE,"SAAJ0577.soap.attachment.getrawcontent.exception", e);
586 throw new SOAPExceptionImpl(e);
587 }
588 } else if (dataHandler != null) {
589 try {
590 ret = dataHandler.getInputStream();
591 return ASCIIUtility.getBytes(ret);
592 } catch (IOException e) {
593 log.severe("SAAJ0574.soap.attachment.datahandler.ioexception");
594 throw new SOAPExceptionImpl("DataHandler error" + e);
595 }
596 } else {
597 log.severe("SAAJ0572.soap.no.content.for.attachment");
598 throw new SOAPExceptionImpl("No data handler/content associated with this attachment");
599 }
600 }
601
602 // attachments are equal if they are the same reference
603 public boolean equals(Object o) {
604 return (this == o);
605 }
606
607 public MimeHeaders getMimeHeaders() {
608 return headers;
609 }
610
611 }
|
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
243 }
244 log.severe("SAAJ0502.soap.no.handler.for.attachment");
245 throw new SOAPExceptionImpl("No data handler associated with this attachment");
246 }
247 return dataHandler;
248 }
249
250 public void setDataHandler(DataHandler dataHandler)
251 throws IllegalArgumentException {
252 if (mimePart != null) {
253 mimePart.close();
254 mimePart = null;
255 }
256 if (dataHandler == null) {
257 log.severe("SAAJ0503.soap.no.null.to.dataHandler");
258 throw new IllegalArgumentException("Null dataHandler argument to setDataHandler");
259 }
260 this.dataHandler = dataHandler;
261 rawContent = null;
262
263 if (log.isLoggable(Level.FINE))
264 log.log(Level.FINE, "SAAJ0580.soap.set.Content-Type",
265 new String[] { dataHandler.getContentType() });
266 setMimeHeader("Content-Type", dataHandler.getContentType());
267 }
268
269 public void removeAllMimeHeaders() {
270 headers.removeAllHeaders();
271 }
272
273 public void removeMimeHeader(String header) {
274 headers.removeHeader(header);
275 }
276
277 public String[] getMimeHeader(String name) {
278 return headers.getHeader(name);
279 }
280
281 public void setMimeHeader(String name, String value) {
282 headers.setHeader(name, value);
283 }
284
285 public void addMimeHeader(String name, String value) {
584 log.log(Level.SEVERE,"SAAJ0577.soap.attachment.getrawcontent.exception", e);
585 throw new SOAPExceptionImpl(e);
586 }
587 } else if (dataHandler != null) {
588 try {
589 ret = dataHandler.getInputStream();
590 return ASCIIUtility.getBytes(ret);
591 } catch (IOException e) {
592 log.severe("SAAJ0574.soap.attachment.datahandler.ioexception");
593 throw new SOAPExceptionImpl("DataHandler error" + e);
594 }
595 } else {
596 log.severe("SAAJ0572.soap.no.content.for.attachment");
597 throw new SOAPExceptionImpl("No data handler/content associated with this attachment");
598 }
599 }
600
601 // attachments are equal if they are the same reference
602 public boolean equals(Object o) {
603 return (this == o);
604 }
605
606 // In JDK 8 we get a warning if we implement equals() but not hashCode().
607 // There is no intuitive value for this, the default one in Object is fine.
608 public int hashCode() {
609 return super.hashCode();
610 }
611
612 public MimeHeaders getMimeHeaders() {
613 return headers;
614 }
615
616 }
|