View Javadoc

1   /*
2    * Copyright 2006 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.soap.saaj;
18  
19  import java.io.IOException;
20  import java.io.InputStream;
21  import javax.activation.DataHandler;
22  import javax.xml.soap.AttachmentPart;
23  import javax.xml.soap.SOAPException;
24  
25  import org.springframework.util.Assert;
26  import org.springframework.ws.mime.Attachment;
27  
28  /**
29   * SAAJ-specific implementation of the <code>Attachment</code> interface. Wraps a {@link
30   * javax.xml.soap.AttachmentPart}.
31   *
32   * @author Arjen Poutsma
33   * @since 1.0.0
34   */
35  class SaajAttachment implements Attachment {
36  
37      private final AttachmentPart saajAttachment;
38  
39      public SaajAttachment(AttachmentPart saajAttachment) {
40          Assert.notNull(saajAttachment, "saajAttachment must not be null");
41          this.saajAttachment = saajAttachment;
42      }
43  
44      public String getContentId() {
45          return saajAttachment.getContentId();
46      }
47  
48      public String getContentType() {
49          return saajAttachment.getContentType();
50      }
51  
52      public InputStream getInputStream() throws IOException {
53          try {
54              return saajAttachment.getDataHandler().getInputStream();
55          }
56          catch (SOAPException ex) {
57              throw new SaajAttachmentException(ex);
58          }
59      }
60  
61      public long getSize() {
62          try {
63              return saajAttachment.getSize();
64          }
65          catch (SOAPException ex) {
66              throw new SaajAttachmentException(ex);
67          }
68      }
69  
70      public DataHandler getDataHandler() {
71          try {
72              return saajAttachment.getDataHandler();
73          }
74          catch (SOAPException ex) {
75              throw new SaajAttachmentException(ex);
76          }
77      }
78  }