1 package Jt.axis; 2 import java.util.*; 3 import java.lang.reflect.*; 4 import java.beans.*; 5 import java.io.*; 6 import Jt.*; 7 import Jt.xml.*; 8 9 10 11 14 15 public class JtWebServicesAdapter extends JtScriptInterpreter { 16 17 JtXMLConverter xmlConverter = null; 18 JtAxisAdapter axisAdapter = null; 19 private String url = null; 20 private String remoteLogFile; 21 22 23 public JtWebServicesAdapter () { 24 } 25 26 27 31 32 public void setUrl (String url) { 33 this.url = url; 34 } 35 36 39 40 public String getUrl () { 41 return (url); 42 } 43 44 45 48 49 public String getRemoteLogFile () { 50 return (remoteLogFile); 51 } 52 53 54 58 59 public void setRemoteLogFile (String remoteLogFile) { 60 this.remoteLogFile = remoteLogFile; 61 } 62 63 64 65 66 67 69 private Exception propagateException (Object obj) 70 { 71 Exception ex; 72 73 if (obj == null) 74 return null; 75 76 ex = (Exception ) 77 super.getValue (obj, "objException"); 78 79 if (ex != null) 80 super.setValue (this, "objException", ex); 81 82 return (ex); 83 } 84 85 86 89 90 public Object createObject (Object class_name, Object id) { 91 String xmlMsg; 92 Object output; 93 94 if (class_name == null || id == null) { handleError ("JtWebServiceAdapter.createObject: invalid parameters"); 96 return (null); 97 } 98 99 if (xmlConverter == null) 100 xmlConverter = new JtXMLConverter (); 101 102 xmlConverter.createObject (class_name, id); 103 xmlMsg = (String ) xmlConverter.processMessage (new JtMessage ("JtCONVERT")); 105 106 107 output = doit (xmlMsg); 108 xmlConverter = null; 109 110 return (output); 111 } 112 113 114 private void updateRemoteLogFile () { 115 116 String xmlMsg; 117 JtMessage msg; 118 JtXMLConverter xmlconverter; 119 120 121 if (axisAdapter == null) 122 return; 123 124 xmlConverter = new JtXMLConverter (); 125 126 xmlConverter.setValue ("this", "logFile", remoteLogFile); 127 128 xmlMsg = (String ) xmlConverter.processMessage (new JtMessage ("JtCONVERT")); 129 130 131 msg = new JtMessage ("JtSCRIPT"); 132 msg.setMsgContent (xmlMsg); 133 134 super.sendMessage (axisAdapter, msg); 135 136 137 } 138 139 public void removeObject (Object id) { 140 String xmlMsg; 141 Object output; 142 143 if (id == null) { handleError ("JtWebServiceAdapter.createObject: invalid parameters"); 145 return; 146 } 147 148 if (xmlConverter == null) 149 xmlConverter = new JtXMLConverter (); 150 151 xmlConverter.removeObject (id); 152 xmlMsg = (String ) xmlConverter.processMessage (new JtMessage ("JtCONVERT")); 154 155 156 output = doit (xmlMsg); 157 xmlConverter = null; 158 159 160 } 161 162 163 private Object doit (String xmlMsg) { 164 165 JtMessage msg; 166 Object output; 167 168 if (xmlMsg == null) 169 return (null); 171 172 175 msg = new JtMessage ("JtSCRIPT"); 176 msg.setMsgContent (xmlMsg); 177 178 179 if (url == null) { 180 handleError ("JtWebServiceAdapter.sendMessage: invalid url (null)"); 181 return (null); 182 } 183 184 if (axisAdapter == null) { 185 axisAdapter = (JtAxisAdapter) super.createObject ("Jt.axis.JtAxisAdapter", 186 "adapter"); 187 188 super.setValue (axisAdapter, "url", url); 189 updateRemoteLogFile (); 190 } 191 192 193 output = super.sendMessage (axisAdapter, msg); 194 195 propagateException (axisAdapter); 196 return (output); 197 198 199 } 200 201 202 public Object sendMessage (Object id, Object msgid) { 203 204 String xmlMsg; 205 JtMessage msg; 206 Object output; 207 Exception ex; 208 209 if (id == null || msgid == null) { 210 handleError ("JtWebServiceAdapter.sendMessage: invalid parameters"); 211 return (null); 212 } 213 214 215 if (xmlConverter == null) 216 xmlConverter = new JtXMLConverter (); 217 218 219 221 xmlConverter.sendMessage (id, msgid); 222 223 xmlMsg = (String ) xmlConverter.processMessage (new JtMessage ("JtCONVERT")); 225 226 xmlConverter = null; 227 228 output = doit (xmlMsg); 229 230 232 return (output); 233 234 } 235 236 237 public void setValue (Object id, Object att, 238 Object value) { 239 String xmlMsg; 240 241 242 if (id == null || att == null) { handleError ("JtWebServiceAdapter.sendMessage: invalid parameters"); 244 return; 245 } 246 247 248 if (xmlConverter == null) 249 xmlConverter = new JtXMLConverter (); 250 251 253 xmlConverter.setValue (id, att, value); 254 xmlMsg = (String ) xmlConverter.processMessage (new JtMessage ("JtCONVERT")); 256 257 xmlConverter = null; 258 259 doit (xmlMsg); 260 } 262 263 264 266 public Object processMessage (Object event) { 267 268 String msgid = null; 269 JtMessage e = (JtMessage) event; 270 Object content; 271 272 if (e == null) 273 return null; 274 275 msgid = (String ) e.getMsgId (); 276 277 if (msgid == null) 278 return null; 279 280 content = e.getMsgContent(); 281 282 handleError ("processMessage: invalid message ID:" + msgid); 283 return (null); 284 285 286 287 } 288 289 290 291 294 295 public static void main(String [] args) { 296 297 JtObject main = new JtObject (); 298 299 JtWebServicesAdapter myService; 300 String str; 301 String reply = null; 302 Exception ex; 303 304 307 308 310 myService = (JtWebServicesAdapter) main.createObject ("Jt.axis.JtWebServicesAdapter", 311 "service"); 312 313 315 if (main.getValue (myService, "url") == null) 316 main.setValue (myService, "url", 317 "http://localhost:8080/axis/services/JtAxisService"); 318 319 321 if (main.getValue (myService, "remoteLogFile") == null) 322 main.setValue (myService, "remoteLogFile", 323 "c:\\log.txt"); 324 325 326 330 myService.createObject ("Jt.examples.HelloWorld", "helloWorld"); 331 333 334 336 myService.setValue ("helloWorld", "greetingMessage", "Hello there..."); 337 338 339 341 myService.createObject ("Jt.JtMessage", "message"); 342 myService.setValue ("message", "msgId", "JtHello"); 343 344 345 347 reply = (String ) myService.sendMessage ("helloWorld", "message"); 348 349 ex = (Exception ) main.getValue (myService, "objException"); 350 351 352 354 if (ex == null) 355 System.out.println (reply); 356 357 359 myService.removeObject ("helloWorld"); 360 361 362 } 363 364 } 365 366 367 | Popular Tags |