WSDL Samples

lpclient_wsdl_rpc.java

 

1 import LPClient.*;
2 
3 
4 /*
5  * for java use the following command to generate the LPClient and MsiAppOriginator wsdl java files
6  *
7  * java org.apache.axis.wsdl.WSDL2Java -pLPClient http://joea:8080/mpower-v53a/services/LPClient?wsdl
8  * 
9  * then cd LPClient and execute 
10  * javac *.java
11  *
12  * then cd up a directory and the following code should work
13  */
14 public class lpclient_wsdl
15    {
16         public static void main(String args[]) throws Exception
17         {
18 
19                 /** 
20                  * the next line actually creates a service locator
21                  * we need the locator because we need to tell the locator 
22                  * to maintain session  
23                  */
24                 LPClientInterfaceServiceLocator locator = new LPClientInterfaceServiceLocator();
25 
26                 /**
27                  * setup maintain session this way successive WSDL calls 
28                  * will NOT create a new session each time 
29                  */
30                 locator.setMaintainSession(true);
31                 
32                 /**
33                  * this is where we actually create an instance of our client Object
34                  */
35                 LPClientInterface clientObj = locator.getLPClient();
36                 if ( clientObj == null ) {
37                         System.out.println("Error has occured, could not create client Object.");
38                         return;
39                 }
40            
41                 /**
42                  * connect to the wsdl service
43                  */
44                 boolean res = clientObj.dsConnect();
45                 System.out.println( "Connection Status = " + res );
46 
47                 
48                 /**
49                  * the connection status should return true on success
50                  */
51                 if ( res ) {
52                         /**
53                          * set this to true for debugging
54                          * it defaults to false
55                          */
56                         //clientObj.dsSetDebugMode(true);
57 
58                         /** 
59                          * create a string to hold the upcoming xml document
60                          */
61                         String result = new String();
62 
63                         /**
64                          * for lessee editing we need number of the client
65                          * getXMLLesseeDoc() ALWAYS returns a STRING 
66                          * which should contain either the lessee record 
67                          * as an xml document or a remote exception
68                          * NOTE: 25 is the les_s field from ral that you want 
69                          * to work on  
70                          */
71                         try { 
72                                 result = clientObj.getXMLLesseeDoc("25"); 
73                                 System.out.println("Result was " + result);
74                                 // example 
75                                 // Result was <?xml version="1.0"?><LESSEE_RECORD><papAchType>PPD </papAchType>
76                                 //      <remittanceAddress>   1</remittanceAddress><age>0</age><portfolio> 2</portfolio>
77                                 //      <name>default dummy                 </name><papAcctType>CHKG</papAcctType>
78                                 //      <lastPhoneUsed> </lastPhoneUsed><useTaxExemptCode>NONE</useTaxExemptCode>
79                                 //      <clientNumber>       25</clientNumber><shortname>DEFAULT DUMMY            </shortname>
80                                 //      <ssnBusinessID>                    </ssnBusinessID><noDependents>0</noDependents>
81                                 //      <prenoteSent>Y</prenoteSent></LESSEE_RECORD>
82                                 
83                         } catch ( Exception e ) {
84                                 System.out.println(e.toString());
85                                 clientObj.dsDisconnect();
86                                 return;
87                         }
88 
89                         /**
90                          * insert your code to modify the xml document you now have
91                          * this example shows the update of an address 
92                          */
93                         StringBuffer xmldocument = new StringBuffer();        
94                         xmldocument.append("<?xml version=\"1.0\"?><MSI_APP_ORIG><LESSEE_RECORD>");
95                         xmldocument.append("<clientNumber>25</clientNumber>");               
96                         xmldocument.append("<portfolio>" + "2" + "</portfolio>");               
97                         xmldocument.append("<region>" + "1" + "</region>");               
98                         xmldocument.append("<office>" + "1" + "</office>");               
99                         xmldocument.append("<company>" + "1" + "</company>");               
100                         xmldocument.append("<address1>" + "111 Anza Blvd" + "</address1>");               
101                         xmldocument.append("<city>" + "San Francisco" + "</city>");                
102                         xmldocument.append("<state>" + "CA" + "</state>");                
103                         xmldocument.append("<zipCode>" + "90141" + "</zipCode>");                
104                         xmldocument.append("</LESSEE_RECORD></MSI_APP_ORIG>");      
105                 
106                         if ( clientObj.apiInitXMLParser( xmldocument.toString() ) ) {
107                                 // false means that you you are updating this record
108                                 // this will return 0 on means error, 
109                                 // 1 for an informational message, usually on adds or updates, 
110                                 // and 2 processing is completed with no message, usually if the 
111                                 // record already exists and the add update flag is set to addOnly or true.
112                                 int rc = clientObj.processLessee( true ); 
113                                 System.out.println("Update returned = " + rc);
114                                 switch ( rc  ) {
115                                         case 0:
116                                                 System.out.println( clientObj.getErrorMessage() );
117                                                 break;
118                                         case 1: 
119                                                 System.out.println( clientObj.getInfoMessage() );
120                                                 break;
121                                 }
122                         }                                                                       
123         
124                         /**
125                          * lastly close this transaction and destroy the session 
126                          */
127                         clientObj.dsDisconnect();
128                 }
129 
130         }
131 }
132