Source Code Cross Referenced for GetQuote1.java in  » J2EE » enhydra » samples » stock » 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 » J2EE » enhydra » samples.stock 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2004 The Apache Software Foundation.
003:         * 
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         * 
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package samples.stock;
018:
019:        import org.apache.axis.client.Call;
020:        import org.apache.axis.client.Service;
021:        import org.apache.axis.encoding.XMLType;
022:        import org.apache.axis.utils.Options;
023:
024:        import javax.xml.namespace.QName;
025:        import javax.xml.rpc.ParameterMode;
026:        import java.net.URL;
027:
028:        /**
029:         * This version of the ever so popular GetQuote shows how to use the
030:         * Axis client APIs with and without WSDL.  The first flavor (getQuote1)
031:         * will use WSDL to prefill all of the data about the remote service.
032:         * The second one (getQuote2) will do it all manually.  Either way the
033:         * service is invoked it should produce the exact same request XML and
034:         * of course same results.
035:         *
036:         * This sample supports the use of the standard options too (-p ...)
037:         *
038:         * @author Doug Davis (dug@us.ibm.com.com)
039:         */
040:        public class GetQuote1 {
041:            public String symbol;
042:
043:            /**
044:             * This will use the WSDL to prefill all of the info needed to make
045:             * the call.  All that's left is filling in the args to invoke().
046:             */
047:            public float getQuote1(String args[]) throws Exception {
048:                Options opts = new Options(args);
049:
050:                args = opts.getRemainingArgs();
051:
052:                if (args == null) {
053:                    System.err.println("Usage: GetQuote <symbol>");
054:                    System.exit(1);
055:                }
056:
057:                /* Define the service QName and port QName */
058:                /*******************************************/
059:                QName servQN = new QName("urn:xmltoday-delayed-quotes",
060:                        "GetQuoteService");
061:                QName portQN = new QName("urn:xmltoday-delayed-quotes",
062:                        "GetQuote");
063:
064:                /* Now use those QNames as pointers into the WSDL doc */
065:                /******************************************************/
066:                Service service = new Service(new URL("file:GetQuote.wsdl"),
067:                        servQN);
068:                Call call = (Call) service.createCall(portQN, "getQuote");
069:
070:                /* Strange - but allows the user to change just certain portions of */
071:                /* the URL we're gonna use to invoke the service.  Useful when you  */
072:                /* want to run it thru tcpmon (ie. put  -p81 on the cmd line).      */
073:                /********************************************************************/
074:                opts.setDefaultURL(call.getTargetEndpointAddress());
075:                call.setTargetEndpointAddress(new URL(opts.getURL()));
076:
077:                /* Define some service specific properties */
078:                /*******************************************/
079:                call.setUsername(opts.getUser());
080:                call.setPassword(opts.getPassword());
081:
082:                /* Get symbol and invoke the service */
083:                /*************************************/
084:                Object result = call.invoke(new Object[] { symbol = args[0] });
085:
086:                return (((Float) result).floatValue());
087:            }
088:
089:            /**
090:             * This will do everything manually (ie. no WSDL).
091:             */
092:            public float getQuote2(String args[]) throws Exception {
093:                Options opts = new Options(args);
094:
095:                args = opts.getRemainingArgs();
096:
097:                if (args == null) {
098:                    System.err.println("Usage: GetQuote <symbol>");
099:                    System.exit(1);
100:                }
101:
102:                /* Create default/empty Service and Call object */
103:                /************************************************/
104:                Service service = new Service();
105:                Call call = (Call) service.createCall();
106:
107:                /* Strange - but allows the user to change just certain portions of */
108:                /* the URL we're gonna use to invoke the service.  Useful when you  */
109:                /* want to run it thru tcpmon (ie. put  -p81 on the cmd line).      */
110:                /********************************************************************/
111:                opts
112:                        .setDefaultURL("http://localhost:8080/axis/servlet/AxisServlet");
113:
114:                /* Set all of the stuff that would normally come from WSDL */
115:                /***********************************************************/
116:                call.setTargetEndpointAddress(new URL(opts.getURL()));
117:                call.setUseSOAPAction(true);
118:                call.setSOAPActionURI("getQuote");
119:                call
120:                        .setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/");
121:                call.setOperationName(new QName("urn:xmltoday-delayed-quotes",
122:                        "getQuote"));
123:                call.addParameter("symbol", XMLType.XSD_STRING,
124:                        ParameterMode.IN);
125:                call.setReturnType(XMLType.XSD_FLOAT);
126:
127:                /* Define some service specific properties */
128:                /*******************************************/
129:                call.setUsername(opts.getUser());
130:                call.setPassword(opts.getPassword());
131:
132:                /* Get symbol and invoke the service */
133:                /*************************************/
134:                Object result = call.invoke(new Object[] { symbol = args[0] });
135:
136:                return (((Float) result).floatValue());
137:            }
138:
139:            /**
140:             * This will use the WSDL to prefill all of the info needed to make
141:             * the call.  All that's left is filling in the args to invoke().
142:             */
143:            public float getQuote3(String args[]) throws Exception {
144:                Options opts = new Options(args);
145:
146:                args = opts.getRemainingArgs();
147:
148:                if (args == null) {
149:                    System.err.println("Usage: GetQuote <symbol>");
150:                    System.exit(1);
151:                }
152:
153:                /* Define the service QName and port QName */
154:                /*******************************************/
155:                QName servQN = new QName("urn:xmltoday-delayed-quotes",
156:                        "GetQuoteService");
157:                QName portQN = new QName("urn:xmltoday-delayed-quotes",
158:                        "GetQuote");
159:
160:                /* Now use those QNames as pointers into the WSDL doc */
161:                /******************************************************/
162:                Service service = new Service(new URL("file:GetQuote.wsdl"),
163:                        servQN);
164:                Call call = (Call) service.createCall(portQN, "getQuote");
165:
166:                /* Strange - but allows the user to change just certain portions of */
167:                /* the URL we're gonna use to invoke the service.  Useful when you  */
168:                /* want to run it thru tcpmon (ie. put  -p81 on the cmd line).      */
169:                /********************************************************************/
170:                opts.setDefaultURL(call.getTargetEndpointAddress());
171:                call.setTargetEndpointAddress(new URL(opts.getURL()));
172:
173:                /* Define some service specific properties */
174:                /*******************************************/
175:                call.setUsername(opts.getUser());
176:                call.setPassword(opts.getPassword());
177:
178:                /* Get symbol and invoke the service */
179:                /*************************************/
180:                Object result = call.invoke(new Object[] { symbol = args[0] });
181:                result = call.invoke(new Object[] { symbol = args[0] });
182:
183:                /* Reuse the call object to call the test method */
184:                /*************************************************/
185:                call.setOperation(portQN, "test");
186:                call.setReturnType(XMLType.XSD_STRING);
187:
188:                System.out.println(call.invoke(new Object[] {}));
189:
190:                return (((Float) result).floatValue());
191:            }
192:
193:            public static void main(String args[]) {
194:                try {
195:                    String save_args[] = new String[args.length];
196:                    float val;
197:                    GetQuote1 gq = new GetQuote1();
198:
199:                    /* Call the getQuote() that uses the WDSL */
200:                    /******************************************/
201:                    System.out.println("Using WSDL");
202:                    System.arraycopy(args, 0, save_args, 0, args.length);
203:                    val = gq.getQuote1(args);
204:                    System.out.println(gq.symbol + ": " + val);
205:
206:                    /* Call the getQuote() that does it all manually */
207:                    /*************************************************/
208:                    System.out.println("Manually");
209:                    System.arraycopy(save_args, 0, args, 0, args.length);
210:                    val = gq.getQuote2(args);
211:                    System.out.println(gq.symbol + ": " + val);
212:
213:                    /* Call the getQuote() that uses Axis's generated WSDL */
214:                    /*******************************************************/
215:                    System.out.println("WSDL + Reuse Call");
216:                    System.arraycopy(save_args, 0, args, 0, args.length);
217:                    val = gq.getQuote3(args);
218:                    System.out.println(gq.symbol + ": " + val);
219:                } catch (Exception e) {
220:                    e.printStackTrace();
221:                }
222:            }
223:        };
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.