Author: ruwan
Date: Thu Jan 27 08:05:22 2011
New Revision: 1064018
URL: http://svn.apache.org/viewvc?rev=1064018&view=rev
Log:
Fixing the issue AXIS2-4881, with proper API, AbstractHandler will remain as it
is to keep the backwards compatibility. I have refactored the classes which
were using the invoke_stage1/2 methods, but I think we can improve most of the
handlers with this approach
Added:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractTemplatedHandler.java
Modified:
axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java
axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/dispatchers/MustUnderstandChecker.java
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/Phase.java
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractHandler.java
Modified:
axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java?rev=1064018&r1=1064017&r2=1064018&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java
(original)
+++
axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingInHandler.java
Thu Jan 27 08:05:22 2011
@@ -39,6 +39,7 @@ import org.apache.axis2.description.Para
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.engine.Handler.InvocationResponse;
import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.handlers.AbstractTemplatedHandler;
import org.apache.axis2.util.JavaUtils;
import org.apache.axis2.util.LoggingControl;
import org.apache.axis2.util.Utils;
@@ -49,7 +50,7 @@ import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Iterator;
-public class AddressingInHandler extends AbstractHandler implements
AddressingConstants {
+public class AddressingInHandler extends AbstractTemplatedHandler implements
AddressingConstants {
private static final int TO_FLAG = 1, FROM_FLAG = 2, REPLYTO_FLAG = 3,
FAULTO_FLAG = 4, MESSAGEID_FLAG = 6, ACTION_FLAG = 0;
@@ -59,7 +60,7 @@ public class AddressingInHandler extends
private boolean disableRefparamExtract = false;
private AxisConfiguration configuration = null;
private RolePlayer rolePlayer = null;
-
+
public void init(HandlerDescription handlerdesc){
super.init(handlerdesc);
// check whether to process reference parameters.
@@ -72,15 +73,7 @@ public class AddressingInHandler extends
}
}
- public InvocationResponse invoke(MessageContext msgContext) throws
AxisFault {
-
- if (invoke_stage1(msgContext)) {
- return invoke_stage2(msgContext);
- } else {
- return InvocationResponse.CONTINUE;
- }
- }
- public boolean invoke_stage1(MessageContext msgContext) throws AxisFault {
+ public boolean shouldInvoke(MessageContext msgContext) throws AxisFault {
//Set the defaults on the message context.
msgContext.setProperty(DISABLE_ADDRESSING_FOR_OUT_MESSAGES,
Boolean.TRUE);
msgContext.setProperty(IS_ADDR_INFO_ALREADY_PROCESSED, Boolean.FALSE);
@@ -100,13 +93,10 @@ public class AddressingInHandler extends
// if there are not headers put a flag to disable addressing temporary
SOAPHeader header = msgContext.getEnvelope().getHeader();
- if (header == null) {
- return false;
- }
- return true;
+ return header != null;
}
- public InvocationResponse invoke_stage2(MessageContext msgContext) throws
AxisFault {
+ public InvocationResponse doInvoke(MessageContext msgContext) throws
AxisFault {
SOAPHeader header = msgContext.getEnvelope().getHeader();
if(configuration == null){
AxisConfiguration conf =
msgContext.getConfigurationContext().getAxisConfiguration();
Modified:
axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java?rev=1064018&r1=1064017&r2=1064018&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
(original)
+++
axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingOutHandler.java
Thu Jan 27 08:05:22 2011
@@ -43,6 +43,7 @@ import org.apache.axis2.description.Axis
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.handlers.AbstractHandler;
+import org.apache.axis2.handlers.AbstractTemplatedHandler;
import org.apache.axis2.util.JavaUtils;
import org.apache.axis2.util.LoggingControl;
import org.apache.axis2.util.Utils;
@@ -55,23 +56,16 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
-public class AddressingOutHandler extends AbstractHandler implements
AddressingConstants {
+public class AddressingOutHandler extends AbstractTemplatedHandler implements
AddressingConstants {
private static final Log log =
LogFactory.getLog(AddressingOutHandler.class);
// TODO: This is required for MessageContext#getModuleParameter.
// Not clear why there is no way to automatically determine this!
private static final String MODULE_NAME = "addressing";
-
- public InvocationResponse invoke(MessageContext msgContext) throws
AxisFault {
-
- if (invoke_stage1(msgContext)) {
- return invoke_stage2(msgContext);
- } else {
- return InvocationResponse.CONTINUE;
- }
- }
- public boolean invoke_stage1(MessageContext msgContext) throws AxisFault {
+
+
+ public boolean shouldInvoke(MessageContext msgContext) throws AxisFault {
Parameter param = null;
boolean disableAddressing = false;
@@ -84,8 +78,7 @@ public class AddressingOutHandler extend
msgContext.isPropertyTrue(DISABLE_ADDRESSING_FOR_OUT_MESSAGES,
JavaUtils.isTrueExplicitly(Utils.getParameterValue(param)));
} else {
- Boolean bool = (Boolean)o;
- disableAddressing = bool.booleanValue();
+ disableAddressing = (Boolean) o;
}
if (disableAddressing) {
@@ -98,7 +91,7 @@ public class AddressingOutHandler extend
return true;
}
- public InvocationResponse invoke_stage2(MessageContext msgContext) throws
AxisFault {
+ public InvocationResponse doInvoke(MessageContext msgContext) throws
AxisFault {
// Determine the addressin namespace in effect.
Modified:
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/dispatchers/MustUnderstandChecker.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/dispatchers/MustUnderstandChecker.java?rev=1064018&r1=1064017&r2=1064018&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/dispatchers/MustUnderstandChecker.java
(original)
+++
axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/dispatchers/MustUnderstandChecker.java
Thu Jan 27 08:05:22 2011
@@ -22,6 +22,7 @@ package org.apache.axis2.jaxws.dispatche
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.handlers.AbstractTemplatedHandler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -32,29 +33,21 @@ import org.apache.commons.logging.LogFac
* Understood headers (per JAXWS 2.0 Section 10.2) include
* - Headers that correspond to SEI method parameters.
*/
-public class MustUnderstandChecker extends
org.apache.axis2.handlers.AbstractHandler {
- private static final Log log =
LogFactory.getLog(MustUnderstandChecker.class);
+public class MustUnderstandChecker extends AbstractTemplatedHandler {
- public boolean invoke_stage1(MessageContext msgContext) throws AxisFault {
+ public boolean shouldInvoke(MessageContext msgContext) throws AxisFault {
if (msgContext == null) {
return false;
}
-
SOAPEnvelope envelope = msgContext.getEnvelope();
- if (envelope.getHeader() == null) {
- return false;
- }
- return true;
- }
-
- public InvocationResponse invoke_stage2(MessageContext msgContext) throws
AxisFault {
- return invoke(msgContext);
+ return envelope.getHeader() != null;
}
- public InvocationResponse invoke(MessageContext msgContext) throws
AxisFault {
+ public InvocationResponse doInvoke(MessageContext msgContext) throws
AxisFault {
// Get the list of headers for the roles we're acting in, then mark
any we understand
// as processed.
MustUnderstandUtils.markUnderstoodHeaderParameters(msgContext);
return InvocationResponse.CONTINUE;
}
+
}
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/Phase.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/Phase.java?rev=1064018&r1=1064017&r2=1064018&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/Phase.java
(original)
+++
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/engine/Phase.java
Thu Jan 27 08:05:22 2011
@@ -330,25 +330,14 @@ public class Phase implements Handler {
return InvocationResponse.CONTINUE;
}
- private InvocationResponse invokeHandler(Handler handler, MessageContext
msgctx) throws AxisFault {
+ private InvocationResponse invokeHandler(Handler handler, MessageContext
msgctx)
+ throws AxisFault {
if (isDebugEnabled) {
log.debug(msgctx.getLogIDString() + " Invoking Handler '" +
handler.getName() +
"' in Phase '" + phaseName + "'");
}
- if (handler instanceof AbstractHandler) {
- // Call this as a two stage handler.
- boolean needStage2 =
((AbstractHandler)handler).invoke_stage1(msgctx);
-
- if (needStage2) {
- return ((AbstractHandler)handler).invoke_stage2(msgctx);
- } else {
- return InvocationResponse.CONTINUE;
- }
-
-
- } else {
- return handler.invoke(msgctx);
- }
+
+ return handler.invoke(msgctx);
}
public void flowComplete(MessageContext msgContext) {
Modified:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractHandler.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractHandler.java?rev=1064018&r1=1064017&r2=1064018&view=diff
==============================================================================
---
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractHandler.java
(original)
+++
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractHandler.java
Thu Jan 27 08:05:22 2011
@@ -102,34 +102,5 @@ public abstract class AbstractHandler im
public void flowComplete(MessageContext msgContext) {
}
-
- /**
- * Alternative to calling invoke()
- * The handler developer can place code in stage1 that
- * will do quick checking to make sure that the handler is
- * enabled and useful for this message.
- * Some handler developers may wish to split the invoke into
- * two stages if the handler is often disabled.
- * @param msgContext
- * @return true if stage2 processing is needed;
- * false if stage2 processing is not needed and flow should continue to
the next handler
- */
- public boolean invoke_stage1(MessageContext msgContext) throws AxisFault {
- // The default behavior is to continue to stage2
- return true;
- }
-
- /**
- * Alternative to calling invoke()
- * The handler developer can place code in stage2 that
- * will do the actual processing.
- * Some handler developers may wish to split the invoke into
- * two stages if the handler is often disabled.
- * @param msgContext
- * @return InvocationResponse
- */
- public InvocationResponse invoke_stage2(MessageContext msgContext) throws
AxisFault {
- // The default behavior is to call the existing invoke method
- return invoke(msgContext);
- }
+
}
Added:
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractTemplatedHandler.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractTemplatedHandler.java?rev=1064018&view=auto
==============================================================================
---
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractTemplatedHandler.java
(added)
+++
axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/handlers/AbstractTemplatedHandler.java
Thu Jan 27 08:05:22 2011
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axis2.handlers;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.MessageContext;
+
+/**
+ * This abstract class differentiates the concern of the conditional check to
see whether this
+ * particular message needs to be handled by the handler implementation and
the actual invocation
+ * logic.
+ *
+ * @see org.apache.axis2.handlers.AbstractHandler
+ */
+public abstract class AbstractTemplatedHandler extends AbstractHandler {
+
+ /**
+ * Implements the separation of the conditional check and the actual logic
+ *
+ * @param msgContext the <code>MessageContext</code> to process with this
<code>Handler</code>.
+ * @return CONTINUE if the handler implementation says 'should not be
invoked'
+ * or the result of the {@link
#doInvoke(org.apache.axis2.context.MessageContext)}
+ * @throws AxisFault if the {@link
#doInvoke(org.apache.axis2.context.MessageContext)}
+ * throws the same
+ */
+ public final InvocationResponse invoke(MessageContext msgContext) throws
AxisFault {
+ return shouldInvoke(msgContext) ? doInvoke(msgContext) :
InvocationResponse.CONTINUE;
+ }
+
+ /**
+ * This method should implement the conditional check of the handler to
decide whether this
+ * particular message needs to be handled by me
+ *
+ * @param msgCtx current <code>MessageContext</code> to be evaluated
+ * @return boolean <code>true<code>, if this handler needs to be further
invoked,
+ * <code>false</code> if this handler has nothing to do with this specific
message
+ * and want the flow to be continued
+ * @throws AxisFault in an error in evaluating the decision
+ */
+ public abstract boolean shouldInvoke(MessageContext msgCtx) throws
AxisFault;
+
+ /**
+ * This should implement the actual handler invocation logic.
+ *
+ * @param msgCtx current message to be handled by this handler
+ * @return flow completion decision, should be one of {@link
InvocationResponse#CONTINUE},
+ * {@link InvocationResponse#ABORT}, {@link InvocationResponse#SUSPEND}
+ * @throws AxisFault in an error in invoking the handler
+ */
+ public abstract InvocationResponse doInvoke(MessageContext msgCtx) throws
AxisFault;
+}