Source Code Cross Referenced for SaajSoapMessage.java in  » Web-Services » spring-ws-1.0.0 » org » springframework » ws » soap » saaj » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services » spring ws 1.0.0 » org.springframework.ws.soap.saaj 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.ws.soap.saaj;
018:
019:        import java.io.IOException;
020:        import java.io.OutputStream;
021:        import java.util.Iterator;
022:        import javax.activation.DataHandler;
023:        import javax.xml.soap.AttachmentPart;
024:        import javax.xml.soap.MimeHeaders;
025:        import javax.xml.soap.SOAPBody;
026:        import javax.xml.soap.SOAPElement;
027:        import javax.xml.soap.SOAPEnvelope;
028:        import javax.xml.soap.SOAPException;
029:        import javax.xml.soap.SOAPMessage;
030:        import javax.xml.soap.SOAPPart;
031:
032:        import org.springframework.util.Assert;
033:        import org.springframework.util.ObjectUtils;
034:        import org.springframework.ws.mime.Attachment;
035:        import org.springframework.ws.mime.AttachmentException;
036:        import org.springframework.ws.soap.AbstractSoapMessage;
037:        import org.springframework.ws.soap.SoapEnvelope;
038:        import org.springframework.ws.soap.SoapMessage;
039:        import org.springframework.ws.soap.saaj.support.SaajUtils;
040:        import org.springframework.ws.transport.TransportConstants;
041:
042:        /**
043:         * SAAJ-specific implementation of the {@link SoapMessage} interface. Created via the {@link SaajSoapMessageFactory},
044:         * wraps a {@link SOAPMessage}.
045:         *
046:         * @author Arjen Poutsma
047:         * @see SOAPMessage
048:         * @since 1.0.0
049:         */
050:        public class SaajSoapMessage extends AbstractSoapMessage {
051:
052:            private SOAPMessage saajMessage;
053:
054:            private SoapEnvelope envelope;
055:
056:            private static final String CONTENT_TYPE_XOP = "application/xop+xml";
057:
058:            /**
059:             * Create a new <code>SaajSoapMessage</code> based on the given SAAJ <code>SOAPMessage</code>.
060:             *
061:             * @param soapMessage the SAAJ SOAPMessage
062:             */
063:            public SaajSoapMessage(SOAPMessage soapMessage) {
064:                Assert.notNull(soapMessage, "soapMessage must not be null");
065:                saajMessage = soapMessage;
066:            }
067:
068:            /** Return the SAAJ <code>SOAPMessage</code> that this <code>SaajSoapMessage</code> is based on. */
069:            public SOAPMessage getSaajMessage() {
070:                return saajMessage;
071:            }
072:
073:            /** Sets the SAAJ <code>SOAPMessage</code> that this <code>SaajSoapMessage</code> is based on. */
074:            public void setSaajMessage(SOAPMessage soapMessage) {
075:                Assert.notNull(soapMessage, "soapMessage must not be null");
076:                saajMessage = soapMessage;
077:            }
078:
079:            public SoapEnvelope getEnvelope() {
080:                if (envelope == null) {
081:                    try {
082:                        SOAPEnvelope saajEnvelope = getImplementation()
083:                                .getEnvelope(getSaajMessage());
084:                        envelope = new SaajSoapEnvelope(saajEnvelope);
085:                    } catch (SOAPException ex) {
086:                        throw new SaajSoapEnvelopeException(ex);
087:                    }
088:                }
089:                return envelope;
090:            }
091:
092:            public String getSoapAction() {
093:                MimeHeaders mimeHeaders = getImplementation().getMimeHeaders(
094:                        getSaajMessage());
095:                String[] values = mimeHeaders
096:                        .getHeader(TransportConstants.HEADER_SOAP_ACTION);
097:                return ObjectUtils.isEmpty(values) ? null : values[0];
098:            }
099:
100:            public void setSoapAction(String soapAction) {
101:                MimeHeaders mimeHeaders = getImplementation().getMimeHeaders(
102:                        getSaajMessage());
103:                mimeHeaders.setHeader(TransportConstants.HEADER_SOAP_ACTION,
104:                        soapAction);
105:            }
106:
107:            public void writeTo(OutputStream outputStream) throws IOException {
108:                try {
109:                    getImplementation().writeTo(getSaajMessage(), outputStream);
110:                    outputStream.flush();
111:                } catch (SOAPException ex) {
112:                    throw new SaajSoapMessageException(
113:                            "Could not write message to OutputStream: "
114:                                    + ex.getMessage(), ex);
115:                }
116:            }
117:
118:            public boolean isXopPackage() {
119:                if (SaajUtils.getSaajVersion() >= SaajUtils.SAAJ_13) {
120:                    SOAPPart saajPart = saajMessage.getSOAPPart();
121:                    String[] contentTypes = saajPart
122:                            .getMimeHeader(TransportConstants.HEADER_CONTENT_TYPE);
123:                    for (int i = 0; i < contentTypes.length; i++) {
124:                        if (contentTypes[i].indexOf(CONTENT_TYPE_XOP) != -1) {
125:                            return true;
126:                        }
127:                    }
128:                }
129:                return false;
130:            }
131:
132:            public boolean convertToXopPackage() {
133:                if (SaajUtils.getSaajVersion() >= SaajUtils.SAAJ_13) {
134:                    convertMessageToXop();
135:                    convertPartToXop();
136:                    return true;
137:                } else {
138:                    return false;
139:                }
140:            }
141:
142:            private void convertMessageToXop() {
143:                MimeHeaders mimeHeaders = saajMessage.getMimeHeaders();
144:                String[] oldContentTypes = mimeHeaders
145:                        .getHeader(TransportConstants.HEADER_CONTENT_TYPE);
146:                String oldContentType = !ObjectUtils.isEmpty(oldContentTypes) ? oldContentTypes[0]
147:                        : getVersion().getContentType();
148:                StringBuffer buffer = new StringBuffer(CONTENT_TYPE_XOP);
149:                buffer.append(";type=");
150:                buffer.append('"');
151:                buffer.append(oldContentType);
152:                buffer.append('"');
153:                mimeHeaders.setHeader(TransportConstants.HEADER_CONTENT_TYPE,
154:                        buffer.toString());
155:            }
156:
157:            private void convertPartToXop() {
158:                SOAPPart saajPart = saajMessage.getSOAPPart();
159:                String[] oldContentTypes = saajPart
160:                        .getMimeHeader(TransportConstants.HEADER_CONTENT_TYPE);
161:                String oldContentType = !ObjectUtils.isEmpty(oldContentTypes) ? oldContentTypes[0]
162:                        : getVersion().getContentType();
163:                StringBuffer buffer = new StringBuffer(CONTENT_TYPE_XOP);
164:                buffer.append(";type=");
165:                buffer.append('"');
166:                buffer.append(oldContentType);
167:                buffer.append('"');
168:                saajPart.setMimeHeader(TransportConstants.HEADER_CONTENT_TYPE,
169:                        buffer.toString());
170:            }
171:
172:            public Iterator getAttachments() throws AttachmentException {
173:                Iterator iterator = getImplementation().getAttachments(
174:                        getSaajMessage());
175:                return new SaajAttachmentIterator(iterator);
176:            }
177:
178:            public Attachment getAttachment(String contentId) {
179:                Assert.hasLength(contentId, "contentId must not be empty");
180:                MimeHeaders mimeHeaders = new MimeHeaders();
181:                mimeHeaders.setHeader(TransportConstants.HEADER_CONTENT_ID,
182:                        contentId);
183:                Iterator iterator = getImplementation().getAttachment(
184:                        getSaajMessage(), mimeHeaders);
185:                if (!iterator.hasNext()) {
186:                    return null;
187:                }
188:                AttachmentPart saajAttachment = (AttachmentPart) iterator
189:                        .next();
190:                return new SaajAttachment(saajAttachment);
191:            }
192:
193:            public Attachment addAttachment(String contentId,
194:                    DataHandler dataHandler) {
195:                Assert.hasLength(contentId, "contentId must not be empty");
196:                Assert.notNull(dataHandler, "dataHandler must not be null");
197:                AttachmentPart saajAttachment = getImplementation()
198:                        .addAttachmentPart(getSaajMessage(), dataHandler);
199:                saajAttachment.setContentId(contentId);
200:                return new SaajAttachment(saajAttachment);
201:            }
202:
203:            protected SaajImplementation getImplementation() {
204:                if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_13) {
205:                    return Saaj13Implementation.getInstance();
206:                } else if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_12) {
207:                    return Saaj12Implementation.getInstance();
208:                } else if (SaajUtils.getSaajVersion() == SaajUtils.SAAJ_11) {
209:                    return Saaj11Implementation.getInstance();
210:                } else {
211:                    throw new IllegalStateException(
212:                            "Could not find SAAJ on the classpath");
213:                }
214:            }
215:
216:            public String toString() {
217:                StringBuffer buffer = new StringBuffer("SaajSoapMessage");
218:                try {
219:                    SOAPEnvelope envelope = getImplementation().getEnvelope(
220:                            saajMessage);
221:                    if (envelope != null) {
222:                        SOAPBody body = getImplementation().getBody(envelope);
223:                        if (body != null) {
224:                            SOAPElement bodyElement = getImplementation()
225:                                    .getFirstBodyElement(body);
226:                            if (bodyElement != null) {
227:                                buffer.append(' ');
228:                                buffer.append(getImplementation().getName(
229:                                        bodyElement));
230:                            }
231:                        }
232:                    }
233:                } catch (SOAPException ex) {
234:                    // ignore
235:                }
236:                return buffer.toString();
237:            }
238:
239:            private static class SaajAttachmentIterator implements  Iterator {
240:
241:                private final Iterator saajIterator;
242:
243:                public SaajAttachmentIterator(Iterator saajIterator) {
244:                    this .saajIterator = saajIterator;
245:                }
246:
247:                public boolean hasNext() {
248:                    return saajIterator.hasNext();
249:                }
250:
251:                public Object next() {
252:                    AttachmentPart saajAttachment = (AttachmentPart) saajIterator
253:                            .next();
254:                    return new SaajAttachment(saajAttachment);
255:                }
256:
257:                public void remove() {
258:                    saajIterator.remove();
259:                }
260:            }
261:
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.