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 ba...@apache.org on 2007/08/24 20:03:14 UTC
svn commit: r569469 - in /webservices/axis2/trunk/java/modules/kernel:
src/org/apache/axis2/description/AxisService.java
src/org/apache/axis2/dispatchers/ActionBasedOperationDispatcher.java
test/org/apache/axis2/engine/SOAPActionBasedDispatcherTest.java
Author: barrettj
Date: Fri Aug 24 11:03:07 2007
New Revision: 569469
URL: http://svn.apache.org/viewvc?rev=569469&view=rev
Log:
Prevent routing to the wrong operation if an alias (specifically a SOAPAction) is not unique to a single operation.
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/ActionBasedOperationDispatcher.java
webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/SOAPActionBasedDispatcherTest.java
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java?rev=569469&r1=569468&r2=569469&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/description/AxisService.java Fri Aug 24 11:03:07 2007
@@ -119,9 +119,17 @@
// Maps httpLocations to corresponding operations. Used to dispatch rest messages.
private HashMap httpLocationDispatcherMap = null;
- /**
- * Map from String(action URI) -> AxisOperation
- */
+ // A map of (String alias, AxisOperation operation). The aliases might include: SOAPAction,
+ // WS-Addressing action, the operation name, the AxisInputMessage name. See:
+ // - invalidOperationsAliases
+ // - mapActionToOperatoin()
+ // - getOperationByAction()
+ // REVIEW: This really should be seperate maps for the different types of aliases so they don't
+ // conflict with each other. For example, so that an identical operation name and soap action
+ // on different operatoins don't cause a collision; the following can't be routed because
+ // "foo" is not unique across different operations:
+ // operation 1: action = foo, name = bar
+ // operation 2: action = bar, name = foo
private HashMap operationsAliasesMap = null;
// Collection of aliases that are invalid for this service because they are duplicated across
@@ -691,9 +699,10 @@
}
/**
- * Maps an action (a SOAPAction or WSA action) to the given operation. This is used by
- * dispatching (both SOAPAction- and WSAddressing- based dispatching) to figure out which
- * operation a given message is for. Some notes on restrictions of "action"
+ * Maps an alias (such as a SOAPAction, WSA action, or an operation name) to the given
+ * AxisOperation. This is used by dispatching (both SOAPAction- and WSAddressing-
+ * based dispatching) to figure out which operation a given message is for.
+ * Some notes on restrictions of "action"
* - A null or empty action will be ignored
* - An action that is a duplicate and references an idential operation is allowed
* - An acton that is a duplicate and references a different operation is NOT allowed. In this
@@ -701,7 +710,11 @@
* the ability to route based on this action. This is necessary to prevent mis-directing
* incoming message to the wrong operation based on SOAPAction.
*
- * @param action the action key
+ * Note that an alias could be a SOAPAction, WS-Addressing Action, the operation name, or some
+ * other alias.
+ * @see #getOperationByAction(String)
+ *
+ * @param action the alias key
* @param axisOperation the operation to map to
*/
public void mapActionToOperation(String action, AxisOperation axisOperation) {
@@ -1278,9 +1291,11 @@
/**
- * Returns the AxisOperation which has been mapped to the given action.
+ * Returns the AxisOperation which has been mapped to the given alias.
*
- * @param action the action key
+ * @see #mapActionToOperation(String, AxisOperation)
+ *
+ * @param action the alias key
* @return Returns the corresponding AxisOperation or null if it isn't found.
*/
public AxisOperation getOperationByAction(String action) {
@@ -1293,7 +1308,8 @@
* this Service. If more than one Endpoint exists, one of them will be
* picked. If more than one Operation is found with the given SOAP Action;
* null will be returned. If no particular Operation is found with the given
- * SOAP Action; null will be returned.
+ * SOAP Action; null will be returned. If the action is in the list of invaliad aliases,
+ * which means it did not uniquely identify an operation, a null will be returned.
*
* @param soapAction SOAP Action defined for the particular Operation
* @return Returns an AxisOperation if a unique Operation can be found with the given
@@ -1301,6 +1317,11 @@
*/
public AxisOperation getOperationBySOAPAction(String soapAction) {
if ((soapAction == null) || soapAction.length() == 0) {
+ return null;
+ }
+ // If the action maps to an alais that is not unique, then it can't be used to map to
+ // an operation.
+ if (invalidOperationsAliases.contains(soapAction)) {
return null;
}
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/ActionBasedOperationDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/ActionBasedOperationDispatcher.java?rev=569469&r1=569468&r2=569469&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/ActionBasedOperationDispatcher.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/dispatchers/ActionBasedOperationDispatcher.java Fri Aug 24 11:03:07 2007
@@ -44,6 +44,12 @@
action);
}
if (action != null) {
+ // REVIEW: Should we FIRST try to find an operation that explicitly mapped this
+ // SOAPAction as an alias by calling:
+ // AxisOperation op = service.getOperationByAction(action);
+ // And THEN, if we didn't find an explicit mapping of this action, see if there's an
+ // operation that has the same name as the action, and route to that by calling:
+ // service.getOperationBySOAPAction(action);
AxisOperation op = service.getOperationBySOAPAction(action);
if (op == null) {
op = service.getOperationByAction(action);
Modified: webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/SOAPActionBasedDispatcherTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/SOAPActionBasedDispatcherTest.java?rev=569469&r1=569468&r2=569469&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/SOAPActionBasedDispatcherTest.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/test/org/apache/axis2/engine/SOAPActionBasedDispatcherTest.java Fri Aug 24 11:03:07 2007
@@ -133,8 +133,8 @@
// doesn't somehow get it added back into the valid alias map
AxisOperation operation4 = new InOnlyAxisOperation(new QName("operation4"));
// Note that the SOAPAction is intentionally duplicated with operation 2 above.
- operation3.setSoapAction("urn:org.apache.axis2.dispatchers.test:operation2");
- as.addOperation(operation3);
+ operation4.setSoapAction("urn:org.apache.axis2.dispatchers.test:operation2");
+ as.addOperation(operation4);
messageContext = new MessageContext();
messageContext.setAxisService(as);
@@ -153,6 +153,83 @@
}
-
-
+
+ public void testActionVsOpName() throws Exception {
+ // Should route based on action before trying to route based on operation name
+ // - method operation1, action = operation2
+ // - method operation2, action = operation1
+ // Incoming action should route to:
+ // - action = operation2, route to operation1
+ // - action = operation1, route to operation2
+ MessageContext messageContext = new MessageContext();
+ AxisService as = new AxisService("Service1");
+ messageContext.setAxisService(as);
+
+ AxisOperation operation1 = new InOnlyAxisOperation(new QName("operation1"));
+ operation1.setSoapAction("operation2");
+
+ AxisOperation operation2 = new InOnlyAxisOperation(new QName("operation2"));
+ operation2.setSoapAction("operation1");
+
+ as.addOperation(operation1);
+ as.addOperation(operation2);
+
+ messageContext.setSoapAction("operation2");
+
+ SOAPActionBasedDispatcher soapActionDispatcher = new SOAPActionBasedDispatcher();
+ soapActionDispatcher.invoke(messageContext);
+ // Since Axis2 uses a single alias table for SOAPActions and operation names (and
+ // WS-Addressing actions and input message names), having an action with the same name
+ // as a different operation will cause that alias to be unusable for routing.
+// assertEquals(operation1, messageContext.getAxisOperation());
+ assertNull(messageContext.getAxisOperation());
+
+ // Make sure the other action works also
+ messageContext = new MessageContext();
+ messageContext.setAxisService(as);
+ messageContext.setSoapAction("operation1");
+ soapActionDispatcher = new SOAPActionBasedDispatcher();
+ soapActionDispatcher.invoke(messageContext);
+// assertEquals(operation2, messageContext.getAxisOperation());
+ assertNull(messageContext.getAxisOperation());
+
+ }
+
+ public void testInvalidActionVsOpName() throws Exception {
+ // Shouldn't route on action because it is invalid (used > 1 time) even though it matches
+ // an operation name
+ // - method operation1, action = operation2
+ // - method operation2, action = operation2
+ // Incoming action should route to:
+ // - action = operation2, null
+ // - action = operation1, route to operation1 (based on method name match to action)
+ //
+ MessageContext messageContext = new MessageContext();
+ AxisService as = new AxisService("Service1");
+ messageContext.setAxisService(as);
+
+ AxisOperation operation1 = new InOnlyAxisOperation(new QName("operation1"));
+ operation1.setSoapAction("operation2");
+
+ AxisOperation operation2 = new InOnlyAxisOperation(new QName("operation2"));
+ operation2.setSoapAction("operation2");
+
+ as.addOperation(operation1);
+ as.addOperation(operation2);
+
+ messageContext.setSoapAction("operation2");
+
+ SOAPActionBasedDispatcher soapActionDispatcher = new SOAPActionBasedDispatcher();
+ soapActionDispatcher.invoke(messageContext);
+ // Verify that we can't route on the SOAPAction because it has been specified > 1 time
+ assertNull(messageContext.getAxisOperation());
+
+ // Now verify that a SOAPAction that happens to map to an operation name can still be routed
+ messageContext = new MessageContext();
+ messageContext.setAxisService(as);
+ messageContext.setSoapAction("operation1");
+ soapActionDispatcher = new SOAPActionBasedDispatcher();
+ soapActionDispatcher.invoke(messageContext);
+ assertEquals(operation1, messageContext.getAxisOperation());
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org