You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsif-dev@ws.apache.org by wh...@apache.org on 2003/03/13 17:22:03 UTC

cvs commit: xml-axis-wsif/java/src/org/apache/wsif/providers/java WSIFOperation_Java.java

whitlock    2003/03/13 08:22:03

  Modified:    java/test/mime Mime.wsdl MimeTest.java MimeImpl.java
               java/src/org/apache/wsif/providers/java
                        WSIFOperation_Java.java
  Log:
  16993: unreferenced attachments in the java provider
  
  Revision  Changes    Path
  1.15      +7 -2      xml-axis-wsif/java/test/mime/Mime.wsdl
  
  Index: Mime.wsdl
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/mime/Mime.wsdl,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- Mime.wsdl	12 Mar 2003 11:42:24 -0000	1.14
  +++ Mime.wsdl	13 Mar 2003 16:22:02 -0000	1.15
  @@ -161,8 +161,6 @@
         <output message="tns:StringMessage"/>
       </operation>
       <operation name="unref">
  -      <!--input message="tns:DataHandlerMessage"/-->
  -      <!--input message="tns:MultiMimePartsMessage"/-->
         <input message="tns:NullMessage"/>
         <output message="tns:StringMessage"/>
       </operation>
  @@ -1029,6 +1027,13 @@
         <java:operation
            methodName="stringToDataHandler"
            parameterOrder="buff"
  +         methodType="instance" />
  +      <input/>
  +      <output/>
  +    </operation>
  +    <operation name="unref">
  +      <java:operation
  +         methodName="unref"
            methodType="instance" />
         <input/>
         <output/>
  
  
  
  1.18      +4 -0      xml-axis-wsif/java/test/mime/MimeTest.java
  
  Index: MimeTest.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/mime/MimeTest.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- MimeTest.java	12 Mar 2003 11:42:24 -0000	1.17
  +++ MimeTest.java	13 Mar 2003 16:22:02 -0000	1.18
  @@ -468,6 +468,10 @@
           doit("JavaPort", RECEIVE_DH, "Mime.wsdl");
       }
   
  +    public void testSendUnrefAttachmentPartJava() {
  +        doit("JavaPort", SEND_UNREF_AP, "Mime.wsdl");
  +    }
  +    
       /* ***************************************************/
       /*                ERROR tests                        */
       /* ***************************************************/
  
  
  
  1.12      +20 -0     xml-axis-wsif/java/test/mime/MimeImpl.java
  
  Index: MimeImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-axis-wsif/java/test/mime/MimeImpl.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- MimeImpl.java	12 Mar 2003 11:42:24 -0000	1.11
  +++ MimeImpl.java	13 Mar 2003 16:22:02 -0000	1.12
  @@ -61,12 +61,15 @@
   import java.io.IOException;
   import java.io.InputStream;
   import java.lang.reflect.Method;
  +import java.util.Iterator;
   import java.util.List;
   import java.util.ListIterator;
   
   import javax.activation.DataHandler;
   import javax.activation.FileDataSource;
   
  +import org.apache.wsif.WSIFAttachmentPart;
  +
   /**
    * Mime service used by MimeTest 
    * @author Mark Whitlock
  @@ -266,6 +269,23 @@
               e.printStackTrace();
           }
   
  +        return s;
  +    }
  +    
  +    public String unref(List l) {
  +        if (l == null || l.isEmpty())
  +            return null;
  +
  +        String s = new String();
  +        Iterator it = l.iterator();
  +        while (it.hasNext()) {
  +            Object next = it.next();
  +            if (next instanceof WSIFAttachmentPart) {
  +                WSIFAttachmentPart wap = (WSIFAttachmentPart) next;
  +                DataHandler dh = wap.getDataHandler();
  +                s = s + dataHandlerToString(dh);
  +            }
  +        }
           return s;
       }
   
  
  
  
  1.32      +143 -39   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.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- WSIFOperation_Java.java	3 Feb 2003 17:35:44 -0000	1.31
  +++ WSIFOperation_Java.java	13 Mar 2003 16:22:02 -0000	1.32
  @@ -64,6 +64,7 @@
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
   import java.util.ArrayList;
  +import java.util.Arrays;
   import java.util.Enumeration;
   import java.util.HashMap;
   import java.util.Iterator;
  @@ -81,6 +82,7 @@
   import javax.wsdl.Port;
   import javax.xml.namespace.QName;
   
  +import org.apache.wsif.WSIFConstants;
   import org.apache.wsif.WSIFException;
   import org.apache.wsif.WSIFMessage;
   import org.apache.wsif.WSIFOperation;
  @@ -89,6 +91,7 @@
   import org.apache.wsif.logging.MessageLogger;
   import org.apache.wsif.logging.Trc;
   import org.apache.wsif.providers.ProviderUtils;
  +import org.apache.wsif.util.WSIFProperties;
   import org.apache.wsif.wsdl.extensions.java.JavaOperation;
   
   /**
  @@ -114,7 +117,9 @@
       protected String[] fieldOutParameterNames = null;
       protected Map fieldFaultMessageInfos = null;
       transient protected Method[] fieldMethods = null;
  +    transient protected Method[] fieldUnrefAttMethods = null;
       transient protected Constructor[] fieldConstructors = null;
  +    transient protected Constructor[] fieldUnrefAttConstructors = null;
       protected String fieldOutputMessageName = null;
       protected boolean fieldIsStatic = false;
       protected boolean fieldIsConstructor = false;
  @@ -145,6 +150,8 @@
           fieldBindingOperationModel = bindingOperationModel;
           fieldPort = port;
           fieldTypeMaps = typeMaps;
  +        
  +        // Find out all the methods on the Java class that is the backend service.
           Method[] allMethods = fieldPort.getServiceObjectMethods();
   
           try {
  @@ -163,13 +170,19 @@
           if (methodType != null) {
               if (methodType.equals("static")) {
                   fieldIsStatic = true;
  -                fieldMethods = getMethods(allMethods);
  +                fieldMethods = getMethods(allMethods, false);
  +                if (WSIFProperties.areUnreferencedAttachmentsSupported())
  +                    fieldUnrefAttMethods = getMethods(allMethods, true);
               } else if (methodType.equals("constructor")) {
                   fieldIsConstructor = true;
  -                fieldConstructors = getConstructors();
  +                fieldConstructors = getConstructors(false);
  +                if (WSIFProperties.areUnreferencedAttachmentsSupported())
  +                    fieldUnrefAttConstructors = getConstructors(true);
               } else {
                   // Assume instance method...
  -                fieldMethods = getMethods(allMethods);
  +                fieldMethods = getMethods(allMethods, false);
  +                if (WSIFProperties.areUnreferencedAttachmentsSupported())
  +                    fieldUnrefAttMethods = getMethods(allMethods, true);
               }
           }
   
  @@ -186,7 +199,9 @@
           String[] outPNames,
           Map faultMsgInfos,
           Method[] m,
  +        Method[] uam,
           Constructor[] c,
  +        Constructor[] uac,
           String outMName,
           boolean isSttc,
           boolean isCnstr,
  @@ -201,7 +216,9 @@
               outPNames,
               faultMsgInfos,
               m,
  +            uam,
               c,
  +            uac,
               outMName,
               new Boolean(isSttc),
               new Boolean(isCnstr),
  @@ -215,7 +232,9 @@
           fieldOutParameterNames = outPNames;
           fieldFaultMessageInfos = faultMsgInfos;
           fieldMethods = m;
  +        fieldUnrefAttMethods = uam;
           fieldConstructors = c;
  +        fieldUnrefAttConstructors = uac;
           fieldOutputMessageName = outMName;
           fieldIsStatic = isSttc;
           fieldIsConstructor = isCnstr;
  @@ -241,7 +260,9 @@
                   fieldOutParameterNames,
                   fieldFaultMessageInfos,
                   fieldMethods,
  +                fieldUnrefAttMethods,
                   fieldConstructors,
  +                fieldUnrefAttConstructors,
                   fieldOutputMessageName,
                   fieldIsStatic,
                   fieldIsConstructor,
  @@ -298,13 +319,19 @@
           return cls;
       }
   
  -    protected Constructor[] getConstructors() throws WSIFException {
  -    	Trc.entry(this);
  +    protected Constructor[] getConstructors(boolean lookForUnrefAtt)
  +        throws WSIFException {
  +        Trc.entry(this, lookForUnrefAtt);
           Constructor[] candidates;
           // Get the possible constructors with the argument classes we've found.
  -        Constructor[] constructors =
  -            fieldPort.getServiceObjectConstructors();
  +        Constructor[] constructors = fieldPort.getServiceObjectConstructors();
           Object[] args = getMethodArgumentClasses();
  +        if (lookForUnrefAtt) {
  +            ArrayList al = new ArrayList(Arrays.asList(args));
  +            al.add(List.class);
  +            args = al.toArray();
  +        }
  +
           Vector possibles = new Vector();
           for (int i = 0; i < constructors.length; i++) {
               Class[] params = constructors[i].getParameterTypes();
  @@ -412,13 +439,26 @@
           return fieldFaultMessageInfos;
       }
   
  -    protected Method[] getMethods(Method[] allMethods) throws WSIFException {
  -    	Trc.entry(this,allMethods);
  +    /**
  +     * Of all the methods on the Java class that is the backend service,
  +     * getMethods finds those that match this operation in the WSDL.
  +     * @param allMethods all the methods on the service's java class
  +     * @return the subset of allMethods that match this WSDL operation
  +     */
  +    protected Method[] getMethods(Method[] allMethods, boolean lookForUnrefAtt)
  +        throws WSIFException {
  +        Trc.entry(this, allMethods, new Boolean(lookForUnrefAtt));
           Method[] candidates;
           try {
               if (!fieldIsConstructor) {
                   // 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();
  +                }
  +                
                   Object retClass = getMethodReturnClass();
                   Vector possibles = new Vector();
                   for (int i = 0; i < allMethods.length; i++) {
  @@ -979,14 +1019,47 @@
                       }
                   }
               }
  +            
  +            Method[] methods = fieldMethods;
  +            Constructor[] constructors = fieldConstructors;
  +            if (WSIFProperties.areUnreferencedAttachmentsSupported()) {
  +                Object unrefAttPart = null;
  +                try {
  +                    unrefAttPart =
  +                        input.getObjectPart(
  +                            WSIFConstants.UNREFERENCED_ATTACHMENT_PART_NAME);
  +                } catch (WSIFException we) {
  +                    Trc.ignoredException(we);
  +                }
  +
  +                if (unrefAttPart != null) {
  +                    Object[] arguments1 = null;
  +                    if (arguments == null)
  +                        arguments1 = new Object[1];
  +                    else {
  +                        arguments1 = new Object[arguments.length + 1];
  +
  +                        System.arraycopy(
  +                            arguments,
  +                            0,
  +                            arguments1,
  +                            0,
  +                            arguments.length);
  +                    }
  +                    arguments1[arguments1.length - 1] = unrefAttPart;
  +                    arguments = arguments1;
  +                    methods = fieldUnrefAttMethods;
  +                    constructors = fieldUnrefAttConstructors;
  +                }
  +            }
   
               boolean invokedOK = false;
               if (fieldIsConstructor) {
  -                for (int a = 0; a < fieldConstructors.length; a++) {
  +                for (int a = 0; a < constructors.length; a++) {
                       try {
                           // Get a set of arguments which are compatible with the ctor
                           Object[] compatibleArguments =
  -                            getCompatibleArguments(fieldConstructors[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;
  @@ -995,12 +1068,12 @@
                           Trc.event(
                               this,
                               "Invoking constructor ",
  -                            fieldConstructors[a],
  +                            constructors[a],
                               " with arguments ",
                               compatibleArguments);
   
                           result =
  -                            fieldConstructors[a].newInstance(
  +                            constructors[a].newInstance(
                                   compatibleArguments);
   
                           Trc.event(
  @@ -1021,7 +1094,7 @@
                   // Side effect: Initialize port's object reference
               } else {
                   if (fieldIsStatic) {
  -                    for (int a = 0; a < fieldMethods.length; a++) {
  +                    for (int a = 0; a < methods.length; a++) {
                           if (usedOutputParam) {
                               for (int i = 0; i < fieldInParameterNames.length; i++) {
                                   String outParameterName = null;
  @@ -1029,7 +1102,7 @@
                                       outParameterName = fieldOutParameterNames[j];
                                       if ((outParameterName != null)
                                           && (outParameterName.equals(fieldInParameterNames[i]))) {
  -                                        arguments[i] = (fieldMethods[a].getParameterTypes()[i]).newInstance();
  +                                        arguments[i] = (methods[a].getParameterTypes()[i]).newInstance();
                                       }
                                   }
                               }
  @@ -1037,7 +1110,7 @@
                           try {
                               // Get a set of arguments which are compatible with the method
                               Object[] compatibleArguments =
  -                                getCompatibleArguments(fieldMethods[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;
  @@ -1046,12 +1119,12 @@
                               Trc.event(
                                   this,
                                   "Invoking method ",
  -                                fieldMethods[a],
  +                                methods[a],
                                   " with arguments ",
                                   compatibleArguments);
   
                               result =
  -                                fieldMethods[a].invoke(
  +                                methods[a].invoke(
                                       null,
                                       compatibleArguments);
   
  @@ -1060,7 +1133,7 @@
                                   "Returned from method, result is ",
                                   result);
   
  -                            chosenMethod = fieldMethods[a];
  +                            chosenMethod = methods[a];
                               invokedOK = true;
                               break;
                           } catch (IllegalArgumentException ia) {
  @@ -1072,7 +1145,7 @@
                           throw new WSIFException(
                               "Failed to invoke method '" + fieldJavaOperationModel.getMethodName() + "'");
                   } else {
  -                    for (int a = 0; a < fieldMethods.length; a++) {
  +                    for (int a = 0; a < methods.length; a++) {
                           if (usedOutputParam) {
                               for (int i = 0; i < fieldInParameterNames.length; i++) {
                                   String outParameterName = null;
  @@ -1080,7 +1153,7 @@
                                       outParameterName = fieldOutParameterNames[j];
                                       if ((outParameterName != null)
                                           && (outParameterName.equals(fieldInParameterNames[i]))) {
  -                                        arguments[i] = (fieldMethods[a].getParameterTypes()[i]).newInstance();
  +                                        arguments[i] = (methods[a].getParameterTypes()[i]).newInstance();
                                       }
                                   }
                               }
  @@ -1088,7 +1161,7 @@
                           try {
                               // Get a set of arguments which are compatible with the method
                               Object[] compatibleArguments =
  -                                getCompatibleArguments(fieldMethods[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;
  @@ -1100,12 +1173,12 @@
                                   "Invoking object ",
                                   objRef,
                                   " method ",
  -                                fieldMethods[a],
  +                                methods[a],
                                   " with arguments ",
                                   compatibleArguments);
   
                               result =
  -                                fieldMethods[a].invoke(
  +                                methods[a].invoke(
                                       objRef,
                                       compatibleArguments);
   
  @@ -1114,7 +1187,7 @@
                                   "Returned from method, result is ",
                                   result);
   
  -                            chosenMethod = fieldMethods[a];
  +                            chosenMethod = methods[a];
                               invokedOK = true;
                               break;
                           } catch (IllegalArgumentException ia) {
  @@ -1268,14 +1341,41 @@
                   }
               }
   
  +            Method[] methods = fieldMethods;
  +            Constructor[] constructors = fieldConstructors;
  +            if (WSIFProperties.areUnreferencedAttachmentsSupported()) {
  +                Object unrefAttPart = null;
  +                try {
  +                    unrefAttPart =
  +                        input.getObjectPart(
  +                            WSIFConstants.UNREFERENCED_ATTACHMENT_PART_NAME);
  +                } catch (WSIFException we) {
  +                    Trc.ignoredException(we);
  +                }
  +
  +                if (unrefAttPart != null) {
  +                    Object[] arguments1 = new Object[arguments.length + 1];
  +                    System.arraycopy(
  +                        arguments,
  +                        0,
  +                        arguments1,
  +                        0,
  +                        arguments.length);
  +                    arguments1[arguments.length] = unrefAttPart;
  +                    arguments = arguments1;
  +                    methods = fieldUnrefAttMethods;
  +                    constructors = fieldUnrefAttConstructors;
  +                }
  +            }
  +
               boolean invokedOK = false;
   
               if (fieldIsConstructor) {
  -                for (int a = 0; a < fieldConstructors.length; a++) {
  +                for (int a = 0; a < constructors.length; a++) {
                       try {
                           // Get a set of arguments which are compatible with the ctor
                           Object[] compatibleArguments =
  -                            getCompatibleArguments(fieldConstructors[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;
  @@ -1284,12 +1384,12 @@
                           Trc.event(
                               this,
                               "Invoking constructor ",
  -                            fieldConstructors[a],
  +                            constructors[a],
                               " with arguments ",
                               compatibleArguments);
   
                           result =
  -                            fieldConstructors[a].newInstance(
  +                            constructors[a].newInstance(
                                   compatibleArguments);
   
                           Trc.event(
  @@ -1309,11 +1409,11 @@
                       throw new WSIFException("Failed to call constructor for object in Java operation");
               } else {
                   if (fieldIsStatic) {
  -                    for (int a = 0; a < fieldMethods.length; a++) {
  +                    for (int a = 0; a < methods.length; a++) {
                           try {
                               // Get a set of arguments which are compatible with the method
                               Object[] compatibleArguments =
  -                                getCompatibleArguments(fieldMethods[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;
  @@ -1322,12 +1422,12 @@
                               Trc.event(
                                   this,
                                   "Invoking method ",
  -                                fieldMethods[a],
  +                                methods[a],
                                   " with arguments ",
                                   compatibleArguments);
   
                               result =
  -                                fieldMethods[a].invoke(
  +                                methods[a].invoke(
                                       null,
                                       compatibleArguments);
   
  @@ -1347,11 +1447,11 @@
                           throw new WSIFException(
                               "Failed to invoke method '" + fieldJavaOperationModel.getMethodName() + "'");
                   } else {
  -                    for (int a = 0; a < fieldMethods.length; a++) {
  +                    for (int a = 0; a < methods.length; a++) {
                           try {
                               // Get a set of arguments which are compatible with the method
                               Object[] compatibleArguments =
  -                                getCompatibleArguments(fieldMethods[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;
  @@ -1363,12 +1463,12 @@
                                   "Invoking object ",
                                   objRef,
                                   " method ",
  -                                fieldMethods[a],
  +                                methods[a],
                                   " with arguments ",
                                   compatibleArguments);
   
                               result =
  -                                fieldMethods[a].invoke(
  +                                methods[a].invoke(
                                       objRef,
                                       compatibleArguments);
   
  @@ -1495,9 +1595,13 @@
           // Re-establish all the Method information
           Method[] allMethods = fieldPort.getServiceObjectMethods();
           if (fieldIsConstructor) {
  -        	fieldConstructors = getConstructors();
  +        	fieldConstructors = getConstructors(false);
  +            if (WSIFProperties.areUnreferencedAttachmentsSupported())
  +                fieldUnrefAttConstructors = getConstructors(true);
           } else {
  -        	fieldMethods = getMethods(allMethods);
  +            fieldMethods = getMethods(allMethods, false);
  +            if (WSIFProperties.areUnreferencedAttachmentsSupported())
  +                fieldUnrefAttMethods = getMethods(allMethods, true);
           }
       }       
   }