You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by du...@apache.org on 2006/01/18 18:16:17 UTC

svn commit: r370192 - in /webservices/axis/trunk/java/src/org/apache/axis/providers/java: JavaProvider.java MsgProvider.java

Author: dug
Date: Wed Jan 18 09:16:12 2006
New Revision: 370192

URL: http://svn.apache.org/viewcvs?rev=370192&view=rev
Log:
1 - add the ability for a service to programmatically tell the
    axis engine that the operation is a one-way - meaning it should
    not try to send back a soap env unless someone else in the processing
    told it to create an env
2 - in a dynamic environment, one where the service being invoked changes
    during the processing of a handler, the msgProvider will not always
    find the appropriate method to call. I'm adding additional logic that
    does some additional searching for the method.  This should not hurt
    anything - it should just prevent an incorrect exception from being
    thrown in some more complex situations.

Modified:
    webservices/axis/trunk/java/src/org/apache/axis/providers/java/JavaProvider.java
    webservices/axis/trunk/java/src/org/apache/axis/providers/java/MsgProvider.java

Modified: webservices/axis/trunk/java/src/org/apache/axis/providers/java/JavaProvider.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/src/org/apache/axis/providers/java/JavaProvider.java?rev=370192&r1=370191&r2=370192&view=diff
==============================================================================
--- webservices/axis/trunk/java/src/org/apache/axis/providers/java/JavaProvider.java (original)
+++ webservices/axis/trunk/java/src/org/apache/axis/providers/java/JavaProvider.java Wed Jan 18 09:16:12 2006
@@ -295,16 +295,20 @@
             // be nice if in the future there was a way to detect an error
             // when trying to install a response message in a MessageContext
             // associated with a one-way operation....
