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
475 * <p/>
476 * <p/>
477 * This method creates a new {@link com.sun.xml.internal.ws.api.message.Message} whose header/payload/attachments/properties
478 * are identical to this {@link com.sun.xml.internal.ws.api.message.Message}. Once created, the created {@link com.sun.xml.internal.ws.api.message.Message}
479 * and the original {@link com.sun.xml.internal.ws.api.message.Message} behaves independently --- adding header/
480 * attachment to one {@link com.sun.xml.internal.ws.api.message.Message} doesn't affect another {@link com.sun.xml.internal.ws.api.message.Message}
481 * at all.
482 * <p/>
483 * <h3>Design Rationale</h3>
484 * <p/>
485 * Since a {@link com.sun.xml.internal.ws.api.message.Message} body is read-once, sometimes
486 * (such as when you do fail-over, or WS-RM) you need to
487 * create an idential copy of a {@link com.sun.xml.internal.ws.api.message.Message}.
488 * <p/>
489 * <p/>
490 * The actual copy operation depends on the layout
491 * of the data in memory, hence it's best to be done by
492 * the {@link com.sun.xml.internal.ws.api.message.Message} implementation itself.
493 */
494 public Message copy() {
495 try {
496 if (!parsedMessage) {
497 return new SAAJMessage(readAsSOAPMessage());
498 } else {
499 SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
500 SOAPBody newBody = msg.getSOAPPart().getEnvelope().getBody();
501 for (Element part : bodyParts) {
502 Node n = newBody.getOwnerDocument().importNode(part, true);
503 newBody.appendChild(n);
504 }
505 addAttributes(newBody, bodyAttrs);
506 return new SAAJMessage(getHeaders(), getAttachments(), msg, soapVersion);
507 }
508 } catch (SOAPException e) {
509 throw new WebServiceException(e);
510 }
511 }
512 private static final AttributesImpl EMPTY_ATTS = new AttributesImpl();
513 private static final LocatorImpl NULL_LOCATOR = new LocatorImpl();
514
515 protected static class SAAJAttachment implements AttachmentEx {
516
517 final AttachmentPart ap;
518
519 String contentIdNoAngleBracket;
520
521 public SAAJAttachment(AttachmentPart part) {
522 this.ap = part;
523 }
524
525 /**
526 * Content ID of the attachment. Uniquely identifies an attachment.
527 */
|
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
475 * <p/>
476 * <p/>
477 * This method creates a new {@link com.sun.xml.internal.ws.api.message.Message} whose header/payload/attachments/properties
478 * are identical to this {@link com.sun.xml.internal.ws.api.message.Message}. Once created, the created {@link com.sun.xml.internal.ws.api.message.Message}
479 * and the original {@link com.sun.xml.internal.ws.api.message.Message} behaves independently --- adding header/
480 * attachment to one {@link com.sun.xml.internal.ws.api.message.Message} doesn't affect another {@link com.sun.xml.internal.ws.api.message.Message}
481 * at all.
482 * <p/>
483 * <h3>Design Rationale</h3>
484 * <p/>
485 * Since a {@link com.sun.xml.internal.ws.api.message.Message} body is read-once, sometimes
486 * (such as when you do fail-over, or WS-RM) you need to
487 * create an idential copy of a {@link com.sun.xml.internal.ws.api.message.Message}.
488 * <p/>
489 * <p/>
490 * The actual copy operation depends on the layout
491 * of the data in memory, hence it's best to be done by
492 * the {@link com.sun.xml.internal.ws.api.message.Message} implementation itself.
493 */
494 public Message copy() {
495 Message result = null;
496 try {
497 access();
498 if (!parsedMessage) {
499 result = new SAAJMessage(readAsSOAPMessage());
500 } else {
501 SOAPMessage msg = soapVersion.getMessageFactory().createMessage();
502 SOAPBody newBody = msg.getSOAPPart().getEnvelope().getBody();
503 for (Element part : bodyParts) {
504 Node n = newBody.getOwnerDocument().importNode(part, true);
505 newBody.appendChild(n);
506 }
507 addAttributes(newBody, bodyAttrs);
508 result = new SAAJMessage(getHeaders(), getAttachments(), msg, soapVersion);
509 }
510 return result.copyFrom(this);
511 } catch (SOAPException e) {
512 throw new WebServiceException(e);
513 }
514 }
515 private static final AttributesImpl EMPTY_ATTS = new AttributesImpl();
516 private static final LocatorImpl NULL_LOCATOR = new LocatorImpl();
517
518 protected static class SAAJAttachment implements AttachmentEx {
519
520 final AttachmentPart ap;
521
522 String contentIdNoAngleBracket;
523
524 public SAAJAttachment(AttachmentPart part) {
525 this.ap = part;
526 }
527
528 /**
529 * Content ID of the attachment. Uniquely identifies an attachment.
530 */
|