1 57 58 package org.apache.wsif.providers.ejb; 59 60 import java.lang.reflect.Constructor; 61 import java.lang.reflect.InvocationTargetException; 62 import java.lang.reflect.Method; 63 import java.util.ArrayList; 64 import java.util.Enumeration; 65 import java.util.HashMap; 66 import java.util.Iterator; 67 import java.util.List; 68 import java.util.Map; 69 import java.util.Vector; 70 71 import javax.ejb.EJBHome; 72 import javax.ejb.EJBObject; 73 import javax.wsdl.BindingFault; 74 import javax.wsdl.BindingInput; 75 import javax.wsdl.BindingOperation; 76 import javax.wsdl.BindingOutput; 77 import javax.wsdl.Fault; 78 import javax.wsdl.Message; 79 import javax.wsdl.Operation; 80 import javax.wsdl.OperationType; 81 import javax.wsdl.Part; 82 import javax.xml.namespace.QName; 83 84 import org.apache.wsif.WSIFException; 85 import org.apache.wsif.WSIFMessage; 86 import org.apache.wsif.WSIFOperation; 87 import org.apache.wsif.WSIFPort; 88 import org.apache.wsif.base.WSIFDefaultOperation; 89 import org.apache.wsif.logging.MessageLogger; 90 import org.apache.wsif.logging.Trc; 91 import org.apache.wsif.providers.ProviderUtils; 92 import org.apache.wsif.wsdl.extensions.ejb.EJBOperation; 93 import org.apache.wsif.wsdl.extensions.format.TypeMap; 94 import org.apache.wsif.wsdl.extensions.format.TypeMapping; 95 96 103 public class WSIFOperation_EJB 104 extends WSIFDefaultOperation 105 implements WSIFOperation { 106 107 private static final long serialVersionUID = 1L; 108 109 protected javax.wsdl.Port fieldPortModel; 110 protected WSIFPort_EJB fieldPort; 111 protected javax.wsdl.BindingOperation fieldBindingOperationModel; 112 protected EJBOperation fieldEJBOperationModel; 113 protected Method fieldMethod = null; 114 protected Method[] fieldAllMethods = null; 115 protected String[] fieldInParameterNames = null; 116 protected String[] fieldOutParameterNames = null; 117 119 protected String fieldOutputMessageName = null; 120 protected String fieldInputMessageName = null; 121 protected Map fieldFaultMessageInfos = null; 122 124 protected boolean fieldIsHomeInterface = false; 125 protected Map fieldTypeMaps = new HashMap(); 126 protected boolean fieldTypeMapBuilt = false; 127 128 private class FaultMessageInfo { 129 String fieldMessageName; 130 String fieldPartName; 131 String fieldFormatType; 132 134 FaultMessageInfo( 135 String messageName, 136 String partName, 137 String formatType) { 138 fieldMessageName = messageName; 139 fieldPartName = partName; 140 fieldFormatType = formatType; 141 } 142 } 143 144 public WSIFOperation_EJB( 145 javax.wsdl.Port portModel, 146 BindingOperation bindingOperationModel, 147 WSIFPort_EJB port) 148 throws WSIFException { 149 Trc.entry(this, portModel, bindingOperationModel, port); 150 151 fieldPortModel = portModel; 152 fieldBindingOperationModel = bindingOperationModel; 153 fieldPort = port; 154 155 try { 156 fieldEJBOperationModel = 157 (EJBOperation) fieldBindingOperationModel 158 .getExtensibilityElements() 159 .get( 160 0); 161 } catch (Exception e) { 162 Trc.exception(e); 163 throw new WSIFException( 164 "Unable to resolve EJB binding for operation '" 165 + bindingOperationModel.getName() 166 + "'"); 167 } 168 169 String ejbInterface = fieldEJBOperationModel.getEjbInterface(); 171 if (ejbInterface != null) { 172 if (ejbInterface.equals("home")) { 173 fieldIsHomeInterface = true; 174 } else if (!ejbInterface.equals("remote")) { 175 throw new WSIFException( 176 "EJB binding interface not recognized for operation '" 177 + bindingOperationModel.getName() 178 + "'. Valid values are 'home' and 'remote'"); 179 } 180 } 181 182 if (fieldIsHomeInterface) { 183 fieldAllMethods = fieldPort.getEjbHome().getClass().getMethods(); 184 } else { 185 fieldAllMethods = fieldPort.getEjbObject().getClass().getMethods(); 186 } 187 188 if (Trc.ON) 189 Trc.exit(deep()); 190 } 191 192 196 public WSIFOperation_EJB copy() throws WSIFException { 197 Trc.entry(this); 198 WSIFOperation_EJB woe = 199 new WSIFOperation_EJB( 200 fieldPortModel, 201 fieldBindingOperationModel, 202 fieldPort); 203 Trc.exit(woe); 204 return woe; 205 } 206 207 private static Class getClassForName(String classname) 208 throws WSIFException { 209 Trc.entry(null, classname); 210 Class cls = null; 211 212 if (classname == null) { 213 throw new WSIFException("Error in getClassForName(): No class name specified!"); 214 } 215 216 try { 217 if (classname.lastIndexOf('.') == -1) { 218 if (classname.equals("char")) { 220 cls = char.class; 221 } else if (classname.equals("boolean")) { 222 cls = boolean.class; 223 } else if (classname.equals("byte")) { 224 cls = byte.class; 225 } else if (classname.equals("short")) { 226 cls = short.class; 227 } else if (classname.equals("int")) { 228 cls = int.class; 229 } else if (classname.equals("long")) { 230 cls = long.class; 231 } else if (classname.equals("float")) { 232 cls = float.class; 233 } else if (classname.equals("double")) { 234 cls = double.class; 235 } else { 236 cls = 237 Class.forName( 238 classname, 239 true, 240 Thread.currentThread().getContextClassLoader()); 241 } 242 } else { 243 cls = 244 Class.forName( 245 classname, 246 true, 247 Thread.currentThread().getContextClassLoader()); 248 } 249 } catch (ClassNotFoundException ex) { 250 Trc.exception(ex); 251 throw new WSIFException( 252 "Could not instantiate class '" + classname + "'", 253 ex); 254 } 255 256 Trc.exit(cls); 257 return cls; 258 } 259 260 protected Map getFaultMessageInfos() throws WSIFException { 261 Trc.entry(this); 262 Operation operation = null; 264 try { 265 operation = getOperation(); 266 } catch (Exception e) { 267 Trc.exception(e); 268 throw new WSIFException("Failed to get Operation", e); 269 } 270 271 if (fieldFaultMessageInfos == null) { 272 fieldFaultMessageInfos = new HashMap(); 273 } 274 275 BindingFault bindingFaultModel = null; 276 Map bindingFaultModels = fieldBindingOperationModel.getBindingFaults(); 277 List parts = null; 278 TypeMap typeMap = null; 279 Iterator modelsIterator = bindingFaultModels.values().iterator(); 280 281 while (modelsIterator.hasNext()) { 282 bindingFaultModel = (BindingFault) modelsIterator.next(); 283 String name = bindingFaultModel.getName(); 284 if (name == null) { 285 throw new WSIFException("Fault name not found in binding"); 286 } 287 288 Map map = operation.getFault(name).getMessage().getParts(); 289 if (map.size() >= 1) { 290 Part part = (Part) map.values().iterator().next(); 291 QName partType = part.getTypeName(); 292 if (partType == null) partType = part.getElementName(); 293 Object formatType = fieldTypeMaps.get(partType); 294 if (formatType == null) { 295 throw new WSIFException( 296 "formatType for typeName '" 297 + part.getName() 298 + "' not found in document"); 299 } 300 301 if (formatType instanceof Vector) { 302 Vector types = (Vector) formatType; 303 Enumeration enum = types.elements(); 304 while (enum.hasMoreElements()) { 305 String type = (String) enum.nextElement(); 306 fieldFaultMessageInfos.put( 308 type, 309 new FaultMessageInfo(name, part.getName(), type)); 310 } 311 } else { 312 String type = (String) formatType; 313 fieldFaultMessageInfos.put( 315 type, 316 new FaultMessageInfo(name, part.getName(), type)); 317 } 318 } 319 } 320 321 Trc.exit(fieldFaultMessageInfos); 322 return fieldFaultMessageInfos; 323 } 324 325 protected String getInputMessageName() throws WSIFException { 326 Trc.entry(this); 327 if (fieldInputMessageName == null) { 328 BindingInput bindingInputModel = 329 fieldBindingOperationModel.getBindingInput(); 330 if (bindingInputModel != null) { 331 fieldInputMessageName = bindingInputModel.getName(); 332 } 333 } 334 Trc.exit(fieldInputMessageName); 335 return fieldInputMessageName; 336 } 337 338 protected Method[] getMethods() throws WSIFException { 339 Trc.entry(this); 340 Method[] candidates; 341 try { 342 Object[] args = getMethodArgumentClasses(); 344 Object retClass = getMethodReturnClass(); 345 Vector possibles = new Vector(); 346 for (int i = 0; i < fieldAllMethods.length; i++) { 347 if (!fieldAllMethods[i] 348 .getName() 349 .equals(fieldEJBOperationModel.getMethodName())) 350 continue; 351 Class[] params = fieldAllMethods[i].getParameterTypes(); 352 if (params.length != args.length) 353 continue; 354 Class retType = fieldAllMethods[i].getReturnType(); 355 if (retClass != null && retClass instanceof Vector) { 356 Vector vec = (Vector) retClass; 357 boolean found = false; 358 for (int p = 0; p < vec.size(); p++) { 359 Class cl = (Class) vec.get(p); 360 if (cl.getName().equals(retType.getName())) { 361 found = true; 362 break; 363 } else if (cl.isAssignableFrom(retType)) { 364 found = true; 365 break; 366 } 367 } 368 if (!found) 369 continue; 370 } else { 371 if (retType != null && retClass != null) { 372 if (!(((Class) retClass).getName().equals(retType.getName())) 373 && !(((Class) retClass).isAssignableFrom(retType))) 374 continue; 375 } 376 } 377 378 boolean match = true; 379 for (int j = 0; j < params.length; j++) { 380 Object obj = args[j]; 381 if (obj instanceof Vector) { 382 Vector vec = (Vector) obj; 383 boolean found = false; 384 for (int p = 0; p < vec.size(); p++) { 385 Class cl = (Class) vec.get(p); 386 if (cl.getName().equals(params[j].getName())) { 387 found = true; 388 break; 389 } else if (params[j].isAssignableFrom(cl)) { 390 found = true; 391 break; 392 } 393 } 394 if (!found) { 395 match = false; 396 break; 397 } 398 } else { 399 if (!(((Class) obj).getName().equals(params[j].getName())) 400 && !(params[j].isAssignableFrom((Class) obj))) { 401 match = false; 402 break; 403 } 404 } 405 } 406 if (match) { 407 possibles.addElement(fieldAllMethods[i]); 408 } 409 } 410 candidates = new Method[possibles.size()]; 411 for (int k = 0; k < candidates.length; k++) { 412 candidates[k] = (Method) possibles.get(k); 413 } 414 Trc.exit(candidates); 415 return candidates; 416 } catch (WSIFException ex) { 417 Trc.exception(ex); 418 throw ex; 419 } catch (Exception ex) { 420 Trc.exception(ex); 421 throw new WSIFException( 422 "Error while resolving meta information of method " 423 + fieldEJBOperationModel.getMethodName() 424 + " : The meta information is not consistent.", 425 ex); 426 } 427 } 428 429 private void buildTypeMap() throws WSIFException { 430 Trc.entry(this); 431 if (fieldTypeMapBuilt) { 433 Trc.exit(); 434 return; 435 } 436 437 TypeMapping typeMapping = null; 438 439 Iterator bindingIterator = 441 fieldPortModel.getBinding().getExtensibilityElements().iterator(); 442 443 451 while (bindingIterator.hasNext()) { 452 Object next = bindingIterator.next(); 453 if (next instanceof TypeMapping) { 454 typeMapping = (TypeMapping) next; 455 if (("Java".equals(typeMapping.getEncoding()) 456 || "EJB".equals(typeMapping.getEncoding())) 457 && "Java".equals(typeMapping.getStyle())) 458 break; 459 Trc.event(this, "Silently ignoring typemapping", typeMapping); 460 typeMapping = null; 461 } 462 Trc.event( 463 this, 464 "Silently ignoring something that was not a typemapping", 465 next); 466 } 467 468 if (typeMapping == null) { 469 QName bindingName = fieldPortModel.getBinding().getQName(); 470 throw new WSIFException( 471 "Binding " 472 + (bindingName == null ? "<null>" : bindingName.toString()) 473 + " does not contain a typeMap with encoding=Java or encoding=EJB and style=Java"); 474 } 475 476 bindingIterator = typeMapping.getMaps().iterator(); 478 while (bindingIterator.hasNext()) { 479 TypeMap typeMap = (TypeMap) bindingIterator.next(); 480 QName typeName = typeMap.getTypeName(); 482 if (typeName == null) typeName = typeMap.getElementName(); 483 String type = typeMap.getFormatType(); 484 if (typeName != null && type != null) { 485 if (fieldTypeMaps.containsKey(typeName)) { 486 Vector v = null; 487 Object obj = fieldTypeMaps.get(typeName); 488 if (obj instanceof Vector) { 489 v = (Vector) obj; 490 } else { 491 v = new Vector(); 492 v.addElement(obj); 493 } 494 v.addElement(type); 495 this.fieldTypeMaps.put(typeName, v); 496 } else { 497 this.fieldTypeMaps.put(typeName, type); 498 } 499 } else { 500 throw new WSIFException("Error in binding TypeMap. Key or Value is null"); 501 } 502 } 503 fieldTypeMapBuilt = true; 504 Trc.exit(); 505 } 506 507 protected Operation getOperation() throws Exception { 508 Trc.entry(this); 509 Operation operation = null; 510 buildTypeMap(); 511 512 String inputName = null; 515 try { 516 inputName = 517 this.fieldBindingOperationModel.getBindingInput().getName(); 518 } catch (NullPointerException e) { 519 Trc.ignoredException(e); 520 inputName = null; 521 } 522 523 String outputName = null; 524 try { 525 outputName = 526 this.fieldBindingOperationModel.getBindingOutput().getName(); 527 } catch (NullPointerException e) { 528 Trc.ignoredException(e); 529 outputName = null; 530 } 531 532 operation = 534 this.fieldPortModel.getBinding().getPortType().getOperation( 535 this.fieldBindingOperationModel.getName(), 536 inputName, 537 outputName); 538 Trc.exit(operation); 540 return operation; 541 } 542 543 protected Object getMethodReturnClass() throws WSIFException { 544 Trc.entry(this); 545 Object methodReturnClass = null; 546 try { 547 String returnPartString = fieldEJBOperationModel.getReturnPart(); 548 if (returnPartString != null) { 549 Part returnPart = 552 getOperation().getOutput().getMessage().getPart( 553 returnPartString); 554 555 if (returnPart != null) { 557 QName partType = returnPart.getTypeName(); 558 if (partType == null) partType = returnPart.getElementName(); 559 560 Object obj = this.fieldTypeMaps.get(partType); 561 if (obj == null) 562 throw new WSIFException( 563 "Could not map type " 564 + partType 565 + " to a java type. Part name was " 566 + returnPart.getName() == null 567 ? "<null>" : returnPart.getName()); 568 569 if (obj instanceof Vector) { 570 Vector v = (Vector) obj; 571 Vector argv = new Vector(); 572 Enumeration enum = v.elements(); 573 while (enum.hasMoreElements()) { 574 String cls = (String) enum.nextElement(); 575 argv.addElement(getClassForName(cls)); 576 } 577 methodReturnClass = argv; 578 } else { 579 methodReturnClass = getClassForName((String) obj); 580 } 581 } else { 582 throw new WSIFException( 585 "returnPart '" 586 + returnPartString 587 + "' was not in the output message"); 588 } 589 } 590 } catch (Exception ex) { 592 Trc.exception(ex); 593 throw new WSIFException( 594 "Error while determining return class of method " 595 + fieldEJBOperationModel.getMethodName() 596 + " : The meta information is not consistent.", 597 ex); 598 } 599 600 Trc.exit(methodReturnClass); 601 return methodReturnClass; 602 } 603 604 protected Object[] getMethodArgumentClasses() throws WSIFException { 605 Trc.entry(this); 606 Object[] methodArgClasses = null; 607 try { 608 609 Operation operation = getOperation(); 610 611 618 619 List parameterOrder = null; 621 622 parameterOrder = fieldEJBOperationModel.getParameterOrder(); 623 624 if (parameterOrder == null) { 625 parameterOrder = operation.getParameterOrdering(); 626 } 627 628 635 if (parameterOrder == null) { 636 List partList = 637 operation.getInput().getMessage().getOrderedParts(null); 638 parameterOrder = new Vector(); 639 Iterator partListIterator = partList.iterator(); 640 while (partListIterator.hasNext()) { 641 Part part = (Part) partListIterator.next(); 642 parameterOrder.add(part.getName()); 643 } 644 } 645 646 665 666 ArrayList argNames = new ArrayList(); 667 ArrayList argTypes = new ArrayList(); 668 669 Iterator parameterIterator = parameterOrder.iterator(); 670 while (parameterIterator.hasNext()) { 671 String param = (String) parameterIterator.next(); 672 Part part = 673 (Part) operation.getInput().getMessage().getPart(param); 674 if (part == null) { 675 part = 676 (Part) operation.getOutput().getMessage().getPart( 677 param); 678 } 679 if (part == null) 680 throw new WSIFException( 681 "Part '" 682 + param 683 + "' from parameterOrder not found in input or output message"); 684 argNames.add((String) part.getName()); 685 686 QName partType = part.getTypeName(); 688 if (partType == null) partType = part.getElementName(); 689 Object obj = this.fieldTypeMaps.get(partType); 690 if (obj == null) 691 throw new WSIFException( 692 "Could not map type " 693 + partType 694 + " to a java type. Part name was " 695 + part.getName() == null ? "<null>" : part.getName()); 696 697 if (obj instanceof Vector) { 698 Vector v = (Vector) obj; 699 Vector argv = new Vector(); 700 Enumeration enum = v.elements(); 701 while (enum.hasMoreElements()) { 702 String cls = (String) enum.nextElement(); 703 argv.addElement(getClassForName(cls)); 704 } 705 argTypes.add(argv); 706 } else { 707 argTypes.add(getClassForName((String) obj)); 708 } 709 710 } 711 712 methodArgClasses = new Object[argTypes.size()]; 713 for (int i = 0; i < argTypes.size(); i++) { 714 methodArgClasses[i] = argTypes.get(i); 715 } 716 717 fieldInParameterNames = new String[argNames.size()]; 718 for (int i = 0; i < argNames.size(); i++) { 719 fieldInParameterNames[i] = (String) argNames.get(i); 720 } 721 722 if (operation.getStyle().equals(OperationType.REQUEST_RESPONSE)) { 724 argNames = new ArrayList(); 725 String returnPart = fieldEJBOperationModel.getReturnPart(); 727 Message outputMessage = operation.getOutput().getMessage(); 728 Iterator outputPartsIterator = 729 outputMessage.getOrderedParts(null).iterator(); 730 while (outputPartsIterator.hasNext()) { 731 Part part = (Part) outputPartsIterator.next(); 732 String partName = part.getName(); 733 if (partName != null 734 && returnPart != null 735 && partName.equals(returnPart)) { 736 argNames.add(0, partName); 738 } else { 739 argNames.add((String) part.getName()); 740 } 741 } 742 743 fieldOutParameterNames = new String[argNames.size()]; 745 for (int i = 0; i < argNames.size(); i++) { 746 fieldOutParameterNames[i] = (String) argNames.get(i); 747 } 748 } else { 749 fieldOutParameterNames = new String[0]; 750 } 751 } catch (Exception ex) { 752 Trc.exception(ex); 753 throw new WSIFException( 754 "Error while determining signature of method " 755 + fieldEJBOperationModel.getMethodName() 756 + " : The meta information is not consistent.", 757 ex); 758 } 759 760 Trc.exit(methodArgClasses); 761 return methodArgClasses; 762 } 763 764 protected Object[] getCompatibleArguments( 768 Class[] parmTypes, 769 Object[] args) { 770 Trc.entry(this,parmTypes,args); 771 if (args == null || parmTypes == null) { 777 Object[] compatibleArgs = new Object[0]; 778 Trc.exit(compatibleArgs); 779 return compatibleArgs; 780 } 781 782 Object[] compatibleArgs = new Object[args.length]; 783 for (int i = 0; i < parmTypes.length; i++) { 784 if (args[i] == null) { 786 compatibleArgs[i] = ProviderUtils.getDefaultObject(parmTypes[i]); 787 continue; 788 } 789 Object convertedArg = getCompatibleObject(parmTypes[i], args[i]); 791 if (convertedArg == null) { 792 Trc.exit(null); 794 return null; 795 } else { 796 compatibleArgs[i] = convertedArg; 797 } 798 799 } 800 Trc.exit(compatibleArgs); 801 return compatibleArgs; 802 } 803 804 protected Object getCompatibleReturn(Method method, Object returnObj) { 805 Trc.entry(this,method,returnObj); 806 Object o = null; 807 Class rt = method.getReturnType(); 808 Class ct = null; 809 int dims = 0; 810 if (rt.isArray()) { 811 ct = rt.getComponentType(); 812 dims++; 813 while (ct.isArray()) { 814 ct = ct.getComponentType(); 815 dims++; 816 } 817 } 818 if (returnObj instanceof java.lang.Character) { 819 o = getCompatibleObject(java.lang.String.class, returnObj); 820 } else if (ct != null && (ct.equals(java.lang.Character.class) || ct.equals(char.class))) { 821 String stringArrayClassName = "[Ljava.lang.String;"; 822 for (int d=1; d<dims; d++) { 823 stringArrayClassName = "["+stringArrayClassName; 824 } 825 try { 826 Class stringArrayClass = Class.forName(stringArrayClassName, true, Thread.currentThread().getContextClassLoader()); 827 o = getCompatibleObject(stringArrayClass, returnObj); 828 } catch(ClassNotFoundException cnf) { 829 Trc.ignoredException(cnf); 830 o = returnObj; 831 } 832 } else { 833 o = returnObj; 834 } 835 Trc.exit(o); 836 return o; 837 } 838 839 protected Object getCompatibleObject(Class cls, Object obj) { 849 Trc.entry(this,cls,obj); 850 851 if (cls.getName().equals(obj.getClass().getName())) return obj; 852 853 if ((cls.equals(java.lang.Character.class) || cls.equals(char.class)) 855 && obj.getClass().equals(java.lang.String.class)) { 856 Character charArg = ProviderUtils.stringToCharacter((String) obj); 857 if (charArg == null) { 858 Trc.exit(null); 860 return null; 861 } 862 Trc.exit(charArg); 863 return charArg; 864 } 865 866 if (cls.isArray() && obj.getClass().isArray()) { 868 Class cct = cls.getComponentType(); 869 Class objct = obj.getClass().getComponentType(); 870 while (cct.isArray()) { 871 cct = cct.getComponentType(); 872 } 873 while (objct.isArray()) { 874 objct = objct.getComponentType(); 875 } 876 if (objct.equals(java.lang.String.class) && cct.equals(char.class)) { 877 try { 878 Object charArray = ProviderUtils.stringArrayToCharArray(obj); 879 Trc.exit(charArray); 880 return charArray; 881 } catch (Exception e) { 882 Trc.ignoredException(e); 883 Trc.exit(null); 884 return null; 885 } 886 } else if (objct.equals(java.lang.String.class) && cct.equals(java.lang.Character.class)) { 887 try { 888 Object charArray = ProviderUtils.stringArrayToCharacterArray(obj); 889 Trc.exit(charArray); 890 return charArray; 891 } catch (Exception e) { 892 Trc.ignoredException(e); 893 Trc.exit(null); 894 return null; 895 } 896 } else if (objct.equals(java.lang.Character.class) && cct.equals(java.lang.String.class)) { 897 try { 898 Object charArray = ProviderUtils.characterArrayToStringArray(obj); 899 Trc.exit(charArray); 900 return charArray; 901 } catch (Exception e) { 902 Trc.ignoredException(e); 903 Trc.exit(null); 904 return null; 905 } 906 } else if (objct.equals(char.class) && cct.equals(java.lang.String.class)) { 907 try { 908 Object charArray = ProviderUtils.charArrayToStringArray(obj); 909 Trc.exit(charArray); 910 return charArray; 911 } catch (Exception e) { 912 Trc.ignoredException(e); 913 Trc.exit(null); 914 return null; 915 } 916 } 917 } 918 919 if (cls.equals(java.lang.String.class) 920 && obj.getClass().equals(java.lang.Character.class)) { 921 Trc.exit(obj.toString()); 922 return (obj.toString()); 923 } 924 925 Trc.exit(obj); 926 return obj; 927 } 928 929 protected String getOutputMessageName() throws WSIFException { 930 Trc.entry(this); 931 if (fieldOutputMessageName == null) { 932 BindingOutput bindingOutputModel = 933 fieldBindingOperationModel.getBindingOutput(); 934 if (bindingOutputModel != null) { 935 fieldOutputMessageName = bindingOutputModel.getName(); 936 } 937 } 938 Trc.exit(fieldOutputMessageName); 939 return fieldOutputMessageName; 940 } 941 942 public WSIFPort getWSIFPort() { 943 Trc.entry(this); 944 Trc.exit(fieldPort); 945 return fieldPort; 946 } 947 948 public boolean executeRequestResponseOperation( 949 WSIFMessage input, 950 WSIFMessage output, 951 WSIFMessage fault) 952 throws WSIFException { 953 954 Trc.entry(this, input, output, fault); 955 close(); 956 957 boolean operationSucceeded = true; 958 boolean foundInputParameter = false; 959 boolean usedOutputParam = false; 960 961 try { 962 Object result = null; 963 Method[] methods = null; 964 Constructor constructor = null; 965 966 methods = getMethods(); 967 if (methods.length <= 0) 968 throw new WSIFException( 969 "No method named '" 970 + fieldEJBOperationModel.getMethodName() 971 + "' found that match the parts specified"); 972 973 Object[] arguments = null; 974 Object part = null; 975 if ((fieldInParameterNames != null) 976 && (fieldInParameterNames.length > 0)) { 977 arguments = new Object[fieldInParameterNames.length]; 978 for (int i = 0; i < fieldInParameterNames.length; i++) { 979 try { 980 part = input.getObjectPart(fieldInParameterNames[i]); 981 arguments[i] = part; 982 foundInputParameter = true; 983 } catch (WSIFException e) { 984 Trc.exception(e); 985 if (fieldOutParameterNames.length > 0) { 986 String outParameterName = null; 987 for (int j = 0; 988 j < fieldOutParameterNames.length; 989 j++) { 990 outParameterName = fieldOutParameterNames[j]; 991 if ((outParameterName != null) 992 && (outParameterName 993 .equals(fieldInParameterNames[i]))) { 994 arguments[i] = 995 (methods[0].getParameterTypes()[i]) 996 .newInstance(); 997 foundInputParameter = true; 998 usedOutputParam = true; 999 } 1000 } 1001 } 1002 } 1003 if (!foundInputParameter) { 1004 throw new WSIFException( 1005 this 1006 + " : Could not set input parameter '" 1007 + fieldInParameterNames[i] 1008 + "'"); 1009 } 1010 } 1011 } 1012 1013 boolean invokedOK = false; 1014 for (int a = 0; a < methods.length; a++) { 1015 if (fieldIsHomeInterface 1016 && methods[a].getName().equals( 1017 "create")) { 1019 try { 1020 Object[] compatibleArguments = 1022 getCompatibleArguments( 1023 methods[a].getParameterTypes(), 1024 arguments); 1025 if (compatibleArguments == null) 1027 break; 1028 1030 EJBHome home = fieldPort.getEjbHome(); 1031 Trc.event( 1032 this, 1033 "Invoking EJB method ", 1034 methods[a], 1035 " home ", 1036 home, 1037 " with arguments ", 1038 compatibleArguments); 1039 1040 result = methods[a].invoke(home, compatibleArguments); 1041 1042 Trc.event(this, "Returned from EJB result is ", result); 1043 1044 fieldPort.setEjbObject((EJBObject) result); 1045 fieldMethod = methods[a]; 1046 invokedOK = true; 1047 break; 1048 } catch (IllegalArgumentException ia) { 1049 Trc.ignoredException(ia); 1050 } 1052 } else { 1054 if (usedOutputParam) { 1055 for (int i = 0; 1056 i < fieldInParameterNames.length; 1057 i++) { 1058 String outParameterName = null; 1059 for (int j = 0; j < fieldOutParameterNames.length; j++) { 1060 outParameterName = fieldOutParameterNames[j]; 1061 if ((outParameterName != null) 1062 && (outParameterName 1063 .equals(fieldInParameterNames[i]))) { 1064 arguments[i] = 1065 (methods[a].getParameterTypes()[i]) 1066 .newInstance(); 1067 } 1068 } 1069 } 1070 } 1071 1072 try { 1073 Object[] compatibleArguments = 1075 getCompatibleArguments( 1076 methods[a].getParameterTypes(), 1077 arguments); 1078 if (compatibleArguments == null) 1080 break; 1081 1083 EJBObject obj = fieldPort.getEjbObject(); 1084 Trc.event( 1085 this, 1086 "Invoking EJB method ", 1087 methods[a], 1088 " object ", 1089 obj, 1090 " with arguments ", 1091 compatibleArguments); 1092 1093 result = methods[a].invoke(obj, compatibleArguments); 1094 1095 Trc.event(this, "Returned from EJB result is ", result); 1096 1097 invokedOK = true; 1098 fieldMethod = methods[a]; 1099 1100 String outParameterName = null; 1101 if (fieldOutParameterNames.length > 0) { 1102 output.setName(getOutputMessageName()); 1103 outParameterName = 1104 (String) fieldOutParameterNames[0]; 1105 if (outParameterName != null) { 1106 output.setObjectPart( 1107 outParameterName, 1108 getCompatibleReturn(fieldMethod, result)); 1109 } 1111 1112 if (arguments != null) { 1113 for (int i = 1; 1114 i < fieldOutParameterNames.length; 1115 i++) { 1116 outParameterName = 1117 fieldOutParameterNames[i]; 1118 if (outParameterName != null) { 1119 try { 1120 for (int r = 0; 1121 r < fieldInParameterNames.length; 1122 r++) { 1123 if (outParameterName 1124 .equals(fieldInParameterNames[r])) { 1125 output.setObjectPart( 1126 outParameterName, 1127 arguments[r]); 1128 break; 1129 } 1130 } 1131 } catch (WSIFException e) { 1132 Trc.ignoredException(e); 1133 } 1135 } 1136 } 1137 } 1138 } 1139 break; 1140 } catch (IllegalArgumentException ia) { 1141 Trc.ignoredException(ia); 1142 } 1144 } 1145 } 1146 if (!invokedOK) 1147 throw new WSIFException( 1148 "Failed to invoke method '" 1149 + fieldEJBOperationModel.getMethodName() 1150 + "'"); 1151 } catch (InvocationTargetException ex) { 1152 Trc.exception(ex); 1153 Throwable invocationFault = ex.getTargetException(); 1154 String className = invocationFault.getClass().getName(); 1155 Map faultMessageInfos = getFaultMessageInfos(); 1156 FaultMessageInfo faultMessageInfo = 1157 (FaultMessageInfo) faultMessageInfos.get(className); 1158 1159 if ((faultMessageInfo != null) 1160 && (faultMessageInfo.fieldPartName != null)) { 1161 Object faultPart = invocationFault; 1163 fault.setObjectPart(faultMessageInfo.fieldPartName, faultPart); 1165 fault.setName(faultMessageInfo.fieldMessageName); 1166 if (faultMessageInfo.fieldMessageName != null) { 1167 Fault wsdlFault = fieldBindingOperationModel.getOperation().getFault(faultMessageInfo.fieldMessageName); 1168 if (wsdlFault != null) { 1169 fault.setMessageDefinition(wsdlFault.getMessage()); 1170 } 1171 } 1172 operationSucceeded = false; 1173 } else { 1174 Class invocationFaultClass = invocationFault.getClass(); 1176 Class tempClass = null; 1177 Iterator it = faultMessageInfos.values().iterator(); 1178 boolean found = false; 1179 while (it.hasNext()) { 1180 faultMessageInfo = (FaultMessageInfo) it.next(); 1181 try { 1182 tempClass = 1183 Class.forName( 1184 faultMessageInfo.fieldFormatType, 1185 true, 1186 Thread.currentThread().getContextClassLoader()); 1187 if (tempClass.isAssignableFrom(invocationFaultClass)) { 1188 found = true; 1189 Object faultPart = invocationFault; 1190 fault.setObjectPart( 1192 faultMessageInfo.fieldPartName, 1193 faultPart); 1194 fault.setName(faultMessageInfo.fieldMessageName); 1195 if (faultMessageInfo.fieldMessageName != null) { 1196 Fault wsdlFault = fieldBindingOperationModel.getOperation().getFault(faultMessageInfo.fieldMessageName); 1197 if (wsdlFault != null) { 1198 fault.setMessageDefinition(wsdlFault.getMessage()); 1199 } 1200 } 1201 operationSucceeded = false; 1202 } 1203 } catch (Exception exc) { 1204 Trc.ignoredException(exc); 1205 } 1207 } 1208 if (!found) { 1209 MessageLogger.log( 1211 "WSIF.0005E", 1212 "EJB", 1213 fieldEJBOperationModel.getMethodName()); 1214 1215 throw new WSIFException("Operation failed!",invocationFault); 1217 } 1218 } 1219 1220 } catch (Exception ex) { 1221 Trc.exception(ex); 1222 1223 MessageLogger.log( 1225 "WSIF.0005E", 1226 "EJB", 1227 fieldEJBOperationModel.getMethodName()); 1228 1229 throw new WSIFException( 1230 this 1231 + " : Could not invoke '" 1232 + fieldEJBOperationModel.getMethodName() 1233 + "'", 1234 ex); 1235 } 1236 1237 Trc.exit(operationSucceeded); 1238 return operationSucceeded; 1239 } 1240 1241 public void executeInputOnlyOperation(WSIFMessage input) 1242 throws WSIFException { 1243 1244 Trc.entry(this, input); 1245 close(); 1246 1247 boolean foundInputParameter = false; 1248 1249 try { 1250 Object result = null; 1251 Method[] methods = null; 1252 Constructor constructor = null; 1253 1254 methods = getMethods(); 1255 if (methods.length <= 0) 1256 throw new WSIFException( 1257 "No method named '" 1258 + fieldEJBOperationModel.getMethodName() 1259 + "' found that match the parts specified"); 1260 1261 Object[] arguments = null; 1262 Object part = null; 1263 if ((fieldInParameterNames != null) 1264 && (fieldInParameterNames.length > 0)) { 1265 arguments = new Object[fieldInParameterNames.length]; 1266 for (int i = 0; i < fieldInParameterNames.length; i++) { 1267 try { 1268 part = input.getObjectPart(fieldInParameterNames[i]); 1269 arguments[i] = part; 1270 foundInputParameter = true; 1271 } catch (WSIFException e) { 1272 Trc.ignoredException(e); 1273 } 1274 1275 if (!foundInputParameter) { 1276 throw new WSIFException( 1277 this 1278 + " : Could not set input parameter '" 1279 + fieldInParameterNames[i] 1280 + "'"); 1281 } 1282 } 1283 } 1284 1285 boolean invokedOK = false; 1286 for (int a = 0; a < methods.length; a++) { 1287 if (fieldIsHomeInterface 1288 && methods[a].getName().equals( 1289 "create")) { 1291 try { 1292 Object[] compatibleArguments = 1294 getCompatibleArguments( 1295 methods[a].getParameterTypes(), 1296 arguments); 1297 if (compatibleArguments == null) 1299 break; 1300 1302 EJBHome home = fieldPort.getEjbHome(); 1303 Trc.event( 1304 this, 1305 "Invoking EJB method ", 1306 methods[a], 1307 " home ", 1308 home, 1309 " with arguments ", 1310 compatibleArguments); 1311 1312 result = methods[a].invoke(home, compatibleArguments); 1313 1314 Trc.event(this, "Returned from EJB result is ", result); 1315 1316 fieldPort.setEjbObject((EJBObject) result); 1317 fieldMethod = methods[a]; 1318 invokedOK = true; 1319 break; 1320 } catch (IllegalArgumentException ia) { 1321 Trc.ignoredException(ia); 1322 } 1324 } else { 1326 try { 1327 Object[] compatibleArguments = 1329 getCompatibleArguments( 1330 methods[a].getParameterTypes(), 1331 arguments); 1332 if (compatibleArguments == null) 1334 break; 1335 1337 EJBObject obj = fieldPort.getEjbObject(); 1338 Trc.event( 1339 this, 1340 "Invoking EJB method ", 1341 methods[a], 1342 " object ", 1343 obj, 1344 " with arguments ", 1345 compatibleArguments); 1346 1347 result = methods[a].invoke(obj, compatibleArguments); 1348 1349 Trc.event(this, "Returned from EJB result is ", result); 1350 1351 fieldMethod = methods[a]; 1352 invokedOK = true; 1353 break; 1354 } catch (IllegalArgumentException ia) { 1355 Trc.ignoredException(ia); 1356 } 1358 } 1359 } 1360 if (!invokedOK) 1361 throw new WSIFException( 1362 "Failed to invoke method '" 1363 + fieldEJBOperationModel.getMethodName() 1364 + "'"); 1365 } catch (InvocationTargetException ex) { 1366 Trc.exception(ex); 1367 1368 MessageLogger.log( 1370 "WSIF.0005E", 1371 "EJB", 1372 fieldEJBOperationModel.getMethodName()); 1373 1374 throw new WSIFException( 1375 this 1376 + " : Invocation of '" 1377 + fieldEJBOperationModel.getMethodName() 1378 + "' failed.", 1379 ex); 1380 } catch (Exception ex) { 1381 Trc.exception(ex); 1382 1383 MessageLogger.log( 1385 "WSIF.0005E", 1386 "EJB", 1387 fieldEJBOperationModel.getMethodName()); 1388 1389 throw new WSIFException( 1390 this 1391 + " : Could not invoke '" 1392 + fieldEJBOperationModel.getMethodName() 1393 + "'", 1394 ex); 1395 } 1396 1397 Trc.exit(); 1398 } 1399 1400 public String deep() { 1401 String buff = ""; 1402 try { 1403 buff = new String(super.toString() + ":\n"); 1404 buff += "portModel:" + Trc.brief(fieldPortModel); 1405 buff += " wsifPort_EJB:" + fieldPort; 1406 1407 buff += " bindingOperationModel:" 1408 + Trc.brief(fieldBindingOperationModel); 1409 buff += " EJBOperation:" 1410 + (fieldEJBOperationModel == null 1411 ? "null" 1412 : fieldEJBOperationModel.toString()); 1413 buff += " method:" 1414 + (fieldMethod == null ? "null" : fieldMethod.toString()); 1415 buff += Trc.brief("inParameterNames", fieldInParameterNames); 1416 buff += Trc.brief("outParameterNames", fieldOutParameterNames); 1417 1418 buff += " outputMessageName:" + fieldOutputMessageName; 1419 buff += " inputMessageName:" + fieldInputMessageName; 1420 1421 if (fieldFaultMessageInfos == null) { 1422 buff += " faultMessageInfos:null"; 1423 } else { 1424 Iterator it = fieldFaultMessageInfos.keySet().iterator(); 1425 int i = 0; 1426 while (it.hasNext()) { 1427 String key = (String) it.next(); 1428 buff += " faultMessageInfos[" 1429 + i 1430 + "]:" 1431 + key 1432 + " " 1433 + fieldFaultMessageInfos.get(key); 1434 i++; 1435 } 1436 } 1437 1438 buff += " isHomeInterface:" + fieldIsHomeInterface; 1439 1440 if (fieldTypeMaps == null) { 1441 buff += " typeMaps:null"; 1442 } else { 1443 Iterator it = fieldTypeMaps.keySet().iterator(); 1444 int i = 0; 1445 while (it.hasNext()) { 1446 QName key = (QName) it.next(); 1447 buff += " typeMaps[" 1448 + i 1449 + "]:" 1450 + key 1451 + " " 1452 + fieldTypeMaps.get(key); 1453 i++; 1454 } 1455 } 1456 1457 buff += " typeMapBuilt:" + fieldTypeMapBuilt; 1458 } catch (Exception e) { 1459 Trc.exceptionInTrace(e); 1460 } 1461 return buff; 1462 } 1463} | Popular Tags |