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 ro...@apache.org on 2008/02/22 00:38:04 UTC

svn commit: r630049 - in /webservices/axis2/trunk/java/modules/jaxws: src/org/apache/axis2/jaxws/handler/SoapMessageContext.java test/org/apache/axis2/jaxws/framework/JAXWSTest.java test/org/apache/axis2/jaxws/handler/context/SOAPMessageContextTests.java

Author: rott
Date: Thu Feb 21 15:38:00 2008
New Revision: 630049

URL: http://svn.apache.org/viewvc?rev=630049&view=rev
Log:
cache the message in SoapMessageContext so we don't deserialize the message for every handleMessage invocation

Added:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/SOAPMessageContextTests.java
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/framework/JAXWSTest.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=630049&r1=630048&r2=630049&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 Thu Feb 21 15:38:00 2008
@@ -52,6 +52,10 @@
 public class SoapMessageContext extends BaseMessageContext implements
         javax.xml.ws.handler.soap.SOAPMessageContext {
     private static final Log log = LogFactory.getLog(SoapMessageContext.class);
+    
+    // cache the message object after transformation --- see getMessage and setMessage methods
+    SOAPMessage cachedSoapMessage = null;
+    
     public SoapMessageContext(MessageContext messageCtx) {
         super(messageCtx);
     }
@@ -123,8 +127,11 @@
     }
 
     public SOAPMessage getMessage() {
-        Message msg = messageCtx.getMEPContext().getMessageObject();
-        return msg.getAsSOAPMessage();
+    	if (cachedSoapMessage == null) {
+    		Message msg = messageCtx.getMEPContext().getMessageObject();
+    		cachedSoapMessage = msg.getAsSOAPMessage();
+    	}
+        return cachedSoapMessage;
     }
 
     public Set<String> getRoles() {
@@ -159,6 +166,7 @@
             Message msg =
                     ((MessageFactory) FactoryRegistry.getFactory(MessageFactory.class)).createFrom(soapmessage);
             messageCtx.getMEPContext().setMessage(msg);
+            cachedSoapMessage = soapmessage;
         } catch (XMLStreamException e) {
             // TODO log it, and throw something?
         }

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java?rev=630049&r1=630048&r2=630049&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/framework/JAXWSTest.java Thu Feb 21 15:38:00 2008
@@ -46,6 +46,7 @@
 import org.apache.axis2.jaxws.handler.HandlerChainProcessorTests;
 import org.apache.axis2.jaxws.handler.context.CompositeMessageContextTests;
 import org.apache.axis2.jaxws.handler.context.LogicalMessageContextTests;
+import org.apache.axis2.jaxws.handler.context.SOAPMessageContextTests;
 import org.apache.axis2.jaxws.i18n.JaxwsMessageBundleTests;
 import org.apache.axis2.jaxws.injection.ResourceInjectionTests;
 import org.apache.axis2.jaxws.lifecycle.EndpointLifecycleTests;
@@ -153,6 +154,7 @@
         
         // ------ Handler Tests ------
         suite.addTestSuite(LogicalMessageContextTests.class);
+        suite.addTestSuite(SOAPMessageContextTests.class);
         suite.addTestSuite(CompositeMessageContextTests.class);
         suite.addTestSuite(HandlerChainProcessorTests.class);
         suite.addTestSuite(HandlerResolverTests.class);

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/SOAPMessageContextTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/SOAPMessageContextTests.java?rev=630049&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/SOAPMessageContextTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/context/SOAPMessageContextTests.java Thu Feb 21 15:38:00 2008
@@ -0,0 +1,83 @@
+/*
+ * 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.jaxws.handler.context;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.soap.SOAPMessage;
+
+import junit.framework.TestCase;
+
+import org.apache.axis2.jaxws.context.factory.MessageContextFactory;
+import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.handler.MEPContext;
+import org.apache.axis2.jaxws.handler.SoapMessageContext;
+import org.apache.axis2.jaxws.message.Block;
+import org.apache.axis2.jaxws.message.Message;
+import org.apache.axis2.jaxws.message.Protocol;
+import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
+import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+
+import test.EchoString;
+import test.ObjectFactory;
+
+public class SOAPMessageContextTests extends TestCase {
+
+	private final String INPUT = "sample input";
+	
+    private SoapMessageContext createSampleContext() throws Exception {
+        MessageFactory factory = (MessageFactory) FactoryRegistry.getFactory(MessageFactory.class);
+        Message msg = factory.create(Protocol.soap11);
+        
+        // Create a jaxb object
+        ObjectFactory objFactory = new ObjectFactory();
+        EchoString echo = objFactory.createEchoString();
+        echo.setInput(INPUT);
+        
+        // Create the necessary JAXBContext
+        JAXBContext jbc = JAXBContext.newInstance("test");
+        JAXBBlockContext blockCtx = new JAXBBlockContext(jbc);
+        
+        // Create the Block 
+        JAXBBlockFactory blockFactory = (JAXBBlockFactory) FactoryRegistry.getFactory(JAXBBlockFactory.class);
+        Block block = blockFactory.createFrom(echo, blockCtx, null);
+        
+        msg.setBodyBlock(block);
+        
+        MessageContext mc = new MessageContext();
+        mc.setMEPContext(new MEPContext(mc));
+        mc.setMessage(msg);
+        
+        return MessageContextFactory.createSoapMessageContext(mc);
+
+    }
+    
+    public void testGetAsSoapMessageObjectID() {
+    	try {
+    		SoapMessageContext smc = createSampleContext();
+    		SOAPMessage m1 = smc.getMessage();
+    		SOAPMessage m2 = smc.getMessage();
+    		// not using assertEquals because I want object id equality
+    		assertTrue("retrieval of message from SoapMessageContext twice in a row should result in same object", m1 == m2);
+    	} catch (Exception e) {
+    		assertNull("should not get an exception in this test", e);
+    	}
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org