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 sc...@apache.org on 2009/10/14 17:07:19 UTC
svn commit: r825160 - in /webservices/axis2/trunk/java/modules/jaxws:
src/org/apache/axis2/jaxws/handler/SoapMessageContext.java
test/org/apache/axis2/jaxws/handler/HandlerPrePostInvokerTests.java
Author: scheu
Date: Wed Oct 14 15:07:19 2009
New Revision: 825160
URL: http://svn.apache.org/viewvc?rev=825160&view=rev
Log:
AXIS2-4528
Contributor: Lori VanGuilick
Summary:
Changes to the SOAPMessageContext to remember if the message has been queried by the JAX-WS handlers.
A unit test to verify the changes.
Modified:
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/SoapMessageContext.java
webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/HandlerPrePostInvokerTests.java
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/SoapMessageContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/SoapMessageContext.java?rev=825160&r1=825159&r2=825160&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/SoapMessageContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/SoapMessageContext.java Wed Oct 14 15:07:19 2009
@@ -128,6 +128,11 @@
}
public SOAPMessage getMessage() {
+ // set a property to indicate that we are accessing the message
+ if(log.isDebugEnabled()){
+ log.debug("getMessage - accessing message.");
+ }
+ this.put("jaxws.isMessageAccessed", true);
Message msg = messageCtx.getMEPContext().getMessageObject();
if (msg != cachedMessage) {
cachedMessage = msg;
Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/HandlerPrePostInvokerTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/HandlerPrePostInvokerTests.java?rev=825160&r1=825159&r2=825160&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/HandlerPrePostInvokerTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/HandlerPrePostInvokerTests.java Wed Oct 14 15:07:19 2009
@@ -45,6 +45,7 @@
private MessageContext mc = null;
private boolean preInvokerCalled = false;
private boolean postInvokerCalled = false;
+ private boolean messageAccessed = false;
private static final String soap11env = "http://schemas.xmlsoap.org/soap/envelope/";
@@ -113,13 +114,40 @@
assertTrue("processChain should have succeeded", success);
assertTrue("preInvoker should have been called", preInvokerCalled);
assertTrue("postInvoker should have been called", postInvokerCalled);
+ assertTrue("Handler did not access message but messageAccessed property is true.", !messageAccessed);
}
-
- /*****************************************
- * Classes needed for junit testcase *
- *****************************************/
-
+
+ public void testPostInvokerMessageAccessed() {
+
+ FactoryRegistry.setFactory(HandlerPostInvokerFactory.class, new HandlerPostInvokerFactoryImpl());
+
+ ArrayList<Handler> handlers = new ArrayList<Handler>();
+ handlers.add(new SOAPHandlerGetsMessage());
+ HandlerChainProcessor processor =
+ new HandlerChainProcessor(handlers, Protocol.soap11);
+ boolean success = true;
+ try {
+ // server-side incoming request
+ success = processor.processChain(mc.getMEPContext(),
+ HandlerChainProcessor.Direction.IN,
+ HandlerChainProcessor.MEP.REQUEST,
+ true);
+ } catch (Exception e) {
+ assertNull(e); // should not get exception
+ }
+
+ assertTrue("processChain should have succeeded", success);
+ assertTrue("postInvoker should have been called", postInvokerCalled);
+ assertTrue("Handler did access message but messageAccessed property is false.", messageAccessed);
+
+
+ }
+
+ /*****************************************
+ * Classes needed for junit testcase *
+ *****************************************/
+
private class SOAPHandler1 implements SOAPHandler<SOAPMessageContext> {
public Set getHeaders() {
@@ -134,7 +162,30 @@
}
public boolean handleMessage(SOAPMessageContext messagecontext) {
- return true;
+ return true;
+ }
+
+ }
+ /*****************************************
+ * Classes needed for junit testcase *
+ *****************************************/
+
+ private class SOAPHandlerGetsMessage implements SOAPHandler<SOAPMessageContext> {
+
+ public Set getHeaders() {
+ return null;
+ }
+
+ public void close(javax.xml.ws.handler.MessageContext messagecontext) {
+ }
+
+ public boolean handleFault(SOAPMessageContext messagecontext) {
+ return true;
+ }
+
+ public boolean handleMessage(SOAPMessageContext messagecontext) {
+ messagecontext.getMessage();
+ return true;
}
}
@@ -160,6 +211,15 @@
private class HandlerPostInvokerImpl implements HandlerPostInvoker {
public void postInvoke(javax.xml.ws.handler.MessageContext mc) {
postInvokerCalled = true;
+ if (mc instanceof SoapMessageContext) {
+ SoapMessageContext smc = (SoapMessageContext) mc;
+ // PK96521 - before getting the message (which is expensive) check first to
+ // see if it was actually accessed by the handlers
+ messageAccessed = false;
+ if (smc.containsKey("jaxws.isMessageAccessed")) {
+ messageAccessed = (Boolean)(smc.get("jaxws.isMessageAccessed"));
+ }
+ }
}
}
}