1 2 package Jt.axis; 3 import java.util.*; 4 import java.lang.reflect.*; 5 import java.beans.*; 6 import java.io.*; 7 import Jt.*; 8 import Jt.xml.*; 9 10 import org.apache.axis.client.Call; 11 import org.apache.axis.client.Service; 12 import org.apache.axis.encoding.XMLType; 13 import org.apache.axis.utils.Options; 14 15 import javax.xml.namespace.QName ; 16 import javax.xml.rpc.ParameterMode ; 17 18 19 22 23 public class JtAxisAdapter extends JtObject { 24 25 26 private String url = null; 27 private Service service = null; 28 private Call call = null; 29 private String remoteLogFile; 30 31 32 public JtAxisAdapter() { 33 } 34 35 37 38 39 43 44 public void setUrl (String url) { 45 this.url = url; 46 } 47 48 51 52 public String getUrl () { 53 return (url); 54 } 55 56 57 60 61 public String getRemoteLogFile () { 62 return (remoteLogFile); 63 } 64 65 66 70 71 public void setRemoteLogFile (String remoteLogFile) { 72 this.remoteLogFile = remoteLogFile; 73 } 74 75 76 78 public Object processMessage (Object event) { 79 80 String msgid = null; 81 JtMessage e = (JtMessage) event; 82 Object content; 83 84 if (e == null) 85 return null; 86 87 msgid = (String ) e.getMsgId (); 88 89 if (msgid == null) 90 return null; 91 92 content = e.getMsgContent(); 93 94 95 if (msgid.equals ("JtSCRIPT")) { 96 97 return (processJtScript ((String ) content)); 98 99 } 100 101 if (msgid.equals ("JtREMOVE")) { 102 return (null); 103 } 104 105 handleError ("JtAxisAdapter.processMessage: invalid message id:" + msgid); 106 return (null); 107 108 } 109 110 111 private Object processJtScript (String xmlMsg) 112 { 113 114 String ret = null; 115 JtXMLHelper xmlHelper = null; 116 JtMessage msg = new JtMessage ("JtCONVERT_XML_TO_OBJECT"); 117 String xmlOutput = null; 118 Object tmp, tmp1, output = null; 119 JtIterator it; 120 121 122 if (xmlMsg == null) 123 return (null); 124 125 try { 127 128 if (service == null) { 129 130 service = new Service(); 131 133 134 call = (Call) service.createCall(); 135 136 if (url == null) { 137 handleError ("processxmlMessage: invalid attribute value: url (null)"); 138 return (null); 139 } 140 141 142 call.setTargetEndpointAddress( new java.net.URL (url) ); 143 call.setMaintainSession (true); 144 145 call.setOperationName("processMessage"); 148 149 call.addParameter( "arg1", XMLType.XSD_STRING, ParameterMode.IN); 150 call.setReturnType( org.apache.axis.encoding.XMLType.XSD_STRING ); 151 } 152 ret = (String ) call.invoke( new Object [] { xmlMsg } ); 153 154 } catch (Exception e) { 155 handleException (e); 156 return (null); 157 } 158 159 160 if (xmlHelper == null) 161 xmlHelper = new JtXMLHelper (); 162 163 166 msg.setMsgContent (ret); 167 169 170 tmp = sendMessage (xmlHelper, msg); 171 172 173 175 if (tmp instanceof JtList) { 176 177 it = (JtIterator) getValue (tmp, "iterator"); 178 179 if (it == null) 180 return (null); 181 182 for (;;) { 183 184 tmp1 = it.processMessage (new JtMessage ("JtNEXT")); 186 187 if (tmp1 == null) 188 break; 189 if (tmp1 instanceof JtRemoteException) { 190 handleError ("JtAxisAdapter.processJtScript: remote exception detected"); 191 192 handleWarning ("<Remote Exception>\n" + 193 ((JtRemoteException) tmp1).getTrace () + "</Remote Exception>\n"); 194 } else 196 output = tmp1; 198 } 199 return (output); } else 201 return (tmp); 202 } 203 204 205 208 209 210 public static void main(String [] args) { 211 212 JtObject main = new JtObject (); 213 JtMessage msg; 214 JtAxisAdapter adapter; 215 String st = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 216 "<Object>\n" + 217 "<classname>Jt.JtList</classname>\n" + 218 "<Object>\n" + 219 "<classname>Jt.JtMessage</classname>\n" + 220 "<msgId>JtCREATE_OBJECT</msgId>\n" + 221 "<msgContent>Jt.JtObject</msgContent>\n" + 222 "<msgData>test</msgData>\n" + 223 "</Object>\n"; 224 225 226 227 228 231 msg = new JtMessage (); 232 233 234 msg.setMsgId ("JtSCRIPT"); 235 msg.setMsgContent ("Hello world"); 236 237 238 240 adapter = (JtAxisAdapter) main.createObject ("Jt.service.JtAxisAdapter", "adapter"); 241 main.setValue (adapter, "url", 242 "http://localhost:8080/axis/services/MyService"); 243 244 main.sendMessage (adapter, msg); 245 246 247 } 248 249 } 250 251 252 | Popular Tags |