1 57 58 package org.apache.wsif.providers.soap.apacheaxis; 59 60 import java.net.MalformedURLException ; 61 import java.net.URL ; 62 import java.util.HashMap ; 63 import java.util.List ; 64 import java.util.Map ; 65 66 import javax.wsdl.Binding; 67 import javax.wsdl.BindingOperation; 68 import javax.wsdl.Definition; 69 import javax.wsdl.Port; 70 import javax.wsdl.extensions.soap.SOAPAddress; 71 import javax.wsdl.extensions.soap.SOAPBinding; 72 import javax.wsdl.extensions.soap.SOAPOperation; 73 import javax.xml.namespace.QName ; 74 import javax.xml.rpc.JAXRPCException ; 75 76 import org.apache.axis.client.Call; 77 import org.apache.axis.client.Transport; 78 import org.apache.axis.transport.http.HTTPTransport; 79 import org.apache.wsif.WSIFException; 80 import org.apache.wsif.WSIFOperation; 81 import org.apache.wsif.base.WSIFDefaultPort; 82 import org.apache.wsif.logging.Trc; 83 import org.apache.wsif.providers.WSIFDynamicTypeMap; 84 import org.apache.wsif.util.WSIFProperties; 85 import org.apache.wsif.util.WSIFUtils; 86 import org.apache.wsif.util.jms.WSIFJMSDestination; 87 import org.apache.wsif.util.jms.WSIFJMSFinder; 88 import org.apache.wsif.wsdl.extensions.jms.JMSAddress; 89 90 99 public class WSIFPort_ApacheAxis extends WSIFDefaultPort { 100 101 private static final long serialVersionUID = 2L; 102 103 protected Definition definition; 104 protected Port port; 105 protected SOAPBinding soapBinding; 106 protected SOAPAddress soapAddress; 107 protected JMSAddress jmsAddress; 108 109 protected String bindingStyle; 110 protected URL endPointURL; 111 protected List jmsAddressPropVals; 112 113 protected WSIFDynamicTypeMap wsifdynamictypemap; 114 protected Map cachedWSIFOperations; 115 116 transient protected Transport transport; 117 transient protected Call call; 118 119 private static final String HTTP_TRANSPORT_URI = 120 WSIFAXISConstants.HTTP_TRANSPORT_URI; 121 private static final String JMS_TRANSPORT_URI = 122 WSIFAXISConstants.JMS_TRANSPORT_URI; 123 124 127 public WSIFPort_ApacheAxis( 128 Definition definition, 129 Port port, 130 SOAPBinding soapBinding, 131 WSIFDynamicTypeMap wsifdynamictypemap) 132 throws WSIFException { 133 Trc.entry(this, definition, port, soapBinding, wsifdynamictypemap); 134 135 this.definition = definition; 136 this.port = port; 137 this.soapBinding = soapBinding; 138 this.wsifdynamictypemap = wsifdynamictypemap; 139 140 parseSoapBinding(); 141 parseServiceAddress(); 142 143 if (Trc.ON) 144 Trc.exit(deep()); 145 } 146 147 152 private void parseSoapBinding() throws WSIFException { 153 this.bindingStyle = soapBinding.getStyle(); 154 if (bindingStyle == null || bindingStyle.length() < 1) { 155 bindingStyle = WSIFAXISConstants.STYLE_DOCUMENT; 156 } else if (!WSIFAXISConstants.VALID_STYLES.contains(bindingStyle)) { 157 throw new WSIFException( 158 "unsupported style '" 159 + bindingStyle 160 + "' for binding:" 161 + soapBinding); 162 } 163 164 String transportURI = soapBinding.getTransportURI(); 165 if (!WSIFAXISConstants.VALID_TRANSPORTS.contains(transportURI)) { 166 throw new WSIFException( 167 "unsupported transport '" 168 + transportURI 169 + "' for binding: " 170 + soapBinding); 171 } 172 } 173 174 195 private void parseServiceAddress() throws WSIFException { 196 this.soapAddress = 197 (SOAPAddress) getExtElem(port, 198 SOAPAddress.class, 199 port.getExtensibilityElements()); 200 this.jmsAddress = 201 (JMSAddress) getExtElem(port, 202 JMSAddress.class, 203 port.getExtensibilityElements()); 204 205 if (soapAddress != null && jmsAddress != null) 206 throw new WSIFException( 207 "Both soap:address and jms:address cannot be specified for port " 208 + port); 209 210 if (soapAddress == null && jmsAddress == null) 211 throw new WSIFException( 212 "Either soap:address or jms:address must be specified for port " 213 + port); 214 215 if (isTransportHTTP() && soapAddress == null) { 216 throw new WSIFException( 217 "binding transport " 218 + HTTP_TRANSPORT_URI 219 + " requires soap:address for port " 220 + port); 221 } 222 223 if (isTransportJMS() && jmsAddress == null) { 224 throw new WSIFException( 225 "binding transport " 226 + JMS_TRANSPORT_URI 227 + " requires jms:address for port " 228 + port); 229 } 230 231 if (soapAddress != null) { 232 String s = soapAddress.getLocationURI(); 233 if (s == null || s.length() < 1) { 234 throw new WSIFException( 235 "soap:address with location URI is required for " + port); 236 } 237 try { 238 this.endPointURL = new URL (s); 239 } catch (MalformedURLException e) { 240 Trc.exception(e); 241 throw new WSIFException( 242 "exception setting SOAP address to " 243 + s 244 + ": " 245 + e.getLocalizedMessage(), 246 e); 247 } 248 } else { 249 this.jmsAddressPropVals = jmsAddress.getJMSPropertyValues(); 250 } 251 } 252 253 259 public WSIFOperation createOperation(String operationName) 260 throws WSIFException { 261 Trc.entry(this, operationName); 262 WSIFOperation wo = createOperation(operationName, null, null); 263 Trc.exit(wo); 264 return wo; 265 } 266 267 273 public WSIFOperation createOperation( 274 String operationName, 275 String inputName, 276 String outputName) 277 throws WSIFException { 278 Trc.entry(this, operationName, inputName, outputName); 279 280 WSIFOperation_ApacheAxis op = 281 getDynamicWSIFOperation(operationName, inputName, outputName); 282 if (op == null) { 283 throw new WSIFException( 284 "Could not create operation: " 285 + operationName 286 + ":" 287 + inputName 288 + ":" 289 + outputName); 290 } 291 Trc.exit(op); 292 return op; 293 } 294 295 300 public void close() throws WSIFException { 301 Trc.entry(this); 302 if (transport != null && transport instanceof WSIFJmsTransport) { 303 ((WSIFJmsTransport) transport).close(); 304 } 305 Trc.exit(); 306 } 307 308 311 public Transport getAxisTransport() throws WSIFException { 312 Trc.entry(this); 313 Transport t = getTransport(); 314 Trc.exit(t); 315 return t; 316 } 317 318 322 public QName getBindingName() { 323 Trc.entry(this); 324 Binding binding = port.getBinding(); 325 QName bindingQN = binding.getQName(); 326 Trc.exit(bindingQN); 327 return bindingQN; 328 } 329 330 334 public String getBindingStyle() { 335 Trc.entry(this); 336 Trc.exit(bindingStyle); 337 return bindingStyle; 338 } 339 340 345 public Call getCall() throws WSIFException { 346 Trc.entry(this); 347 if (call == null) { 348 call = makeNewAXISCall(); 349 } 350 Trc.exit(call); 351 return call; 352 } 353 354 357 private Call makeNewAXISCall() throws WSIFException { 358 Call c = null; 359 java.net.URL url = getEndPoint(); 360 try { 361 if (url != null) { 362 c = new Call(url); 363 Transport axistransport = getTransport(); 364 if (axistransport != null) { 365 axistransport.setUrl(url.toString()); 366 } 367 } else { 368 c = new Call(new org.apache.axis.client.Service()); 369 } 370 c.setMaintainSession(true); 371 } catch (JAXRPCException e) { 372 Trc.exception(e); 373 throw new WSIFException( 374 "exception creating call object: " 375 + e.getLocalizedMessage(), 376 e); 377 } 378 return c; 379 } 380 381 385 public Definition getDefinition() { 386 Trc.entry(this); 387 Trc.exit(definition); 388 return definition; 389 } 390 391 394 public WSIFOperation_ApacheAxis getDynamicWSIFOperation( 395 String opName, 396 String inputName, 397 String outputName) 398 throws WSIFException { 399 Trc.entry(this, opName, inputName, outputName); 400 401 WSIFOperation_ApacheAxis cachedOp = null; 402 403 if (cachedWSIFOperations == null) { 404 cachedWSIFOperations = new HashMap (); 405 } else { 406 cachedOp = (WSIFOperation_ApacheAxis) cachedWSIFOperations.get( 407 getKey(opName, inputName, outputName)); 408 } 409 410 WSIFOperation_ApacheAxis wsifOperation; 411 if (cachedOp == null) { 412 BindingOperation bop = 413 WSIFUtils.getBindingOperation( 414 port.getBinding(), opName, inputName, outputName ); 415 if (bop == null) { 416 throw new WSIFException( 417 "no operation found named " + 418 opName + ", input:" + inputName + ", output:" + outputName ); 419 } 420 cachedOp = 421 new WSIFOperation_ApacheAxis( 422 this, 423 bop.getOperation(), 424 wsifdynamictypemap); 425 cachedWSIFOperations.put( 426 getKey(opName, inputName, outputName), 427 cachedOp); 428 wsifOperation = cachedOp; 429 } else { 430 wsifOperation = cachedOp.copy(); 431 } 432 433 Trc.exit(wsifOperation); 434 return wsifOperation; 435 } 436 437 441 public URL getEndPoint() { 442 Trc.entry(this); 443 Trc.exit(endPointURL); 444 return endPointURL; 445 } 446 447 452 public Object getExtElem(Object ctx, Class extType, List extElems) 453 throws WSIFException { 454 Trc.entry(this, ctx, extType, extElems); 455 Object o = super.getExtElem(ctx, extType, extElems); 456 Trc.exit(o); 457 return o; 458 } 459 460 464 public List getExtElems(Object ctx, Class extType, List extElems) 465 throws WSIFException { 466 Trc.entry(this, ctx, extType, extElems); 467 List l = super.getExtElems(ctx, extType, extElems); 468 Trc.exit(l); 469 return l; 470 } 471 472 476 public List getJmsAddressPropVals() { 477 Trc.entry(this); 478 Trc.exit(jmsAddressPropVals); 479 return jmsAddressPropVals; 480 } 481 482 486 public Port getPort() { 487 Trc.entry(this); 488 Trc.exit(port); 489 return port; 490 } 491 492 505 public SOAPOperation getSOAPOperation(BindingOperation bindingOp) 506 throws WSIFException { 507 Trc.entry(this, bindingOp); 508 SOAPOperation soapOperation = 509 (SOAPOperation) getExtElem(bindingOp, 510 javax.wsdl.extensions.soap.SOAPOperation.class, 511 bindingOp.getExtensibilityElements()); 512 if (soapOperation == null) 513 throw new WSIFException( 514 "no soap:operation found in binding for: " + bindingOp); 515 Trc.exit(soapOperation); 516 return soapOperation; 517 } 518 519 524 public Transport getTransport() throws WSIFException { 525 Trc.entry(this); 526 if (transport == null) { 527 String s = soapBinding.getTransportURI(); 528 if (HTTP_TRANSPORT_URI.equals(s)) { 529 transport = new HTTPTransport(); 530 } else if (JMS_TRANSPORT_URI.equals(s)) { 531 WSIFJMSDestination jmsDestination = 532 new WSIFJMSDestination( 533 WSIFJMSFinder.newFinder(jmsAddress, port.getName()), 534 jmsAddress.getJmsProvDestName(), 535 WSIFProperties.getSyncTimeout()); 536 transport = new WSIFJmsTransport(jmsDestination); 537 } 538 } 539 Trc.exit(transport); 540 return transport; 541 } 542 543 548 public boolean isTransportHTTP() { 549 Trc.entry(this); 550 String transportURI = soapBinding.getTransportURI(); 551 boolean httpTransport = HTTP_TRANSPORT_URI.equals(transportURI); 552 Trc.exit(httpTransport); 553 return httpTransport; 554 } 555 556 561 public boolean isTransportJMS() { 562 Trc.entry(this); 563 String transportURI = soapBinding.getTransportURI(); 564 boolean jmsTransport = JMS_TRANSPORT_URI.equals(transportURI); 565 Trc.exit(jmsTransport); 566 return jmsTransport; 567 } 568 569 572 public void setDefinition(Definition definition1) { 573 Trc.entry(this, definition1); 574 definition = definition1; 575 Trc.exit(); 576 } 577 578 581 public void setDynamicWSIFOperation( 582 String s, 583 String s1, 584 String s2, 585 WSIFOperation_ApacheAxis wsifoperation_apacheaxis) { 586 Trc.entry(this, s, s1, s2, wsifoperation_apacheaxis); 587 if (cachedWSIFOperations == null) { 588 cachedWSIFOperations = new HashMap (); 589 } 590 cachedWSIFOperations.put(getKey(s, s1, s2), wsifoperation_apacheaxis); 591 Trc.exit(); 592 } 593 594 597 public void setEndPoint(URL url1) { 598 Trc.entry(this, url1); 599 endPointURL = url1; 600 Trc.exit(); 601 } 602 603 606 public void setPort(Port port1) { 607 Trc.entry(this, port1); 608 port = port1; 609 Trc.exit(); 610 } 611 612 616 public boolean supportsAsync() { 617 Trc.entry(this); 618 if (isTransportJMS()) { 619 Trc.exit(true); 620 return true; 621 } else { 622 Trc.exit(false); 623 return false; 624 } 625 } 626 627 public String deep() { 628 StringBuffer buff = new StringBuffer (); 629 try { 630 buff.append(new String (super.toString())); 631 buff.append(":\n"); 632 buff.append(" port: ").append(port); 633 buff.append(" definition: ").append(definition); 634 buff.append(" soapbinding: ").append(soapBinding); 635 buff.append(" bindingStyle: ").append(bindingStyle); 636 buff.append(" soapAddress: ").append(soapAddress); 637 buff.append(" jmsAddress: ").append(jmsAddress); 638 buff.append(" service url: ").append(endPointURL); 639 buff.append(" jmsAddressPropVals: ").append(jmsAddressPropVals); 640 buff.append(" dynamicTypeMap: ").append(wsifdynamictypemap); 641 buff.append(" transport: ").append(transport); 642 buff.append(" call: ").append(call); 643 buff.append("operationInstances: ").append(cachedWSIFOperations); 644 } catch (Exception e) { 645 Trc.exceptionInTrace(e); 646 } 647 return buff.toString(); 648 } 649 650 } | Popular Tags |