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


001:        package ejb.client.dynamic;
002:
003:        import javax.xml.namespace.QName;
004:
005:        import org.apache.wsif.WSIFMessage;
006:        import org.apache.wsif.WSIFException;
007:        import org.apache.wsif.WSIFOperation;
008:        import org.apache.wsif.WSIFPort;
009:        import org.apache.wsif.WSIFService;
010:        import org.apache.wsif.WSIFServiceFactory;
011:
012:        import ejb.service.addressbook.wsiftypes.Address;
013:        import ejb.service.addressbook.wsiftypes.Phone;
014:
015:        public class Run {
016:            private static void addFirstAddress(WSIFPort port) {
017:                try {
018:                    // create the operation
019:                    // note that we have two operations with the same name, so we need to specify the
020:                    // name of the input and output messages as well
021:                    WSIFOperation operation = port.createOperation("addEntry",
022:                            "AddEntryWholeNameRequest", null);
023:                    // create the input message associated with this operation
024:                    WSIFMessage input = operation.createInputMessage();
025:                    // populate the input message
026:                    input.setObjectPart("name", "John Smith");
027:                    // create an address object to populate the input
028:                    Address address = new Address();
029:                    address.setStreetNum(25);
030:                    address.setStreetName("Willow Road");
031:                    address.setCity("MyTown");
032:                    address.setState("PA");
033:                    address.setZip(28382);
034:                    Phone phone = new Phone();
035:                    phone.setAreaCode(288);
036:                    phone.setExchange("555");
037:                    phone.setNumber("9891");
038:                    address.setPhoneNumber(phone);
039:                    input.setObjectPart("address", address);
040:                    // do the invocation
041:                    System.out.println("Adding address for John Smith...");
042:                    operation.executeInputOnlyOperation(input);
043:                } catch (WSIFException we) {
044:                    System.out.println("Got exception from WSIF, details:");
045:                    we.printStackTrace();
046:                }
047:            }
048:
049:            private static void addSecondAddress(WSIFPort port) {
050:                try {
051:                    // create the operation
052:                    // note that we have two operations with the same name, so we need to specify the
053:                    // name of the input and output messages as well
054:                    WSIFOperation operation = port.createOperation("addEntry",
055:                            "AddEntryFirstAndLastNamesRequest", null);
056:                    // create the input message associated with this operation
057:                    WSIFMessage input = operation.createInputMessage();
058:                    // populate the input message
059:                    input.setObjectPart("firstName", "Jane");
060:                    input.setObjectPart("lastName", "White");
061:                    // create an address object to populate the input
062:                    Address address = new Address();
063:                    address.setStreetNum(20);
064:                    address.setStreetName("Peachtree Avenue");
065:                    address.setCity("Atlanta");
066:                    address.setState("GA");
067:                    address.setZip(39892);
068:                    Phone phone = new Phone();
069:                    phone.setAreaCode(701);
070:                    phone.setExchange("555");
071:                    phone.setNumber("8721");
072:                    address.setPhoneNumber(phone);
073:                    input.setObjectPart("address", address);
074:                    // do the invocation
075:                    System.out.println("Adding address for Jane White...");
076:                    operation.executeInputOnlyOperation(input);
077:                } catch (WSIFException we) {
078:                    System.out.println("Got exception from WSIF, details:");
079:                    we.printStackTrace();
080:                }
081:            }
082:
083:            private static void queryAddresses(WSIFPort port) {
084:                try {
085:                    // create the operation
086:                    WSIFOperation operation = port
087:                            .createOperation("getAddressFromName");
088:                    // create the input message associated with this operation
089:                    WSIFMessage input = operation.createInputMessage();
090:                    WSIFMessage output = operation.createOutputMessage();
091:                    WSIFMessage fault = operation.createFaultMessage();
092:                    // populate the input message
093:                    input.setObjectPart("name", "John Smith");
094:                    // do the invocation
095:                    System.out.println("Querying address for John Smith...");
096:                    if (operation.executeRequestResponseOperation(input,
097:                            output, fault)) {
098:                        // invocation succeeded
099:                        // extract the address from the output message
100:                        Address address = (Address) output
101:                                .getObjectPart("address");
102:                        System.out
103:                                .println("Service returned the following address:");
104:                        System.out.println(address.getStreetNum() + " "
105:                                + address.getStreetName() + ", "
106:                                + address.getCity() + " " + address.getState()
107:                                + " " + address.getZip() + "; Phone: ("
108:                                + address.getPhoneNumber().getAreaCode() + ") "
109:                                + address.getPhoneNumber().getExchange() + "-"
110:                                + address.getPhoneNumber().getNumber());
111:                    } else {
112:                        // invocation failed, check fault message
113:                    }
114:                    // create the operation
115:                    operation = port.createOperation("getAddressFromName");
116:                    // create the input message associated with this operation
117:                    input = operation.createInputMessage();
118:                    output = operation.createOutputMessage();
119:                    fault = operation.createFaultMessage();
120:                    // populate the input message
121:                    input.setObjectPart("name", "Jane White");
122:                    // do the invocation
123:                    System.out.println("Querying address for Jane White...");
124:                    if (operation.executeRequestResponseOperation(input,
125:                            output, fault)) {
126:                        // invocation succeeded
127:                        // extract the address from the output message
128:                        Address address = (Address) output
129:                                .getObjectPart("address");
130:                        System.out
131:                                .println("Service returned the following address:");
132:                        System.out.println(address.getStreetNum() + " "
133:                                + address.getStreetName() + ", "
134:                                + address.getCity() + " " + address.getState()
135:                                + " " + address.getZip() + "; Phone: ("
136:                                + address.getPhoneNumber().getAreaCode() + ") "
137:                                + address.getPhoneNumber().getExchange() + "-"
138:                                + address.getPhoneNumber().getNumber());
139:                    } else {
140:                        // invocation failed, check fault message
141:                    }
142:                } catch (WSIFException we) {
143:                    System.out.println("Got exception from WSIF, details:");
144:                    we.printStackTrace();
145:                }
146:            }
147:
148:            public static void main(String[] args) throws Exception {
149:                if (args.length != 1) {
150:                    System.out
151:                            .println("Usage: java ejb.client.dynamic.Run <wsdl location>");
152:                    System.exit(1);
153:                }
154:                // create a service factory
155:                WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
156:
157:                WSIFService service = factory.getService(args[0], null, null,
158:                        "http://wsifservice.addressbook/", "AddressBook");
159:                // map types
160:                service.mapType(new QName("http://wsiftypes.addressbook/",
161:                        "Address"), Class
162:                        .forName("ejb.service.addressbook.wsiftypes.Address"));
163:                service.mapType(new QName("http://wsiftypes.addressbook/",
164:                        "Phone"), Class
165:                        .forName("ejb.service.addressbook.wsiftypes.Phone"));
166:
167:                // get the port
168:                WSIFPort port = service.getPort();
169:                // add the first address
170:                addFirstAddress(port);
171:                // add the second address
172:                addSecondAddress(port);
173:                // query addresses
174:                queryAddresses(port);
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.