1 55 56 package org.jboss.axis.message; 57 58 import org.jboss.axis.AxisFault; 59 import org.jboss.axis.Constants; 60 import org.jboss.axis.Message; 61 import org.jboss.axis.MessageContext; 62 import org.jboss.axis.description.OperationDesc; 63 import org.jboss.axis.description.ParameterDesc; 64 import org.jboss.axis.description.ServiceDesc; 65 import org.jboss.axis.encoding.DeserializationContext; 66 import org.jboss.axis.encoding.SerializationContext; 67 import org.jboss.axis.enums.Style; 68 import org.jboss.axis.enums.Use; 69 import org.jboss.axis.handlers.soap.SOAPService; 70 import org.jboss.axis.soap.SOAPConstants; 71 import org.jboss.axis.utils.JavaUtils; 72 import org.jboss.axis.utils.Messages; 73 import org.jboss.axis.wsdl.toJava.Utils; 74 import org.jboss.logging.Logger; 75 import org.xml.sax.Attributes ; 76 import org.xml.sax.SAXException ; 77 78 import javax.xml.namespace.QName ; 79 import javax.xml.soap.SOAPElement ; 80 import javax.xml.soap.SOAPException ; 81 import java.util.ArrayList ; 82 import java.util.Enumeration ; 83 import java.util.Vector ; 84 85 public class RPCElement extends SOAPBodyElementAxisImpl 86 { 87 private static Logger log = Logger.getLogger(RPCElement.class.getName()); 88 89 protected Vector params = new Vector (); 90 protected boolean needDeser = false; 91 OperationDesc[] operations = null; 92 93 public RPCElement(String namespace, String localName, String prefix, Attributes attributes, DeserializationContext context, OperationDesc[] operations) throws AxisFault 94 { 95 super(namespace, localName, prefix, attributes, context); 96 97 needDeser = true; 99 100 MessageContext msgContext = context.getMessageContext(); 101 102 if (operations == null && msgContext != null) 104 { 105 SOAPService service = msgContext.getService(); 106 if (service != null) 107 { 108 ServiceDesc serviceDesc = 109 service.getInitializedServiceDesc(msgContext); 110 111 String lc = Utils.xmlNameToJava(name); 112 if (serviceDesc == null) 113 { 114 AxisFault.makeFault(new ClassNotFoundException (Messages.getMessage("noClassForService00", 115 lc))); 116 } 117 118 operations = serviceDesc.getOperationsByName(lc); 119 } 120 } 121 this.operations = operations; 122 } 123 124 public RPCElement(String namespace, String methodName, Object [] args) 125 { 126 super(namespace, methodName); 127 this.setNamespaceURI(namespace); 128 this.name = methodName; 129 130 for (int i = 0; args != null && i < args.length; i++) 131 { 132 RPCParam rpcParam = null; 133 if (args[i] instanceof RPCParam) 134 { 135 rpcParam = (RPCParam)args[i]; 136 137 } 138 else 139 { 140 String name = null; 141 if (name == null) name = "arg" + i; 142 rpcParam = new RPCParam(namespace, name, args[i]); 143 } 144 145 addParam(rpcParam); 146 147 151 try 152 { 153 addChildElement(new RPCParamElementImpl(rpcParam)); 154 } 155 catch (SOAPException e) 156 { 157 log.error("Cannot ass rpc param child element", e); 158 } 159 } 160 } 161 162 public RPCElement(String methodName) 163 { 164 super(methodName); 165 this.name = methodName; 166 } 167 168 public String getMethodName() 169 { 170 return name; 171 } 172 173 public void setNeedDeser(boolean needDeser) 174 { 175 this.needDeser = needDeser; 176 } 177 178 public void deserialize() throws SAXException 179 { 180 needDeser = false; 181 182 MessageContext msgContext = context.getMessageContext(); 183 184 Message msg = msgContext.getCurrentMessage(); 187 SOAPConstants soapConstants = msgContext.getSOAPConstants(); 188 189 boolean isResponse = ((msg != null) && 190 Message.RESPONSE.equals(msg.getMessageType())); 191 192 RPCHandler rpcHandler = new RPCHandler(this, isResponse); 194 195 if (operations != null) 196 { 197 int numParams = getChildren().size(); 198 199 SAXException savedException = null; 200 201 boolean acceptMissingParams = msgContext.isPropertyTrue(MessageContext.ACCEPTMISSINGPARAMS, 204 true); 205 206 211 for (int i = 0; i < operations.length; i++) 212 { 213 OperationDesc operation = operations[i]; 214 215 boolean needHeaderProcessing = 217 needHeaderProcessing(operation, isResponse); 218 219 if (operation.getStyle() == Style.DOCUMENT || 236 operation.getStyle() == Style.WRAPPED || 237 operation.getUse() == Use.LITERAL || 238 (acceptMissingParams ? 239 (operation.getNumInParams() >= numParams) : 240 (operation.getNumInParams() == numParams))) 241 { 242 243 boolean isEncoded = operation.getUse() == Use.ENCODED; 244 rpcHandler.setOperation(operation); 245 try 246 { 247 if ((operation.getStyle() == Style.DOCUMENT) && 251 operation.getNumInParams() > 0) 252 { 253 context.pushElementHandler(rpcHandler); 254 context.setCurElement(null); 255 } 256 else 257 { 258 context.pushElementHandler(new EnvelopeHandler(rpcHandler)); 259 context.setCurElement(this); 260 } 261 262 publishToHandler((org.xml.sax.ContentHandler )context); 263 264 if (needHeaderProcessing) 268 { 269 processHeaders(operation, isResponse, 270 context, rpcHandler); 271 } 272 273 boolean match = true; 276 for (int j = 0; j < params.size() && match; j++) 277 { 278 RPCParam rpcParam = (RPCParam)params.get(j); 279 Object value = rpcParam.getValue(); 280 281 ParameterDesc paramDesc = rpcParam.getParamDesc(); 283 284 if (paramDesc != null && paramDesc.getJavaType() != null) 288 { 289 290 Class sigType = paramDesc.getJavaType(); 292 if (!JavaUtils.isConvertable(value, sigType, isEncoded)) 293 match = false; 294 } 295 } 296 if (!match) 298 { 299 params = new Vector (); 300 continue; 301 } 302 303 msgContext.setOperation(operation); 305 return; 306 } 307 catch (SAXException e) 308 { 309 savedException = e; 311 params = new Vector (); 312 continue; 313 } 314 catch (AxisFault e) 315 { 316 savedException = new SAXException (e); 319 params = new Vector (); 320 continue; 321 } 322 } 323 } 324 325 if (!msgContext.isClient() && soapConstants == SOAPConstants.SOAP12_CONSTANTS) 327 { 328 AxisFault fault = new AxisFault(Constants.FAULT_SOAP12_SENDER, "string", null, null); 329 fault.addFaultSubCode(Constants.FAULT_SUBCODE_BADARGS); 330 throw new SAXException (fault); 331 } 332 333 if (savedException != null) 334 { 335 throw savedException; 336 } 337 else if (!msgContext.isClient()) 338 { 339 QName faultCode = new QName (Constants.FAULT_SERVER_USER); 340 if (soapConstants == SOAPConstants.SOAP12_CONSTANTS) 341 faultCode = Constants.FAULT_SOAP12_SENDER; 342 AxisFault fault = new AxisFault(faultCode, 343 null, Messages.getMessage("noSuchOperation", name), null, null, null); 344 345 throw new SAXException (fault); 346 } 347 } 348 349 if (operations != null) 350 { 351 rpcHandler.setOperation(operations[0]); 352 } 353 354 if (operations != null && operations.length > 0 && 357 (operations[0].getStyle() == Style.DOCUMENT)) 358 { 359 context.pushElementHandler(rpcHandler); 360 context.setCurElement(null); 361 } 362 else 363 { 364 context.pushElementHandler(new EnvelopeHandler(rpcHandler)); 365 context.setCurElement(this); 366 } 367 368 publishToHandler((org.xml.sax.ContentHandler )context); 369 } 370 371 375 public RPCParam getParam(String name) throws SAXException 376 { 377 if (needDeser) 378 { 379 deserialize(); 380 } 381 382 for (int i = 0; i < params.size(); i++) 383 { 384 RPCParam param = (RPCParam)params.elementAt(i); 385 if (param.getName().equals(name)) 386 return param; 387 } 388 389 return null; 390 } 391 392 public Vector getParams() throws SAXException 393 { 394 if (needDeser) 395 { 396 deserialize(); 397 } 398 399 return params; 400 } 401 402 public void addParam(RPCParam param) 403 { 404 param.setRPCCall(this); 405 params.addElement(param); 406 } 407 408 protected void outputImpl(SerializationContext context) throws Exception 409 { 410 boolean hasOperationElement = true; 411 412 MessageContext msgContext = context.getMessageContext(); 413 if (msgContext != null) 414 hasOperationElement = msgContext.getOperationStyle() == Style.RPC || msgContext.getOperationStyle() == Style.WRAPPED; 415 416 boolean noParams = params.size() == 0; 421 if (this.needDeser && context.getCurrentMessage() != null) 423 noParams = getParams().size() == 0; 424 425 if (hasOperationElement || noParams) 426 { 427 if (encodingStyle != null && encodingStyle.equals("")) 430 { 431 context.registerPrefixForURI("", getNamespaceURI()); 432 } 433 context.startElement(new QName (getNamespaceURI(), name), attributes); 434 } 435 436 for (int i = 0; i < params.size(); i++) 437 { 438 RPCParam param = (RPCParam)params.elementAt(i); 439 if (!hasOperationElement && encodingStyle != null && encodingStyle.equals("")) 440 { 441 String uri = param.getQName().getNamespaceURI(); 442 String prefix = context.getPrefixForURI(uri); 443 context.registerPrefixForURI(prefix, uri); 444 } 445 param.serialize(context); 446 } 447 448 if (hasOperationElement || noParams) 449 { 450 context.endElement(); 451 } 452 } 453 454 462 private boolean needHeaderProcessing(OperationDesc operation, 463 boolean isResponse) 464 { 465 466 ArrayList paramDescs = operation.getParameters(); 469 if (paramDescs != null) 470 { 471 for (int j = 0; j < paramDescs.size(); j++) 472 { 473 ParameterDesc paramDesc = 474 (ParameterDesc)paramDescs.get(j); 475 if ((!isResponse && paramDesc.isInHeader()) || 476 (isResponse && paramDesc.isOutHeader())) 477 { 478 return true; 479 } 480 } 481 } 482 if (isResponse && 483 operation.getReturnParamDesc() != null && 484 operation.getReturnParamDesc().isOutHeader()) 485 { 486 return true; 487 } 488 return false; 489 } 490 491 500 private void processHeaders(OperationDesc operation, 501 boolean isResponse, 502 DeserializationContext context, 503 RPCHandler handler) 504 throws AxisFault, SAXException 505 { 506 try 509 { 510 handler.setHeaderElement(true); 511 SOAPElement envelope = getParentElement(); 513 while (envelope != null && 514 !(envelope instanceof SOAPEnvelopeAxisImpl)) 515 { 516 envelope = envelope.getParentElement(); 517 } 518 if (envelope == null) 519 return; 520 521 ArrayList paramDescs = operation.getParameters(); 524 if (paramDescs != null) 525 { 526 for (int j = 0; j < paramDescs.size(); j++) 527 { 528 ParameterDesc paramDesc = 529 (ParameterDesc)paramDescs.get(j); 530 if ((!isResponse && paramDesc.isInHeader()) || 531 (isResponse && paramDesc.isOutHeader())) 532 { 533 Enumeration headers = ((SOAPEnvelopeAxisImpl)envelope). 536 getHeadersByName(paramDesc.getQName().getNamespaceURI(), 537 paramDesc.getQName().getLocalPart(), 538 true); 539 while (headers != null && 545 headers.hasMoreElements()) 546 { 547 context.pushElementHandler(handler); 548 context.setCurElement(null); 549 ((SOAPElementAxisImpl)headers.nextElement()). 550 publishToHandler((org.xml.sax.ContentHandler )context); 551 } 552 } 553 } 554 } 555 556 if (isResponse && 558 operation.getReturnParamDesc() != null && 559 operation.getReturnParamDesc().isOutHeader()) 560 { 561 ParameterDesc paramDesc = operation.getReturnParamDesc(); 562 Enumeration headers = 563 ((SOAPEnvelopeAxisImpl)envelope). 564 getHeadersByName(paramDesc.getQName().getNamespaceURI(), 565 paramDesc.getQName().getLocalPart(), 566 true); 567 while (headers != null && 568 headers.hasMoreElements()) 569 { 570 context.pushElementHandler(handler); 571 context.setCurElement(null); 572 573 ((SOAPElementAxisImpl)headers.nextElement()). 574 publishToHandler((org.xml.sax.ContentHandler )context); 575 } 576 } 577 } 578 finally 579 { 580 handler.setHeaderElement(false); 581 } 582 } 583 } 584 | Popular Tags |