Source Code Cross Referenced for MtomSampleTests.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » sample » 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.sample 
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.sample;
020:
021:        import java.awt.Image;
022:        import java.io.File;
023:
024:        import javax.activation.DataHandler;
025:        import javax.activation.DataSource;
026:        import javax.imageio.ImageIO;
027:        import javax.imageio.stream.FileImageInputStream;
028:        import javax.imageio.stream.ImageInputStream;
029:        import javax.xml.bind.JAXBContext;
030:        import javax.xml.namespace.QName;
031:        import javax.xml.ws.Dispatch;
032:        import javax.xml.ws.Service;
033:        import javax.xml.ws.Service.Mode;
034:        import javax.xml.ws.soap.SOAPBinding;
035:
036:        import junit.framework.TestCase;
037:        import org.apache.axis2.jaxws.provider.DataSourceImpl;
038:        import org.apache.axis2.jaxws.TestLogger;
039:        import org.test.mtom.ImageDepot;
040:        import org.test.mtom.ObjectFactory;
041:        import org.test.mtom.SendImage;
042:        import org.test.mtom.SendImageResponse;
043:
044:        public class MtomSampleTests extends TestCase {
045:
046:            private static final QName QNAME_SERVICE = new QName(
047:                    "urn://mtom.test.org", "MtomSampleService");
048:            private static final QName QNAME_PORT = new QName(
049:                    "urn://mtom.test.org", "MtomSample");
050:            private static final String URL_ENDPOINT = "http://localhost:8080/axis2/services/MtomSampleService";
051:            private static final String IMAGE_DIR = System.getProperty(
052:                    "basedir", ".")
053:                    + "/" + "test-resources" + File.separator + "image";
054:
055:            /*
056:             * Enable attachment Optimization through the SOAPBinding method 
057:             * -- setMTOMEnabled([true|false])
058:             * Using SOAP11
059:             */
060:            public void testSendImageAttachmentAPI11() throws Exception {
061:                TestLogger.logger.debug("----------------------------------");
062:                TestLogger.logger.debug("test: " + getName());
063:
064:                String imageResourceDir = IMAGE_DIR;
065:
066:                //Create a DataSource from an image 
067:                File file = new File(imageResourceDir + File.separator
068:                        + "test.jpg");
069:                ImageInputStream fiis = new FileImageInputStream(file);
070:                Image image = ImageIO.read(fiis);
071:                DataSource imageDS = new DataSourceImpl("image/jpeg",
072:                        "test.jpg", image);
073:
074:                //Create a DataHandler with the String DataSource object
075:                DataHandler dataHandler = new DataHandler(imageDS);
076:
077:                //Store the data handler in ImageDepot bean
078:                ImageDepot imageDepot = new ObjectFactory().createImageDepot();
079:                imageDepot.setImageData(dataHandler);
080:
081:                SendImage request = new ObjectFactory().createSendImage();
082:                request.setInput(imageDepot);
083:
084:                //Create the necessary JAXBContext
085:                JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
086:
087:                // Create the JAX-WS client needed to send the request
088:                Service service = Service.create(QNAME_SERVICE);
089:                service.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_BINDING,
090:                        URL_ENDPOINT);
091:                Dispatch<Object> dispatch = service.createDispatch(QNAME_PORT,
092:                        jbc, Mode.PAYLOAD);
093:
094:                //Enable attachment optimization
095:                SOAPBinding binding = (SOAPBinding) dispatch.getBinding();
096:                binding.setMTOMEnabled(true);
097:
098:                SendImageResponse response = (SendImageResponse) dispatch
099:                        .invoke(request);
100:
101:                assertNotNull(response);
102:                assertNotNull(response.getOutput().getImageData());
103:            }
104:
105:            /*
106:             * Enable attachment optimization using the SOAP11 binding
107:             * property for MTOM.
108:             */
109:            public void testSendImageAttachmentProperty11() throws Exception {
110:                TestLogger.logger.debug("----------------------------------");
111:                TestLogger.logger.debug("test: " + getName());
112:
113:                String imageResourceDir = IMAGE_DIR;
114:
115:                //Create a DataSource from an image 
116:                File file = new File(imageResourceDir + File.separator
117:                        + "test.jpg");
118:                ImageInputStream fiis = new FileImageInputStream(file);
119:                Image image = ImageIO.read(fiis);
120:                DataSource imageDS = new DataSourceImpl("image/jpeg",
121:                        "test.jpg", image);
122:
123:                //Create a DataHandler with the String DataSource object
124:                DataHandler dataHandler = new DataHandler(imageDS);
125:
126:                //Store the data handler in ImageDepot bean
127:                ImageDepot imageDepot = new ObjectFactory().createImageDepot();
128:                imageDepot.setImageData(dataHandler);
129:
130:                SendImage request = new ObjectFactory().createSendImage();
131:                request.setInput(imageDepot);
132:
133:                //Create the necessary JAXBContext
134:                JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
135:
136:                // Create the JAX-WS client needed to send the request with soap 11 binding
137:                // property for MTOM
138:                Service service = Service.create(QNAME_SERVICE);
139:                service.addPort(QNAME_PORT,
140:                        SOAPBinding.SOAP11HTTP_MTOM_BINDING, URL_ENDPOINT);
141:                Dispatch<Object> dispatch = service.createDispatch(QNAME_PORT,
142:                        jbc, Mode.PAYLOAD);
143:
144:                SendImageResponse response = (SendImageResponse) dispatch
145:                        .invoke(request);
146:
147:                assertNotNull(response);
148:                assertNotNull(response.getOutput().getImageData());
149:            }
150:
151:            /*
152:             * Enable attachment optimization using both the SOAP11 binding
153:             * property for MTOM and the Binding API
154:             */
155:            public void testSendImageAttachmentAPIProperty11() throws Exception {
156:                TestLogger.logger.debug("----------------------------------");
157:                TestLogger.logger.debug("test: " + getName());
158:
159:                String imageResourceDir = IMAGE_DIR;
160:
161:                //Create a DataSource from an image 
162:                File file = new File(imageResourceDir + File.separator
163:                        + "test.jpg");
164:                ImageInputStream fiis = new FileImageInputStream(file);
165:                Image image = ImageIO.read(fiis);
166:                DataSource imageDS = new DataSourceImpl("image/jpeg",
167:                        "test.jpg", image);
168:
169:                //Create a DataHandler with the String DataSource object
170:                DataHandler dataHandler = new DataHandler(imageDS);
171:
172:                //Store the data handler in ImageDepot bean
173:                ImageDepot imageDepot = new ObjectFactory().createImageDepot();
174:                imageDepot.setImageData(dataHandler);
175:
176:                SendImage request = new ObjectFactory().createSendImage();
177:                request.setInput(imageDepot);
178:
179:                //Create the necessary JAXBContext
180:                JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
181:
182:                // Create the JAX-WS client needed to send the request with soap 11 binding
183:                // property for MTOM
184:                Service service = Service.create(QNAME_SERVICE);
185:                service.addPort(QNAME_PORT,
186:                        SOAPBinding.SOAP11HTTP_MTOM_BINDING, URL_ENDPOINT);
187:                Dispatch<Object> dispatch = service.createDispatch(QNAME_PORT,
188:                        jbc, Mode.PAYLOAD);
189:
190:                //Enable attachment optimization
191:                SOAPBinding binding = (SOAPBinding) dispatch.getBinding();
192:                binding.setMTOMEnabled(true);
193:
194:                SendImageResponse response = (SendImageResponse) dispatch
195:                        .invoke(request);
196:
197:                assertNotNull(response);
198:                assertNotNull(response.getOutput().getImageData());
199:            }
200:
201:            /*
202:             * Enable attachment optimization using both the SOAP12 binding
203:             * property for MTOM
204:             * 
205:             * Sending SOAP12 message to SOAP11 endpoint will correctly result in exception
206:             * 
207:             */
208:            public void testSendImageAttachmentProperty12() throws Exception {
209:                TestLogger.logger.debug("----------------------------------");
210:                TestLogger.logger.debug("test: " + getName());
211:
212:                String imageResourceDir = IMAGE_DIR;
213:
214:                //Create a DataSource from an image 
215:                File file = new File(imageResourceDir + File.separator
216:                        + "test.jpg");
217:                ImageInputStream fiis = new FileImageInputStream(file);
218:                Image image = ImageIO.read(fiis);
219:                DataSource imageDS = new DataSourceImpl("image/jpeg",
220:                        "test.jpg", image);
221:
222:                //Create a DataHandler with the String DataSource object
223:                DataHandler dataHandler = new DataHandler(imageDS);
224:
225:                //Store the data handler in ImageDepot bean
226:                ImageDepot imageDepot = new ObjectFactory().createImageDepot();
227:                imageDepot.setImageData(dataHandler);
228:
229:                SendImage request = new ObjectFactory().createSendImage();
230:                request.setInput(imageDepot);
231:
232:                //Create the necessary JAXBContext
233:                JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
234:
235:                // Create the JAX-WS client needed to send the request with soap 11 binding
236:                // property for MTOM
237:                Service service = Service.create(QNAME_SERVICE);
238:                service.addPort(QNAME_PORT,
239:                        SOAPBinding.SOAP12HTTP_MTOM_BINDING, URL_ENDPOINT);
240:                Dispatch<Object> dispatch = service.createDispatch(QNAME_PORT,
241:                        jbc, Mode.PAYLOAD);
242:
243:                try {
244:                    SendImageResponse response = (SendImageResponse) dispatch
245:                            .invoke(request);
246:                    fail("Was expecting an exception due to sending SOAP12 message to SOAP11 endpoint.");
247:                } catch (Exception e) {
248:                    assertNotNull(e);
249:                }
250:                /*
251:                assertNotNull(response);
252:                assertNotNull(response.getOutput().getImageData());
253:                 */
254:            }
255:
256:            /*
257:             * Enable attachment optimization using both the SOAP12 binding API
258:             * for MTOM
259:             * 
260:             * Sending SOAP12 message to SOAP11 endpoint will correctly result in exception
261:             * 
262:             */
263:            public void testSendImageAttachmentAPI12() throws Exception {
264:                TestLogger.logger.debug("----------------------------------");
265:                TestLogger.logger.debug("test: " + getName());
266:
267:                String imageResourceDir = IMAGE_DIR;
268:
269:                //Create a DataSource from an image 
270:                File file = new File(imageResourceDir + File.separator
271:                        + "test.jpg");
272:                ImageInputStream fiis = new FileImageInputStream(file);
273:                Image image = ImageIO.read(fiis);
274:                DataSource imageDS = new DataSourceImpl("image/jpeg",
275:                        "test.jpg", image);
276:
277:                //Create a DataHandler with the String DataSource object
278:                DataHandler dataHandler = new DataHandler(imageDS);
279:
280:                //Store the data handler in ImageDepot bean
281:                ImageDepot imageDepot = new ObjectFactory().createImageDepot();
282:                imageDepot.setImageData(dataHandler);
283:
284:                SendImage request = new ObjectFactory().createSendImage();
285:                request.setInput(imageDepot);
286:
287:                //Create the necessary JAXBContext
288:                JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
289:
290:                // Create the JAX-WS client needed to send the request with soap 11 binding
291:                // property for MTOM
292:                Service service = Service.create(QNAME_SERVICE);
293:                service.addPort(QNAME_PORT, SOAPBinding.SOAP12HTTP_BINDING,
294:                        URL_ENDPOINT);
295:                Dispatch<Object> dispatch = service.createDispatch(QNAME_PORT,
296:                        jbc, Mode.PAYLOAD);
297:
298:                //Enable attachment optimization
299:                SOAPBinding binding = (SOAPBinding) dispatch.getBinding();
300:                binding.setMTOMEnabled(true);
301:
302:                try {
303:                    SendImageResponse response = (SendImageResponse) dispatch
304:                            .invoke(request);
305:                    fail("Was expecting an exception due to sending SOAP12 message to SOAP11 endpoint.");
306:                } catch (Exception e) {
307:                    assertNotNull(e);
308:                }
309:                /*
310:                assertNotNull(response);
311:                assertNotNull(response.getOutput().getImageData());
312:                 */
313:            }
314:
315:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.