1 16 17 package org.apache.axis.client; 18 19 import org.apache.axis.AxisFault; 20 import org.apache.axis.message.SOAPHeaderElement; 21 import org.apache.axis.utils.Messages; 22 23 import javax.xml.namespace.QName ; 24 import javax.xml.rpc.JAXRPCException ; 25 import javax.xml.rpc.Service ; 26 import javax.xml.rpc.ServiceException ; 27 import java.net.MalformedURLException ; 28 import java.net.URL ; 29 import java.util.Iterator ; 30 import java.util.Properties ; 31 import java.util.Vector ; 32 33 36 37 public abstract class Stub implements javax.xml.rpc.Stub { 38 39 protected Service service = null; 40 41 protected boolean maintainSessionSet = false; 48 protected boolean maintainSession = false; 49 50 protected Properties cachedProperties = new Properties (); 51 protected String cachedUsername = null; 52 protected String cachedPassword = null; 53 protected URL cachedEndpoint = null; 54 protected Integer cachedTimeout = null; 55 protected QName cachedPortName = null; 56 57 private Vector headers = new Vector (); 59 60 private Vector attachments = new Vector (); 62 63 private boolean firstCall = true; 67 68 protected Call _call = null; 70 71 74 protected boolean firstCall() { 75 boolean ret = firstCall; 76 firstCall = false; 77 return ret; 78 } 80 94 public void _setProperty(String name, Object value) { 95 if (name == null || value == null) { 96 throw new JAXRPCException ( 97 Messages.getMessage(name == null ? 98 "badProp03" : "badProp04")); 99 } 100 else if (name.equals(Call.USERNAME_PROPERTY)) { 101 if (!(value instanceof String )) { 102 throw new JAXRPCException ( 103 Messages.getMessage("badProp00", new String [] { 104 name, "java.lang.String", value.getClass().getName()})); 105 } 106 cachedUsername = (String ) value; 107 } 108 else if (name.equals(Call.PASSWORD_PROPERTY)) { 109 if (!(value instanceof String )) { 110 throw new JAXRPCException ( 111 Messages.getMessage("badProp00", new String [] { 112 name, "java.lang.String", value.getClass().getName()})); 113 } 114 cachedPassword = (String ) value; 115 } 116 else if (name.equals(Stub.ENDPOINT_ADDRESS_PROPERTY)) { 117 if (!(value instanceof String )) { 118 throw new JAXRPCException ( 119 Messages.getMessage("badProp00", new String [] { 120 name, "java.lang.String", value.getClass().getName()})); 121 } 122 try { 123 cachedEndpoint = new URL ((String ) value); 124 } 125 catch (MalformedURLException mue) { 126 throw new JAXRPCException (mue.getMessage()); 127 } 128 } 129 else if (name.equals(Call.SESSION_MAINTAIN_PROPERTY)) { 130 if (!(value instanceof Boolean )) { 131 throw new JAXRPCException ( 132 Messages.getMessage("badProp00", new String [] 133 {name, 134 "java.lang.Boolean", 135 value.getClass().getName()})); 136 } 137 maintainSessionSet = true; 138 maintainSession = ((Boolean ) value).booleanValue(); 139 } 140 else if (name.startsWith("java.") || name.startsWith("javax.")) { 141 throw new JAXRPCException ( 142 Messages.getMessage("badProp05", name)); 143 } 144 else { 145 cachedProperties.put(name, value); 146 } 147 } 149 156 public Object _getProperty(String name) { 157 if (name == null) { 158 throw new JAXRPCException ( 159 Messages.getMessage("badProp05", name)); 160 } 161 else { 162 if (name.equals(Call.USERNAME_PROPERTY)) { 163 return cachedUsername; 164 } 165 else if (name.equals(Call.PASSWORD_PROPERTY)) { 166 return cachedPassword; 167 } 168 else if (name.equals(Stub.ENDPOINT_ADDRESS_PROPERTY)) { 169 return cachedEndpoint.toString(); 170 } 171 else if (name.equals(Call.SESSION_MAINTAIN_PROPERTY)) { 172 return maintainSessionSet ? (maintainSession ? Boolean.TRUE : Boolean.FALSE) : null; 173 } 174 else if (name.startsWith("java.") || name.startsWith("javax.")) { 175 throw new JAXRPCException ( 176 Messages.getMessage("badProp05", name)); 177 } 178 else { 179 return cachedProperties.get(name); 180 } 181 } 182 } 184 191 public Object removeProperty(String name) { 192 return cachedProperties.remove(name); 193 } 194 197 public Iterator _getPropertyNames() { 198 return cachedProperties.keySet().iterator(); 199 } 201 204 public void setUsername(String username) { 205 cachedUsername = username; 206 } 208 211 public String getUsername() { 212 return cachedUsername; 213 } 215 218 public void setPassword(String password) { 219 cachedPassword = password; 220 } 222 225 public String getPassword() { 226 return cachedPassword; 227 } 229 232 public int getTimeout() { 233 return cachedTimeout == null ? 0 : cachedTimeout.intValue(); 234 } 236 239 public void setTimeout(int timeout) { 240 cachedTimeout = new Integer (timeout); 241 } 243 246 public QName getPortName() { 247 return cachedPortName; 248 } 250 253 public void setPortName(QName portName) { 254 cachedPortName = portName; 255 } 257 260 public void setPortName(String portName) { 261 setPortName(new QName (portName)); 262 } 264 267 public void setMaintainSession(boolean session) { 268 maintainSessionSet = true; 269 maintainSession = session; 270 cachedProperties.put(Call.SESSION_MAINTAIN_PROPERTY, session ? Boolean.TRUE : Boolean.FALSE); 271 } 273 274 280 public void setHeader(String namespace, String partName, Object headerValue) { 281 headers.add(new SOAPHeaderElement(namespace, partName, headerValue)); 282 } 283 284 287 public void setHeader(SOAPHeaderElement header) { 288 headers.add(header); 289 } 290 291 295 public void extractAttachments(Call call) { 296 attachments.clear(); 297 if(call.getResponseMessage() != null) { 298 Iterator iterator = call.getResponseMessage().getAttachments(); 299 while(iterator.hasNext()){ 300 attachments.add(iterator.next()); 301 } 302 } 303 } 304 305 309 public void addAttachment(Object handler) { 310 attachments.add(handler); 311 } 312 313 316 public SOAPHeaderElement getHeader(String namespace, String partName) { 317 for(int i=0;i<headers.size();i++) { 318 SOAPHeaderElement header = (SOAPHeaderElement)headers.get(i); 319 if(header.getNamespaceURI().equals(namespace) && 320 header.getName().equals(partName)) 321 return header; 322 } 323 return null; 324 } 325 326 329 public SOAPHeaderElement getResponseHeader(String namespace, String partName) { 330 try 331 { 332 if (_call == null) 333 return null; 334 return _call.getResponseMessage().getSOAPEnvelope().getHeaderByName(namespace, partName); 335 } 336 catch (Exception e) 337 { 338 return null; 339 } 340 } 341 342 345 public SOAPHeaderElement[] getHeaders() { 346 SOAPHeaderElement[] array = new SOAPHeaderElement[headers.size()]; 347 headers.copyInto(array); 348 return array; 349 } 350 351 354 public SOAPHeaderElement[] getResponseHeaders() { 355 SOAPHeaderElement[] array = new SOAPHeaderElement[0]; 356 try 357 { 358 if (_call == null) 359 return array; 360 Vector h = _call.getResponseMessage().getSOAPEnvelope().getHeaders(); 361 array = new SOAPHeaderElement[h.size()]; 362 h.copyInto(array); 363 return array; 364 } 365 catch (Exception e) 366 { 367 return array; 368 } 369 } 370 371 377 public Object [] getAttachments() { 378 Object [] array = new Object [attachments.size()]; 379 attachments.copyInto(array); 380 attachments.clear(); 381 return array; 382 } 383 384 387 public void clearHeaders() { 388 headers.clear(); 389 } 390 391 394 public void clearAttachments() { 395 attachments.clear(); 396 } 397 398 protected void setRequestHeaders(org.apache.axis.client.Call call) throws AxisFault { 399 SOAPHeaderElement[] headers = getHeaders(); 401 for(int i=0;i<headers.length;i++){ 402 call.addHeader(headers[i]); 403 } 404 } 405 406 412 protected void setAttachments(org.apache.axis.client.Call call) throws AxisFault { 413 Object [] attachments = getAttachments(); 415 for(int i=0;i<attachments.length;i++){ 416 call.addAttachmentPart(attachments[i]); 417 } 418 clearAttachments(); 419 } 420 421 426 public Service _getService() { 427 return service; 428 } 429 430 434 public Call _createCall() throws ServiceException { 435 _call = (Call) service.createCall(); 436 437 return _call; 440 } 441 442 445 public Call _getCall() { 446 return _call; 447 } 448 449 460 protected void getResponseHeaders(org.apache.axis.client.Call call) throws AxisFault { 461 } 462 463 } 464 | Popular Tags |