1 55 56 package org.jboss.axis.client; 57 58 import org.jboss.axis.AxisFault; 59 import org.jboss.axis.Message; 60 import org.jboss.axis.message.SOAPHeaderElementAxisImpl; 61 import org.jboss.axis.utils.Messages; 62 63 import javax.xml.namespace.QName ; 64 import javax.xml.rpc.JAXRPCException ; 65 import javax.xml.rpc.Service ; 66 import java.net.MalformedURLException ; 67 import java.net.URL ; 68 import java.util.Iterator ; 69 import java.util.Properties ; 70 import java.util.Vector ; 71 72 75 76 public abstract class Stub implements javax.xml.rpc.Stub 77 { 78 79 protected Service service = null; 80 81 protected boolean maintainSessionSet = false; 88 protected boolean maintainSession = false; 89 90 protected Properties cachedProperties = new Properties (); 91 protected String cachedUsername = null; 92 protected String cachedPassword = null; 93 protected URL cachedEndpoint = null; 94 protected Integer cachedTimeout = null; 95 protected QName cachedPortName = null; 96 97 private Vector headers = new Vector (); 99 100 private Vector attachments = new Vector (); 102 103 private boolean firstCall = true; 107 108 111 protected boolean firstCall() 112 { 113 boolean ret = firstCall; 114 firstCall = false; 115 return ret; 116 } 118 132 public void _setProperty(String name, Object value) 133 { 134 if (name == null || value == null) 135 { 136 throw new JAXRPCException (Messages.getMessage(name == null ? 137 "badProp03" : "badProp04")); 138 } 139 else if (name.equals(Call.USERNAME_PROPERTY)) 140 { 141 if (!(value instanceof String )) 142 { 143 throw new JAXRPCException (Messages.getMessage("badProp00", new String []{ 144 name, "java.lang.String", value.getClass().getName()})); 145 } 146 cachedUsername = (String )value; 147 } 148 else if (name.equals(Call.PASSWORD_PROPERTY)) 149 { 150 if (!(value instanceof String )) 151 { 152 throw new JAXRPCException (Messages.getMessage("badProp00", new String []{ 153 name, "java.lang.String", value.getClass().getName()})); 154 } 155 cachedPassword = (String )value; 156 } 157 else if (name.equals(Stub.ENDPOINT_ADDRESS_PROPERTY)) 158 { 159 if (!(value instanceof String )) 160 { 161 throw new JAXRPCException (Messages.getMessage("badProp00", new String []{ 162 name, "java.lang.String", value.getClass().getName()})); 163 } 164 try 165 { 166 cachedEndpoint = new URL ((String )value); 167 } 168 catch (MalformedURLException mue) 169 { 170 throw new JAXRPCException (mue.getMessage()); 171 } 172 } 173 else if (name.equals(Call.SESSION_MAINTAIN_PROPERTY)) 174 { 175 if (!(value instanceof Boolean )) 176 { 177 throw new JAXRPCException (Messages.getMessage("badProp00", new String [] 178 {name, 179 "java.lang.Boolean", 180 value.getClass().getName()})); 181 } 182 maintainSessionSet = true; 183 maintainSession = ((Boolean )value).booleanValue(); 184 } 185 else if (name.startsWith("java.") || name.startsWith("javax.")) 186 { 187 throw new JAXRPCException (Messages.getMessage("badProp05", name)); 188 } 189 else 190 { 191 cachedProperties.put(name, value); 192 } 193 } 195 201 public Object _getProperty(String name) 202 { 203 if (name != null) 204 { 205 if (name.equals(Call.USERNAME_PROPERTY)) 206 { 207 return cachedUsername; 208 } 209 else if (name.equals(Call.PASSWORD_PROPERTY)) 210 { 211 return cachedPassword; 212 } 213 else if (name.equals(Stub.ENDPOINT_ADDRESS_PROPERTY)) 214 { 215 return cachedEndpoint.toString(); 216 } 217 else if (name.equals(Call.SESSION_MAINTAIN_PROPERTY)) 218 { 219 return maintainSessionSet ? new Boolean (maintainSession) : null; 220 } 221 else if (name.startsWith("java.") || name.startsWith("javax.")) 222 { 223 throw new JAXRPCException (Messages.getMessage("badProp05", name)); 224 } 225 else 226 { 227 return cachedProperties.get(name); 228 } 229 } 230 else 231 { 232 return null; 233 } 234 } 236 243 public Object removeProperty(String name) 244 { 245 return cachedProperties.remove(name); 246 } 247 248 251 public Iterator _getPropertyNames() 252 { 253 return cachedProperties.keySet().iterator(); 254 } 256 259 public void setUsername(String username) 260 { 261 cachedUsername = username; 262 } 264 267 public String getUsername() 268 { 269 return cachedUsername; 270 } 272 275 public void setPassword(String password) 276 { 277 cachedPassword = password; 278 } 280 283 public String getPassword() 284 { 285 return cachedPassword; 286 } 288 291 public int getTimeout() 292 { 293 return cachedTimeout == null ? 0 : cachedTimeout.intValue(); 294 } 296 299 public void setTimeout(int timeout) 300 { 301 cachedTimeout = new Integer (timeout); 302 } 304 307 public QName getPortName() 308 { 309 return cachedPortName; 310 } 312 315 public void setPortName(QName portName) 316 { 317 cachedPortName = portName; 318 } 320 323 public void setPortName(String portName) 324 { 325 setPortName(new QName (portName)); 326 } 328 331 public void setMaintainSession(boolean session) 332 { 333 maintainSessionSet = true; 334 maintainSession = session; 335 cachedProperties.put(Call.SESSION_MAINTAIN_PROPERTY, new Boolean (session)); 336 } 338 339 346 public void setHeader(String namespace, String partName, String headerValue) 347 { 348 headers.add(new SOAPHeaderElementAxisImpl(namespace, partName, headerValue)); 349 } 350 351 354 public void setHeader(SOAPHeaderElementAxisImpl header) 355 { 356 headers.add(header); 357 } 358 359 364 public void extractAttachments(Call call) 365 { 366 attachments.clear(); 367 Message resMessage = call.getResponseMessage(); 368 if (resMessage != null && resMessage.countAttachments() > 0) 369 { 370 Iterator iterator = resMessage.getAttachments(); 371 while (iterator.hasNext()) 372 { 373 attachments.add(iterator.next()); 374 } 375 } 376 } 377 378 383 public void addAttachment(Object handler) 384 { 385 attachments.add(handler); 386 } 387 388 391 public SOAPHeaderElementAxisImpl getHeader(String namespace, String partName) 392 { 393 for (int i = 0; i < headers.size(); i++) 394 { 395 SOAPHeaderElementAxisImpl header = (SOAPHeaderElementAxisImpl)headers.get(i); 396 if (header.getNamespaceURI().equals(namespace) && 397 header.getName().equals(partName)) 398 return header; 399 } 400 return null; 401 } 402 403 406 public SOAPHeaderElementAxisImpl[] getHeaders() 407 { 408 SOAPHeaderElementAxisImpl[] array = new SOAPHeaderElementAxisImpl[headers.size()]; 409 headers.copyInto(array); 410 return array; 411 } 412 413 416 public Object [] getAttachments() 417 { 418 Object [] array = new Object [attachments.size()]; 419 attachments.copyInto(array); 420 attachments.clear(); 421 return array; 422 } 423 424 427 public void clearHeaders() 428 { 429 headers.clear(); 430 } 431 432 435 public void clearAttachments() 436 { 437 attachments.clear(); 438 } 439 440 protected void setRequestHeaders(org.jboss.axis.client.Call call) throws AxisFault 441 { 442 SOAPHeaderElementAxisImpl[] headers = getHeaders(); 443 for (int i = 0; i < headers.length; i++) 444 { 445 call.addHeader(headers[i]); 446 } 447 } 448 449 protected void setAttachments(org.jboss.axis.client.Call call) throws AxisFault 450 { 451 Object [] attachments = getAttachments(); 452 for (int i = 0; i < attachments.length; i++) 453 { 454 call.addAttachmentPart(attachments[i]); 455 } 456 } 457 458 468 protected void getResponseHeaders(org.jboss.axis.client.Call call) throws AxisFault 469 { 470 } 471 472 } 473 | Popular Tags |