-            OperationDesc operation = msgContext.getOperation();
+            OperationDesc operation  = msgContext.getOperation();
+            boolean       createdEnv = false ;
+            Message       resMsg     = null ;
+
             if (operation != null &&
                     OperationType.ONE_WAY.equals(operation.getMep())) {
                 msgContext.setResponseMessage(null);
             } else {
-                Message        resMsg  = msgContext.getResponseMessage();
+                resMsg = msgContext.getResponseMessage();
 
                 // If we didn't have a response message, make sure we set one up
                 // with the appropriate versions of SOAP and Schema
                 if (resMsg == null) {
+                    createdEnv = true ;
                     resEnv  = new SOAPEnvelope(msgContext.getSOAPConstants(),
                                                msgContext.getSchemaVersion());
                     
@@ -321,6 +325,22 @@
             SOAPEnvelope   reqEnv  = reqMsg.getSOAPEnvelope();
 
             processMessage(msgContext, reqEnv, resEnv, serviceObject);
+
+            // If the service sets this "IsOneWay" flag then they don't want
+            // a response sent back at all.  However, we can only erase
+            // any env that might be there if we created it just before we
+            // called the service.  If someone else in the processing 
+            // created the env then we can't just blindly erase it - the 
+            // best we can do is erase the Body element.
+            // Ideally, I'd like the service to return back the desired
+            // env instead but I think that would break too many people's
+            // current impls.
+            if ( msgContext.getIsOneWay() ) {
+              if ( createdEnv )
+                msgContext.setResponseMessage( null );
+              else
+                resMsg.getSOAPEnvelope().clearBody();
+            }
         } catch( SAXException exp ) {
             entLog.debug( Messages.getMessage("toAxisFault00"), exp);
             Exception real = exp.getException();

Modified: webservices/axis/trunk/java/src/org/apache/axis/providers/java/MsgProvider.java
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/java/src/org/apache/axis/providers/java/MsgProvider.java?rev=370192&r1=370191&r2=370192&view=diff
==============================================================================
--- webservices/axis/trunk/java/src/org/apache/axis/providers/java/MsgProvider.java (original)
+++ webservices/axis/trunk/java/src/org/apache/axis/providers/java/MsgProvider.java Wed Jan 18 09:16:12 2006
@@ -22,6 +22,7 @@
 import org.apache.axis.description.OperationDesc;
 import org.apache.axis.description.ServiceDesc;
 import org.apache.axis.i18n.Messages;
+import org.apache.axis.Handler;
 import org.apache.axis.message.SOAPBodyElement;
 import org.apache.axis.message.SOAPEnvelope;
 import org.apache.axis.message.MessageElement;
@@ -29,6 +30,7 @@
 import org.w3c.dom.Element;
 import javax.xml.namespace.QName;
 import java.lang.reflect.Method;
+import java.util.StringTokenizer;
 import java.util.Vector;
 
 /**
@@ -67,12 +69,69 @@
                                 Object obj)
         throws Exception
     {
-        OperationDesc operation = msgContext.getOperation();
+        OperationDesc operation  = msgContext.getOperation();
+        Method        method     = null ;
+        int           methodType = 0 ;
+
         SOAPService service = msgContext.getService();
         ServiceDesc serviceDesc = service.getServiceDescription();
         QName opQName = null;
         
         if (operation == null) {
+          Class   cls      = obj.getClass();
+          String  opName   = null ;
+          if ( reqEnv.getFirstBody() != null )
+            opName = reqEnv.getFirstBody().getQName().getLocalPart();
+
+          Handler h = msgContext.getService();
+          String  tmp     = (String) h.getOption( "allowedMethods" );
+
+          if ( "*".equals(tmp) )
+            ; // opName = tmp ;
+          else if ( tmp.indexOf(" ") < 0 && tmp.indexOf(",") < 0 )
+            opName = tmp ;
+          else {
+            boolean gotOne = false ;
+            StringTokenizer st = new StringTokenizer(tmp," ,");
+
+            while (st.hasMoreTokens()) {
+              String nt = st.nextToken();
+              if ( nt.equals(opName) ) {
+                gotOne = true ;
+                break ;
+              }
+            }
+            if ( !gotOne )
+              throw new AxisFault(Messages.getMessage("noOperationForQName",
+                                                      reqEnv.getFirstBody().
+                                                      getQName().toString()));
+          }
+          if ( method == null ) { try {
+            method = cls.getDeclaredMethod(opName,
+                                   new Class[] {SOAPEnvelope.class,
+                                                SOAPEnvelope.class});
+            methodType = OperationDesc.MSG_METHOD_SOAPENVELOPE ;
+          } catch(NoSuchMethodException exp) {} }
+
+          if ( method == null ) { try {
+            method = cls.getDeclaredMethod(opName,
+                                   new Class[] {SOAPBodyElement[].class});
+            methodType = OperationDesc.MSG_METHOD_BODYARRAY ;
+          } catch(NoSuchMethodException exp) {} }
+
+          if ( method == null ) { try {
+            method = cls.getDeclaredMethod(opName,
+                                   new Class[] {Element[].class});
+            methodType = OperationDesc.MSG_METHOD_ELEMENTARRAY ;
+          } catch(NoSuchMethodException exp) {} }
+
+          if ( method == null ) { try {
+            method = cls.getDeclaredMethod(opName,
+                                   new Class[] {Document.class});
+            methodType = OperationDesc.MSG_METHOD_DOCUMENT ;
+          } catch(NoSuchMethodException exp) {} }
+
+          if ( method == null ) {
             Vector bodyElements = reqEnv.getBodyElements();
             if(bodyElements.size() > 0) {
                 MessageElement element = (MessageElement) bodyElements.get(0);
@@ -82,16 +141,17 @@
                     operation = serviceDesc.getOperationByElementQName(opQName);
                 }
             }
+            if (operation == null)
+              throw new AxisFault(Messages.getMessage("noOperationForQName",
+                              opQName == null ? "null" : opQName.toString()));
+            method = operation.getMethod();
+            methodType = operation.getMessageOperationStyle();
+          }
         }
-
-        if (operation == null) {
-            throw new AxisFault(Messages.getMessage("noOperationForQName",
-                                opQName == null ? "null" : opQName.toString()));
+        else {
+          method = operation.getMethod();
+          methodType = operation.getMessageOperationStyle();
         }
-        
-        Method method = operation.getMethod();
-
-        int methodType = operation.getMessageOperationStyle();
 
         if (methodType != OperationDesc.MSG_METHOD_SOAPENVELOPE) {
             // dig out just the body, and pass it on