Source Code Cross Referenced for MTOMSerializationTests.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » attachments » 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.attachments 
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.attachments;
020:
021:        import java.awt.*;
022:        import java.io.ByteArrayOutputStream;
023:        import java.io.File;
024:
025:        import javax.activation.DataHandler;
026:        import javax.activation.DataSource;
027:        import javax.imageio.ImageIO;
028:        import javax.imageio.stream.FileImageInputStream;
029:        import javax.imageio.stream.ImageInputStream;
030:        import javax.xml.bind.JAXBContext;
031:
032:        import junit.framework.TestCase;
033:        import org.apache.axiom.om.OMAbstractFactory;
034:        import org.apache.axiom.om.OMElement;
035:        import org.apache.axiom.om.OMFactory;
036:        import org.apache.axiom.om.OMNamespace;
037:        import org.apache.axiom.om.OMOutputFormat;
038:        import org.apache.axiom.om.OMText;
039:        import org.apache.axiom.soap.SOAPBody;
040:        import org.apache.axiom.soap.SOAPEnvelope;
041:        import org.apache.axiom.soap.SOAPFactory;
042:        import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
043:        import org.apache.axis2.jaxws.message.Block;
044:        import org.apache.axis2.jaxws.message.Message;
045:        import org.apache.axis2.jaxws.message.Protocol;
046:        import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
047:        import org.apache.axis2.jaxws.message.factory.BlockFactory;
048:        import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
049:        import org.apache.axis2.jaxws.message.factory.MessageFactory;
050:        import org.apache.axis2.jaxws.provider.DataSourceImpl;
051:        import org.apache.axis2.jaxws.registry.FactoryRegistry;
052:        import org.apache.axis2.jaxws.TestLogger;
053:        import org.test.mtom.ImageDepot;
054:        import org.test.mtom.ObjectFactory;
055:        import org.test.mtom.SendImage;
056:
057:        public class MTOMSerializationTests extends TestCase {
058:
059:            private DataSource imageDS;
060:
061:            public void setUp() throws Exception {
062:                String imageResourceDir = System.getProperty("basedir", ".")
063:                        + "/" + "test-resources" + File.separator + "image";
064:
065:                //Create a DataSource from an image 
066:                File file = new File(imageResourceDir + File.separator
067:                        + "test.jpg");
068:                ImageInputStream fiis = new FileImageInputStream(file);
069:                Image image = ImageIO.read(fiis);
070:                imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
071:            }
072:
073:            public MTOMSerializationTests(String name) {
074:                super (name);
075:            }
076:
077:            /*
078:             * Simulate building up an OM that is sourced from JAXB and contains
079:             * binary data that should be optimized when serialized.  
080:             */
081:            public void testPlainOMSerialization() throws Exception {
082:                TestLogger.logger
083:                        .debug("---------------------------------------");
084:                TestLogger.logger.debug("test: " + getName());
085:
086:                OMElement payload = createPayload();
087:
088:                OMOutputFormat format = new OMOutputFormat();
089:                format.setDoOptimize(true);
090:                format.setSOAP11(true);
091:
092:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
093:                payload.serializeAndConsume(baos, format);
094:
095:                TestLogger.logger.debug("==================================");
096:                TestLogger.logger.debug(baos.toString());
097:                TestLogger.logger.debug("==================================");
098:            }
099:
100:            /*
101:             * Simulate building up an OM SOAPEnvelope that has the contents of
102:             * the body sourced from JAXB and contains binary data that should be 
103:             * optimized when serialized.  
104:             */
105:            public void testSoapOMSerialization() throws Exception {
106:                TestLogger.logger
107:                        .debug("---------------------------------------");
108:                TestLogger.logger.debug("test: " + getName());
109:
110:                OMElement payload = createPayload();
111:
112:                SOAPFactory factory = new SOAP11Factory();
113:                SOAPEnvelope env = factory.createSOAPEnvelope();
114:                SOAPBody body = factory.createSOAPBody(env);
115:
116:                body.addChild(payload);
117:
118:                OMOutputFormat format = new OMOutputFormat();
119:                format.setDoOptimize(true);
120:                format.setSOAP11(true);
121:
122:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
123:                env.serializeAndConsume(baos, format);
124:
125:                TestLogger.logger.debug("==================================");
126:                TestLogger.logger.debug(baos.toString());
127:                TestLogger.logger.debug("==================================");
128:            }
129:
130:            public void testMTOMAttachmentWriter() throws Exception {
131:                TestLogger.logger
132:                        .debug("---------------------------------------");
133:                TestLogger.logger.debug("test: " + getName());
134:
135:                //Create a DataHandler with the String DataSource object
136:                DataHandler dataHandler = new DataHandler(imageDS);
137:
138:                //Store the data handler in ImageDepot bean
139:                ImageDepot imageDepot = new ObjectFactory().createImageDepot();
140:                imageDepot.setImageData(dataHandler);
141:
142:                //JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
143:                JAXBBlockContext context = new JAXBBlockContext(SendImage.class
144:                        .getPackage().getName());
145:
146:                //Create a request bean with imagedepot bean as value
147:                ObjectFactory factory = new ObjectFactory();
148:                SendImage request = factory.createSendImage();
149:                request.setInput(imageDepot);
150:
151:                BlockFactory blkFactory = (JAXBBlockFactory) FactoryRegistry
152:                        .getFactory(JAXBBlockFactory.class);
153:                Block block = blkFactory.createFrom(request, context, null);
154:
155:                MessageFactory msgFactory = (MessageFactory) FactoryRegistry
156:                        .getFactory(MessageFactory.class);
157:                Message msg = msgFactory.create(Protocol.soap11);
158:
159:                msg.setBodyBlock(block);
160:
161:                msg.setMTOMEnabled(true);
162:
163:                SOAPEnvelope soapOM = (SOAPEnvelope) msg.getAsOMElement();
164:
165:                OMOutputFormat format = new OMOutputFormat();
166:                format.setDoOptimize(true);
167:                format.setSOAP11(true);
168:
169:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
170:                soapOM.serializeAndConsume(baos, format);
171:
172:                TestLogger.logger.debug("==================================");
173:                TestLogger.logger.debug(baos.toString());
174:                TestLogger.logger.debug("==================================");
175:            }
176:
177:            private OMElement createPayload() {
178:                //Create a DataHandler with the String DataSource object
179:                DataHandler dataHandler = new DataHandler(imageDS);
180:
181:                OMFactory fac = OMAbstractFactory.getOMFactory();
182:                OMNamespace omNs = fac.createOMNamespace("urn://mtom.test.org",
183:                        "mtom");
184:
185:                OMElement sendImage = fac.createOMElement("sendImage", omNs);
186:
187:                OMElement input = fac.createOMElement("input", omNs);
188:                sendImage.addChild(input);
189:
190:                OMElement imageData = fac.createOMElement("imageData", omNs);
191:                input.addChild(imageData);
192:
193:                OMText binaryData = fac.createOMText(dataHandler, true);
194:                imageData.addChild(binaryData);
195:
196:                return sendImage;
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.