Source Code Cross Referenced for OutputPartsTest.java in  » Web-Services » wsif » soap » 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 » wsif » soap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The Apache Software License, Version 1.1
003:         *
004:         *  
005:         * Copyright (c) 2002 The Apache Software Foundation.  All rights 
006:         * reserved.
007:         *
008:         * Redistribution and use in source and binary forms, with or without
009:         * modification, are permitted provided that the following conditions
010:         * are met:
011:         *
012:         * 1. Redistributions of source code must retain the above copyright
013:         *    notice, this list of conditions and the following disclaimer. 
014:         *
015:         * 2. Redistributions in binary form must reproduce the above copyright
016:         *    notice, this list of conditions and the following disclaimer in
017:         *    the documentation and/or other materials provided with the
018:         *    distribution.
019:         *
020:         * 3. The end-user documentation included with the redistribution,
021:         *    if any, must include the following acknowledgment:  
022:         *       "This product includes software developed by the
023:         *        Apache Software Foundation (http://www.apache.org/)."
024:         *    Alternately, this acknowledgment may appear in the software itself,
025:         *    if and wherever such third-party acknowledgments normally appear.
026:         *
027:         * 4. The names "WSIF" and "Apache Software Foundation" must
028:         *    not be used to endorse or promote products derived from this
029:         *    software without prior written permission. For written 
030:         *    permission, please contact apache@apache.org.
031:         *
032:         * 5. Products derived from this software may not be called "Apache",
033:         *    nor may "Apache" appear in their name, without prior written
034:         *    permission of the Apache Software Foundation.
035:         *
036:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039:         * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
040:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047:         * SUCH DAMAGE.
048:         * ====================================================================
049:         *
050:         * This software consists of voluntary contributions made by many
051:         * individuals on behalf of the Apache Software Foundation and was
052:         * originally based on software copyright (c) 2001, 2002, International
053:         * Business Machines, Inc., http://www.apache.org.  For more
054:         * information on the Apache Software Foundation, please see
055:         * <http://www.apache.org/>.
056:         */
057:
058:        package soap;
059:
060:        import java.util.Iterator;
061:
062:        import javax.jms.JMSException;
063:        import javax.jms.Message;
064:        import javax.jms.Queue;
065:        import javax.jms.QueueConnection;
066:        import javax.jms.QueueConnectionFactory;
067:        import javax.jms.QueueReceiver;
068:        import javax.jms.QueueSession;
069:        import javax.jms.Session;
070:        import javax.jms.TextMessage;
071:        import junit.framework.Test;
072:        import junit.framework.TestCase;
073:        import junit.framework.TestSuite;
074:
075:        import org.apache.wsif.WSIFConstants;
076:        import org.apache.wsif.WSIFCorrelationId;
077:        import org.apache.wsif.WSIFCorrelationService;
078:        import org.apache.wsif.WSIFException;
079:        import org.apache.wsif.WSIFMessage;
080:        import org.apache.wsif.WSIFOperation;
081:        import org.apache.wsif.WSIFPort;
082:        import org.apache.wsif.WSIFService;
083:        import org.apache.wsif.WSIFServiceFactory;
084:        import org.apache.wsif.base.WSIFServiceImpl;
085:        import org.apache.wsif.providers.soap.apacheaxis.WSIFDynamicProvider_ApacheAxis;
086:        import org.apache.wsif.util.WSIFCorrelationServiceLocator;
087:        import org.apache.wsif.util.WSIFPluggableProviders;
088:        import org.apache.wsif.util.WSIFProperties;
089:        import org.apache.wsif.util.jms.WSIFJMSFinder;
090:        import org.apache.wsif.util.jms.WSIFJMSFinderForJndi;
091:        import util.TestUtilities;
092:
093:        import async.AsyncResponseHandler;
094:
095:        /**
096:         * Junit test to test out output message parts.
097:         * 
098:         * The WSDL output message can define multiple parts, but the response 
099:         * recieved from the remote service may not match what is defined in the WSDL.
100:         * Its been decided that parts defined in the WSDL but not received should be
101:         * set in the output WSIFMessage with a null value, and that parts in the 
102:         * response but not in the WSDL should be added to the ouput WSIFMessage.
103:         *   
104:         * @author Ant Elder <ant.elder@uk.ibm.com>
105:         */
106:        public class OutputPartsTest extends TestCase {
107:
108:            static final String WSDL_LOCATION = TestUtilities
109:                    .getWsdlPath("java\\test\\soap\\wsifservice")
110:                    + "FakeStockQuote.wsdl";
111:
112:            static final String FAKE_SOAP_MSG_FILENAME1 = TestUtilities
113:                    .getWsdlPath("java\\test\\soap")
114:                    + "FakeSQRespOK.txt";
115:            static final String FAKE_SOAP_MSG_FILENAME2 = TestUtilities
116:                    .getWsdlPath("java\\test\\soap")
117:                    + "FakeSQRespNull.txt";
118:            static final String FAKE_SOAP_MSG_FILENAME3 = TestUtilities
119:                    .getWsdlPath("java\\test\\soap")
120:                    + "FakeSQRespMissingReturn.txt";
121:            static final String FAKE_SOAP_MSG_FILENAME4 = TestUtilities
122:                    .getWsdlPath("java\\test\\soap")
123:                    + "FakeSQRespMissingPart.txt";
124:            static final String FAKE_SOAP_MSG_FILENAME5 = TestUtilities
125:                    .getWsdlPath("java\\test\\soap")
126:                    + "FakeSQRespMissingAllParts.txt";
127:            static final String FAKE_SOAP_MSG_FILENAME6 = TestUtilities
128:                    .getWsdlPath("java\\test\\soap")
129:                    + "FakeSQRespRtnTypeErr.txt";
130:            static final String FAKE_SOAP_MSG_FILENAME7 = TestUtilities
131:                    .getWsdlPath("java\\test\\soap")
132:                    + "FakeSQRespExtraParts.txt";
133:
134:            public OutputPartsTest(String name) {
135:                super (name);
136:            }
137:
138:            public static void main(String[] args) {
139:                TestUtilities.startListeners();
140:                junit.textui.TestRunner.run(suite());
141:                TestUtilities.stopListeners();
142:            }
143:
144:            public static Test suite() {
145:                return new TestSuite(OutputPartsTest.class);
146:            }
147:
148:            public void setUp() {
149:                TestUtilities.setUpExtensionsAndProviders();
150:            }
151:
152:            public void tearDown() {
153:                WSIFPluggableProviders.overrideDefaultProvider(
154:                        "http://schemas.xmlsoap.org/wsdl/soap/", null);
155:            }
156:
157:            public void testSOAP1() {
158:                doitStockquote("SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME1,
159:                        null);
160:            }
161:
162:            public void testAxis1() {
163:                doitStockquote("SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME1,
164:                        null);
165:            }
166:
167:            public void testSOAP2() {
168:                doitStockquote("SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME2,
169:                        "return value not found in response message");
170:            }
171:
172:            public void testAxis2() {
173:                doitStockquote("SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME2,
174:                        "<null>");
175:            }
176:
177:            public void testSOAP3() {
178:                doitStockquote("SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME3,
179:                        "java.lang.String");
180:            }
181:
182:            public void testAxis3() {
183:                doitStockquote("SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME3,
184:                        "java.lang.String");
185:            }
186:
187:            public void testSOAP4() {
188:                doitStockquote("SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME4,
189:                        "p1=null");
190:            }
191:
192:            public void testAxis4() {
193:                doitStockquote("SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME4,
194:                        "p1=null");
195:            }
196:
197:            public void testSOAP5() {
198:                doitStockquote("SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME5,
199:                        "parms=null");
200:            }
201:
202:            public void testAxis5() {
203:                doitStockquote("SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME5,
204:                        "parms=null");
205:            }
206:
207:            public void testSOAP6() {
208:                doitStockquote("SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME6,
209:                        "java.lang.String");
210:            }
211:
212:            // AXIS doesn't work with incorect return type
213:            //  public void testAxis6() {
214:            //  	 doitStockquote( "SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME6, "java.lang.String" );
215:            //  }
216:            public void testSOAP7() {
217:                doitStockquote("SOAPJMSPort", "soap", FAKE_SOAP_MSG_FILENAME7,
218:                        null);
219:            }
220:
221:            // AXIS doesn't like unknown parts coming in
222:            //public void testAxis7() {
223:            //	 doitStockquote( "SOAPJMSPort", "axis", FAKE_SOAP_MSG_FILENAME7, null );
224:            //}
225:
226:            /**
227:             * Query Stockquote sample
228:             */
229:            public void doitStockquote(String portName, String protocol,
230:                    String fakeFile, String error) {
231:                float value;
232:                WSIFPort port;
233:                WSIFOperation operation;
234:                WSIFMessage input, output, fault, context;
235:
236:                if (portName.toUpperCase().indexOf("JMS") != -1
237:                        && !TestUtilities.areWeTesting("jms")) {
238:                    return;
239:                }
240:
241:                TestUtilities.setProviderForProtocol(protocol);
242:
243:                System.out.println("\n=== StockQuote");
244:                try {
245:                    WSIFServiceFactory factory = WSIFServiceFactory
246:                            .newInstance();
247:                    WSIFService service = factory.getService(WSDL_LOCATION,
248:                            null, // serviceNS
249:                            null, // serviceName
250:                            "http://wsifservice.stockquote/", // portTypeNS
251:                            "StockquotePT"); // portTypeName
252:
253:                    port = service.getPort(portName);
254:
255:                    // Executing executeRequestResponseAsync(input)
256:                    operation = port.createOperation("getQuote");
257:
258:                    context = operation.getContext();
259:                    context.setObjectPart(WSIFConstants.CONTEXT_JMS_PREFIX
260:                            + "WSIF_FAKE", "\"" + fakeFile + "\"");
261:
262:                    input = operation.createInputMessage();
263:                    input.setName("GetQuoteInput");
264:                    input.setObjectPart("symbol", "");
265:                    output = operation.createOutputMessage();
266:
267:                    //output = doAsyncOpNoHandler( operation, input, context );
268:                    doSyncOp(operation, input, output, context);
269:
270:                    Object o;
271:
272:                    o = output.getObjectPart("quote");
273:                    if (o != null) {
274:                        value = ((Float) o).floatValue();
275:                        assertTrue(
276:                                "doAsyncOpNoHandler stockquote value incorrect!",
277:                                value == -1.0F);
278:                    } else if (error.equals("<null>")) {
279:                        assertNull("return value not null!!", o);
280:                    } else {
281:                        assertTrue("return value null!!", error
282:                                .equals("return=null")
283:                                || error.equals("all=null"));
284:                    }
285:
286:                    System.out.println("out message contains:");
287:                    String partName;
288:                    for (Iterator i = output.getPartNames(); i.hasNext();) {
289:                        partName = (String) i.next();
290:                        o = output.getObjectPart(partName);
291:                        System.out.println("part=" + partName + " value=" + o);
292:                    }
293:
294:                    o = output.getObjectPart("p1");
295:                    if (o != null) {
296:                        assertTrue("error on part p1!!", o instanceof  String);
297:                    } else if (error.equals("<null>")) {
298:                        assertNull("return value not null!!", o);
299:                    } else {
300:                        assertTrue("p1 is null!!", error.equals("p1=null")
301:                                || error.equals("parms=null")
302:                                || error.equals("all=null"));
303:                    }
304:                    o = output.getObjectPart("p2");
305:                    if (o != null) {
306:                        assertTrue("error on part p2!!", o instanceof  Float);
307:                    } else if (error.equals("<null>")) {
308:                        assertNull("return value not null!!", o);
309:                    } else {
310:                        assertTrue("p2 is null!!", error.equals("p2=null")
311:                                || error.equals("parms=null")
312:                                || error.equals("all=null"));
313:                    }
314:                    o = output.getObjectPart("p3");
315:                    if (o != null) {
316:                        assertTrue("error on part p3!!", o instanceof  String);
317:                    } else if (error.equals("<null>")) {
318:                        assertNull("return value not null!!", o);
319:                    } else {
320:                        assertTrue("p3 is null!!", error.equals("p3=null")
321:                                || error.equals("parms=null")
322:                                || error.equals("all=null"));
323:                    }
324:
325:                } catch (Exception ex) {
326:                    if (error == null || !error.equals(ex.getMessage())) {
327:                        ex.printStackTrace();
328:                        assertTrue("exception during stockquote test: "
329:                                + ex.getMessage(), false);
330:                    }
331:                }
332:            }
333:
334:            private void doSyncOp(WSIFOperation op, WSIFMessage input,
335:                    WSIFMessage output, WSIFMessage context)
336:                    throws WSIFException {
337:                //try {
338:                op.setContext(context);
339:                WSIFMessage fault = op.createFaultMessage();
340:                boolean ok = op.executeRequestResponseOperation(input, output,
341:                        fault);
342:                assertTrue("executeRequestResponseOperation returned false!",
343:                        ok);
344:                //} catch (Exception ex) {
345:                // 	 ex.printStackTrace();
346:                //	 assertTrue( "exception executing request: " + ex.getMessage(), false );
347:                //}
348:            }
349:
350:            private WSIFMessage doAsyncOp(WSIFOperation op, WSIFMessage input,
351:                    WSIFMessage context) throws WSIFException {
352:                AsyncResponseHandler handler = new AsyncResponseHandler(1); // 2 async calls
353:                context.setObjectPart(WSIFConstants.CONTEXT_JMS_PREFIX
354:                        + "JMSReplyTo", TestUtilities
355:                        .getWsifProperty("wsif.async.replytoq"));
356:                op.setContext(context);
357:                WSIFCorrelationId id = op.executeRequestResponseAsync(input,
358:                        handler);
359:
360:                int i = 5; // 15 seconds timout
361:                while (i-- > 0 && !handler.isDone()) {
362:                    System.out
363:                            .println("async requests sent, waiting for responses - "
364:                                    + i);
365:                    try {
366:                        Thread.sleep(3000);
367:                    } catch (InterruptedException ex) {
368:                    }
369:                }
370:                assertTrue("no response to async operation!", i > 0); // no responses in time
371:                return handler.getOutputs()[0];
372:            }
373:
374:            private WSIFMessage doAsyncOpNoHandler(WSIFOperation op,
375:                    WSIFMessage input, WSIFMessage context)
376:                    throws WSIFException, JMSException {
377:                WSIFMessage output = null;
378:
379:                context.setObjectPart(WSIFConstants.CONTEXT_JMS_PREFIX
380:                        + "JMSReplyTo", TestUtilities
381:                        .getWsifProperty("wsif.async.replytoq2"));
382:                context.setObjectPart("testJMSnoHandler", "true");
383:                op.setContext(context);
384:                WSIFCorrelationId id = op.executeRequestResponseAsync(input);
385:                System.out.println("async operation done, correlation id="
386:                        + id.getCorrelationId());
387:                op = null;
388:
389:                Object jmsResponse = TestUtilities.getJMSAsyncResponse(id
390:                        .getCorrelationId(), TestUtilities
391:                        .getWsifProperty("wsif.async.replytoq2"));
392:
393:                WSIFCorrelationService cs = WSIFCorrelationServiceLocator
394:                        .getCorrelationService();
395:                Object o;
396:                synchronized (cs) {
397:                    o = cs.get(id);
398:                }
399:                if (o != null && o instanceof  WSIFOperation) {
400:                    cs.remove(id);
401:                    op = (WSIFOperation) o;
402:                } else {
403:                    assertTrue("stored correlation object not as expected: "
404:                            + o, false);
405:                }
406:                output = op.createOutputMessage();
407:                WSIFMessage fault = op.createFaultMessage();
408:                op.processAsyncResponse(jmsResponse, output, fault);
409:
410:                return output;
411:            }
412:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.