1 57 58 package org.apache.wsif.providers.soap.apacheaxis; 59 60 import java.rmi.RemoteException ; 61 import java.util.ArrayList ; 62 import java.util.Arrays ; 63 import java.util.HashMap ; 64 import java.util.Iterator ; 65 import java.util.List ; 66 import java.util.Map ; 67 import java.util.Vector ; 68 69 import javax.jms.TextMessage ; 70 import javax.wsdl.Binding; 71 import javax.wsdl.BindingFault; 72 import javax.wsdl.BindingInput; 73 import javax.wsdl.BindingOperation; 74 import javax.wsdl.BindingOutput; 75 import javax.wsdl.Definition; 76 import javax.wsdl.Input; 77 import javax.wsdl.Operation; 78 import javax.wsdl.Output; 79 import javax.wsdl.Part; 80 import javax.wsdl.extensions.mime.MIMEContent; 81 import javax.wsdl.extensions.mime.MIMEMimeXml; 82 import javax.wsdl.extensions.mime.MIMEMultipartRelated; 83 import javax.wsdl.extensions.mime.MIMEPart; 84 import javax.wsdl.extensions.soap.SOAPBody; 85 import javax.wsdl.extensions.soap.SOAPFault; 86 import javax.wsdl.extensions.soap.SOAPHeader; 87 import javax.wsdl.extensions.soap.SOAPHeaderFault; 88 import javax.wsdl.extensions.soap.SOAPOperation; 89 import javax.xml.namespace.QName ; 90 import javax.xml.rpc.ParameterMode ; 91 import javax.xml.soap.SOAPException ; 92 93 import org.apache.axis.AxisEngine; 94 import org.apache.axis.AxisFault; 95 import org.apache.axis.Message; 96 import org.apache.axis.MessageContext; 97 import org.apache.axis.attachments.AttachmentPart; 98 import org.apache.axis.client.Call; 99 import org.apache.axis.client.Service; 100 import org.apache.axis.client.Transport; 101 import org.apache.axis.encoding.DeserializerFactory; 102 import org.apache.axis.encoding.SerializerFactory; 103 import org.apache.axis.encoding.SimpleType; 104 import org.apache.axis.encoding.TypeMapping; 105 import org.apache.axis.encoding.TypeMappingRegistry; 106 import org.apache.axis.encoding.ser.ArrayDeserializerFactory; 107 import org.apache.axis.encoding.ser.ArraySerializerFactory; 108 import org.apache.axis.encoding.ser.BeanDeserializerFactory; 109 import org.apache.axis.encoding.ser.BeanSerializerFactory; 110 import org.apache.axis.encoding.ser.SimpleDeserializerFactory; 111 import org.apache.axis.encoding.ser.SimpleSerializerFactory; 112 import org.apache.axis.message.RPCElement; 113 import org.apache.axis.message.RPCParam; 114 import org.apache.axis.message.SOAPBodyElement; 115 import org.apache.axis.message.SOAPEnvelope; 116 import org.apache.axis.message.SOAPFaultElement; 117 import org.apache.axis.message.SOAPHeaderElement; 118 import org.apache.wsif.WSIFConstants; 119 import org.apache.wsif.WSIFCorrelationId; 120 import org.apache.wsif.WSIFException; 121 import org.apache.wsif.WSIFMessage; 122 import org.apache.wsif.WSIFPort; 123 import org.apache.wsif.WSIFResponseHandler; 124 import org.apache.wsif.base.WSIFDefaultOperation; 125 import org.apache.wsif.logging.Trc; 126 import org.apache.wsif.providers.WSIFDynamicTypeMap; 127 import org.apache.wsif.providers.WSIFDynamicTypeMapping; 128 import org.apache.wsif.util.TypeSerializerInfo; 129 import org.apache.wsif.util.WSIFUtils; 130 import org.apache.wsif.util.jms.WSIFJMSDestination; 131 import org.apache.wsif.wsdl.extensions.jms.JMSProperty; 132 import org.apache.wsif.wsdl.extensions.jms.JMSPropertyValue; 133 import org.w3c.dom.Element ; 134 import org.w3c.dom.Node ; 135 import org.w3c.dom.NodeList ; 136 import org.xml.sax.SAXException ; 137 138 import com.ibm.wsdl.extensions.mime.MIMEConstants; 139 140 146 public class WSIFOperation_ApacheAxis extends WSIFDefaultOperation { 147 148 private static final long serialVersionUID = 2L; 149 150 transient protected WSIFPort_ApacheAxis wsifPort; 151 152 transient protected Operation portTypeOperation; 153 transient protected BindingOperation bindingOperation; 154 transient protected SOAPOperation soapOperation; 155 156 transient protected List inputSOAPParts; 157 transient protected List inputUnwrappedSOAPParts; 158 transient protected List inputMIMEParts; 159 transient protected Part inputSOAPHeader; 160 transient protected Part inputSOAPHeaderFault; 161 162 protected List outputSOAPParts; 163 protected List outputUnwrappedSOAPParts; 164 protected List outputMIMEParts; 165 protected Part outputSOAPHeader; 166 protected Part outputSOAPHeaderFault; 167 168 transient protected String inputEncodingStyle; 169 transient protected String inputNamespace; 170 transient protected String soapActionURI; 171 172 transient protected HashMap responseMessageParameters; 173 174 transient protected boolean asyncOperation; 176 transient protected WSIFCorrelationId asyncRequestID; 177 178 protected WSIFResponseHandler responseHandler; 180 protected String outputEncodingStyle; 181 protected WSIFDynamicTypeMap typeMap; 182 protected String operationStyle; 183 184 187 public WSIFOperation_ApacheAxis( 188 WSIFPort_ApacheAxis wsifPort, 189 Operation portTypeOperation, 190 WSIFDynamicTypeMap typeMap) 191 throws WSIFException { 192 Trc.entry(this, wsifPort, portTypeOperation, typeMap); 193 194 198 199 this.wsifPort = wsifPort; 200 this.portTypeOperation = portTypeOperation; 201 this.typeMap = typeMap; 202 203 this.bindingOperation = getBindingOperation(portTypeOperation); 204 205 this.inputEncodingStyle = WSIFAXISConstants.DEFAULT_SOAP_ENCODING_URI; 206 this.outputEncodingStyle = WSIFAXISConstants.DEFAULT_SOAP_ENCODING_URI; 207 208 if (Trc.ON) { 209 Trc.exit(deep()); 210 } 211 } 212 213 222 public WSIFOperation_ApacheAxis copy() throws WSIFException { 223 Trc.entry(this); 224 225 229 230 WSIFOperation_ApacheAxis op = 231 new WSIFOperation_ApacheAxis(wsifPort, portTypeOperation, typeMap); 232 233 op.inputSOAPParts = inputSOAPParts; 234 op.inputUnwrappedSOAPParts = inputUnwrappedSOAPParts; 235 op.inputMIMEParts = inputMIMEParts; 236 op.inputSOAPHeader = inputSOAPHeader; 237 op.inputSOAPHeaderFault = inputSOAPHeaderFault; 238 239 op.outputSOAPParts = outputSOAPParts; 240 op.outputUnwrappedSOAPParts = outputUnwrappedSOAPParts; 241 op.outputMIMEParts = outputMIMEParts; 242 op.outputSOAPHeader = outputSOAPHeader; 243 op.outputSOAPHeaderFault = outputSOAPHeaderFault; 244 245 op.soapOperation = soapOperation; 246 247 op.setSoapActionURI(getSoapActionURI()); 248 op.setInputNamespace(getInputNamespace()); 249 op.setInputEncodingStyle(getInputEncodingStyle()); 250 op.setOutputEncodingStyle(getOutputEncodingStyle()); 251 op.setAsyncOperation(isAsyncOperation()); 252 op.setResponseHandler(getResponseHandler()); 253 op.setInputJmsProperties(getInputJmsProperties()); 254 op.setOutputJmsProperties(getOutputJmsProperties()); 255 op.setInputJmsPropertyValues(getInputJmsPropertyValues()); 256 op.setOperationStyle(getOperationStyle()); 257 258 if (Trc.ON) 259 Trc.exit(op.deep()); 260 return op; 261 } 262 263 268 private void parseSoapOperation() throws WSIFException { 269 270 this.soapOperation = wsifPort.getSOAPOperation(bindingOperation); 271 this.soapActionURI = soapOperation.getSoapActionURI(); 272 this.operationStyle = soapOperation.getStyle(); 273 274 if (operationStyle == null || operationStyle.length() < 1) { 275 operationStyle = wsifPort.getBindingStyle(); 276 } else if (!WSIFAXISConstants.VALID_STYLES.contains(operationStyle)) { 277 throw new WSIFException( 278 "unsupported style " 279 + operationStyle 280 + " for operation " 281 + portTypeOperation.getName()); 282 } 283 if (operationStyle == null || operationStyle.length() < 1) { 284 operationStyle = WSIFAXISConstants.STYLE_DOCUMENT; 285 } 286 } 287 288 302 private void parseBindingInput() throws WSIFException { 303 BindingInput bindinginput = bindingOperation.getBindingInput(); 304 List inExtElems = bindinginput.getExtensibilityElements(); 305 306 SOAPBody inSoapBody = 307 (SOAPBody) wsifPort.getExtElem( 308 bindinginput, 309 javax.wsdl.extensions.soap.SOAPBody.class, 310 inExtElems); 311 if (inSoapBody != null) { 312 this.inputSOAPParts = parseSoapBody(inSoapBody, true); 313 } 314 315 MIMEMultipartRelated inMimeMultipart = 316 (MIMEMultipartRelated) wsifPort.getExtElem( 317 bindinginput, 318 MIMEMultipartRelated.class, 319 inExtElems); 320 321 if (inSoapBody != null && inMimeMultipart != null) { 322 throw new WSIFException( 323 "In a binding operation that contains a mime:multipartRelated, " 324 + "a soap:body was found that was not in a mime:part. " 325 + "OperationName=" 326 + getName()); 327 } 328 if (inSoapBody == null && inMimeMultipart == null) { 329 throw new WSIFException( 330 "binding operation input must contain either a soap:body " + 331 "or a mime:multipartRelated element. " 332 + "OperationName=" 333 + getName()); 334 } 335 336 if (inMimeMultipart != null) { 337 parseMimeMultipart(inMimeMultipart, true); 338 } 339 340 MIMEMimeXml inMimeMimeXml = 341 (MIMEMimeXml) wsifPort.getExtElem( 342 bindinginput, 343 MIMEMimeXml.class, 344 inExtElems); 345 if (inMimeMimeXml != null) 346 throw new WSIFException( 347 "WSIF does not support mime:mimeXml. Operation=" 348 + getName()); 349 350 parseSOAPHeaderElement(bindinginput); 351 352 List inJmsProps = 353 wsifPort.getExtElems( 354 bindinginput, 355 JMSProperty.class, 356 bindinginput.getExtensibilityElements()); 357 if (inJmsProps != null && inJmsProps.size() > 0) { 358 if (wsifPort.isTransportJMS()) 359 setInputJmsProperties(inJmsProps); 360 else 361 throw new WSIFException("jms:property found in non-jms binding"); 362 } 363 364 List inJmsPropVals = 365 wsifPort.getExtElems( 366 bindinginput, 367 JMSPropertyValue.class, 368 bindinginput.getExtensibilityElements()); 369 if (inJmsPropVals != null && inJmsPropVals.size() > 0) { 370 if (wsifPort.isTransportJMS()) 371 addInputJmsPropertyValues(inJmsPropVals); 372 else 373 throw new WSIFException("jms:propertyValue found in non-jms binding"); 374 } 375 } 376 377 391 private void parseBindingOutput() throws WSIFException { 392 BindingOutput bindingoutput = bindingOperation.getBindingOutput(); 393 if (bindingoutput != null) { 394 List outExtElems = bindingoutput.getExtensibilityElements(); 395 SOAPBody outSoapBody = 396 (SOAPBody) wsifPort.getExtElem( 397 bindingoutput, 398 javax.wsdl.extensions.soap.SOAPBody.class, 399 outExtElems); 400 if (outSoapBody != null) { 401 this.outputSOAPParts = parseSoapBody(outSoapBody, false); 402 } 403 404 MIMEMultipartRelated outMimeMultipart = 405 (MIMEMultipartRelated) wsifPort.getExtElem( 406 bindingoutput, 407 MIMEMultipartRelated.class, 408 outExtElems); 409 410 if (outSoapBody != null && outMimeMultipart != null) { 411 throw new WSIFException( 412 "In a binding operation that contains a mime:multipartRelated, " 413 + "a soap:body was found that was not in a mime:part. " 414 + "OperationName=" 415 + getName()); 416 } 417 if (outSoapBody == null && outMimeMultipart == null) { 418 throw new WSIFException( 419 "binding operation output must contain either a soap:body " + 420 "or a mime:multipartRelated element. " + 421 "OperationName=" + 422 getName()); 423 } 424 425 if (outMimeMultipart != null) { 426 parseMimeMultipart(outMimeMultipart, false); 427 } 428 429 MIMEMimeXml outMimeMimeXml = 430 (MIMEMimeXml) wsifPort.getExtElem( 431 bindingoutput, 432 MIMEMimeXml.class, 433 outExtElems); 434 if (outMimeMimeXml != null) { 435 throw new WSIFException( 436 "WSIF does not support mime:mimeXml. Operation=" + 437 getName()); 438 } 439 440 parseSOAPHeaderElement(bindingoutput); 441 442 for (Iterator iterator1 = 443 bindingOperation.getBindingFaults().values().iterator(); 444 iterator1.hasNext(); 445 ) { 446 BindingFault bindingfault = (BindingFault) iterator1.next(); 447 SOAPFault soapfault = 448 (SOAPFault) wsifPort.getExtElem( 449 bindingfault, 450 javax.wsdl.extensions.soap.SOAPFault.class, 451 bindingfault.getExtensibilityElements()); 452 } 453 454 List outJmsProps = 455 wsifPort.getExtElems( 456 bindingoutput, 457 JMSProperty.class, 458 outExtElems); 459 if (outJmsProps != null && outJmsProps.size() > 0) { 460 if (wsifPort.isTransportJMS()) { 461 setOutputJmsProperties(outJmsProps); 462 } else { 463 throw new WSIFException("jms:properties found in non-jms binding"); 464 } 465 } 466 } 467 } 468 469 478 private void parseSOAPHeaderElement(Object element) throws WSIFException { 479 480 List extensabilityElements; 481 if (element instanceof BindingInput) { 482 extensabilityElements = 483 ((BindingInput) element).getExtensibilityElements(); 484 } else if (element instanceof BindingOutput) { 485 extensabilityElements = 486 ((BindingOutput) element).getExtensibilityElements(); 487 } else { 488 throw new WSIFException( 489 "internal error, unexpected object: " + element); 490 } 491 492 Part soapHeaderPart = null; 493 Part soapHeaderFaultPart = null; 494 495 SOAPHeader soapHeader = 496 (SOAPHeader) wsifPort.getExtElem( 497 element, 498 javax.wsdl.extensions.soap.SOAPHeader.class, 499 extensabilityElements); 500 if (soapHeader != null) { 501 QName messageName = soapHeader.getMessage(); 502 if (messageName == null) { 503 throw new WSIFException( 504 "no message attribute on soap:header: " + soapHeader); 505 } 506 String messagePart = soapHeader.getPart(); 507 if (messagePart == null) { 508 throw new WSIFException( 509 "no part attribute on soap:header: " + soapHeader); 510 } 511 soapHeaderPart = getPart(messageName, messagePart); 512 if (soapHeaderPart == null) { 513 throw new WSIFException( 514 "non existent part specified on soap:header: " 515 + soapHeader); 516 } 517 518 SOAPHeaderFault soapHeaderFault = 519 (SOAPHeaderFault) wsifPort.getExtElem( 520 soapHeader, 521 javax.wsdl.extensions.soap.SOAPHeaderFault.class, 522 extensabilityElements); 523 if (soapHeaderFault != null) { 524 messageName = soapHeader.getMessage(); 525 if (messageName == null) { 526 throw new WSIFException( 527 "no message attribute on soap:header: " + soapHeader); 528 } 529 messagePart = soapHeader.getPart(); 530 if (messagePart == null) { 531 throw new WSIFException( 532 "no part attribute on soap:header: " + soapHeader); 533 } 534 soapHeaderFaultPart = getPart(messageName, messagePart); 535 if (soapHeaderFaultPart == null) { 536 throw new WSIFException( 537 "non existent part specified on soap:header: " 538 + soapHeader); 539 } 540 } 541 } 542 543 if (element instanceof BindingInput) { 544 this.inputSOAPHeader = soapHeaderPart; 545 this.inputSOAPHeaderFault = soapHeaderFaultPart; 546 } else { 547 this.outputSOAPHeader = soapHeaderPart; 548 this.outputSOAPHeaderFault = soapHeaderFaultPart; 549 } 550 } 552 553 560 private List parseSoapBody(SOAPBody soapbody, boolean isInput) 561 throws WSIFException { 562 Trc.entry(this, soapbody, new Boolean (isInput)); 563 564 if (isInput) { 566 String ns = soapbody.getNamespaceURI(); 567 if (ns != null) { 568 setInputNamespace(soapbody.getNamespaceURI()); 569 } 570 } 571 572 String use = soapbody.getUse(); 574 if (!WSIFAXISConstants.VALID_USES.contains(use)) { 575 throw new WSIFException( 576 "unsupported use " + use + " in " + soapOperation); 577 } 578 579 if (isInput) { 581 List l = soapbody.getEncodingStyles(); 582 if (l != null && l.size() > 0) { 583 setInputEncodingStyle((String ) l.get(0)); 584 } 585 } 586 587 javax.wsdl.Message m = null; 590 if (isInput) { 591 Input in = portTypeOperation.getInput(); 592 if (in != null) { 593 m = in.getMessage(); 594 } 595 } else { 596 Output out = portTypeOperation.getOutput(); 597 if (out != null) { 598 m = out.getMessage(); 599 } 600 } 601 ArrayList al = getParts(m, soapbody.getParts()); 602 603 Trc.exit(al); 604 return al; 605 } 606 607 613 private ArrayList getParts(javax.wsdl.Message m, List partNames ) throws WSIFException{ 614 ArrayList al = new ArrayList (); 615 List parts = null; 616 if (m != null) { 617 parts = m.getOrderedParts(null); 618 } 619 620 if ((parts == null || parts.size() < 1) 621 && (partNames != null && partNames.size() > 0)) { 622 throw new WSIFException("part '" + 623 partNames.get(0) + 624 "' not defined in message " + m); 625 } 626 627 if (partNames == null) { 628 if (parts != null) { 629 al.addAll(parts); 630 } 631 } else { 632 for (Iterator i = partNames.iterator(); i.hasNext(); ) { 633 String partName = (String ) i.next(); 634 Part p = m.getPart(partName); 635 if (p == null) { 636 throw new WSIFException("Part '" + 637 partName + 638 "' in soap:body parts not in message " + m); 639 } 640 if (!al.contains(p)) { 644 al.add(p); 645 } 646 } 647 } 648 return al; 649 } 650 651 660 private void parseMimeMultipart( 661 MIMEMultipartRelated mimeMultipart, 662 boolean isInput) 663 throws WSIFException { 664 Trc.entry(this, mimeMultipart); 665 666 ArrayList mimePartNames = new ArrayList (); 667 SOAPBody soapBody = null; 668 669 Operation op = bindingOperation.getOperation(); 670 Map mapInParts = op.getInput().getMessage().getParts(); 671 Map mapOutParts = 672 op.getOutput() == null 673 ? new HashMap () 674 : op.getOutput().getMessage().getParts(); 675 676 List mimeParts = mimeMultipart.getMIMEParts(); 677 Iterator mimePartIt = mimeParts.iterator(); 678 while (mimePartIt.hasNext()) { 679 Object nextMimePart = mimePartIt.next(); 680 if (nextMimePart instanceof MIMEPart) { 681 MIMEPart mimePart = (MIMEPart) nextMimePart; 682 if (!MIMEConstants 683 .NS_URI_MIME 684 .equals(mimePart.getElementType().getNamespaceURI())) 685 throw new WSIFException( 686 "A MIME part in binding operation " 687 + bindingOperation.getName() 688 + " did not have the correct namespace URI of " 689 + MIMEConstants.NS_URI_MIME 690 + "."); 691 692 boolean containsSoapBody = false; 693 boolean containsMimeContent = false; 694 List mimePartChildren = mimePart.getExtensibilityElements(); 695 Iterator mimePartChildrenIt = mimePartChildren.iterator(); 696 while (mimePartChildrenIt.hasNext()) { 697 Object nextChild = mimePartChildrenIt.next(); 698 if (nextChild instanceof MIMEContent) { 699 MIMEContent mimeContent = (MIMEContent) nextChild; 700 if (!MIMEConstants 701 .NS_URI_MIME 702 .equals( 703 mimePart.getElementType().getNamespaceURI())) 704 throw new WSIFException( 705 "A MIME part in binding operation " 706 + bindingOperation.getName() 707 + " did not have the correct namespace URI of " 708 + MIMEConstants.NS_URI_MIME 709 + "."); 710 containsMimeContent = true; 711 if (containsSoapBody) 712 throw new WSIFException( 713 "A mime:part that contains a mime:content also " 714 + "contains a soap:body. Operation=" 715 + getName()); 716 717 String partName = mimeContent.getPart(); 718 if (partName == null || partName.length() == 0) 719 throw new WSIFException( 720 "No part name for a mime:content. Operation=" 721 + getName()); 722 723 if ((isInput && mapInParts.get(partName) == null) 724 || (!isInput && mapOutParts.get(partName) == null)) 725 throw new WSIFException( 726 "The part specified in a mime:content does " 727 + "not exist in the operation. Operation=" 728 + getName() 729 + " Part=" 730 + partName); 731 732 mimePartNames.add(partName); 733 734 } else if (nextChild instanceof SOAPBody) { 735 if (soapBody!=null) { 736 throw new WSIFException( 737 "Multiple soap:body tags found in a " 738 + "mime:multipartRelated. Operation=" 739 + getName()); 740 } 741 soapBody = (SOAPBody)nextChild; 742 743 containsSoapBody = true; 744 if (containsMimeContent) 745 throw new WSIFException( 746 "A mime:part that contains a mime:content also " 747 + "contains a soap:body. Operation=" 748 + getName()); 749 750 } else if (nextChild instanceof MIMEMultipartRelated) { 751 throw new WSIFException( 752 "WSIF does not support nesting mime:multipartRelated " 753 + "inside a mime:part. Operation=" 754 + getName()); 755 } else if (nextChild instanceof MIMEMimeXml) { 756 throw new WSIFException( 757 "WSIF does not support mime:mimeXml. Operation=" 758 + getName()); 759 } 760 } 761 } 762 } 763 764 if (soapBody != null) 766 { 767 List soapBodyParts = soapBody.getParts(); 768 if (soapBodyParts == null && !mimePartNames.isEmpty()) 769 { 770 780 Map soapParts; 781 if (isInput) 782 soapParts = mapInParts; 783 else 784 soapParts = mapOutParts; 785 786 if (soapParts != null && !soapParts.isEmpty()) 787 { 788 ArrayList nonMimeParts = 789 new ArrayList ( 790 Arrays.asList(soapParts.keySet().toArray())); 791 nonMimeParts.removeAll( 792 Arrays.asList(soapParts.keySet().toArray())); 793 soapBody.setParts(nonMimeParts); 794 } 795 } 796 797 List soapParts = parseSoapBody(soapBody, isInput); 798 if (isInput) 799 this.inputSOAPParts = soapParts; 800 else 801 this.outputSOAPParts = soapParts; 802 } 803 804 if (mimePartNames != null && !mimePartNames.isEmpty()) { 805 javax.wsdl.Message m = null; 806 if (isInput) { 807 Input in = portTypeOperation.getInput(); 808 if (in != null) { 809 m = in.getMessage(); 810 } 811 } else { 812 Output out = portTypeOperation.getOutput(); 813 if (out != null) { 814 m = out.getMessage(); 815 } 816 } 817 ArrayList al = getParts(m, mimePartNames); 818 if (isInput) { 819 this.inputMIMEParts = al; 820 } else { 821 this.outputMIMEParts = al; 822 } 823 824 } 825 826 Trc.exit(); 827 } 828 829 838 private void unwrapSOAPParts() throws WSIFException { 839 if (WSIFAXISConstants.STYLE_DOCUMENT.equals(operationStyle)) { 840 String operationName = getName(); 841 if (inputSOAPParts.size() == 1) { 842 Part p = (Part)inputSOAPParts.get(0); 843 QName elementName = p.getElementName(); 844 if (elementName != null && operationName.equals(elementName.getLocalPart())) { 845 this.inputUnwrappedSOAPParts = 846 WSIFUtils.unWrapPart(p, getDefinition()); 847 } 848 } 849 if (outputSOAPParts.size() == 1) { 850 String s = operationName + "Response"; 851 Part p = (Part)outputSOAPParts.get(0); 852 QName elementName = p.getElementName(); 853 if (elementName != null && s.equals(elementName.getLocalPart())) { 854 this.outputUnwrappedSOAPParts = 855 WSIFUtils.unWrapPart(p, getDefinition()); 856 } 857 } 858 } 859 } 860 861 864 private BindingOperation getBindingOperation(Operation operation) 865 throws WSIFException { 866 Binding binding = wsifPort.getPort().getBinding(); 867 BindingOperation bindingOp = 868 WSIFUtils.getBindingOperation(binding, operation); 869 if (bindingOp == null) { 870 throw new WSIFException( 871 "cannot find binding operation for port operation:" 872 + operation.getName()); 873 } 874 return bindingOp; 875 } 876 877 881 public Definition getDefinition() { 882 Trc.entry(this); 883 Definition d = wsifPort.getDefinition(); 884 Trc.exit(d); 885 return d; 886 } 887 888 891 public WSIFPort_ApacheAxis getDynamicWSIFPort() { 892 Trc.entry(this); 893 Trc.exit(wsifPort); 894 return wsifPort; 895 } 896 897 public String getInputEncodingStyle() { 898 Trc.entry(this); 899 Trc.exit(inputEncodingStyle); 900 return inputEncodingStyle; 901 } 902 903 public String getInputNamespace() { 904 Trc.entry(this); 905 Trc.exit(inputNamespace); 906 return inputNamespace; 907 } 908 909 914 public String getName() { 915 Trc.entry(this); 916 String s = portTypeOperation.getName(); 917 Trc.exit(s); 918 return s; 919 } 920 921 924 public Operation getOperation() { 925 Trc.entry(this); 926 Operation o = getPortTypeOperation(); 927 Trc.exit(o); 928 return o; 929 } 930 931 934 private Part getPart(QName message, String partName) { 935 Part p = null; 936 Definition def = wsifPort.getDefinition(); 937 javax.wsdl.Message m = def.getMessage(message); 938 if (m != null) { 939 p = m.getPart(partName); 940 } 941 return p; 942 } 943 944 948 public Operation getPortTypeOperation() { 949 Trc.entry(this); 950 Trc.exit(portTypeOperation); 951 return portTypeOperation; 952 } 953 954 public String getOutputEncodingStyle() { 955 Trc.entry(this); 956 Trc.exit(outputEncodingStyle); 957 return outputEncodingStyle; 958 } 959 960 public String getSoapActionURI() { 961 Trc.entry(this); 962 Trc.exit(soapActionURI); 963 return soapActionURI; 964 } 965 966 public Transport getTransport() throws WSIFException { 967 Trc.entry(this); 968 Transport t = wsifPort.getTransport(); 969 Trc.exit(t); 970 return t; 971 } 972 973 public WSIFCorrelationId getAsyncRequestID() { 974 Trc.entry(this); 975 Trc.exit(asyncRequestID); 976 return asyncRequestID; 977 } 978 979 private HashMap getResponseMessageParameters() { 980 return responseMessageParameters; 981 } 982 983 public WSIFPort getWSIFPort() { 984 Trc.entry(this); 985 Trc.exit(wsifPort); 986 return wsifPort; 987 } 988 989 995 public boolean isAsyncOperation() { 996 Trc.entry(this); 997 Trc.exit(asyncOperation); 998 return asyncOperation; 999 } 1000 1001 public void executeInputOnlyOperation(WSIFMessage inMsg) 1002 throws WSIFException { 1003 Trc.entry(this, inMsg); 1004 1005 if (inMsg == null) { 1006 throw new IllegalArgumentException ("input message is null"); 1007 } 1008 1009 setAsyncOperation(false); 1010 invokeRequestResponseOperation(inMsg, null, null); 1011 Trc.exit(); 1012 return; 1013 } 1014 1015 public boolean executeRequestResponseOperation( 1016 WSIFMessage inMsg, 1017 WSIFMessage outMsg, 1018 WSIFMessage faultMsg) 1019 throws WSIFException { 1020 1021 Trc.entry(this, inMsg, outMsg, faultMsg); 1022 1023 if (inMsg == null) { 1024 throw new IllegalArgumentException ("input message is null"); 1025 } 1026 if (outMsg == null) { 1027 throw new IllegalArgumentException ("output message is null"); 1028 } 1029 if (faultMsg == null) { 1030 throw new IllegalArgumentException ("fault message is null"); 1031 } 1032 1033 close(); 1034 setAsyncOperation(false); 1035 1036 boolean succ = 1037 invokeRequestResponseOperation(inMsg, outMsg, faultMsg); 1038 1039 Trc.exit(succ); 1040 return succ; 1041 } 1042 1043 1052 public WSIFCorrelationId executeRequestResponseAsync(WSIFMessage inMsg) 1053 throws WSIFException { 1054 Trc.entry(this, inMsg); 1055 1056 if (inMsg == null) { 1057 throw new IllegalArgumentException ("input message is null"); 1058 } 1059 1060 WSIFCorrelationId id = executeRequestResponseAsync(inMsg, null); 1061 Trc.exit(id); 1062 return id; 1063 1064 } 1065 1066 1077 public WSIFCorrelationId executeRequestResponseAsync( 1078 WSIFMessage inMsg, 1079 WSIFResponseHandler handler) 1080 throws WSIFException { 1081 Trc.entry(this, inMsg, handler); 1082 1083 if (inMsg == null) { 1084 throw new IllegalArgumentException ("input message is null"); 1085 } 1086 close(); 1087 1088 if (!wsifPort.supportsAsync()) { 1089 throw new WSIFException("asynchronous operations not available"); 1090 } 1091 1092 setAsyncOperation(true); 1093 setResponseHandler(handler); 1094 WSIFJmsTransport transport = (WSIFJmsTransport) getTransport(); 1095 transport.setWsifOperation(this); 1096 transport.setAsyncOperation("true"); 1097 1098 invokeRequestResponseOperation(inMsg, null, null); 1099 1100 transport.setAsyncOperation("false"); 1101 WSIFCorrelationId id = getAsyncRequestID(); 1102 Trc.exit(id); 1103 return id; 1104 1105 } 1106 1107 1116 public void fireAsyncResponse(Object response) throws WSIFException { 1117 Trc.entry(this, response); 1118 1119 Object result = deserialiseResponseObject(response); 1120 1121 WSIFMessage outMsg = createOutputMessage(); 1122 WSIFMessage faultMsg = createFaultMessage(); 1123 buildResponseMessages(result, outMsg, faultMsg); 1124 1125 getResponseHandler().executeAsyncResponse(outMsg, faultMsg); 1126 1127 Trc.exit(outMsg); 1128 } 1129 1130 1151 public boolean processAsyncResponse( 1152 Object response, 1153 WSIFMessage output, 1154 WSIFMessage fault) 1155 throws WSIFException { 1156 Trc.entry(this, response, output, fault); 1157 1158 Object result = deserialiseResponseObject(response); 1159 boolean ok = buildResponseMessages(result, output, fault); 1160 1161 Trc.exit(ok); 1162 return ok; 1163 } 1164 1165 1171 private Object deserialiseResponseObject(Object msg) throws WSIFException { 1172 if (msg == null) { 1173 throw new WSIFException("null response to async send"); 1174 } 1175 if (!(msg instanceof TextMessage )) { 1176 throw new WSIFException("response not a javax.jms.TextMessage"); 1177 } 1178 1179 try { 1180 TextMessage m = (TextMessage ) msg; 1181 Message responseMessage = new Message (m.getText()); 1182 responseMessage.setMessageType(Message.RESPONSE); 1183 1184 Service service = new Service(); 1185 MessageContext msgContext = new MessageContext(service.getEngine()); 1186 msgContext.setResponseMessage(responseMessage); 1187 1188 TypeMappingRegistry tmr = msgContext.getTypeMappingRegistry(); 1189 org.apache.axis.encoding.TypeMapping tm = 1190 (org.apache.axis.encoding.TypeMapping) tmr.getTypeMapping( 1191 outputEncodingStyle); 1192 1193 registerDefaultTypeMappings(tm, getContext()); 1195 1196 registerDynamicTypes(tm, typeMap, getContext()); 1198 1199 Message resMsg = msgContext.getResponseMessage(); 1200 SOAPEnvelope resEnv = resMsg.getSOAPEnvelope(); 1201 1202 Object b = resEnv.getFirstBody(); 1203 if (b instanceof SOAPFaultElement) { 1204 return new AxisFault(b.toString()); 1205 } 1206 1207 RPCElement body = (RPCElement) b; 1208 1209 Object result = null; 1210 HashMap outParams; 1211 Vector resArgs = body.getParams(); 1212 1213 if (resArgs != null && resArgs.size() > 0) { 1214 RPCParam param = (RPCParam) resArgs.get(0); 1215 result = param.getValue(); 1216 1217 if (resArgs.size() > 1) { 1218 outParams = new HashMap (); 1219 for (int i = 1; i < resArgs.size(); i++) { 1220 RPCParam p = (RPCParam) resArgs.get(i); 1221 outParams.put(p.getName(), p.getValue()); 1222 } 1223 setResponseMessageParameters(outParams); 1224 } 1225 } 1226 return result; 1227 } catch (Exception ex) { 1228 Trc.exception(ex); 1229 throw new WSIFException(ex.getMessage()); 1230 } 1231 1232 } 1233 1234 1237 private boolean buildResponseMessages( 1238 Object resp, 1239 WSIFMessage outMsg, 1240 WSIFMessage faultMsg) 1241 throws WSIFException { 1242 1243 boolean respOK; 1244 1245 if (resp instanceof AxisFault) { 1246 respOK = false; 1247 if (faultMsg != null) { 1248 AxisFault f = (AxisFault) resp; 1249 faultMsg.setName(WSIFConstants.SOAP_FAULT_MSG_NAME); 1250 faultMsg.setObjectPart(WSIFConstants.SOAP_FAULT_OBJECT, f); 1251 } 1252 } else { 1253 respOK = true; 1254 populateOutMsgReturnPart(resp, outMsg); 1255 populateOutMsgParts(outMsg); 1256 } 1257 1258 return respOK; 1259 } 1260 1261 1264 private void populateOutMsgReturnPart(Object resp, WSIFMessage outMsg) 1265 throws WSIFException { 1266 if (outMsg != null) { 1267 1268 List soapParts; 1270 if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) { 1271 soapParts = outputUnwrappedSOAPParts; 1272 } else { 1273 soapParts = outputSOAPParts; 1274 } 1275 1276 Part returnPart = null; 1277 if (soapParts.size() > 0) { 1278 returnPart = (Part)soapParts.get(0); 1279 setSOAPMessagePart(outMsg,returnPart.getName(), resp); 1280 } else if (outputMIMEParts.size() > 0) { 1281 returnPart = (Part)outputMIMEParts.get(0); 1282 setMIMEMessagePart( 1283 outMsg, 1284 returnPart.getName(), 1285 resp, 1286 resp == null ? null : resp.getClass()); 1287 } 1288 } 1289 } 1290 1291 1295 private void populateOutMsgParts(WSIFMessage outMsg) throws WSIFException { 1296 if (outMsg != null) { 1297 HashMap respParms = getResponseMessageParameters(); 1298 1299 if (respParms != null) { 1300 List soapParts; 1302 if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) { 1303 soapParts = outputUnwrappedSOAPParts; 1304 } else { 1305 soapParts = outputSOAPParts; 1306 } 1307 for (int i=1; i < soapParts.size(); i++) { 1308 Part p = (Part) soapParts.get(i); 1309 String name = p.getName(); 1310 Object value = respParms.get(name); 1311 setSOAPMessagePart(outMsg, name, value); 1312 } 1313 int startMIMEindex; 1314 if (soapParts.size() > 0) { 1315 startMIMEindex = 0; 1316 } else { 1317 startMIMEindex = 1; 1318 } 1319 for (int i=startMIMEindex; i < outputMIMEParts.size(); i++) { 1320 Part p = (Part) outputMIMEParts.get(i); 1321 String name = p.getName(); 1322 Object value = respParms.get(name); 1323 setMIMEMessagePart( 1324 outMsg, 1325 name, 1326 value, 1327 value == null ? null : value.getClass()); 1328 } 1329 } 1330 } 1331 1332 } 1333 1334 private static void setSOAPMessagePart( 1335 WSIFMessage msg, 1336 String name, 1337 Object value) 1338 throws WSIFException { 1339 Trc.entry(null, msg, name, value); 1340 1341 msg.setObjectPart(name, value); 1343 1344 Trc.exit(); 1345 } 1346 1347 1348 private static void setMIMEMessagePart( 1349 WSIFMessage msg, 1350 String name, 1351 Object value, 1352 Class type) 1353 throws WSIFException { 1354 Trc.entry(null, msg, name, value, type); 1355 1356 MIMEHelper.setMIMEMessagePart(msg, name, value, type); 1357 1358 Trc.exit(); 1359 } 1360 1361 1366 private QName getPartType(Part p) { 1367 QName type = p.getTypeName(); 1368 if (type == null) { 1369 type = p.getElementName(); 1370 } 1371 return type; 1372 } 1373 1374 public boolean invokeRequestResponseOperation( 1375 WSIFMessage inMsg, 1376 WSIFMessage outMsg, 1377 WSIFMessage faultMsg) 1378 throws WSIFException { 1379 Trc.entry(this, inMsg, outMsg, faultMsg); 1380 boolean workedOK = false; 1381 1382 Call call = wsifPort.getCall(); 1383 1384 call.removeAllParameters(); 1386 call.clearHeaders(); 1387 1388 call.setTargetEndpointAddress(wsifPort.getEndPoint()); 1389 1390 if (inputSOAPParts == null) { 1391 prepare(call); 1392 } 1393 call.setSOAPActionURI(getSoapActionURI()); 1394 1395 if (WSIFAXISConstants.STYLE_DOCUMENT.equals(operationStyle) 1396 && isInputMessageUnWrapped(inMsg)) { 1397 operationStyle = WSIFAXISConstants.AXIS_STYLE_WRAPPED; 1398 } 1399 1400 if (isMessaging(inMsg)) { 1402 operationStyle = WSIFAXISConstants.AXIS_STYLE_MESSAGE; 1403 } 1404 1405 Transport axistransport = getTransport(); 1406 WSIFJMSDestination dest = null; 1407 if (axistransport != null) { 1408 call.setTransport(axistransport); 1409 if (axistransport instanceof WSIFJmsTransport) { 1410 WSIFJmsTransport jmst = (WSIFJmsTransport) axistransport; 1411 dest = jmst.getDestination(); 1412 dest.setAsyncMode(isAsyncOperation()); 1413 jmst.setSyncTimeout(null); jmst.setAsyncTimeout(null); 1415 } 1416 } 1417 1418 if (dest != null 1419 && inJmsPropVals != null 1420 && !inJmsPropVals.isEmpty()) { 1421 checkForTimeoutProperties(inJmsPropVals, dest); 1422 dest.setProperties(inJmsPropVals); 1423 } 1424 1425 1427 setDestinationContext(dest); 1428 setCallContext(call); 1429 1430 if (WSIFAXISConstants.AXIS_STYLE_MESSAGE.equals(operationStyle)) { 1431 workedOK = invokeAXISMessaging(call, inMsg, outMsg, faultMsg); 1432 } else if (WSIFAXISConstants.STYLE_RPC.equals(operationStyle)) { 1433 workedOK = invokeAXISRPCStyle(call, inMsg, outMsg, faultMsg, dest); 1434 } else { 1435 workedOK = invokeAXISDocStyle(call, inMsg, outMsg, faultMsg); 1436 } 1437 1438 setResponseContext(call); 1439 1440 Trc.exit(workedOK); 1441 return workedOK; 1442 } 1443 1444 1452 private boolean isInputMessageUnWrapped(WSIFMessage msg) { 1453 boolean unWrapped = true; 1454 1455 Object style = null; 1456 try { 1457 WSIFMessage context = getContext(); 1458 style = context.getObjectPart(WSIFConstants.CONTEXT_OPERATION_STYLE); 1459 } catch (WSIFException e) { 1460 Trc.ignoredException(e); 1461 } 1462 if (WSIFConstants.CONTEXT_OPERATION_STYLE_WRAPPED.equals(style)) { 1463 unWrapped = true; 1464 } else if (WSIFConstants.CONTEXT_OPERATION_STYLE_UNWRAPPED.equals(style)) { 1465 unWrapped = false; 1466 } else if (inputUnwrappedSOAPParts != null 1467 && inputUnwrappedSOAPParts.size() > 0) { 1468 unWrapped = true; 1469 for (Iterator i=inputUnwrappedSOAPParts.iterator(); i.hasNext() && unWrapped; ) { 1470 Part p = (Part) i.next(); 1471 try { 1472 msg.getObjectPart(p.getName()); 1473 } catch (WSIFException e) { 1474 unWrapped = false; 1475 } 1476 } 1477 } else { 1478 unWrapped = false; 1479 } 1480 1481 return unWrapped; 1482 } 1483 1484 1491 private boolean isMessaging(WSIFMessage msg) { 1492 boolean allDOMElements = true; 1493 boolean anyDOMElements = false; 1494 1495 if (msg != null) { 1496 for (Iterator i = inputSOAPParts.iterator(); i.hasNext(); ) { 1497 Part p = (Part) i.next(); 1498 try { 1499 Object o = msg.getObjectPart(p.getName()); 1500 if (o instanceof Element) { 1501 anyDOMElements = true; 1502 } else { 1503 allDOMElements = false; 1504 } 1505 } catch (WSIFException e) { 1506 Trc.ignoredException(e); 1507 } 1508 } 1509 } 1510 return anyDOMElements && allDOMElements; 1511 } 1512 1513 1514 1518 private boolean invokeAXISRPCStyle( 1519 Call call, 1520 WSIFMessage inMsg, 1521 WSIFMessage outMsg, 1522 WSIFMessage faultMsg, 1523 WSIFJMSDestination dest) 1524 throws WSIFException { 1525 1526 call.setOperationName( 1527 new QName (getInputNamespace(), portTypeOperation.getName())); 1528 1529 setCallParameterNames(call); 1530 1531 Object [] inputValues = getInputMessageValues(inMsg, dest); 1532 1533 Object response = null; 1534 boolean respOK = true; 1535 try { 1536 String name = portTypeOperation.getName(); 1537 Trc.event( 1538 this, 1539 "Invoking operation ", 1540 name, 1541 " input namespace ", 1542 getInputNamespace(), 1543 " parameters ", 1544 inputValues, 1545 " call object ", 1546 call); 1547 1548 response = call.invoke(getInputNamespace(), name, inputValues); 1549 1550 } catch (AxisFault e) { 1551 Trc.exception(e); 1552 response = e; 1553 respOK = false; 1554 } 1555 1556 Trc.event(this, "Returned from operation, response ", response); 1557 1558 1560 if (!isAsyncOperation() 1561 && (outputSOAPParts.size() > 0 || outputMIMEParts.size() > 0) ) { 1562 Map callParams = call.getOutputParams(); 1563 if (callParams != null) { 1564 HashMap outParams = new HashMap (); 1565 QName qn; 1566 for (Iterator i = callParams.keySet().iterator(); 1567 i.hasNext(); 1568 ) { 1569 qn = (QName ) i.next(); 1570 outParams.put(qn.getLocalPart(), callParams.get(qn)); 1571 } 1572 setResponseMessageParameters(outParams); 1573 } 1574 respOK = 1575 buildResponseMessages(response, outMsg, faultMsg); 1576 } 1577 1578 return respOK; 1579 } 1580 1581 1584 private void setCallParameterNames(Call call) throws WSIFException { 1585 1586 String inputNamespace = getInputNamespace(); 1587 String outputNamespace = ""; 1588 1589 List soapParts; 1590 if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) { 1592 soapParts = inputUnwrappedSOAPParts; 1593 } else { 1594 soapParts = inputSOAPParts; 1595 } 1596 1597 1602 if (inputMIMEParts.isEmpty()) 1603 { 1604 for (int i = 0; i < soapParts.size(); i++) 1606 { 1607 Part p = (Part) soapParts.get(i); 1608 String partName = p.getName(); 1609 if (!inJmsProps.containsKey(partName)) 1610 { 1611 if (WSIFAXISConstants 1612 .STYLE_DOCUMENT 1613 .equals(operationStyle)) 1614 { 1615 QName qn = p.getElementName(); 1616 if (qn != null) 1617 { 1618 partName = qn.getLocalPart(); 1619 } 1620 } 1621 QName name = new QName (inputNamespace, partName); 1622 QName type = getPartType(p); 1623 call.addParameter(name, type, ParameterMode.IN); 1624 } 1625 } 1626 } 1627 else 1628 { 1629 List order = 1632 portTypeOperation.getInput().getMessage().getOrderedParts(null); 1633 Iterator it = order.iterator(); 1634 while (it.hasNext()) 1635 { 1636 Part p = (Part) it.next(); 1637 1638 if (inputMIMEParts.contains(p) || soapParts.contains(p)) 1641 { 1642 QName name = new QName (inputNamespace, p.getName()); 1643 QName type = getPartType(p); 1644 call.addParameter(name, type, ParameterMode.IN); 1645 } 1646 } 1647 } 1648 1649 if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) { 1651 soapParts = outputUnwrappedSOAPParts; 1652 } else { 1653 soapParts = outputSOAPParts; 1654 } 1655 1656 Part returnPart = null; 1658 if (soapParts.size() > 0) { 1659 returnPart = (Part)soapParts.get(0); 1660 } else if (outputMIMEParts.size() > 0) { 1661 returnPart = (Part)outputMIMEParts.get(0); 1662 } 1663 if (returnPart == null) { 1664 call.setReturnType(org.apache.axis.encoding.XMLType.AXIS_VOID); 1665 } else { 1666 QName type = getPartType(returnPart); 1667 call.setReturnType(type); 1668 } 1669 1670 for (int i = 1; i < soapParts.size(); i++) { 1673 Part p = (Part) soapParts.get(i); 1674 QName name = new QName (outputNamespace, p.getName()); 1675 QName type = getPartType(p); 1676 call.addParameter(name, type, ParameterMode.OUT); 1677 } 1678 1679 int startMIMEIndex = (soapParts.size() > 0) ? 0 : 1; 1682 for (int i = startMIMEIndex; i < outputMIMEParts.size(); i++) { 1683 Part p = (Part) outputMIMEParts.get(i); 1684 QName name = new QName (outputNamespace, p.getName()); 1685 QName type = getPartType(p); 1686 call.addParameter(name, type, ParameterMode.OUT); 1687 } 1688 } 1689 1690 1694 private boolean invokeAXISDocStyle( 1695 Call call, 1696 WSIFMessage inMsg, 1697 WSIFMessage outMsg, 1698 WSIFMessage faultMsg) 1699 throws WSIFException { 1700 1701 boolean respOK = false; 1702 1703 call.setOperationName( 1705 new QName (getInputNamespace(), portTypeOperation.getName())); 1706 call.setScopedProperty(Call.SEND_TYPE_ATTR, Boolean.FALSE); 1707 call.setScopedProperty(AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE); 1708 call.setOperationStyle(operationStyle); 1709 setCallParameterNames(call); 1710 1711 Object [] inputValues = getInputMessageValues(inMsg, null); 1712 1713 Trc.event(this, "Invoking AXIS call", call, inputValues); 1715 Object response; 1716 try { 1717 response = call.invoke(inputValues); 1718 respOK = true; 1719 } catch (RemoteException ex) { 1720 Trc.exception(ex); 1721 throw new WSIFException( 1722 "exception on AXIS invoke: " + ex.getLocalizedMessage(), 1723 ex); 1724 } 1725 Trc.event(this, "Returned from AXIS invoke, response: ", response); 1726 1727 if (!isAsyncOperation()) { 1729 1730 List soapParts; 1732 if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) { 1733 soapParts = outputUnwrappedSOAPParts; 1734 } else { 1735 soapParts = outputSOAPParts; 1736 } 1737 1738 if (soapParts.size() > 0 || outputMIMEParts.size() > 0) { 1739 Map callParams = call.getOutputParams(); 1740 if (callParams != null) { 1741 HashMap outParams = new HashMap (); 1742 QName qn; 1743 for (Iterator i = callParams.keySet().iterator(); i.hasNext(); ) { 1744 qn = (QName ) i.next(); 1745 outParams.put(qn.getLocalPart(), callParams.get(qn)); 1746 } 1747 setResponseMessageParameters(outParams); 1748 } 1749 respOK = 1750 buildResponseMessages(response, outMsg, faultMsg); 1751 } 1752 } 1753 1754 return respOK; 1755 } 1756 1757 1761 private boolean invokeAXISMessaging( 1762 Call call, 1763 WSIFMessage inMsg, 1764 WSIFMessage outMsg, 1765 WSIFMessage faultMsg) 1766 throws WSIFException { 1767 1768 boolean workedOK = false; 1769 1770 List attachments = addAttachments(inMsg, call); 1771 1772 Object [] inputValues = getInputMessageValues(inMsg, null); 1773 ArrayList soapBodies = new ArrayList (); 1774 for (int i = 0; i < inputValues.length; i++) { 1775 if (inputValues[i] instanceof Element) { 1776 Element el = (Element) inputValues[i]; 1777 1778 if ((attachments.size() > 0) && (i == 0)) { 1779 fixAttachmentPartsCID(el, attachments); 1780 } 1781 1782 soapBodies.add(new SOAPBodyElement(el)); 1783 } else { 1784 throw new WSIFException( 1785 "unexpected input type: " + inputValues[i]); 1786 } 1787 } 1788 1789 Object [] axisInputs = soapBodies.toArray(); 1790 1791 Trc.event(this, "Invoking AXIS call", call, axisInputs); 1792 Object axisResponse; try { 1794 axisResponse = call.invoke(axisInputs); 1795 } catch (RemoteException ex) { 1796 throw new WSIFException( 1797 "exception on AXIS invoke: " + ex.getLocalizedMessage(), 1798 ex); 1799 } 1800 Trc.event(this, "Returned from AXIS invoke, response: ", axisResponse); 1801 1802 setOutputMessageValues(axisResponse, outMsg); 1803 1804 workedOK = true; 1805 return workedOK; 1806 } 1807 1808 1821 private void fixAttachmentPartsCID(Element body, List attachments) throws WSIFException { 1822 1823 ArrayList al = new ArrayList (); 1825 getAttachmentElements(al, body); 1826 1827 1831 if (al.size() != attachments.size()) { 1832 throw new WSIFException("unexpected number of attachments," 1833 + attachments.size() + " AttachmentParts, " 1834 + al.size() + " attachment href elements"); 1835 } 1836 1837 for (int i = 0; i < attachments.size(); i++ ) { 1839 AttachmentPart attachment = (AttachmentPart) attachments.get(i); 1840 Element attachmentElement = (Element) al.get(i); 1841 attachmentElement.setAttribute("href", "cid:" + attachment.getContentId()); 1842 } 1843 } 1844 1845 1852 private static void getAttachmentElements(ArrayList al, Element el) { 1853 NodeList childNodes = el.getChildNodes(); 1854 for (int j = 0; j < childNodes.getLength(); j++) { 1855 Node n = childNodes.item(j); 1856 if (n instanceof Element) { 1857 Element childElement = (Element) n; 1858 String s = childElement.getAttribute("href"); 1859 if (s != null && s.toLowerCase().startsWith("cid:")) { 1860 al.add(childElement); 1861 } else { 1862 getAttachmentElements(al, childElement); 1863 } 1864 } 1865 } 1866 } 1867 1868 1875 private void prepare(Call call) throws WSIFException { 1876 Trc.entry(this, call); 1877 1878 1882 1883 1886 this.inputSOAPParts = new ArrayList (); 1887 this.inputMIMEParts = new ArrayList (); 1888 this.outputSOAPParts = new ArrayList (); 1889 this.outputMIMEParts = new ArrayList (); 1890 1891 parseSoapOperation(); 1892 parseBindingInput(); 1893 parseBindingOutput(); 1894 unwrapSOAPParts(); 1895 1896 addInputJmsPropertyValues(wsifPort.getJmsAddressPropVals()); 1898 1899 if (!WSIFAXISConstants.STYLE_RPC.equals(operationStyle)) { 1900 call.setEncodingStyle(null); 1901 inputEncodingStyle = ""; 1902 outputEncodingStyle = ""; 1903 } 1904 1905 if (inputNamespace == null || inputNamespace.length() < 1) { 1906 this.inputNamespace = getTargetNamespaceURI(); 1907 } 1908 1909 TypeMapping tm = call.getTypeMapping(); 1910 WSIFMessage context = getContext(); 1911 1912 registerDefaultTypeMappings(tm, context); 1914 1915 registerDynamicTypes(tm, typeMap, context); 1917 1918 registerMIMETypes( 1919 inputMIMEParts, 1920 call); 1921 1922 registerMIMETypes( 1923 outputMIMEParts, 1924 call); 1925 1926 if (Trc.ON) { 1927 Trc.exit(deep()); 1928 } 1929 } 1930 1931 1934 static void registerDefaultTypeMappings(TypeMapping callTypeMappings, WSIFMessage context) throws WSIFException { 1935 Object value = null; 1936 try { 1937 value = context.getObjectPart(WSIFAXISConstants.CONTEXT_DEFAULT_SOAP_TYPE_SERIALIZERS); 1938 } catch (WSIFException e) { 1939 Trc.ignoredException(e); 1940 } 1941 if (value == null) { 1942 return; 1943 } 1944 if (!(value instanceof List )) { 1945 throw new WSIFException( 1946 "context part '" 1947 + WSIFAXISConstants.CONTEXT_DEFAULT_SOAP_TYPE_SERIALIZERS 1948 + "' value is not an instance of java.util.List: " 1949 + value); 1950 } 1951 List defaultMappings = (List ) value; 1952 for (Iterator i = defaultMappings.iterator(); i.hasNext(); ) { 1953 Object o = i.next(); 1954 if (!(o instanceof TypeSerializerInfo)) { 1955 throw new WSIFException( 1956 "context part '" 1957 + WSIFAXISConstants.CONTEXT_DEFAULT_SOAP_TYPE_SERIALIZERS 1958 + "' value List contains an entry that is not an instance " 1959 + "of org.apache.wsif.util.TypeSerializer: " 1960 + value); 1961 } 1962 TypeSerializerInfo ts = (TypeSerializerInfo) o; 1963 1964 Class javaType = ts.getJavaType(); 1965 QName elementType = ts.getElementType(); 1966 Object tmp = ts.getSerializer(); 1967 SerializerFactory sf = null; 1968 if (tmp instanceof SerializerFactory) { 1969 sf = (SerializerFactory) tmp; 1970 } 1971 tmp = ts.getDeserializer(); 1972 DeserializerFactory df = null; 1973 if (tmp instanceof DeserializerFactory) { 1974 df = (DeserializerFactory) tmp; 1975 } 1976 1977 if (javaType != null 1978 && elementType != null 1979 && (sf != null || df != null) ) { 1980 callTypeMappings.register(javaType, elementType, sf, df); 1981 } else { 1982 Trc.event(null, "ignoring default TypeSerializer invalid for AXIS:" + ts); 1983 } 1984 } 1985 } 1986 1987 1990 static void registerDynamicTypes( 1991 TypeMapping tm, 1992 WSIFDynamicTypeMap typeMap, 1993 WSIFMessage context) 1994 throws WSIFException { 1995 1996 Class objClass; 1997 String namespaceURI, localPart; 1998 WSIFDynamicTypeMapping wsifdynamictypemapping; 1999 for (Iterator iterator = typeMap.iterator(); iterator.hasNext();) { 2000 wsifdynamictypemapping = (WSIFDynamicTypeMapping) iterator.next(); 2001 objClass = wsifdynamictypemapping.getJavaType(); 2002 QName xmlType = wsifdynamictypemapping.getXmlType(); 2003 2004 SerializerFactory sf = null; 2005 DeserializerFactory df = null; 2006 2007 TypeSerializerInfo contextTypeSerializer = 2009 findContextTypeSerialzer(context, objClass, xmlType); 2010 if (contextTypeSerializer != null) { 2011 objClass = contextTypeSerializer.getJavaType(); 2012 xmlType = contextTypeSerializer.getElementType(); 2013 sf = (SerializerFactory) contextTypeSerializer.getSerializer(); 2014 df = (DeserializerFactory) contextTypeSerializer.getDeserializer(); 2015 } 2016 2017 if (sf == null && tm.getSerializer(objClass, xmlType) == null) { 2018 if (objClass.isArray()) { 2019 sf = new ArraySerializerFactory(); 2020 } else if (SimpleType.class.isAssignableFrom(objClass)) { 2021 sf = new SimpleSerializerFactory(objClass, xmlType); 2022 } else { 2023 sf = new BeanSerializerFactory(objClass, xmlType); 2024 } 2025 } 2026 2027 if (df == null && tm.getDeserializer(objClass, xmlType) == null) { 2028 if (objClass.isArray()) { 2029 df = new ArrayDeserializerFactory(); 2030 } else if (SimpleType.class.isAssignableFrom(objClass)) { 2031 df = new SimpleDeserializerFactory(objClass, xmlType); 2032 } else { 2033 df = new BeanDeserializerFactory(objClass, xmlType); 2034 } 2035 } 2036 2037 namespaceURI = 2038 wsifdynamictypemapping.getXmlType().getNamespaceURI(); 2039 2040 if (!isDefaultSOAPNamespace(namespaceURI) ) { 2044 2045 localPart = wsifdynamictypemapping.getXmlType().getLocalPart(); 2046 QName qn = new QName (namespaceURI, localPart); 2047 2048 if (sf != null || df != null) { 2049 tm.register(objClass, qn, sf, df); 2050 } 2051 } 2052 } 2053 } 2054 2055 private static TypeSerializerInfo findContextTypeSerialzer( 2056 WSIFMessage context, 2057 Class clazz, 2058 QName xmlType) 2059 throws WSIFException { 2060 2061 Object value = null; 2062 try { 2063 value = context.getObjectPart(WSIFAXISConstants.CONTEXT_SOAP_TYPE_SERIALIZERS); 2064 } catch (WSIFException e) { 2065 Trc.ignoredException(e); 2066 } 2067 if (value == null) { 2068 return null; 2069 } 2070 if (!(value instanceof List )) { 2071 throw new WSIFException( 2072 "context part '" 2073 + WSIFAXISConstants.CONTEXT_SOAP_TYPE_SERIALIZERS 2074 + "' value is not an instance of java.util.List: " 2075 + value); 2076 } 2077 2078 List typeSerializers = (List ) value; 2079 for (Iterator i = typeSerializers.iterator(); i.hasNext(); ) { 2080 Object o = i.next(); 2081 if (!(o instanceof TypeSerializerInfo)) { 2082 throw new WSIFException( 2083 "context part '" 2084 + WSIFAXISConstants.CONTEXT_SOAP_TYPE_SERIALIZERS 2085 + "' value List contains an entry that is not an instance " 2086 + "of org.apache.wsif.util.TypeSerializer: " 2087 + value); 2088 } 2089 TypeSerializerInfo tm = (TypeSerializerInfo) o; 2090 2091 Class javaType = tm.getJavaType(); 2092 QName elementType = tm.getElementType(); 2093 Object serializer = tm.getSerializer(); 2094 Object deserializer = tm.getDeserializer(); 2095 2096 if ( (javaType != null) || (javaType.isAssignableFrom(clazz)) 2097 && ( (elementType != null) || (elementType.equals(xmlType)) ) ){ 2098 if (serializer == null || serializer instanceof SerializerFactory 2099 && deserializer == null || deserializer instanceof DeserializerFactory 2100 && serializer != null || deserializer != null) { 2101 return tm; 2102 } 2103 } 2104 } 2105 2106 return null; } 2108 2109 private static boolean isDefaultSOAPNamespace(String ns) { 2110 boolean soapNamespace = false; 2111 if (WSIFConstants.NS_URI_1999_SCHEMA_XSD.equals(ns) 2112 || WSIFConstants.NS_URI_2000_SCHEMA_XSD.equals(ns) 2113 || WSIFConstants.NS_URI_2001_SCHEMA_XSD.equals(ns) 2114 || WSIFConstants.NS_URI_SOAP_ENC.equals(ns) ){ 2115 soapNamespace = true; 2116 } 2117 return soapNamespace; 2118 } 2119 2120 2123 private Object [] getInputMessageValues(WSIFMessage inMsg, WSIFJMSDestination dest) throws WSIFException { 2124 ArrayList axisInputs = new ArrayList (); 2125 List soapParts; 2126 2127 if (WSIFAXISConstants.AXIS_STYLE_WRAPPED.equals(operationStyle)) { 2129 soapParts = inputUnwrappedSOAPParts; 2130 } else { 2131 soapParts = inputSOAPParts; 2132 } 2133 2134 2139 if (inputMIMEParts.isEmpty()) 2140 { 2141 for (int i = 0; i < soapParts.size(); i++) 2142 { 2143 Part p = (Part) soapParts.get(i); 2144 String partName = p.getName(); 2145 Object value; 2146 try 2147 { 2148 value = inMsg.getObjectPart(partName); 2149 } 2150 catch (WSIFException e) 2151 { 2152 Trc.ignoredException(e); 2153 value = null; } 2155 if (inJmsProps.containsKey(partName) && dest != null) 2156 { 2157 String name = (String ) (inJmsProps.get(partName)); 2158 if (!timeoutProperty(dest, name, value)) 2159 { 2160 dest.setProperty(name, value); 2161 } 2162 } 2163 else 2164 { 2165 axisInputs.add(value); 2166 } 2167 2168 } 2169 } 2170 else 2171 { 2172 List order = 2175 portTypeOperation.getInput().getMessage().getOrderedParts(null); 2176 Iterator it = order.iterator(); 2177 while (it.hasNext()) 2178 { 2179 Part p = (Part) it.next(); 2180 String partName = p.getName(); 2181 2182 if (soapParts.contains(p) 2185 || (inputMIMEParts.contains(p) 2186 && !WSIFAXISConstants.AXIS_STYLE_MESSAGE.equals( 2187 operationStyle))) 2188 { 2189 Object value; 2190 try 2191 { 2192 value = inMsg.getObjectPart(partName); 2193 } 2194 catch (WSIFException e) 2195 { 2196 Trc.ignoredException(e); 2197 value = null; } 2199 if (inJmsProps.containsKey(partName) && dest != null) 2200 { 2201 String name = (String ) (inJmsProps.get(partName)); 2202 if (!timeoutProperty(dest, name, value)) 2203 { 2204 dest.setProperty(name, value); 2205 } 2206 } 2207 else 2208 { 2209 axisInputs.add(value); 2210 } 2211 } 2212 } 2213 } 2214 return axisInputs.toArray(); 2215 } 2216 2217 2222 private List addAttachments(WSIFMessage inMsg, Call call) throws WSIFException { 2223 ArrayList attachments = new ArrayList (); 2224 for (int i = 0; i < inputMIMEParts.size(); i++) { 2225 Part p = (Part) inputMIMEParts.get(i); 2226 try { 2227 String partName = p.getName(); 2228 Object value = inMsg.getObjectPart(partName); 2229 AttachmentPart ap = MIMEHelper.getAttachementPart(value); 2230 call.addAttachmentPart(ap); 2231 attachments.add(ap); 2232 } catch (WSIFException e) { 2233 throw new WSIFException("attachment part '" + p.getName() + "' not in input WSIFMessage"); 2234 } 2235 } 2236 return attachments; 2237 } 2238 2239 2246 private void setOutputMessageValues( 2247 Object axisResponse, 2248 WSIFMessage outMsg) 2249 throws WSIFException { 2250 if (!(axisResponse instanceof Vector )) { 2251 throw new WSIFException( 2252 "expect response type of java.util.Vector of SOAPBodyElement, found: " 2253 + axisResponse); 2254 } 2255 2256 Vector v = (Vector ) axisResponse; 2257 for (int i = 0; i < v.size(); i++) { 2258 if (v.elementAt(i) instanceof RPCElement) { 2259 RPCElement rpcEl = (RPCElement) v.elementAt(i); 2260 2261 QName qn = new QName (rpcEl.getNamespaceURI(), rpcEl.getName()); 2262 Part p = findPart(outputSOAPParts, qn); 2263 if (p != null) { 2264 setSOAPPart(outMsg, rpcEl, p); 2265 } else { 2266 setAttachmentPart(outMsg, rpcEl); 2267 } 2268 2269 } else { 2270 throw new WSIFException( 2271 "expecting response type org.w3c.dom.Element, found: " 2272 + v.elementAt(i)); 2273 } 2274 } 2275 } 2276 2277 2280 private void setSOAPPart(WSIFMessage outMsg, RPCElement rpcEl, Part p) throws WSIFException { 2281 Object responseValue = null; 2282 try { 2283 responseValue = rpcEl.getAsDOM(); 2284 } catch (Exception e) { 2285 throw new WSIFException( 2286 "exception getting soap body as DOM: " + 2287 e.getLocalizedMessage(), 2288 e); 2289 } 2290 String partName = p.getName(); 2291 outMsg.setObjectPart(partName, responseValue); 2292 } 2293 2294 2297 private void setAttachmentPart(WSIFMessage outMsg, RPCElement rpcEl) throws WSIFException { 2298 2299 Vector params; 2300 try { 2301 params = rpcEl.getParams(); 2302 } catch (SAXException e) { 2303 throw new WSIFException( 2304 "SAXException getting response MIME part: " + 2305 e.getLocalizedMessage(), 2306 e); 2307 } 2308 2309 if (params == null || params.size() < 1) { 2310 throw new WSIFException( 2311 "no attachments found in response element: " + rpcEl); 2312 } 2313 2314 RPCParam rpcParam = (RPCParam) params.get(0); 2316 2317 QName qn = rpcParam.getQName(); 2318 Part p = findPart(outputMIMEParts, qn); 2319 if (p != null) { 2320 Object responseValue = rpcParam.getValue(); 2321 if (responseValue instanceof AttachmentPart) { 2322 try { 2323 Object attachment = ((AttachmentPart)responseValue).getDataHandler(); 2324 String partName = p.getName(); 2325 outMsg.setObjectPart(partName, attachment); 2326 } catch (SOAPException e) { 2327 throw new WSIFException( 2328 "SOAPException getting DataHandler from AttachmentPart: " + 2329 e.getLocalizedMessage(), 2330 e); 2331 } 2332 } else { 2333 throw new WSIFException( 2334 "expecting response AttachmentPart but found: " + responseValue); 2335 } 2336 } else { 2337 throw new WSIFException("cannot find a WSDL output MIME part for response element: " + rpcEl); 2338 } 2339 2340 } 2341 2342 2346 private Part findPart(List partsList, QName partName) { 2347 Part part = null; 2348 for (Iterator i = partsList.iterator(); i.hasNext() && part == null; ) { 2349 Part p = (Part) i.next(); 2350 if (partName.equals(p.getElementName())) { 2351 part = p; 2352 } else if (partName.getLocalPart().equals(p.getName())) { 2353 part = p; 2354 } 2355 } 2356 return part; 2357 } 2358 2359 2362 private void registerMIMETypes( 2363 List mimeParts, 2364 Call call) { 2365 if (mimeParts != null && !mimeParts.isEmpty()) { 2366 for (Iterator i = mimeParts.iterator(); i.hasNext(); ) { 2367 Part p = (Part) i.next(); 2368 QName type = getPartType(p); 2369 MIMEHelper.registerAttachmentType(call, type); 2370 } 2371 } 2372 } 2373 2374 2379 private void setResponseHandler(WSIFResponseHandler responseHandler) { 2380 this.responseHandler = responseHandler; 2381 } 2382 2383 2389 WSIFResponseHandler getResponseHandler() { 2390 return responseHandler; 2391 } 2392 2393 2396 public void setDefinition(Definition definition1) { 2397 Trc.entry(this, definition1); 2398 throw new RuntimeException ("method nolonger supported"); 2399 } 2400 2401 public void setDynamicWSIFPort(WSIFPort_ApacheAxis wsifport_apacheaxis) { 2402 Trc.entry(this, wsifport_apacheaxis); 2403 wsifPort = wsifport_apacheaxis; 2404 Trc.exit(); 2405 } 2406 2407 public void setInputEncodingStyle(String s) { 2408 Trc.entry(this, s); 2409 inputEncodingStyle = s; 2410 Trc.exit(); 2411 } 2412 2413 public void setInputNamespace(String s) { 2414 Trc.entry(this, s); 2415 inputNamespace = s; 2416 Trc.exit(); 2417 } 2418 2419 public void setOperation(Operation operation1) { 2420 Trc.entry(this, operation1); 2421 portTypeOperation = operation1; 2422 Trc.exit(); 2423 } 2424 2425 public void setOutputEncodingStyle(String s) { 2426 Trc.entry(this, s); 2427 outputEncodingStyle = s; 2428 Trc.exit(); 2429 } 2430 2431 public void setSoapActionURI(String s) { 2432 Trc.entry(this, s); 2433 soapActionURI = s; 2434 Trc.exit(); 2435 } 2436 2437 private void setResponseMessageParameters(HashMap hm) { 2438 this.responseMessageParameters = hm; 2439 } 2440 2441 2447 private void setAsyncOperation(boolean b) { 2448 asyncOperation = b; 2449 } 2450 2451 2456 public String getTargetNamespaceURI() { 2457 Trc.entry(this); 2458 Definition d = getDefinition(); 2459 String s = (d == null) ? "" : d.getTargetNamespace(); 2460 Trc.exit(s); 2461 return s; 2462 } 2463 2464 2467 private void setJMSOutPropsInContext(WSIFJMSDestination dest) 2468 throws WSIFException { 2469 if (dest == null) { 2470 return; 2471 } 2472 HashMap props = dest.getProperties(); 2473 if (props != null) { 2474 getContext().setParts(props); 2475 } 2476 } 2477 2478 2481 private void setDestinationContext(WSIFJMSDestination dest) throws WSIFException { 2482 if (dest == null) { 2483 return; 2484 } 2485 WSIFMessage context = getContext(); 2486 HashMap jmsProps = new HashMap (); 2487 for (Iterator i = context.getPartNames(); i.hasNext();) { 2488 String partName = (String ) i.next(); 2489 try { 2490 Object value = context.getObjectPart(partName); 2491 if (!timeoutProperty(dest, partName, value)) { 2492 if (partName 2493 .startsWith(WSIFConstants.CONTEXT_JMS_PREFIX)) { 2494 String propertyName = 2495 partName.substring( 2496 WSIFConstants.CONTEXT_JMS_PREFIX.length()); 2497 jmsProps.put(propertyName, value); 2498 } 2499 } 2500 } catch (WSIFException ex) { 2501 Trc.ignoredException(ex); 2502 } 2503 } 2504 if (jmsProps.size() > 0) { 2505 dest.setProperties(jmsProps); 2506 } 2507 } 2508 2509 2513 private void setCallContext(Call call) throws WSIFException { 2514 Object o; 2515 String name; 2516 WSIFMessage context = getContext(); 2517 2518 name = WSIFConstants.CONTEXT_HTTP_USER; 2519 try { 2520 o = context.getObjectPart(name); 2521 if (o instanceof String ) { 2522 addHTTPHeader(call, name, (String ) o); 2523 } 2524 } catch (WSIFException ex) { 2525 Trc.ignoredException(ex); 2526 } 2527 2528 name = WSIFConstants.CONTEXT_HTTP_PSWD; 2529 try { 2530 o = context.getObjectPart(name); 2531 if (o instanceof String ) { 2532 addHTTPHeader(call, name, (String ) o); 2533 } 2534 } catch (WSIFException ex) { 2535 Trc.ignoredException(ex); 2536 } 2537 2538 try { 2539 name = WSIFConstants.CONTEXT_REQUEST_SOAP_HEADERS; 2540 o = context.getObjectPart(name); 2541 if (o instanceof List ) { 2542 addSOAPHeader(call, name, (List ) o); 2543 } 2544 } catch (WSIFException ex) { 2545 Trc.ignoredException(ex); 2546 } 2547 } 2548 2549 2552 private void setResponseContext(Call call) throws WSIFException { 2553 org.apache.axis.Message m = call.getResponseMessage(); 2554 if (m != null) { 2555 javax.xml.soap.SOAPEnvelope env; 2556 try { 2557 env = m.getSOAPEnvelope(); 2558 } catch (AxisFault e) { 2559 throw new WSIFException( 2560 "AxisFault getting response SOAP envelope", e); 2561 } 2562 if (env != null) { 2563 javax.xml.soap.SOAPHeader soapHeader; 2564 try { 2565 soapHeader = env.getHeader(); 2566 } catch (SOAPException e) { 2567 throw new WSIFException( 2568 "SOAPException getting response headers from SOAP envelope", e); 2569 } 2570 addContextResponseSOAPHeaders(soapHeader); 2571 } 2572 } 2573 } 2574 2575 2578 private void addSOAPHeader(Call call, String name, List soapHeaders) { 2579 for (Iterator i = soapHeaders.iterator(); i.hasNext();) { 2580 Object o = i.next(); 2581 if (o instanceof Element) { 2582 call.addHeader(new SOAPHeaderElement((Element) o)); 2583 } 2584 } 2585 } 2586 2587 2590 private void addContextResponseSOAPHeaders( 2591 javax.xml.soap.SOAPHeader soapHeader) throws WSIFException { 2592 2593 if( soapHeader != null ) { 2594 ArrayList headers = new ArrayList (); 2595 for(Iterator i = soapHeader.getChildElements(); i.hasNext(); ) { 2596 Object o = i.next(); 2597 if (o instanceof SOAPHeaderElement) { 2598 SOAPHeaderElement she = (SOAPHeaderElement) o; 2599 try { 2600 headers.add(she.getAsDOM()); 2601 } catch (Exception e) { 2602 throw new WSIFException( 2603 "exception getting response SOAP header", 2604 e); 2605 } 2606 } else { 2607 Trc.event("unexpected response SOAP header type: ", o); 2608 } 2609 } 2610 if (headers.size() > 0) { 2611 WSIFMessage context = getContext(); 2612 context.setObjectPart( 2613 WSIFConstants.CONTEXT_RESPONSE_SOAP_HEADERS, 2614 headers); 2615 setContext(context); 2616 } 2617 } 2618 } 2619 2620 2627 private void addHTTPHeader(Call call, String name, String value) { 2628 if (name.equals(WSIFConstants.CONTEXT_HTTP_USER)) { 2629 call.setProperty(Call.USERNAME_PROPERTY, value); 2630 } else if (name.equals(WSIFConstants.CONTEXT_HTTP_PSWD)) { 2631 call.setProperty(Call.PASSWORD_PROPERTY, value); 2632 } 2633 } 2634 2635 2641 private void checkForTimeoutProperties( 2642 HashMap inJmsPropVals, 2643 WSIFJMSDestination dest) 2644 throws WSIFException { 2645 for (Iterator i = inJmsPropVals.keySet().iterator(); i.hasNext();) { 2646 String name = (String ) i.next(); 2647 Object value = inJmsPropVals.get(name); 2648 if (timeoutProperty(dest, name, value)) { 2649 i.remove(); 2650 } 2651 } 2652 } 2653 2654 private boolean timeoutProperty( 2655 WSIFJMSDestination dest, 2656 String propertyName, 2657 Object value) 2658 throws WSIFException { 2659 boolean isTimeoutProperty = false; 2660 try { 2661 if (WSIFConstants.WSIF_PROP_SYNC_TIMEOUT.equals(propertyName)) { 2662 isTimeoutProperty = true; 2663 Long syncTimeout = new Long (value.toString()); 2664 WSIFJmsTransport transport = (WSIFJmsTransport) getTransport(); 2665 transport.setSyncTimeout(syncTimeout); 2666 Trc.event(this, "overridding syncTimeout to " + syncTimeout); 2667 } else if ( 2668 WSIFConstants.WSIF_PROP_ASYNC_TIMEOUT.equals(propertyName)) { 2669 isTimeoutProperty = true; 2670 Long asyncTimeout = new Long (value.toString()); 2671 WSIFJmsTransport transport = (WSIFJmsTransport) getTransport(); 2672 transport.setAsyncTimeout(asyncTimeout); 2673 Trc.event(this, "overridding asyncTimeout to " + asyncTimeout); 2674 } 2675 } catch (NumberFormatException ex) { 2676 Trc.ignoredException(ex); 2677 } 2678 return isTimeoutProperty; 2679 } 2680 2681 2685 private static boolean isPrimitiveOf(Class clazz, Class primitive) { 2686 if ((primitive.equals(boolean.class) 2687 && Boolean .class.isAssignableFrom(clazz)) 2688 || (primitive.equals(char.class) 2689 && Character .class.isAssignableFrom(clazz)) 2690 || (primitive.equals(byte.class) 2691 && Byte .class.isAssignableFrom(clazz)) 2692 || (primitive.equals(short.class) 2693 && Short .class.isAssignableFrom(clazz)) 2694 || (primitive.equals(int.class) 2695 && Integer .class.isAssignableFrom(clazz)) 2696 || (primitive.equals(long.class) 2697 && Long .class.isAssignableFrom(clazz)) 2698 || (primitive.equals(float.class) 2699 && Float .class.isAssignableFrom(clazz)) 2700 || (primitive.equals(double.class) 2701 && Double .class.isAssignableFrom(clazz))) 2702 return true; 2703 else 2704 return false; 2705 } 2706 2707 void setAsyncRequestID(WSIFCorrelationId asyncRequestID) { 2709 Trc.entry(this, asyncRequestID); 2710 this.asyncRequestID = asyncRequestID; 2711 Trc.exit(); 2712 } 2713 2714 2717 public String getStyle() { 2718 return operationStyle; 2719 } 2720 2721 2725 public String getOperationStyle() { 2726 return operationStyle; 2727 } 2728 2729 2732 public void setStyle(String style) { 2733 this.operationStyle = style; 2734 } 2735 2736 2739 public void setOperationStyle(String style) { 2740 this.operationStyle = style; 2741 } 2742 2743 public String deep() { 2744 StringBuffer buff = new StringBuffer (); 2745 try { 2746 buff.append(super.toString()).append(":\n"); 2747 buff.append("wsifPort:").append(wsifPort); 2748 buff.append(" portTypeOperation:").append(Trc.brief(portTypeOperation)); 2749 buff.append(" bindingOperation:").append(bindingOperation); 2750 buff.append(" soapOperation:").append(soapOperation); 2751 buff.append(" operationStyle:").append(operationStyle); 2752 buff.append(" inputSOAPParts:").append(inputSOAPParts); 2753 buff.append(" inputUnwrappedSOAPParts:").append(inputUnwrappedSOAPParts); 2754 buff.append(" inputMIMEParts:").append(inputMIMEParts); 2755 buff.append(" inputSOAPHeader:").append(inputSOAPHeader); 2756 buff.append(" inputSOAPHeaderFault:").append(inputSOAPHeaderFault); 2757 buff.append(" outputSOAPParts:").append(outputSOAPParts); 2758 buff.append(" outputUnwrappedSOAPParts:").append(outputUnwrappedSOAPParts); 2759 buff.append(" outputMIMEParts:").append(outputMIMEParts); 2760 buff.append(" outputSOAPHeader:").append(outputSOAPHeader); 2761 buff.append(" outputSOAPHeaderFault:").append(outputSOAPHeaderFault); 2762 buff.append(" inputEncodingStyle:").append(inputEncodingStyle); 2763 buff.append(" inputNamespace:").append(inputNamespace); 2764 buff.append(" actionUri:").append(soapActionURI); 2765 buff.append(" inJmsProps:").append(inJmsProps); 2766 buff.append(" outJmsProps:").append(outJmsProps); 2767 buff.append(" inJmsPropVals:").append(inJmsPropVals); 2768 buff.append(" context:").append(context); 2769 buff.append(" asyncOperation:").append(asyncOperation); 2770 buff.append(" asyncRequestID:").append(asyncRequestID); 2771 buff.append(" responseHandler:").append(responseHandler); 2772 buff.append(" responseMessageParameters:").append(responseMessageParameters); 2773 buff.append(" outputEncodingStyle:").append(outputEncodingStyle); 2774 buff.append(" typeMap:").append(typeMap); 2775 } catch (Exception e) { 2776 Trc.exceptionInTrace(e); 2777 } 2778 return buff.toString(); 2779 } 2780} 2781 | Popular Tags |