Source Code Cross Referenced for SOAP12Tests.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » message » 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.message 
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.message;
020:
021:        import java.io.StringReader;
022:
023:        import javax.xml.stream.XMLInputFactory;
024:        import javax.xml.stream.XMLStreamReader;
025:
026:        import junit.framework.TestCase;
027:        import org.apache.axiom.om.OMElement;
028:        import org.apache.axiom.om.OMNamespace;
029:        import org.apache.axiom.soap.SOAPEnvelope;
030:        import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
031:        import org.apache.axis2.jaxws.message.factory.MessageFactory;
032:        import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
033:        import org.apache.axis2.jaxws.message.util.Reader2Writer;
034:        import org.apache.axis2.jaxws.registry.FactoryRegistry;
035:        import org.apache.axis2.jaxws.TestLogger;
036:
037:        /**
038:         * This suite is used to test the creation of messages based on SOAP 1.2
039:         * with both inbound and outbound simulations. 
040:         *
041:         */
042:        public class SOAP12Tests extends TestCase {
043:
044:            private static final String sampleText = "<echo>test string</echo>";
045:
046:            private static final String sampleSoap12EnvelopeHead = "<soapenv:Envelope xmlns:soapenv=\"http://www.w3.org/2003/05/soap-envelope\">"
047:                    + "<soapenv:Header /><soapenv:Body>";
048:
049:            private static final String sampleEnvelopeTail = "</soapenv:Body></soapenv:Envelope>";
050:
051:            private static final String sampleSoap12Envelope = sampleSoap12EnvelopeHead
052:                    + sampleText + sampleEnvelopeTail;
053:
054:            private static final String SOAP12_NS_URI = "http://www.w3.org/2003/05/soap-envelope";
055:
056:            public static final XMLInputFactory inputFactory = XMLInputFactory
057:                    .newInstance();
058:
059:            public SOAP12Tests(String name) {
060:                super (name);
061:            }
062:
063:            /**
064:             * Simulate creating a SOAP 1.2 message when the business object
065:             * provided is just the payload. 
066:             */
067:            public void testCreateSoap12FromPayload() throws Exception {
068:                // Create a SOAP 1.2 Message
069:                MessageFactory mf = (MessageFactory) FactoryRegistry
070:                        .getFactory(MessageFactory.class);
071:                Message m = mf.create(Protocol.soap12);
072:
073:                // Get the BlockFactory
074:                XMLStringBlockFactory f = (XMLStringBlockFactory) FactoryRegistry
075:                        .getFactory(XMLStringBlockFactory.class);
076:
077:                // Create a Block using the sample string as the content.  This simulates
078:                // what occurs on the outbound JAX-WS dispatch<String> client
079:                Block block = f.createFrom(sampleText, null, null);
080:
081:                // Add the block to the message as normal body content.
082:                m.setBodyBlock(block);
083:
084:                // Assuming no handlers are installed, the next thing that will happen
085:                // is a XMLStreamReader will be requested...to go to OM.   At this point the
086:                // block should be consumed.
087:                OMElement om = m.getAsOMElement();
088:
089:                // The block should not be consumed yet...because the message has not been read
090:                assertTrue(!block.isConsumed());
091:
092:                // To check that the output is correct, get the String contents of the 
093:                // reader
094:                Reader2Writer r2w = new Reader2Writer(om.getXMLStreamReader());
095:                String newText = r2w.getAsString();
096:                TestLogger.logger.debug(newText);
097:                assertTrue(newText.contains(sampleText));
098:                assertTrue(newText.contains("soap"));
099:                assertTrue(newText.contains("Envelope"));
100:                assertTrue(newText.contains("Body"));
101:
102:                assertTrue(m.getProtocol().equals(Protocol.soap12));
103:
104:                SOAPEnvelope omSoapEnv = (SOAPEnvelope) m.getAsOMElement();
105:                OMNamespace ns = omSoapEnv.getNamespace();
106:                assertTrue(ns.getNamespaceURI().equals(SOAP12_NS_URI));
107:
108:                // The block should be consumed at this point
109:                assertTrue(block.isConsumed());
110:            }
111:
112:            /**
113:             * Simulate creating a SOAP 1.2 message when the business object
114:             * provided is the full message.
115:             */
116:            public void testCreateSoap12FromMessage() throws Exception {
117:                // Create a SOAP 1.2 Message
118:                MessageFactory mf = (MessageFactory) FactoryRegistry
119:                        .getFactory(MessageFactory.class);
120:
121:                // Get the BlockFactory
122:                XMLStringBlockFactory f = (XMLStringBlockFactory) FactoryRegistry
123:                        .getFactory(XMLStringBlockFactory.class);
124:
125:                // Create a Block using the sample string as the content.  This simulates
126:                // what occurs on the outbound JAX-WS dispatch<String> client
127:                Block block = f.createFrom(sampleSoap12Envelope, null, null);
128:
129:                // Create a Message with the full XML contents that we have
130:                Message m = mf.createFrom(block.getXMLStreamReader(true), null);
131:
132:                // Assuming no handlers are installed, the next thing that will happen
133:                // is a XMLStreamReader will be requested...to go to OM.   At this point the
134:                // block should be consumed.
135:                OMElement om = m.getAsOMElement();
136:
137:                // To check that the output is correct, get the String contents of the 
138:                // reader
139:                Reader2Writer r2w = new Reader2Writer(om
140:                        .getXMLStreamReaderWithoutCaching());
141:                String newText = r2w.getAsString();
142:                TestLogger.logger.debug(newText);
143:                assertTrue(newText.contains(sampleText));
144:                assertTrue(newText.contains("soap"));
145:                assertTrue(newText.contains("Envelope"));
146:                assertTrue(newText.contains("Body"));
147:
148:                assertTrue(m.getProtocol().equals(Protocol.soap12));
149:
150:                SOAPEnvelope omSoapEnv = (SOAPEnvelope) m.getAsOMElement();
151:                OMNamespace ns = omSoapEnv.getNamespace();
152:                assertTrue(ns.getNamespaceURI().equals(SOAP12_NS_URI));
153:
154:                // The block should be consumed at this point
155:                assertTrue(block.isConsumed());
156:            }
157:
158:            public void testGetPayloadFromSoap12() throws Exception {
159:                // On inbound, there will already be an OM
160:                // which represents the message.  The following code simulates the input
161:                // OM
162:                StringReader sr = new StringReader(sampleSoap12Envelope);
163:                XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
164:                StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow,
165:                        null);
166:                OMElement omElement = builder.getSOAPEnvelope();
167:
168:                // The JAX-WS layer creates a Message from the OM
169:                MessageFactory mf = (MessageFactory) FactoryRegistry
170:                        .getFactory(MessageFactory.class);
171:                Message m = mf.createFrom(omElement, null);
172:
173:                // Make sure the right Protocol was set on the Message
174:                assertTrue(m.getProtocol().equals(Protocol.soap12));
175:
176:                // Check the SOAPEnvelope to make sure we've got the right
177:                // protocol namespace there as well.
178:                SOAPEnvelope soapEnv = (SOAPEnvelope) m.getAsOMElement();
179:                OMNamespace ns = soapEnv.getNamespace();
180:                assertTrue(ns.getNamespaceURI().equals(SOAP12_NS_URI));
181:
182:                // Assuming no handlers are installed, the next thing that will happen
183:                // is the proxy code will ask for the business object (String).
184:                XMLStringBlockFactory blockFactory = (XMLStringBlockFactory) FactoryRegistry
185:                        .getFactory(XMLStringBlockFactory.class);
186:                Block block = m.getBodyBlock(null, blockFactory);
187:                Object bo = block.getBusinessObject(true);
188:                assertTrue(bo instanceof  String);
189:
190:                // The block should be consumed
191:                assertTrue(block.isConsumed());
192:
193:                // Check the String for accuracy
194:                assertTrue(sampleText.equals(bo));
195:            }
196:
197:            public void testGetMessageFromSoap12() throws Exception {
198:                // On inbound, there will already be an OM
199:                // which represents the message.  The following code simulates the input
200:                // OM
201:                StringReader sr = new StringReader(sampleSoap12Envelope);
202:                XMLStreamReader inflow = inputFactory.createXMLStreamReader(sr);
203:                StAXSOAPModelBuilder builder = new StAXSOAPModelBuilder(inflow,
204:                        null);
205:                OMElement omElement = builder.getSOAPEnvelope();
206:
207:                // The JAX-WS layer creates a Message from the OM
208:                MessageFactory mf = (MessageFactory) FactoryRegistry
209:                        .getFactory(MessageFactory.class);
210:                Message m = mf.createFrom(omElement, null);
211:
212:                // Make sure the right Protocol was set on the Message
213:                assertTrue(m.getProtocol().equals(Protocol.soap12));
214:
215:                // Check the SOAPEnvelope to make sure we've got the right
216:                // protocol namespace there as well.
217:                SOAPEnvelope soapEnv = (SOAPEnvelope) m.getAsOMElement();
218:                OMNamespace ns = soapEnv.getNamespace();
219:                assertTrue(ns.getNamespaceURI().equals(SOAP12_NS_URI));
220:
221:                // Assuming no handlers are installed, the next thing that will happen
222:                // is the proxy code will ask for the business object (String).
223:                XMLStringBlockFactory blockFactory = (XMLStringBlockFactory) FactoryRegistry
224:                        .getFactory(XMLStringBlockFactory.class);
225:                Block block = blockFactory.createFrom(m.getAsOMElement(), null,
226:                        null);
227:                Object bo = block.getBusinessObject(true);
228:                assertTrue(bo instanceof  String);
229:
230:                // The block should be consumed
231:                assertTrue(block.isConsumed());
232:
233:                // Check the String for accuracy
234:                assertTrue(((String) bo)
235:                        .contains("<soapenv:Body><echo>test string</echo></soapenv:Body>"));
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.