1 57 58 package org.apache.wsif.providers.soap.apachesoap; 59 60 import java.io.IOException ; 61 import java.io.ObjectInputStream ; 62 import java.io.ObjectOutputStream ; 63 import java.net.MalformedURLException ; 64 import java.net.URL ; 65 import java.util.HashMap ; 66 import java.util.Iterator ; 67 import java.util.List ; 68 import java.util.Map ; 69 70 import javax.wsdl.Binding; 71 import javax.wsdl.BindingInput; 72 import javax.wsdl.BindingOperation; 73 import javax.wsdl.BindingOutput; 74 import javax.wsdl.Definition; 75 import javax.wsdl.Port; 76 import javax.wsdl.Service; 77 import javax.wsdl.extensions.soap.SOAPAddress; 78 import javax.wsdl.extensions.soap.SOAPBinding; 79 import javax.wsdl.extensions.soap.SOAPBody; 80 import javax.wsdl.extensions.soap.SOAPHeader; 81 import javax.wsdl.extensions.soap.SOAPOperation; 82 83 import org.apache.soap.Constants; 84 import org.apache.soap.encoding.SOAPMappingRegistry; 85 import org.apache.soap.encoding.soapenc.Base64Serializer; 86 import org.apache.soap.encoding.soapenc.BeanSerializer; 87 import org.apache.soap.encoding.soapenc.DateSerializer; 88 import org.apache.soap.rpc.Call; 89 import org.apache.soap.transport.SOAPTransport; 90 import org.apache.soap.transport.http.SOAPHTTPConnection; 91 import org.apache.soap.util.xml.Deserializer; 92 import org.apache.soap.util.xml.Serializer; 93 import org.apache.wsif.WSIFException; 94 import org.apache.wsif.WSIFOperation; 95 import org.apache.wsif.base.WSIFDefaultPort; 96 import org.apache.wsif.logging.Trc; 97 import org.apache.wsif.providers.WSIFDynamicTypeMap; 98 import org.apache.wsif.providers.WSIFDynamicTypeMapping; 99 import org.apache.wsif.util.WSIFUtils; 100 import org.apache.wsif.wsdl.extensions.jms.JMSAddress; 101 import org.apache.wsif.wsdl.extensions.jms.JMSProperty; 102 import org.apache.wsif.wsdl.extensions.jms.JMSPropertyValue; 103 104 113 public class WSIFPort_ApacheSOAP extends WSIFDefaultPort { 114 115 private static final long serialVersionUID = 1L; 116 117 transient protected Map operationInstances = new HashMap (); 118 protected Port port; 119 protected Definition definition; 120 transient protected Call call; 121 transient protected SOAPTransport st; 122 protected URL url; 123 protected String style = "document"; 124 protected String partSerializerName = null; 125 126 private WSIFDynamicTypeMap wsifTypeMap = null; 127 private HashMap localTypeMap; 128 private List jmsAddressPropVals = null; 129 130 private static final String LITERAL_ENCODING = "literal"; 131 132 138 public WSIFPort_ApacheSOAP( 139 Definition def, 140 Service service, 141 Port port, 142 WSIFDynamicTypeMap typeMap, 143 String partSerName) 144 throws WSIFException { 145 Trc.entry(this, def, service, port, typeMap, partSerName); 146 147 setPartSerializerName(partSerName); 148 setDefinition(def); 149 setPort(port); 150 wsifTypeMap = typeMap; 151 152 JMSAddress ja = 153 (JMSAddress) getExtElem(port, 154 JMSAddress.class, 155 port.getExtensibilityElements()); 156 SOAPAddress sa = 157 (SOAPAddress) getExtElem(port, 158 SOAPAddress.class, 159 port.getExtensibilityElements()); 160 161 if (sa != null && ja != null) 162 throw new WSIFException( 163 "Both soap:address and jms:address cannot be specified for port " 164 + port.getName()); 165 166 if (sa == null && ja == null) 167 throw new WSIFException( 168 "Either soap:address or jms:address must be specified for port " 169 + port.getName()); 170 171 if (ja != null) { 172 jmsAddressPropVals = ja.getJMSPropertyValues(); 174 st = new SOAPJMSConnection(ja, port.getName()); 175 } else { 176 st = new SOAPHTTPConnection(); 178 180 String s = sa.getLocationURI(); 181 try { 182 url = new URL (s); 183 } catch (MalformedURLException meu) { 184 Trc.exception(meu); 185 throw new WSIFException( 186 "could not set SOAP address to " + s, 187 meu); 188 } 189 if (url == null) { 190 throw new WSIFException( 191 "soap:address with location URI is required for " + port.getName()); 192 } 193 } 194 195 Binding binding = port.getBinding(); 197 SOAPBinding soapBinding = 198 (SOAPBinding) getExtElem(binding, 199 SOAPBinding.class, 200 binding.getExtensibilityElements()); 201 if (soapBinding != null) { 202 style = soapBinding.getStyle(); 203 if (style == null) 204 style = "document"; 206 String transport = soapBinding.getTransportURI(); 207 if ((ja != null 208 && !"http://schemas.xmlsoap.org/soap/jms".equals(transport)) 209 || (sa != null 210 && !"http://schemas.xmlsoap.org/soap/http".equals( 211 transport))) { 212 throw new WSIFException( 213 "unsupported transport " 214 + transport 215 + " for " 216 + soapBinding); 217 } 218 } 219 220 if (Trc.ON) 221 Trc.exit(deep()); 222 } 223 224 public static SOAPMappingRegistry createSOAPMappingRegistry(Call call) { 225 Trc.entry(null,call); 226 SOAPMappingRegistry smr = call.getSOAPMappingRegistry(); 227 228 DateSerializer dateSer = new DateSerializer(); 230 smr.mapTypes( 232 Constants.NS_URI_SOAP_ENC, 233 new org.apache.soap.util.xml.QName( 234 Constants.NS_URI_1999_SCHEMA_XSD, 235 "dateTime"), 236 java.util.Date .class, 237 null, 238 dateSer); 239 smr.mapTypes( 241 Constants.NS_URI_SOAP_ENC, 242 new org.apache.soap.util.xml.QName( 243 Constants.NS_URI_2000_SCHEMA_XSD, 244 "dateTime"), 245 java.util.Date .class, 246 null, 247 dateSer); 248 smr.mapTypes( 250 Constants.NS_URI_SOAP_ENC, 251 new org.apache.soap.util.xml.QName( 252 Constants.NS_URI_2001_SCHEMA_XSD, 253 "dateTime"), 254 java.util.Date .class, 255 null, 256 dateSer); 257 smr.mapTypes( 259 Constants.NS_URI_SOAP_ENC, 260 new org.apache.soap.util.xml.QName( 261 Constants.NS_URI_CURRENT_SCHEMA_XSD, 262 "dateTime"), 263 java.util.Date .class, 264 dateSer, 265 null); 266 267 Base64Serializer base64Ser = new Base64Serializer(); 269 smr.mapTypes( 271 Constants.NS_URI_SOAP_ENC, 272 new org.apache.soap.util.xml.QName( 273 Constants.NS_URI_1999_SCHEMA_XSD, 274 "base64Binary"), 275 byte[].class, 276 null, 277 base64Ser); 278 smr.mapTypes( 280 Constants.NS_URI_SOAP_ENC, 281 new org.apache.soap.util.xml.QName( 282 Constants.NS_URI_2000_SCHEMA_XSD, 283 "base64Binary"), 284 byte[].class, 285 null, 286 base64Ser); 287 smr.mapTypes( 289 Constants.NS_URI_SOAP_ENC, 290 new org.apache.soap.util.xml.QName( 291 Constants.NS_URI_2001_SCHEMA_XSD, 292 "base64Binary"), 293 byte[].class, 294 null, 295 base64Ser); 296 smr.mapTypes( 298 Constants.NS_URI_SOAP_ENC, 299 new org.apache.soap.util.xml.QName( 300 Constants.NS_URI_CURRENT_SCHEMA_XSD, 301 "base64Binary"), 302 byte[].class, 303 base64Ser, 304 null); 305 306 Trc.exit(smr); 307 return smr; 308 } 309 310 public Call getCall() { 311 Trc.entry(this); 312 if ( call == null ) { 313 call = new Call(); 314 call.setSOAPMappingRegistry( 315 new WSIFSOAPMappingRegistry(createSOAPMappingRegistry( call ))); 316 prepareTypeMappings(); 317 } 318 Trc.exit(call); 319 return call; 320 } 321 322 public SOAPMappingRegistry getSOAPMappingRegistry() { 323 Trc.entry(this); 324 SOAPMappingRegistry smr = getCall().getSOAPMappingRegistry(); 325 Trc.exit(smr); 326 return smr; 327 } 328 329 protected HashMap getLocalTypeMap() { 330 if (localTypeMap == null ) { 331 localTypeMap = new HashMap (); 332 getCall(); 334 } 335 return localTypeMap; 336 } 337 338 private void prepareTypeMappings() { 339 if (localTypeMap == null ) { 343 localTypeMap = new HashMap (); 344 } 345 prepareTypeMappings( 346 getSOAPMappingRegistry(), 347 this.wsifTypeMap, 348 partSerializerName, 349 localTypeMap); 350 } 351 352 static void prepareTypeMappings( 353 SOAPMappingRegistry theSMR, 354 WSIFDynamicTypeMap theTypeMap, 355 String thePartSerializerName, 356 HashMap theLocalTypeMap) { 357 358 BeanSerializer beanSer = new BeanSerializer(); 359 PartSerializer partSer = null; 360 if (thePartSerializerName != null) 361 try { 362 partSer = 363 (PartSerializer) Class 364 .forName( 365 thePartSerializerName, 366 true, 367 Thread.currentThread().getContextClassLoader()) 368 .newInstance(); 369 } catch (Throwable ignored) { 370 Trc.ignoredException(ignored); 371 } 372 373 Serializer literalSerializer = partSer; 374 Deserializer literalDeserializer = partSer; 375 Serializer soapSerializer = beanSer; 376 Deserializer soapDeserializer = beanSer; 377 String soapEncoding = Constants.NS_URI_SOAP_ENC; 378 379 for (Iterator i = theTypeMap.iterator(); i.hasNext();) { 381 WSIFDynamicTypeMapping mapping = (WSIFDynamicTypeMapping) i.next(); 382 383 Class javaClass = mapping.getJavaType(); 384 org.apache.soap.util.xml.QName typeName = 385 new org.apache.soap.util.xml.QName( 386 mapping.getXmlType().getNamespaceURI(), 387 mapping.getXmlType().getLocalPart()); 388 389 theLocalTypeMap.put(typeName, javaClass); 391 392 Serializer ser = null; 393 try { 395 ser = theSMR.querySerializer(javaClass, soapEncoding); 396 } catch (IllegalArgumentException iae) { 397 Trc.ignoredException(iae); 398 } 399 if (ser == null) { 401 theSMR.mapTypes( 402 soapEncoding, 403 typeName, 404 javaClass, 405 soapSerializer, 406 soapDeserializer); 407 } 408 409 try { 411 ser = null; 412 ser = theSMR.querySerializer(javaClass, LITERAL_ENCODING); 413 } catch (IllegalArgumentException iae) { 414 Trc.ignoredException(iae); 415 } 416 if (ser == null) { 418 theSMR.mapTypes( 419 LITERAL_ENCODING, 420 typeName, 421 javaClass, 422 literalSerializer, 423 literalDeserializer); 424 } 425 } 426 } 427 428 public URL getEndPoint() { 429 Trc.entry(this); 430 Trc.exit(url); 431 return url; 432 } 433 434 public void setEndPoint(URL url) { 435 Trc.entry(this, url); 436 this.url = url; 437 Trc.exit(); 438 } 439 440 public SOAPTransport getSOAPTransport() { 441 Trc.entry(this); 442 Trc.exit(st); 443 return st; 444 } 445 446 public void setSOAPTransport(SOAPTransport st) { 447 Trc.entry(this, st); 448 this.st = st; 449 Trc.exit(); 450 } 451 452 public Definition getDefinition() { 454 Trc.entry(this); 455 Trc.exit(definition); 456 return definition; 457 } 458 459 public void setDefinition(Definition value) { 460 Trc.entry(this, value); 461 definition = value; 462 Trc.exit(); 463 } 464 465 public Port getPort() { 466 Trc.entry(this); 467 Trc.exit(port); 468 return port; 469 } 470 471 public void setPort(Port value) { 472 Trc.entry(this, value); 473 port = value; 474 Trc.exit(); 475 } 476 477 public void setDynamicWSIFOperation( 479 String name, 480 String inputName, 481 String outputName, 482 WSIFOperation_ApacheSOAP value) { 483 Trc.entry(this, name, inputName, outputName, value); 484 operationInstances.put(getKey(name, inputName, outputName), value); 485 Trc.exit(); 486 } 487 488 public WSIFOperation createOperation(String operationName) 489 throws WSIFException { 490 Trc.entry(this, operationName); 491 WSIFOperation wo = createOperation(operationName, null, null); 492 Trc.exit(wo); 493 return wo; 494 } 495 496 public WSIFOperation createOperation( 497 String operationName, 498 String inputName, 499 String outputName) 500 throws WSIFException { 501 Trc.entry(this, operationName, inputName, outputName); 502 WSIFOperation_ApacheSOAP op = 503 getDynamicWSIFOperation(operationName, inputName, outputName); 504 if (op == null) { 505 throw new WSIFException( 506 "Could not create operation: " 507 + operationName 508 + ":" 509 + inputName 510 + ":" 511 + outputName); 512 } 513 WSIFOperation wo = op.copy(); 514 Trc.exit(wo); 515 return wo; 516 } 517 518 public WSIFOperation_ApacheSOAP getDynamicWSIFOperation( 519 String name, 520 String inputName, 521 String outputName) 522 throws WSIFException { 523 Trc.entry(this, name, inputName, outputName); 524 525 WSIFOperation_ApacheSOAP tempOp = 526 (WSIFOperation_ApacheSOAP) operationInstances.get( 527 getKey(name, inputName, outputName)); 528 529 WSIFOperation_ApacheSOAP operation = null; 530 if (tempOp != null) { 531 operation = tempOp.copy(); 532 } 533 534 if (operation == null) { 535 BindingOperation bop = 536 WSIFUtils.getBindingOperation( 537 port.getBinding(), name, inputName, outputName ); 538 539 if (bop != null) { 540 operation = 541 new WSIFOperation_ApacheSOAP( 542 this, 543 bop.getOperation(), 544 wsifTypeMap); 545 if (operation == null) { 546 throw new WSIFException( 547 "Operation not found from binding operation: " 548 + bop.getName()); 549 } 550 551 operation.setStyle(this.style); 552 operation.setPartSerializerName(this.partSerializerName); 553 554 if (jmsAddressPropVals != null 555 && jmsAddressPropVals.size() > 0) { 556 if (st instanceof SOAPJMSConnection) 557 operation.addInputJmsPropertyValues(jmsAddressPropVals); 558 else 559 throw new WSIFException("jms:propertyValue found in non-jms address"); 560 } 561 562 SOAPOperation soapOperation = 564 (SOAPOperation) getExtElem(bop, 565 SOAPOperation.class, 566 bop.getExtensibilityElements()); 567 if (soapOperation == null) { 568 throw new WSIFException( 569 "soapAction must be specified in " 570 + " required by WSDL 1.1 soap:operation binding for " 571 + bop.getName()); 572 } 573 String soapActionURI = soapOperation.getSoapActionURI(); 574 operation.setSoapActionURI(soapActionURI); 575 576 Trc.event( 577 this, 578 "setting actionURI ", 579 soapActionURI, 580 " for op ", 581 operation.getName()); 582 String opStyle = soapOperation.getStyle(); 583 584 BindingInput binpt = bop.getBindingInput(); 586 SOAPBody soapInputBody = 587 (SOAPBody) getExtElem(binpt, 588 SOAPBody.class, 589 binpt.getExtensibilityElements()); 590 if (soapInputBody != null) { 591 String namespaceURI = soapInputBody.getNamespaceURI(); 592 593 Trc.event( 594 this, 595 "setting namespace ", 596 namespaceURI, 597 " for op ", 598 operation.getName()); 599 600 operation.setInputNamespace(namespaceURI); 601 String use = soapInputBody.getUse(); 602 operation.setInputUse(use); 603 604 List encodingStyles = soapInputBody.getEncodingStyles(); 605 if (encodingStyles != null) { 606 if (encodingStyles.size() == 0) { 607 } 608 operation.setInputEncodingStyle( 609 (String ) encodingStyles.get(0)); 610 } 612 List parts = soapInputBody.getParts(); 613 if (parts != null) 614 operation.setPartNames(parts); 615 } 616 617 SOAPHeader soapHeader = 618 (SOAPHeader) getExtElem(binpt, 619 SOAPHeader.class, 620 binpt.getExtensibilityElements()); 621 if (soapHeader != null) { 622 throw new WSIFException( 623 "not supported input soap:header " + soapHeader); 624 } 625 626 List inJmsProps = 627 getExtElems( 628 binpt, 629 JMSProperty.class, 630 binpt.getExtensibilityElements()); 631 if (inJmsProps != null && inJmsProps.size() > 0) { 632 if (st instanceof SOAPJMSConnection) 633 operation.setInputJmsProperties(inJmsProps); 634 else 635 throw new WSIFException("jms:properties found in non-jms binding"); 636 } 637 638 List inJmsPropVals = 639 getExtElems( 640 binpt, 641 JMSPropertyValue.class, 642 binpt.getExtensibilityElements()); 643 if (inJmsPropVals != null && inJmsPropVals.size() > 0) { 644 if (st instanceof SOAPJMSConnection) 645 operation.addInputJmsPropertyValues(inJmsPropVals); 646 else 647 throw new WSIFException("jms:propertyValue found in non-jms binding"); 648 } 649 650 BindingOutput boutpt = bop.getBindingOutput(); 652 if (boutpt != null) { 653 SOAPBody soapOutputBody = 654 (SOAPBody) getExtElem(boutpt, 655 SOAPBody.class, 656 boutpt.getExtensibilityElements()); 657 if (soapOutputBody != null) { 658 String use = soapOutputBody.getUse(); 661 operation.setOutputUse(use); 662 663 List parts = soapOutputBody.getParts(); 666 if (parts != null && parts.size() > 0) { 667 operation.setReturnName((String ) parts.get(0)); 668 } 669 } 670 soapHeader = 671 (SOAPHeader) getExtElem(boutpt, 672 SOAPHeader.class, 673 boutpt.getExtensibilityElements()); 674 if (soapHeader != null) { 675 throw new WSIFException( 676 "not supported output soap:header " + soapHeader); 677 } 678 679 List outJmsProps = 680 getExtElems( 681 boutpt, 682 JMSProperty.class, 683 boutpt.getExtensibilityElements()); 684 if (outJmsProps != null && outJmsProps.size() > 0) { 685 if (st instanceof SOAPJMSConnection) 686 operation.setOutputJmsProperties(outJmsProps); 687 else 688 throw new WSIFException("jms:properties found in non-jms binding"); 689 } 690 } 691 692 695 setDynamicWSIFOperation(name, inputName, outputName, operation); 697 } 698 } 699 700 Trc.exit(operation); 701 return operation; 702 } 703 704 708 public String getPartSerializerName() { 709 Trc.entry(this); 710 Trc.exit(partSerializerName); 711 return partSerializerName; 712 } 713 714 718 public void setPartSerializerName(String partSerializerName) { 719 Trc.entry(this, partSerializerName); 720 this.partSerializerName = partSerializerName; 721 Trc.exit(); 722 } 723 724 727 public void close() throws WSIFException { 728 Trc.entry(this); 729 if (st != null && st instanceof SOAPJMSConnection) 730 ((SOAPJMSConnection) st).close(); 731 Trc.exit(); 732 } 733 734 739 public boolean supportsAsync() { 740 if (st instanceof SOAPJMSConnection) { 741 return true; 742 } else { 743 return false; 744 } 745 } 746 747 public String deep() { 748 String buff = ""; 749 try { 750 buff = new String (super.toString() + ":\n"); 751 752 if (operationInstances == null) { 753 buff += " operationInstances: null"; 754 } else { 755 buff += " operationInstances: size:" 756 + operationInstances.size(); 757 Iterator it = operationInstances.keySet().iterator(); 758 int i = 0; 759 while (it.hasNext()) { 760 String key = (String ) it.next(); 761 WSIFOperation_ApacheSOAP woas = 762 (WSIFOperation_ApacheSOAP) operationInstances.get(key); 763 buff += "\noperationInstances[" 764 + i 765 + "]:" 766 + key 767 + " " 768 + woas.getName() 769 + " "; 770 i++; 771 } 772 } 773 774 buff += "\nport:" + Trc.brief(port); 775 buff += " definition:" + Trc.brief(definition); 776 buff += " call:" + call; 777 buff += " soapTransport:" + st; 778 buff += " url:" + url; 779 buff += " style:" + style; 780 buff += " partSerializerName:" + partSerializerName; 781 buff += " wsifTypeMap:" + wsifTypeMap; 782 buff += " jmsAddressPropVals:" + jmsAddressPropVals; 783 } catch (Exception e) { 784 Trc.exceptionInTrace(e); 785 } 786 787 return buff; 788 } 789 790 private void writeObject(ObjectOutputStream oos) throws IOException { 791 oos.defaultWriteObject(); 792 } 793 794 private void readObject(ObjectInputStream ois) 795 throws ClassNotFoundException , IOException { 796 ois.defaultReadObject(); 797 798 operationInstances = new HashMap (); 800 801 JMSAddress ja = 805 (JMSAddress) getExtElem(port, 806 JMSAddress.class, 807 port.getExtensibilityElements()); 808 SOAPAddress sa = 809 (SOAPAddress) getExtElem(port, 810 SOAPAddress.class, 811 port.getExtensibilityElements()); 812 813 if (sa != null && ja != null) 814 throw new WSIFException( 815 "Both soap:address and jms:address cannot be specified for port " 816 + port.getName()); 817 818 if (sa == null && ja == null) 819 throw new WSIFException( 820 "Either soap:address or jms:address must be specified for port " 821 + port.getName()); 822 823 if (ja != null) { 824 jmsAddressPropVals = ja.getJMSPropertyValues(); 826 st = new SOAPJMSConnection(ja, port.getName()); 827 } else { 828 st = new SOAPHTTPConnection(); 830 } 831 } 832 } | Popular Tags |