owenb       2003/03/14 03:48:08

  Modified:    java/src/org/apache/wsif/providers/java
                        WSIFOperation_Java.java
               java/src/org/apache/wsif/providers/ejb
                        WSIFOperation_EJB.java
               java     build.xml
               java/test/util WSIFTestRunner.java
  Added:       java/test/multiout/ejb TestHome.java Test.java TestBean.java
               java/test/multiout MultiOutTest.java MultiOut.wsdl
               java/test/multiout/java Test_Java.java
  Log:
  Add support for returning multiple output parts from Java and EJB services.
  The Java/EJB method must return a java.util.Map containing the names and
  values of all output parts.
  
  Revision  Changes    Path
  1.33      +292 -99   
xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFOperation_Java.java
  
  Index: WSIFOperation_Java.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/java/WSIFOperation_Java.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- WSIFOperation_Java.java   13 Mar 2003 16:22:02 -0000      1.32
  +++ WSIFOperation_Java.java   14 Mar 2003 11:48:07 -0000      1.33
  @@ -76,6 +76,7 @@
   import javax.wsdl.BindingOperation;
   import javax.wsdl.BindingOutput;
   import javax.wsdl.Fault;
  +import javax.wsdl.Message;
   import javax.wsdl.Operation;
   import javax.wsdl.OperationType;
   import javax.wsdl.Part;
  @@ -124,6 +125,8 @@
       protected boolean fieldIsStatic = false;
       protected boolean fieldIsConstructor = false;
       protected Map fieldTypeMaps = null;
  +    protected boolean multiOutParts = false;
  +    transient private Object returnClass = null;
   
       private class FaultMessageInfo {
           String fieldMessageName;
  @@ -205,7 +208,9 @@
           String outMName,
           boolean isSttc,
           boolean isCnstr,
  -        Map tMap) {
  +        Map tMap,
  +        boolean mulOP,
  +        Object retCl) {
           Trc.entry(
               this,
               p,
  @@ -223,6 +228,7 @@
               new Boolean(isSttc),
               new Boolean(isCnstr),
               tMap);
  +        Trc.event(this, "mulOP was " + mulOP + ", retCl was " + retCl);            
   
           fieldPortModel = p;
           fieldPort = pj;
  @@ -239,6 +245,8 @@
           fieldIsStatic = isSttc;
           fieldIsConstructor = isCnstr;
           fieldTypeMaps = tMap;
  +        multiOutParts = mulOP;
  +        returnClass = retCl;
   
           if (Trc.ON)
               Trc.exit(deep());
  @@ -266,10 +274,12 @@
                   fieldOutputMessageName,
                   fieldIsStatic,
                   fieldIsConstructor,
  -                fieldTypeMaps);
  -
  +                fieldTypeMaps,
  +                multiOutParts,
  +                returnClass);
  +        
           woj.wsdlOperation = wsdlOperation;
  -
  +        
           Trc.exit(woj);
           return woj;
       }
  @@ -454,11 +464,11 @@
                   // Get the possible methods with the argument classes we've found.
                   Object[] args = getMethodArgumentClasses();
                   if (lookForUnrefAtt) {
  -                     ArrayList al = new ArrayList(Arrays.asList(args));
  -                     al.add(List.class);
  -                     args = al.toArray();
  +                    ArrayList al = new ArrayList(Arrays.asList(args));
  +                    al.add(List.class);
  +                    args = al.toArray();
                   }
  -                
  +
                   Object retClass = getMethodReturnClass();
                   Vector possibles = new Vector();
                   for (int i = 0; i < allMethods.length; i++) {
  @@ -470,26 +480,42 @@
                       if (params.length != args.length)
                           continue;
                       Class retType = allMethods[i].getReturnType();
  -                    if (retClass != null && retClass instanceof Vector) {
  -                        Vector vec = (Vector) retClass;
  +
  +                    boolean tryAMap = false;
  +                    if (multiOutParts) {
  +                        Class mapClass = java.util.Map.class;
                           boolean found = false;
  -                        for (int p = 0; p < vec.size(); p++) {
  -                            Class cl = (Class) vec.get(p);
  -                            if (cl.getName().equals(retType.getName())) {
  -                                found = true;
  -                                break;
  -                            } else if (cl.isAssignableFrom(retType)) {
  -                                     found = true;
  -                                     break;
  -                            }
  +                        if (mapClass.getName().equals(retType.getName())) {
  +                            tryAMap = true;
  +                        } else if (mapClass.isAssignableFrom(retType)) {
  +                            tryAMap = true;
                           }
  -                        if (!found)
  -                            continue;
  -                    } else {
  -                        if (retType != null && retClass != null) {
  -                            if (!(((Class) 
retClass).getName().equals(retType.getName()))
  -                             && !(((Class) retClass).isAssignableFrom(retType)))
  +                    }
  +                    if (!tryAMap) {
  +                        if (retClass != null && retClass instanceof Vector) {
  +                            Vector vec = (Vector) retClass;
  +                            boolean found = false;
  +                            for (int p = 0; p < vec.size(); p++) {
  +                                Class cl = (Class) vec.get(p);
  +                                if (cl.getName().equals(retType.getName())) {
  +                                    found = true;
  +                                    break;
  +                                } else if (cl.isAssignableFrom(retType)) {
  +                                    found = true;
  +                                    break;
  +                                }
  +                            }
  +                            if (!found)
                                   continue;
  +                        } else {
  +                            if (retType != null && retClass != null) {
  +                                if (!(((Class) retClass)
  +                                    .getName()
  +                                    .equals(retType.getName()))
  +                                    && !(((Class) retClass)
  +                                        .isAssignableFrom(retType)))
  +                                    continue;
  +                            }
                           }
                       }
   
  @@ -505,8 +531,8 @@
                                       found = true;
                                       break;
                                   } else if (params[j].isAssignableFrom(cl)) {
  -                                     found = true;
  -                                     break;
  +                                    found = true;
  +                                    break;
                                   }
                               }
                               if (!found) {
  @@ -514,8 +540,10 @@
                                   break;
                               }
                           } else {
  -                            if (!(((Class) 
obj).getName().equals(params[j].getName()))
  -                             && !(params[j].isAssignableFrom((Class) obj))) {
  +                            if (!(((Class) obj)
  +                                .getName()
  +                                .equals(params[j].getName()))
  +                                && !(params[j].isAssignableFrom((Class) obj))) {
                                   match = false;
                                   break;
                               }
  @@ -536,10 +564,10 @@
               Trc.exit(m);
               return m;
           } catch (WSIFException ex) {
  -             Trc.exception(ex);
  +            Trc.exception(ex);
               throw ex;
           } catch (Exception ex) {
  -             Trc.exception(ex);
  +            Trc.exception(ex);
               throw new WSIFException(
                   "Error while resolving meta information of method "
                       + fieldJavaOperationModel.getMethodName()
  @@ -583,6 +611,20 @@
           Object methodReturnClass = null;
           try {
               String returnPartString = fieldJavaOperationModel.getReturnPart();
  +            List parameterOrder = fieldJavaOperationModel.getParameterOrder();
  +
  +                     // Service with multiple output parts
  +            if (fieldOutParameterNames.length > 1) {
  +             multiOutParts = true;
  +                for (int p = 0; p < fieldOutParameterNames.length; p++) {
  +                    String pName = fieldOutParameterNames[p];
  +                    if (pName != null
  +                        && parameterOrder.contains(pName)) {
  +                        multiOutParts = false;
  +                    }
  +                }
  +            }
  +            
               if (returnPartString != null) {
                   // A returnPart has been specified so check that this method has 
the correct
                   // return type
  @@ -631,6 +673,7 @@
                       + " : The meta information is not consistent.",
                   ex);
           }
  +        returnClass = methodReturnClass;
           Trc.exit(methodReturnClass);
           return methodReturnClass;
       }
  @@ -980,37 +1023,39 @@
               // Need to get the stuff here because this also initializes 
fieldInParameterNames
               if (fieldIsConstructor) {
                   if (fieldConstructors.length <= 0)
  -                    throw new WSIFException(
  -                        "No constructor found that match the parts specified");
  +                    throw new WSIFException("No constructor found that match the 
parts specified");
               } else {
                   if (fieldMethods.length <= 0)
  -                    throw new WSIFException("No method named '"
  -                        + fieldJavaOperationModel.getMethodName()
  -                        + "' found that match the parts specified");
  +                    throw new WSIFException(
  +                        "No method named '"
  +                            + fieldJavaOperationModel.getMethodName()
  +                            + "' found that match the parts specified");
               }
   
               Object[] arguments = null;
               Object part = null;
  -            if ((fieldInParameterNames != null) && (fieldInParameterNames.length > 
0)) {
  +            if ((fieldInParameterNames != null)
  +                && (fieldInParameterNames.length > 0)) {
                   arguments = new Object[fieldInParameterNames.length];
                   for (int i = 0; i < fieldInParameterNames.length; i++) {
                       try {
                           part = input.getObjectPart(fieldInParameterNames[i]);
                           arguments[i] = part;
                       } catch (WSIFException e) {
  -                             Trc.exception(e);
  +                        Trc.exception(e);
                           arguments[i] = null;
  -                        // Check for inout parts
                           if (fieldOutParameterNames.length > 0) {
                               String outParameterName = null;
  -                            for (int j = 0; j < fieldOutParameterNames.length; j++) 
{
  -                                outParameterName =
  -                                    fieldOutParameterNames[j];
  +                            for (int j = 0;
  +                                j < fieldOutParameterNames.length;
  +                                j++) {
  +                                outParameterName = fieldOutParameterNames[j];
                                   if ((outParameterName != null)
                                       && (outParameterName
                                           .equals(fieldInParameterNames[i]))) {
                                       arguments[i] =
  -                                        (fieldMethods[0].getParameterTypes()[i])
  +                                        (fieldMethods[0]
  +                                            .getParameterTypes()[i])
                                               .newInstance();
                                       usedOutputParam = true;
                                   }
  @@ -1019,7 +1064,7 @@
                       }
                   }
               }
  -            
  +
               Method[] methods = fieldMethods;
               Constructor[] constructors = fieldConstructors;
               if (WSIFProperties.areUnreferencedAttachmentsSupported()) {
  @@ -1059,7 +1104,9 @@
                       try {
                           // Get a set of arguments which are compatible with the ctor
                           Object[] compatibleArguments =
  -                            
getCompatibleArguments(constructors[a].getParameterTypes(), arguments);
  +                            getCompatibleArguments(
  +                                constructors[a].getParameterTypes(),
  +                                arguments);
                           // If we didn't get any arguments then the parts aren't 
compatible with the ctor
                           if (compatibleArguments == null)
                               break;
  @@ -1073,19 +1120,18 @@
                               compatibleArguments);
   
                           result =
  -                            constructors[a].newInstance(
  -                                compatibleArguments);
  +                            constructors[a].newInstance(compatibleArguments);
   
                           Trc.event(
                               this,
                               "Returned from constructor, result is ",
                               result);
  -                        
  +
                           fieldPort.setObjectReference(result);
                           invokedOK = true;
                           break;
                       } catch (IllegalArgumentException ia) {
  -                     Trc.ignoredException(ia);
  +                        Trc.ignoredException(ia);
                           // Ignore and try next constructor
                       }
                   }
  @@ -1096,13 +1142,21 @@
                   if (fieldIsStatic) {
                       for (int a = 0; a < methods.length; a++) {
                           if (usedOutputParam) {
  -                            for (int i = 0; i < fieldInParameterNames.length; i++) {
  +                            for (int i = 0;
  +                                i < fieldInParameterNames.length;
  +                                i++) {
                                   String outParameterName = null;
  -                                for (int j = 0; j < fieldOutParameterNames.length; 
j++) {
  -                                    outParameterName = fieldOutParameterNames[j];
  +                                for (int j = 0;
  +                                    j < fieldOutParameterNames.length;
  +                                    j++) {
  +                                    outParameterName =
  +                                        fieldOutParameterNames[j];
                                       if ((outParameterName != null)
  -                                        && 
(outParameterName.equals(fieldInParameterNames[i]))) {
  -                                        arguments[i] = 
(methods[a].getParameterTypes()[i]).newInstance();
  +                                        && (outParameterName
  +                                            .equals(fieldInParameterNames[i]))) {
  +                                        arguments[i] =
  +                                            (methods[a].getParameterTypes()[i])
  +                                                .newInstance();
                                       }
                                   }
                               }
  @@ -1110,7 +1164,9 @@
                           try {
                               // Get a set of arguments which are compatible with the 
method
                               Object[] compatibleArguments =
  -                                
getCompatibleArguments(methods[a].getParameterTypes(), arguments);
  +                                getCompatibleArguments(
  +                                    methods[a].getParameterTypes(),
  +                                    arguments);
                               // If we didn't get any arguments then the parts aren't 
compatible with the method
                               if (compatibleArguments == null)
                                   break;
  @@ -1124,9 +1180,7 @@
                                   compatibleArguments);
   
                               result =
  -                                methods[a].invoke(
  -                                    null,
  -                                    compatibleArguments);
  +                                methods[a].invoke(null, compatibleArguments);
   
                               Trc.event(
                                   this,
  @@ -1137,23 +1191,33 @@
                               invokedOK = true;
                               break;
                           } catch (IllegalArgumentException ia) {
  -                             Trc.ignoredException(ia);
  +                            Trc.ignoredException(ia);
                               // Ignore and try next method
                           }
                       }
                       if (!invokedOK)
                           throw new WSIFException(
  -                            "Failed to invoke method '" + 
fieldJavaOperationModel.getMethodName() + "'");
  +                            "Failed to invoke method '"
  +                                + fieldJavaOperationModel.getMethodName()
  +                                + "'");
                   } else {
                       for (int a = 0; a < methods.length; a++) {
                           if (usedOutputParam) {
  -                            for (int i = 0; i < fieldInParameterNames.length; i++) {
  +                            for (int i = 0;
  +                                i < fieldInParameterNames.length;
  +                                i++) {
                                   String outParameterName = null;
  -                                for (int j = 0; j < fieldOutParameterNames.length; 
j++) {
  -                                    outParameterName = fieldOutParameterNames[j];
  +                                for (int j = 0;
  +                                    j < fieldOutParameterNames.length;
  +                                    j++) {
  +                                    outParameterName =
  +                                        fieldOutParameterNames[j];
                                       if ((outParameterName != null)
  -                                        && 
(outParameterName.equals(fieldInParameterNames[i]))) {
  -                                        arguments[i] = 
(methods[a].getParameterTypes()[i]).newInstance();
  +                                        && (outParameterName
  +                                            .equals(fieldInParameterNames[i]))) {
  +                                        arguments[i] =
  +                                            (methods[a].getParameterTypes()[i])
  +                                                .newInstance();
                                       }
                                   }
                               }
  @@ -1161,7 +1225,9 @@
                           try {
                               // Get a set of arguments which are compatible with the 
method
                               Object[] compatibleArguments =
  -                                
getCompatibleArguments(methods[a].getParameterTypes(), arguments);
  +                                getCompatibleArguments(
  +                                    methods[a].getParameterTypes(),
  +                                    arguments);
                               // If we didn't get any arguments then the parts aren't 
compatible with the method
                               if (compatibleArguments == null)
                                   break;
  @@ -1178,9 +1244,7 @@
                                   compatibleArguments);
   
                               result =
  -                                methods[a].invoke(
  -                                    objRef,
  -                                    compatibleArguments);
  +                                methods[a].invoke(objRef, compatibleArguments);
   
                               Trc.event(
                                   this,
  @@ -1191,48 +1255,166 @@
                               invokedOK = true;
                               break;
                           } catch (IllegalArgumentException ia) {
  -                             Trc.ignoredException(ia);
  +                            Trc.ignoredException(ia);
                               // Ignore and try next method
                           }
                       }
                       if (!invokedOK)
                           throw new WSIFException(
  -                            "Failed to invoke method '" + 
fieldJavaOperationModel.getMethodName() + "'");
  +                            "Failed to invoke method '"
  +                                + fieldJavaOperationModel.getMethodName()
  +                                + "'");
                   }
   
  +                // Deal with the output message
                   String outParameterName = null;
  -                if (fieldOutParameterNames != null && fieldOutParameterNames.length 
> 0) {
  +                if (fieldOutParameterNames.length == 1) {
  +                    // Only one output part - it must be the object returned by the
  +                    // Java service invocation
                       output.setName(getOutputMessageName());
                       outParameterName = (String) fieldOutParameterNames[0];
                       if (outParameterName != null) {
                           output.setObjectPart(
                               outParameterName,
                               getCompatibleReturn(chosenMethod, result));
  -                        // Should we use the class of the method signature instead 
here ?
                       }
  +                } else if (fieldOutParameterNames.length > 1) {
  +                    if (multiOutParts) {
  +                        if (Map
  +                            .class
  +                            .isAssignableFrom(chosenMethod.getReturnType())) {
  +                            // Method should have returned a Map
  +                            if (!(result instanceof Map)) {
  +                                throw new WSIFException(
  +                                    "Operation "
  +                                        + getOperation().getName()
  +                                        + " defined as returning multiple parts "
  +                                        + "and the Java method did not return an 
instance of java.util.Map");
  +                            }
  +
  +                            Map returnedMap = (Map) result;
  +                            output.setName(getOutputMessageName());
   
  -                    if (arguments != null) {
  -                        for (int i = 1; i < fieldOutParameterNames.length; i++) {
  -                            outParameterName = fieldOutParameterNames[i];
  +                            // Get multiple output parts from the map
  +
  +                            for (int p = 0;
  +                                p < fieldOutParameterNames.length;
  +                                p++) {
  +                                String pName = fieldOutParameterNames[p];
  +                                if (returnedMap.containsKey(pName)) {
  +                                    Object outPart = returnedMap.get(pName);
  +                                    Message outputMessage =
  +                                        getOperation().getOutput().getMessage();
  +                                    Part wsdlPart =
  +                                        outputMessage.getPart(pName);
  +                                    QName partType = wsdlPart.getTypeName();
  +                                    if (partType == null) {
  +                                        partType = wsdlPart.getElementName();
  +                                    }
  +                                    Object typeObj =
  +                                        this.fieldTypeMaps.get(partType);
  +                                    if (typeObj != null) {
  +                                        Class c =
  +                                            getClassForName((String) typeObj);
  +                                        Object outPart2 =
  +                                            getCompatibleObject(c, outPart);
  +                                        output.setObjectPart(pName, outPart2);
  +                                    } else {
  +                                        throw new WSIFException(
  +                                            "The Class of part "
  +                                                + pName
  +                                                + ", returned by the Java method 
for"
  +                                                + " operation "
  +                                                + getOperation().getName()
  +                                                + " does not match the Class 
defined in the format "
  +                                                + "binding for that part.");
  +                                    }
  +                                } else {
  +                                    // A part was not found in the map. Check the 
return
  +                                    // class. If it's a Map, just add the map to 
the output
  +                                    // message. If not, throw an exception to say 
the map
  +                                    // does not contain the missing part.
  +                                    if (returnClass != null
  +                                        && returnClass instanceof Class
  +                                        && Map.class.isAssignableFrom(
  +                                            (Class) returnClass)) {
  +                                        Map m = new HashMap();
  +                                        m.put(
  +                                            fieldOutParameterNames[0],
  +                                            result);
  +                                        output.setParts(m);
  +                                        break;
  +                                    }
  +                                    throw new WSIFException(
  +                                        "Operation "
  +                                            + getOperation().getName()
  +                                            + " defined as returning multiple 
parts."
  +                                            + " Part "
  +                                            + pName
  +                                            + " was missing from the Map returned 
by "
  +                                            + "the Java service class");
  +                                }
  +                            }
  +
  +                        } else {
  +                            // Backwards compatiblity - method returns just the 
output part specified
  +                            // by returnPart
  +                            output.setName(getOutputMessageName());
  +                            outParameterName =
  +                                (String) fieldOutParameterNames[0];
                               if (outParameterName != null) {
  -                             try {
  -                                     for (int r = 0; r < 
fieldInParameterNames.length; r++) {
  -                                             if 
(outParameterName.equals(fieldInParameterNames[r])) {
  -                                                     
output.setObjectPart(outParameterName, arguments[r]);
  -                                                     break;
  -                                             }
  -                                     }
  -                             } catch (WSIFException e) {
  -                                     Trc.ignoredException(e);
  -                                     //ignore
  -                             }
  +                                output.setObjectPart(
  +                                    outParameterName,
  +                                    getCompatibleReturn(chosenMethod, result));
  +                            }
  +                        }
  +                    } else {
  +                        // Method has returned one object and updated the 
references of
  +                        // other objects passed into the method.             
  +                        output.setName(getOutputMessageName());
  +
  +                        // Add the returned object to the output message
  +                        outParameterName = (String) fieldOutParameterNames[0];
  +                        if (outParameterName != null) {
  +                            output.setObjectPart(
  +                                outParameterName,
  +                                getCompatibleReturn(chosenMethod, result));
  +                        }
  +
  +                        // Deal with objects whose reference has been updated by 
the Java
  +                        // service method. Parts for such objects will appear in 
the WSDL
  +                        // output message and their names will also be included in 
the 
  +                        // parameterOrder attribute
  +                        if (arguments != null) {
  +                            for (int i = 1;
  +                                i < fieldOutParameterNames.length;
  +                                i++) {
  +                                outParameterName = fieldOutParameterNames[i];
  +                                if (outParameterName != null) {
  +                                    try {
  +                                        for (int r = 0;
  +                                            r < fieldInParameterNames.length;
  +                                            r++) {
  +                                            if (outParameterName
  +                                                .equals(fieldInParameterNames[r])) {
  +                                                output.setObjectPart(
  +                                                    outParameterName,
  +                                                    arguments[r]);
  +                                                break;
  +                                            }
  +                                        }
  +                                    } catch (WSIFException e) {
  +                                        Trc.ignoredException(e);
  +                                        //ignore
  +                                    }
  +                                }
                               }
                           }
                       }
                   }
               }
           } catch (InvocationTargetException ex) {
  -             Trc.exception(ex);
  +            Trc.exception(ex);
               Throwable invocationFault = ex.getTargetException();
               String className = invocationFault.getClass().getName();
               Map faultMessageInfos = getFaultMessageInfos();
  @@ -1245,10 +1427,12 @@
                   fault.setObjectPart(faultMessageInfo.fieldPartName, faultPart);
                   fault.setName(faultMessageInfo.fieldMessageName);
                   if (faultMessageInfo.fieldMessageName != null) {
  -                     Fault wsdlFault = 
fieldBindingOperationModel.getOperation().getFault(faultMessageInfo.fieldMessageName);
  -                     if (wsdlFault != null) {
  -                         fault.setMessageDefinition(wsdlFault.getMessage());
  -                     }
  +                    Fault wsdlFault =
  +                        fieldBindingOperationModel.getOperation().getFault(
  +                            faultMessageInfo.fieldMessageName);
  +                    if (wsdlFault != null) {
  +                        fault.setMessageDefinition(wsdlFault.getMessage());
  +                    }
                   }
                   operationSucceeded = false;
               } else {
  @@ -1269,22 +1453,31 @@
                               found = true;
                               Object faultPart = invocationFault;
                               // Should we use the class of the method signature here 
?
  -                            fault.setObjectPart(faultMessageInfo.fieldPartName, 
faultPart);
  +                            fault.setObjectPart(
  +                                faultMessageInfo.fieldPartName,
  +                                faultPart);
                               fault.setName(faultMessageInfo.fieldMessageName);
                               if (faultMessageInfo.fieldMessageName != null) {
  -                             Fault wsdlFault = 
fieldBindingOperationModel.getOperation().getFault(faultMessageInfo.fieldMessageName);
  -                                 if (wsdlFault != null) {
  -                                     
fault.setMessageDefinition(wsdlFault.getMessage());
  -                                 }
  +                                Fault wsdlFault =
  +                                    fieldBindingOperationModel
  +                                        .getOperation()
  +                                        .getFault(
  +                                        faultMessageInfo.fieldMessageName);
  +                                if (wsdlFault != null) {
  +                                    fault.setMessageDefinition(
  +                                        wsdlFault.getMessage());
  +                                }
                               }
                               operationSucceeded = false;
                           }
                       } catch (Exception exc) { // Nothing to do - just try the next 
one...
  -                     Trc.ignoredException(exc);
  +                        Trc.ignoredException(exc);
                       }
                   }
                   if (!found) {
  -                    throw new WSIFException("Operation failed!", invocationFault);
  +                    throw new WSIFException(
  +                        "Operation failed!",
  +                        invocationFault);
                   }
               }
           } catch (Exception ex) {
  
  
  
  1.2       +70 -0     xml-axis-wsif/java/test/multiout/ejb/TestHome.java
  
  
  
  
  1.2       +68 -0     xml-axis-wsif/java/test/multiout/ejb/Test.java
  
  
  
  
  1.2       +127 -0    xml-axis-wsif/java/test/multiout/ejb/TestBean.java
  
  
  
  
  1.29      +159 -104  
xml-axis-wsif/java/src/org/apache/wsif/providers/ejb/WSIFOperation_EJB.java
  
  Index: WSIFOperation_EJB.java
  ===================================================================
  RCS file: 
/home/cvs/xml-axis-wsif/java/src/org/apache/wsif/providers/ejb/WSIFOperation_EJB.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- WSIFOperation_EJB.java    4 Feb 2003 13:54:12 -0000       1.28
  +++ WSIFOperation_EJB.java    14 Mar 2003 11:48:07 -0000      1.29
  @@ -127,6 +127,7 @@
       protected boolean fieldIsHomeInterface = false;
       protected Map fieldTypeMaps = new HashMap();
       protected boolean fieldTypeMapBuilt = false;
  +    transient protected Object returnClass = null;
   
       private class FaultMessageInfo {
           String fieldMessageName;
  @@ -355,26 +356,39 @@
                   if (params.length != args.length)
                       continue;
                   Class retType = fieldAllMethods[i].getReturnType();
  -                if (retClass != null && retClass instanceof Vector) {
  -                    Vector vec = (Vector) retClass;
  +
  +                boolean tryAMap = false;
  +                if (fieldOutParameterNames.length > 1) {
  +                    Class mapClass = java.util.Map.class;
                       boolean found = false;
  -                    for (int p = 0; p < vec.size(); p++) {
  -                        Class cl = (Class) vec.get(p);
  -                        if (cl.getName().equals(retType.getName())) {
  -                            found = true;
  -                            break;
  -                        } else if (cl.isAssignableFrom(retType)) {
  -                            found = true;
  -                            break;
  -                        }
  +                    if (mapClass.getName().equals(retType.getName())) {
  +                        tryAMap = true;
  +                    } else if (mapClass.isAssignableFrom(retType)) {
  +                        tryAMap = true;
                       }
  -                    if (!found)
  -                        continue;
  -                } else {
  -                    if (retType != null && retClass != null) {
  -                        if (!(((Class) 
retClass).getName().equals(retType.getName()))
  -                             && !(((Class) retClass).isAssignableFrom(retType)))
  +                }
  +                if (!tryAMap) {
  +                    if (retClass != null && retClass instanceof Vector) {
  +                        Vector vec = (Vector) retClass;
  +                        boolean found = false;
  +                        for (int p = 0; p < vec.size(); p++) {
  +                            Class cl = (Class) vec.get(p);
  +                            if (cl.getName().equals(retType.getName())) {
  +                                found = true;
  +                                break;
  +                            } else if (cl.isAssignableFrom(retType)) {
  +                                found = true;
  +                                break;
  +                            }
  +                        }
  +                        if (!found)
                               continue;
  +                    } else {
  +                        if (retType != null && retClass != null) {
  +                            if (!(((Class) 
retClass).getName().equals(retType.getName()))
  +                                && !(((Class) retClass).isAssignableFrom(retType)))
  +                                continue;
  +                        }
                       }
                   }
   
  @@ -399,8 +413,10 @@
                               break;
                           }
                       } else {
  -                        if (!(((Class) obj).getName().equals(params[j].getName()))
  -                             && !(params[j].isAssignableFrom((Class) obj))) {
  +                        if (!(((Class) obj)
  +                            .getName()
  +                            .equals(params[j].getName()))
  +                            && !(params[j].isAssignableFrom((Class) obj))) {
                               match = false;
                               break;
                           }
  @@ -417,10 +433,10 @@
               Trc.exit(candidates);
               return candidates;
           } catch (WSIFException ex) {
  -             Trc.exception(ex);
  +            Trc.exception(ex);
               throw ex;
           } catch (Exception ex) {
  -             Trc.exception(ex);
  +            Trc.exception(ex);
               throw new WSIFException(
                   "Error while resolving meta information of method "
                       + fieldEJBOperationModel.getMethodName()
  @@ -600,6 +616,7 @@
                   ex);
           }
   
  +        returnClass = methodReturnClass;
           Trc.exit(methodReturnClass);
           return methodReturnClass;
       }
  @@ -958,7 +975,6 @@
           close();
   
           boolean operationSucceeded = true;
  -        boolean foundInputParameter = false;
           boolean usedOutputParam = false;
   
           try {
  @@ -982,33 +998,9 @@
                       try {
                           part = input.getObjectPart(fieldInParameterNames[i]);
                           arguments[i] = part;
  -                        foundInputParameter = true;
                       } catch (WSIFException e) {
  -                     Trc.exception(e);
  -                        if (fieldOutParameterNames.length > 0) {
  -                            String outParameterName = null;
  -                            for (int j = 0;
  -                                j < fieldOutParameterNames.length;
  -                                j++) {
  -                                outParameterName = fieldOutParameterNames[j];
  -                                if ((outParameterName != null)
  -                                    && (outParameterName
  -                                        .equals(fieldInParameterNames[i]))) {
  -                                    arguments[i] =
  -                                        (methods[0].getParameterTypes()[i])
  -                                            .newInstance();
  -                                    foundInputParameter = true;
  -                                    usedOutputParam = true;
  -                                }
  -                            }
  -                        }
  -                    }
  -                    if (!foundInputParameter) {
  -                        throw new WSIFException(
  -                            this
  -                                + " : Could not set input parameter '"
  -                                + fieldInParameterNames[i]
  -                                + "'");
  +                        // if we can't find the part, a default value will be used 
later
  +                        Trc.ignoredException(e);
                       }
                   }
               }
  @@ -1020,7 +1012,8 @@
                           "create")) // only handle create methods -> entity EJB 
finders not supported
                       {
                       try {
  -                        // Get a set of arguments which are compatible with the ctor
  +                        // Get a set of arguments which are compatible with the 
ctor. Creates default
  +                        // values for missing parts
                           Object[] compatibleArguments =
                               getCompatibleArguments(
                                   methods[a].getParameterTypes(),
  @@ -1054,26 +1047,9 @@
                       }
                       // Side effect: Initialize port's object reference 
                   } else {
  -                    if (usedOutputParam) {
  -                        for (int i = 0;
  -                            i < fieldInParameterNames.length;
  -                            i++) {
  -                            String outParameterName = null;
  -                            for (int j = 0; j < fieldOutParameterNames.length; j++) 
{
  -                                outParameterName = fieldOutParameterNames[j];
  -                                if ((outParameterName != null)
  -                                    && (outParameterName
  -                                        .equals(fieldInParameterNames[i]))) {
  -                                    arguments[i] =
  -                                        (methods[a].getParameterTypes()[i])
  -                                            .newInstance();
  -                                }
  -                            }
  -                        }
  -                    }
  -
                       try {
  -                        // Get a set of arguments which are compatible with the ctor
  +                        // Get a set of arguments which are compatible with the 
method. Creates default
  +                        // values for missing parts
                           Object[] compatibleArguments =
                               getCompatibleArguments(
                                   methods[a].getParameterTypes(),
  @@ -1082,7 +1058,7 @@
                           if (compatibleArguments == null)
                               break;
                           // Parts are compatible so invoke the ctor with the 
compatible set
  -                        
  +
                           EJBObject obj = fieldPort.getEjbObject();
                           Trc.event(
                               this,
  @@ -1101,7 +1077,7 @@
                           fieldMethod = methods[a];
   
                           String outParameterName = null;
  -                        if (fieldOutParameterNames.length > 0) {
  +                        if (fieldOutParameterNames.length == 1) {
                               output.setName(getOutputMessageName());
                               outParameterName =
                                   (String) fieldOutParameterNames[0];
  @@ -1111,37 +1087,107 @@
                                       getCompatibleReturn(fieldMethod, result));
                                   // Should we use the class of the method signature 
instead here ?
                               }
  +                        } else if (fieldOutParameterNames.length > 1) {
  +                            if (Map
  +                                .class
  +                                .isAssignableFrom(
  +                                    fieldMethod.getReturnType())) {
  +
  +                                // Method should have returned a Map
  +                                if (!(result instanceof Map)) {
  +                                    throw new WSIFException(
  +                                        "Operation "
  +                                            + getOperation().getName()
  +                                            + " defined as returning multiple parts 
"
  +                                            + "and the EJB method did not return an 
instance of java.util.Map");
  +                                }
  +
  +                                Map returnedMap = (Map) result;
  +                                output.setName(getOutputMessageName());
   
  -                            if (arguments != null) {
  -                                for (int i = 1;
  -                                    i < fieldOutParameterNames.length;
  -                                    i++) {
  -                                    outParameterName =
  -                                        fieldOutParameterNames[i];
  -                                    if (outParameterName != null) {
  -                                        try {
  -                                            for (int r = 0;
  -                                                r < fieldInParameterNames.length;
  -                                                r++) {
  -                                                if (outParameterName
  -                                                    
.equals(fieldInParameterNames[r])) {
  -                                                    output.setObjectPart(
  -                                                        outParameterName,
  -                                                        arguments[r]);
  -                                                    break;
  -                                                }
  -                                            }
  -                                        } catch (WSIFException e) {
  -                                             Trc.ignoredException(e);
  -                                            //ignore
  +                                // Get multiple output parts from the map
  +                                for (int p = 0;
  +                                    p < fieldOutParameterNames.length;
  +                                    p++) {
  +                                    String pName = fieldOutParameterNames[p];
  +                                    if (returnedMap.containsKey(pName)) {
  +                                        Object outPart = returnedMap.get(pName);
  +                                        Message outputMessage =
  +                                            getOperation()
  +                                                .getOutput()
  +                                                .getMessage();
  +                                        Part wsdlPart =
  +                                            outputMessage.getPart(pName);
  +                                        QName partType = wsdlPart.getTypeName();
  +                                        if (partType == null) {
  +                                            partType =
  +                                                wsdlPart.getElementName();
  +                                        }
  +                                        Object typeObj =
  +                                            this.fieldTypeMaps.get(partType);
  +                                        if (typeObj != null) {
  +                                            Class c =
  +                                                getClassForName(
  +                                                    (String) typeObj);
  +                                            Object outPart2 =
  +                                                getCompatibleObject(c, outPart);
  +                                            output.setObjectPart(
  +                                                pName,
  +                                                outPart2);
  +                                        } else {
  +                                            throw new WSIFException(
  +                                                "The Class of part "
  +                                                    + pName
  +                                                    + ", returned by the EJB method 
for"
  +                                                    + " operation "
  +                                                    + getOperation().getName()
  +                                                    + " does not match the Class 
defined in the format "
  +                                                    + "binding for that part.");
                                           }
  +                                    } else {
  +                                        // A part was not found in the map. Check 
the return
  +                                        // class. If it's a Map, just add the map 
to the output
  +                                        // message. If not, throw an exception to 
say the map
  +                                        // does not contain the missing part.
  +                                        if (returnClass != null
  +                                            && returnClass instanceof Class
  +                                            && Map.class.isAssignableFrom(
  +                                                (Class) returnClass)) {
  +                                            Map m = new HashMap();
  +                                            m.put(
  +                                                fieldOutParameterNames[0],
  +                                                result);
  +                                            output.setParts(m);
  +                                            break;
  +                                        }
  +                                        throw new WSIFException(
  +                                            "Operation "
  +                                                + getOperation().getName()
  +                                                + " defined as returning multiple 
parts."
  +                                                + " Part "
  +                                                + pName
  +                                                + " was missing from the Map 
returned by "
  +                                                + "the EJB service");
                                       }
                                   }
  +                            } else {
  +                                // Backwards compatiblity - method returns just the 
output part specified
  +                                // by returnPart
  +                                output.setName(getOutputMessageName());
  +                                outParameterName =
  +                                    (String) fieldOutParameterNames[0];
  +                                if (outParameterName != null) {
  +                                    output.setObjectPart(
  +                                        outParameterName,
  +                                        getCompatibleReturn(
  +                                            fieldMethod,
  +                                            result));
  +                                }
                               }
                           }
                           break;
                       } catch (IllegalArgumentException ia) {
  -                             Trc.ignoredException(ia);
  +                        Trc.ignoredException(ia);
                           // Ingore and try next method
                       }
                   }
  @@ -1152,7 +1198,7 @@
                           + fieldEJBOperationModel.getMethodName()
                           + "'");
           } catch (InvocationTargetException ex) {
  -             Trc.exception(ex);
  +            Trc.exception(ex);
               Throwable invocationFault = ex.getTargetException();
               String className = invocationFault.getClass().getName();
               Map faultMessageInfos = getFaultMessageInfos();
  @@ -1167,10 +1213,12 @@
                   fault.setObjectPart(faultMessageInfo.fieldPartName, faultPart);
                   fault.setName(faultMessageInfo.fieldMessageName);
                   if (faultMessageInfo.fieldMessageName != null) {
  -                     Fault wsdlFault = 
fieldBindingOperationModel.getOperation().getFault(faultMessageInfo.fieldMessageName);
  -                     if (wsdlFault != null) {
  -                         fault.setMessageDefinition(wsdlFault.getMessage());
  -                     }
  +                    Fault wsdlFault =
  +                        fieldBindingOperationModel.getOperation().getFault(
  +                            faultMessageInfo.fieldMessageName);
  +                    if (wsdlFault != null) {
  +                        fault.setMessageDefinition(wsdlFault.getMessage());
  +                    }
                   }
                   operationSucceeded = false;
               } else {
  @@ -1196,15 +1244,20 @@
                                   faultPart);
                               fault.setName(faultMessageInfo.fieldMessageName);
                               if (faultMessageInfo.fieldMessageName != null) {
  -                             Fault wsdlFault = 
fieldBindingOperationModel.getOperation().getFault(faultMessageInfo.fieldMessageName);
  -                                 if (wsdlFault != null) {
  -                                     
fault.setMessageDefinition(wsdlFault.getMessage());
  -                                 }
  +                                Fault wsdlFault =
  +                                    fieldBindingOperationModel
  +                                        .getOperation()
  +                                        .getFault(
  +                                        faultMessageInfo.fieldMessageName);
  +                                if (wsdlFault != null) {
  +                                    fault.setMessageDefinition(
  +                                        wsdlFault.getMessage());
  +                                }
                               }
                               operationSucceeded = false;
                           }
                       } catch (Exception exc) {
  -                     Trc.ignoredException(exc);
  +                        Trc.ignoredException(exc);
                           // Nothing to do - just try the next one...
                       }
                   }
  @@ -1216,7 +1269,9 @@
                           fieldEJBOperationModel.getMethodName());
   
                       // End message
  -                    throw new WSIFException("Operation failed!",invocationFault);
  +                    throw new WSIFException(
  +                        "Operation failed!",
  +                        invocationFault);
                   }
               }
   
  
  
  
  1.2       +327 -0    xml-axis-wsif/java/test/multiout/MultiOutTest.java
  
  
  
  
  1.2       +128 -0    xml-axis-wsif/java/test/multiout/MultiOut.wsdl
  
  
  
  
  1.2       +84 -0     xml-axis-wsif/java/test/multiout/java/Test_Java.java
  
  
  
  
  1.35      +1 -0      xml-axis-wsif/java/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/build.xml,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- build.xml 3 Feb 2003 21:30:49 -0000       1.34
  +++ build.xml 14 Mar 2003 11:48:08 -0000      1.35
  @@ -206,6 +206,7 @@
     <patternset id="test.source.files">
       <include name="**/*.java"/>
       <exclude name="shop/**/*.java" unless="ejb.present"/>
  +    <exclude name="multiout/**/*.java" unless="ejb.present"/>
     </patternset>
   
     <patternset id="j2c.source.files">
  
  
  
  1.33      +7 -7      xml-axis-wsif/java/test/util/WSIFTestRunner.java
  
  Index: WSIFTestRunner.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/util/WSIFTestRunner.java,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- WSIFTestRunner.java       7 Mar 2003 11:45:29 -0000       1.32
  +++ WSIFTestRunner.java       14 Mar 2003 11:48:08 -0000      1.33
  @@ -116,7 +116,8 @@
           suite.addTest(new TestSuite(ProvidersInitialisationTest.class));
   
           //suite.addTest(new TestSuite(ShoppingCartTest.class));
  -        addIfAvaliable(suite, "ShoppingCartTest");
  +        addIfAvaliable(suite, "shop.ShoppingCartTest");
  +        addIfAvaliable(suite, "multiout.MultiOutTest");
           suite.addTest(new TestSuite(FeaturesTest.class));
           suite.addTest(new TestSuite(AsyncTests.class));
           suite.addTest(new TestSuite(HeadersTest.class));
  @@ -155,11 +156,10 @@
       }
   
       public static void addIfAvaliable(TestSuite suite, String className) {
  -     try {
  -         Class klass = Class.forName("ShoppingCartTest");
  -         suite.addTest(new TestSuite(klass));
  -     } catch(Exception ex) {
  -     }
  -
  +         try {
  +             Class klass = Class.forName(className);
  +             suite.addTest(new TestSuite(klass));
  +         } catch(Exception ex) {
  +         }
       }
   }
  
  
  

Reply via email to