Source Code Cross Referenced for AttachmentUtil.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » provider » 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 AXIS2 » jax ws » org.apache.axis2.jaxws.provider 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.jaxws.provider;
020:
021:        import java.awt.*;
022:        import java.awt.image.BufferedImage;
023:        import java.io.OutputStream;
024:        import java.io.StringReader;
025:        import java.io.StringWriter;
026:        import java.util.Iterator;
027:
028:        import javax.imageio.IIOImage;
029:        import javax.imageio.ImageWriter;
030:        import javax.imageio.stream.ImageOutputStream;
031:        import javax.xml.soap.MessageFactory;
032:        import javax.xml.soap.SOAPConstants;
033:        import javax.xml.soap.SOAPException;
034:        import javax.xml.soap.SOAPMessage;
035:        import javax.xml.transform.Result;
036:        import javax.xml.transform.Source;
037:        import javax.xml.transform.Transformer;
038:        import javax.xml.transform.TransformerFactory;
039:        import javax.xml.transform.stream.StreamResult;
040:        import javax.xml.transform.stream.StreamSource;
041:
042:        /**
043:         * This will serve as a helper class for attachments utility methods. All methods
044:         * are intended to be referenced staticly.
045:         *
046:         */
047:        public class AttachmentUtil {
048:            public static final String SOAP11_NAMESPACE = "http://schemas.xmlsoap.org/soap/envelope";
049:            public static final String SOAP12_NAMESPACE = "http://www.w3.org/2003/05/soap-envelope";
050:
051:            public static final String MU_TEXT = "soap message mustUnderstand header request";
052:            public static final String UNDERSTOOD_MU_TEXT = "understood headers soap message mustUnderstand header request";
053:            public static final String TEXT = "soap message request";
054:            public static final String VALUE = "value";
055:            public static final String VALUE_NODE = "<" + VALUE + ">";
056:            public static final String VALUE_NODE_SLASH = "</" + VALUE + ">";
057:            public static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
058:            public static final String MUHEADER_CLIENT = "ns1:muclient";
059:            public static final String MUHEADER_SERVER = "ns1:muserver";
060:            public static final String MUHEADER_CLIENT_UNDERSTOOD = "ns1:muclientunderstood";
061:            public static final String MUHEADER_SERVER_UNDERSTOOD = "ns1:muserverunderstood";
062:            public static final String msgEnvMU = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
063:                    + "<soapenv:Header>"
064:                    + "<"
065:                    + MUHEADER_CLIENT
066:                    + " xmlns:ns1=\"http://ws.apache.org/axis2\" soapenv:mustUnderstand=\"1\">MUinfo</"
067:                    + MUHEADER_CLIENT
068:                    + ">"
069:                    + "</soapenv:Header>"
070:                    + "<soapenv:Body>"
071:                    + "<ns1:invoke xmlns:ns1=\"http://ws.apache.org/axis2\">"
072:                    + VALUE_NODE
073:                    + MU_TEXT
074:                    + VALUE_NODE_SLASH
075:                    + "</ns1:invoke>"
076:                    + "</soapenv:Body>" + "</soapenv:Envelope>";
077:
078:            public static final String msgEnv = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
079:                    + "<soapenv:Body>"
080:                    + "<ns1:invoke xmlns:ns1=\"http://ws.apache.org/axis2\">"
081:                    + VALUE_NODE
082:                    + MU_TEXT
083:                    + VALUE_NODE_SLASH
084:                    + "</ns1:invoke>"
085:                    + "</soapenv:Body>" + "</soapenv:Envelope>";
086:
087:            public static final String msgEnvPlain = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
088:                    + "<soapenv:Body>"
089:                    + "<ns1:invoke xmlns:ns1=\"http://ws.apache.org/axis2\">"
090:                    + VALUE_NODE
091:                    + TEXT
092:                    + VALUE_NODE_SLASH
093:                    + "</ns1:invoke>"
094:                    + "</soapenv:Body>" + "</soapenv:Envelope>";
095:
096:            public static final String msgEnvMU_understood = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
097:                    + "<soapenv:Header>"
098:                    + "<"
099:                    + MUHEADER_CLIENT_UNDERSTOOD
100:                    + " xmlns:ns1=\"http://ws.apache.org/axis2\" soapenv:mustUnderstand=\"1\">MUinfo</"
101:                    + MUHEADER_CLIENT_UNDERSTOOD
102:                    + ">"
103:                    + "</soapenv:Header>"
104:                    + "<soapenv:Body>"
105:                    + "<ns1:invoke xmlns:ns1=\"http://ws.apache.org/axis2\">"
106:                    + VALUE_NODE
107:                    + UNDERSTOOD_MU_TEXT
108:                    + VALUE_NODE_SLASH
109:                    + "</ns1:invoke>"
110:                    + "</soapenv:Body>"
111:                    + "</soapenv:Envelope>";
112:
113:            public static final String msgEnv_understood = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"
114:                    + "<soapenv:Body>"
115:                    + "<ns1:invoke xmlns:ns1=\"http://ws.apache.org/axis2\">"
116:                    + VALUE_NODE
117:                    + UNDERSTOOD_MU_TEXT
118:                    + VALUE_NODE_SLASH
119:                    + "</ns1:invoke>"
120:                    + "</soapenv:Body>"
121:                    + "</soapenv:Envelope>";
122:
123:            /**
124:             * Store a given image to an Image output stream
125:             * @param mimeType
126:             * @param image
127:             * @param os
128:             * @throws Exception
129:             */
130:            public static void storeImage(String mimeType, Image image,
131:                    OutputStream os) throws Exception {
132:                ImageWriter imageWriter = null;
133:                BufferedImage bufferedImage = (BufferedImage) image;
134:
135:                Iterator iterator = javax.imageio.ImageIO
136:                        .getImageWritersByMIMEType(mimeType);
137:                if (iterator.hasNext()) {
138:                    imageWriter = (ImageWriter) iterator.next();
139:                }
140:                ImageOutputStream ios = javax.imageio.ImageIO
141:                        .createImageOutputStream(os);
142:                imageWriter.setOutput(ios);
143:
144:                imageWriter.write(new IIOImage(bufferedImage, null, null));
145:                ios.flush();
146:                imageWriter.dispose();
147:            }
148:
149:            /**
150:             * Adapter method used to convert any type of Source to a String
151:             * 
152:             * @param input
153:             * @return
154:             */
155:            public static String toString(Source input) {
156:
157:                if (input == null)
158:                    return null;
159:
160:                StringWriter writer = new StringWriter();
161:                Transformer trasformer;
162:                try {
163:                    trasformer = TransformerFactory.newInstance()
164:                            .newTransformer();
165:                    Result result = new StreamResult(writer);
166:                    trasformer.transform(input, result);
167:                } catch (Exception e) {
168:                    return null;
169:                }
170:
171:                return writer.getBuffer().toString();
172:            }
173:
174:            /**
175:             * Adapter method used to convert any type of SOAPMessage to a String
176:             * 
177:             * @param input
178:             * @return
179:             */
180:            public static String toString(SOAPMessage input) {
181:
182:                if (input == null)
183:                    return null;
184:
185:                Source result = null;
186:                try {
187:                    result = input.getSOAPPart().getContent();
188:                } catch (SOAPException e) {
189:                    e.printStackTrace();
190:                }
191:
192:                return toString(result);
193:            }
194:
195:            /**
196:             * Method used to convert Strings to SOAPMessages
197:             * 
198:             * @param msgString
199:             * @return
200:             */
201:            public static SOAPMessage toSOAPMessage(String msgString) {
202:
203:                if (msgString == null)
204:                    return null;
205:
206:                SOAPMessage message = null;
207:                try {
208:                    MessageFactory factory = null;
209:
210:                    // Force the usage of specific MesasgeFactories
211:                    if (msgString.indexOf(SOAP11_NAMESPACE) >= 0) {
212:                        factory = MessageFactory
213:                                .newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
214:                    } else {
215:                        factory = MessageFactory
216:                                .newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
217:                    }
218:                    message = factory.createMessage();
219:                    message.getSOAPPart().setContent(
220:                            (Source) new StreamSource(new StringReader(
221:                                    msgString)));
222:                    message.saveChanges();
223:                } catch (SOAPException e) {
224:                    System.out.println("toSOAPMessage Exception encountered: "
225:                            + e);
226:                    e.printStackTrace();
227:                }
228:                return message;
229:            }
230:
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.