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/08/31 15:01:29 UTC

svn commit: r809569 - in /webservices/axis2/trunk/java/modules: jaxws-integration/test/org/apache/axis2/jaxws/context/ jaxws-integration/test/org/apache/axis2/jaxws/context/tests/ jaxws/src/org/apache/axis2/datasource/jaxb/ jaxws/src/org/apache/axis2/j...

Author: scheu
Date: Mon Aug 31 13:01:28 2009
New Revision: 809569

URL: http://svn.apache.org/viewvc?rev=809569&view=rev
Log:
AXIS2-4481
Fix JAX-WS marshaling flow using xsi:type to use the marshal to OutputStream optimization
Contributor:Rich Scheuerle
Performance Testing: Doug Larson

Added:
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBDSContextTests.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/MessageContextImpl.java
    webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/tests/MessageContextTests.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/WebServiceContextImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointCallback.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/lifecycle/impl/EndpointLifecycleManagerImpl.java
    webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/echo.xsd

Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/MessageContextImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/MessageContextImpl.java?rev=809569&r1=809568&r2=809569&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/MessageContextImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/MessageContextImpl.java Mon Aug 31 13:01:28 2009
@@ -34,14 +34,21 @@
 
     @Resource
     WebServiceContext ctxt;
+    
+    public static WebServiceContext webServiceContext = null;
 
     public void isPropertyPresent(
             Holder<String> propertyName,
             Holder<String> value,
             Holder<String> type,
             Holder<Boolean> isFound) {
-        System.out.println(">> isPropertyPresent(" + propertyName.value + ")");
+        
+        // Put the context in the static variable so that the test can 
+        // make sure that its contents don't persist past the method invocation
+        webServiceContext = ctxt;
+        
         javax.xml.ws.handler.MessageContext msgCtxt = ctxt.getMessageContext();
+        
         if (msgCtxt != null) {
             isFound.value = msgCtxt.containsKey(propertyName.value);
             Object val = msgCtxt.get(propertyName.value);
@@ -53,6 +60,5 @@
                 value.value = val.toString();
             }
         }
-        System.out.println("<< isPropertyPresent()");
     }
 }
\ No newline at end of file

Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/tests/MessageContextTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/tests/MessageContextTests.java?rev=809569&r1=809568&r2=809569&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/tests/MessageContextTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/context/tests/MessageContextTests.java Mon Aug 31 13:01:28 2009
@@ -21,6 +21,8 @@
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
+
+import org.apache.axis2.jaxws.context.MessageContextImpl;
 import org.apache.axis2.jaxws.context.sei.MessageContext;
 import org.apache.axis2.jaxws.context.sei.MessageContextService;
 import org.apache.axis2.jaxws.framework.AbstractTestCase;
@@ -29,6 +31,7 @@
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Holder;
 import javax.xml.ws.WebServiceClient;
+import javax.xml.ws.WebServiceContext;
 
 public class MessageContextTests extends AbstractTestCase {
 
@@ -85,6 +88,13 @@
         System.out.println("Type = " + type.value + "/" + exType);
 
         assertTrue("WebServiceContext did not expose " + propertyName.value, isFound.value);
+        
+        // Make sure that the WebServiceContext's contents don't persist after the
+        // invocation.  This is necessary to ensure proper gc and avoid accidental misuse.
+        WebServiceContext wsc = org.apache.axis2.jaxws.context.MessageContextImpl.webServiceContext;
+        
+        assertTrue("WebServiceContext resources were not freed",
+                   wsc.getMessageContext() == null);
 
         if (exType != null)
             assertTrue("Type of " + propertyName.value + " does not match [" + type.value + ", " + exType + "]",

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java?rev=809569&r1=809568&r2=809569&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java Mon Aug 31 13:01:28 2009
@@ -351,7 +351,8 @@
                               writer,
                               getProcessType(),
                               isxmlList(),
-                              getConstructionType());
+                              getConstructionType(),
+                              true); // Attempt to optimize by writing to OutputStream
             }
 
             // Successfully marshalled the data
@@ -376,10 +377,6 @@
                 // XMLStreamWriter. 
                 // Take advantage of this optimization if there is an output stream.
                 try {
-                    if (!optimize) {
-                        log.trace(JavaUtils.stackToString());
-                        getOutputStream(writer);
-                    }
                     OutputStream os = (optimize) ? getOutputStream(writer) : null;
                     if (os != null) {
                         if (DEBUG_ENABLED) {
@@ -722,11 +719,17 @@
      * schema (i.e. rpc)
      * @param m Marshaller
      * @param writer XMLStreamWriter
-     * @param type
+     * @param type Class
+     * @param isList true if this is an XmlList
+     * @param ctype CONSTRUCTION_TYPE
+     * @param optimize boolean set to true if optimization directly to 
+     * outputstream should be attempted.
      */
     private static void marshalByType(final Object b, final Marshaller m,
                                       final XMLStreamWriter writer, final Class type,
-                                      final boolean isList, final JAXBUtils.CONSTRUCTION_TYPE ctype)
+                                      final boolean isList, 
+                                      final JAXBUtils.CONSTRUCTION_TYPE ctype,
+                                      final boolean optimize) 
         throws WebServiceException {
         AccessController.doPrivileged(new PrivilegedAction() {
             public Object run() {
@@ -819,16 +822,23 @@
                         }
                     }
 
-                    if (DEBUG_ENABLED) {
-                        log.debug("Invoking marshalByType.  " +
-                                        "Marshaling to an XMLStreamWriter. Object is "
-                                + getDebugName(b));
+                    // If the output stream is available, marshal directly to it
+                    OutputStream os = (optimize) ? getOutputStream(writer) : null;
+                    if (os == null){ 
+                        if (DEBUG_ENABLED) {
+                            log.debug("Invoking marshalByType.  " +
+                                    "Marshaling to an XMLStreamWriter. Object is "
+                                    + getDebugName(jbo));
+                        }   
+                        m.marshal(jbo, writer);
+                    } else {
+                        if (DEBUG_ENABLED) {
+                            log.debug("Invoking marshalByType.  " +
+                                    "Marshaling to an OutputStream. Object is "
+                                    + getDebugName(jbo));
+                        }   
+                        m.marshal(jbo, os);
                     }
-                    
-                    /// TODO 
-                    // For the cases like enum and list, should we 
-                    // intercept exceptions and try a different approach ?
-                    m.marshal(jbo, writer);
 
                 } catch (OMException e) {
                     throw e;

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/WebServiceContextImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/WebServiceContextImpl.java?rev=809569&r1=809568&r2=809569&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/WebServiceContextImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/WebServiceContextImpl.java Mon Aug 31 13:01:28 2009
@@ -48,6 +48,14 @@
      * @see javax.xml.ws.WebServiceContext#getMessageContext()
      */
     public MessageContext getMessageContext() {
+        
+        // Note that the MessageContext might not be set up yet, or it
+        // may have been released because the lifetime of the WebServiceContext is completed.
+        if (log.isDebugEnabled()) {
+            if (soapMessageContext == null) {
+                log.debug("The MessageContext is not available");
+            }
+        }
         return soapMessageContext;
     }
 
@@ -55,6 +63,15 @@
      * @see javax.xml.ws.WebServiceContext#getUserPrincipal()
      */
     public Principal getUserPrincipal() {
+        
+        // Note that the MessageContext might not be set up yet, or it
+        // may have been released because the lifetime of the WebServiceContext is completed.
+        if (log.isDebugEnabled()) {
+            if (soapMessageContext == null) {
+                log.debug("The MessageContext is not available");
+            }
+        }
+        
         if (soapMessageContext != null) {
             HttpServletRequest request = (HttpServletRequest) soapMessageContext.get(MessageContext.SERVLET_REQUEST);
             if (request != null) {
@@ -77,6 +94,15 @@
      * @see javax.xml.ws.WebServiceContext#isUserInRole(java.lang.String)
      */
     public boolean isUserInRole(String user) {
+        
+        // Note that the MessageContext might not be set up yet, or it
+        // may have been released because the lifetime of the WebServiceContext is completed.
+        if (log.isDebugEnabled()) {
+            if (soapMessageContext == null) {
+                log.debug("The MessageContext is not available");
+            }
+        }
+        
         if (soapMessageContext != null) {
             HttpServletRequest request = (HttpServletRequest) soapMessageContext.get(MessageContext.SERVLET_REQUEST);
             if (request != null) {
@@ -100,6 +126,15 @@
     }
 
     public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, Element... referenceParameters) {
+        
+        // Note that the MessageContext might not be set up yet, or it
+        // may have been released because the lifetime of the WebServiceContext is completed.
+        if (log.isDebugEnabled()) {
+            if (soapMessageContext == null) {
+                log.debug("The MessageContext is not available");
+            }
+        }
+        
         EndpointReference jaxwsEPR = null;
         String addressingNamespace = EndpointReferenceUtils.getAddressingNamespace(clazz);
         
@@ -130,4 +165,14 @@
     public EndpointReference getEndpointReference(Element... referenceParameters) {
         return getEndpointReference(W3CEndpointReference.class, referenceParameters);
     }
+    
+    /**
+     * Release objects held by WebServiceContext so that they can be garbage collected.
+     */
+    public void releaseResources() {
+        if (log.isDebugEnabled()) {
+            log.debug("Releasing WebServiceContextImpl resources");
+        }
+        soapMessageContext = null; // unlink the soapMessageContxt so that it can be gc'd
+    }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java?rev=809569&r1=809568&r2=809569&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/context/utils/ContextUtils.java Mon Aug 31 13:01:28 2009
@@ -22,6 +22,7 @@
 import org.apache.axiom.soap.SOAPHeader;
 import org.apache.axis2.context.ServiceContext;
 import org.apache.axis2.jaxws.addressing.util.ReferenceParameterList;
+import org.apache.axis2.jaxws.context.WebServiceContextImpl;
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.description.EndpointDescription;
 import org.apache.axis2.jaxws.description.EndpointInterfaceDescription;
@@ -50,6 +51,8 @@
 
 public class ContextUtils {
     private static final Log log = LogFactory.getLog(ContextUtils.class);
+    
+    private static final String WEBSERVICE_MESSAGE_CONTEXT = "javax.xml.ws.WebServiceContext";
 
     /**
      * Adds the appropriate properties to the MessageContext that the user will see
@@ -253,4 +256,27 @@
             log.debug(name + " :" + value);
         }
     }
+    
+    /**
+     * Release the contents of the WebServiceContext.
+     * @param mc
+     */
+    public static void releaseWebServiceContextResources(MessageContext mc) {
+        if (log.isDebugEnabled()) {
+            log.debug("Find and release WebServiceContext resources");
+        }
+        WebServiceContext wsc = null;
+        // If a WebServiceContext was created, get it from the MessageContext
+        if (mc != null) {
+            wsc = (WebServiceContext) mc.getProperty(WEBSERVICE_MESSAGE_CONTEXT);
+        } 
+        
+        if (wsc != null && wsc instanceof WebServiceContextImpl) {
+            ((WebServiceContextImpl) wsc).releaseResources();
+        } else {
+            if (log.isDebugEnabled()) {
+                log.debug("A WebServiceContext was not found");
+            }
+        }
+    }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointCallback.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointCallback.java?rev=809569&r1=809568&r2=809569&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointCallback.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointCallback.java Mon Aug 31 13:01:28 2009
@@ -23,6 +23,7 @@
 import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.engine.AxisEngine;
 import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.context.utils.ContextUtils;
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.handler.HandlerChainProcessor;
 import org.apache.axis2.jaxws.handler.HandlerInvocationContext;
@@ -47,24 +48,34 @@
                 responseMsgCtx.getAxisMessageContext();
 
         try {
+            if (log.isDebugEnabled()) {
+                log.debug("start handleResponse");
+            }
             invokeOutboundHandlerFlow(eic);
             responseReady(eic);
             MessageUtils.putMessageOnMessageContext(responseMsgCtx.getMessage(),
                                                     axisResponseMsgCtx);
 
             OperationContext opCtx = axisResponseMsgCtx.getOperationContext();
-            opCtx.addMessageContext(axisResponseMsgCtx);            
+            opCtx.addMessageContext(axisResponseMsgCtx);         
             
+            
+            if (log.isDebugEnabled()) {
+                log.debug("perform thread migration");
+            }
             // This assumes that we are on the ultimate execution thread
             ThreadContextMigratorUtil.performMigrationToContext(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID,
                                                                 axisResponseMsgCtx);
     
-            //Create the AxisEngine for the reponse and send it.
+            //Create the AxisEngine for the response and send it.
             if (log.isDebugEnabled()) {
                 log.debug("Sending async response.");
             }
             AxisEngine.send(axisResponseMsgCtx);
             
+            if (log.isDebugEnabled()) {
+                log.debug("perform thread cleanup");
+            }
             //This assumes that we are on the ultimate execution thread
             ThreadContextMigratorUtil.performContextCleanup(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID,
                                                             axisResponseMsgCtx);
@@ -79,13 +90,22 @@
                 t = faultMessage;
             }
             eic.getResponseMessageContext().setCausedByException(AxisFault.makeFault(t));
-            
+           
             ThreadContextMigratorUtil.performThreadCleanup(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID,
                 eic.getRequestMessageContext().getAxisMessageContext());
             
             // FIXME (NLG): This is probably not right
             handleFaultResponse(eic);
-        } 
+        } finally {
+            if (log.isDebugEnabled()) {
+                log.debug("release resources");
+            }
+            ContextUtils.releaseWebServiceContextResources(eic.getRequestMessageContext());
+            
+            if (log.isDebugEnabled()) {
+                log.debug("end handleResponse");
+            }
+        }
     }
     
     public void handleFaultResponse(EndpointInvocationContext eic) {
@@ -94,6 +114,10 @@
                 responseMsgCtx.getAxisMessageContext();
         
         try {
+            if (log.isDebugEnabled()) {
+                log.debug("start handleFaultResponse");
+            }
+            
             responseReady(eic);
             MessageUtils.putMessageOnMessageContext(responseMsgCtx.getMessage(),
                 axisResponseMsgCtx);
@@ -101,6 +125,9 @@
             OperationContext opCtx = axisResponseMsgCtx.getOperationContext();
             opCtx.addMessageContext(axisResponseMsgCtx);
             
+            if (log.isDebugEnabled()) {
+                log.debug("perform thread cleanup");
+            }
             ThreadContextMigratorUtil.performThreadCleanup(Constants.THREAD_CONTEXT_MIGRATOR_LIST_ID,
                 eic.getRequestMessageContext().getAxisMessageContext());
             
@@ -114,6 +141,14 @@
             }
             
             throw ExceptionFactory.makeWebServiceException(AxisFault.makeFault(t));
+        } finally {
+            if (log.isDebugEnabled()) {
+                log.debug("release resources");
+            }
+            ContextUtils.releaseWebServiceContextResources(eic.getRequestMessageContext());
+            if (log.isDebugEnabled()) {
+                log.debug("end handleFaultResponse");
+            }
         }
     }
     

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java?rev=809569&r1=809568&r2=809569&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java Mon Aug 31 13:01:28 2009
@@ -28,6 +28,7 @@
 import org.apache.axis2.description.WSDL2Constants;
 import org.apache.axis2.java.security.AccessController;
 import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.context.utils.ContextUtils;
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.core.util.MessageContextUtils;
 import org.apache.axis2.jaxws.description.EndpointDescription;
@@ -128,6 +129,8 @@
             } else {
                 destroyHandlers(eic, request);
             }
+            // Release WebServiceContextResources if available
+            ContextUtils.releaseWebServiceContextResources(request);
         }
         
         return eic;

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java?rev=809569&r1=809568&r2=809569&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/dispatcher/JavaDispatcher.java Mon Aug 31 13:01:28 2009
@@ -23,6 +23,7 @@
 import org.apache.axis2.jaxws.Constants;
 import org.apache.axis2.jaxws.WebServiceExceptionLogger;
 import org.apache.axis2.jaxws.ExceptionFactory;
+import org.apache.axis2.jaxws.context.utils.ContextUtils;
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.server.EndpointCallback;
 import org.apache.axis2.jaxws.server.EndpointInvocationContext;
@@ -144,7 +145,13 @@
                 // If this is a one way invocation, we are done and just need to return.
                 if (eic.isOneWay()) {
                     if (log.isDebugEnabled()) {
-                        log.debug("Invocation pattern was one way, work complete.");
+                        log.debug("Completed invoke of one-way operation");
+                        log.debug("Release resources");
+                    }
+                    ContextUtils.releaseWebServiceContextResources(eic.getRequestMessageContext());
+                    
+                    if (log.isDebugEnabled()) {
+                        log.debug("Indicate Response ready");
                     }
                     
                     responseReady(eic);

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/lifecycle/impl/EndpointLifecycleManagerImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/lifecycle/impl/EndpointLifecycleManagerImpl.java?rev=809569&r1=809568&r2=809569&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/lifecycle/impl/EndpointLifecycleManagerImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/lifecycle/impl/EndpointLifecycleManagerImpl.java Mon Aug 31 13:01:28 2009
@@ -26,6 +26,7 @@
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.context.WebServiceContextImpl;
 import org.apache.axis2.jaxws.context.factory.MessageContextFactory;
+import org.apache.axis2.jaxws.context.utils.ContextUtils;
 import org.apache.axis2.jaxws.core.MessageContext;
 import org.apache.axis2.jaxws.description.ServiceDescription;
 import org.apache.axis2.jaxws.handler.SoapMessageContext;
@@ -155,6 +156,9 @@
         //Add the MessageContext for current invocation
         if (ws != null) {
             updateWebServiceContext(ws, soapMessageContext);
+            // Store the WebServiceContext on the MessageContext so that its resource
+            // can be freed after the web service method completes.
+            mc.setProperty(WEBSERVICE_MESSAGE_CONTEXT, ws);
         }
     }
 
@@ -177,6 +181,10 @@
         WebServiceContextImpl wsContext = new WebServiceContextImpl();
         //Add MessageContext for this request.
         wsContext.setSoapMessageContext(soapMessageContext);
+        
+        // Store the WebServiceContext on the MessageContext so that its resource
+        // can be freed after the web service method completes.
+        mc.setProperty(WEBSERVICE_MESSAGE_CONTEXT, wsContext);
         return wsContext;
     }
 

Modified: webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/echo.xsd
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/echo.xsd?rev=809569&r1=809568&r2=809569&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/echo.xsd (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test-resources/xsd/echo.xsd Mon Aug 31 13:01:28 2009
@@ -36,4 +36,9 @@
       </s:sequence>
     </s:complexType>
   </s:element>
+  <s:complexType name="data">
+      <s:sequence>
+        <s:element minOccurs="0" maxOccurs="1" name="input" type="s:string" />
+      </s:sequence>
+  </s:complexType>
 </s:schema>
\ No newline at end of file

Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBDSContextTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBDSContextTests.java?rev=809569&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBDSContextTests.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/message/JAXBDSContextTests.java Mon Aug 31 13:01:28 2009
@@ -0,0 +1,138 @@
+/*
+ * 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.message;
+
+import junit.framework.TestCase;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
+import org.apache.axis2.datasource.jaxb.JAXBDSContext;
+import org.apache.axis2.datasource.jaxb.JAXBDataSource;
+import org.apache.axis2.jaxws.message.databinding.JAXBBlockContext;
+import org.apache.axis2.jaxws.message.databinding.JAXBUtils;
+import org.apache.axis2.jaxws.message.factory.BlockFactory;
+import org.apache.axis2.jaxws.message.factory.JAXBBlockFactory;
+import org.apache.axis2.jaxws.message.factory.MessageFactory;
+import org.apache.axis2.jaxws.message.factory.OMBlockFactory;
+import org.apache.axis2.jaxws.message.factory.SourceBlockFactory;
+import org.apache.axis2.jaxws.message.factory.XMLStringBlockFactory;
+import org.apache.axis2.jaxws.message.util.Reader2Writer;
+import org.apache.axis2.jaxws.registry.FactoryRegistry;
+import org.apache.axis2.jaxws.unitTest.TestLogger;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+import test.Data;
+import test.ObjectFactory;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBIntrospector;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.util.JAXBSource;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.TreeSet;
+
+/**
+ * JAXBDSContextTests
+ * Tests to create and validate JAXBDSContext
+ * These are not client/server tests.
+ */
+public class JAXBDSContextTests extends TestCase {
+
+    
+    private static XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+    private static XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+
+
+    public JAXBDSContextTests() {
+        super();
+    }
+
+    public JAXBDSContextTests(String arg0) {
+        super(arg0);
+    }
+
+    
+    /**
+     * Create a Block representing an JAXB and simulate a 
+     * normal Dispatch<JAXB> flow
+     * @throws Exception
+     */
+    public void testMarshal() throws Exception {
+        
+        // Create a JAXBDSContext for the package containing Data
+        TreeSet<String> packages = new TreeSet<String>();
+        packages.add(Data.class.getPackage().getName());
+        JAXBDSContext context = new JAXBDSContext(packages);
+        
+        System.out.println(context.getJAXBContext().toString());
+        
+        // Force marshal by type
+        context.setProcessType(Data.class);
+        
+        // Create an Data value
+        ObjectFactory factory = new ObjectFactory();
+        Data value = factory.createData(); 
+        value.setInput("Hello World");
+        
+        // Create a JAXBElement
+        QName qName = new QName("urn://sample", "data");
+        JAXBElement jaxbElement = new JAXBElement(qName, Data.class, value);
+
+        // Create a writer
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        OMOutputFormat format = new OMOutputFormat();
+        format.setDoOptimize(true);
+        MTOMXMLStreamWriter writer = new MTOMXMLStreamWriter(baos, format);
+        
+        // Marshal the value
+        writer.writeStartDocument();
+        writer.writeStartElement("root");
+        context.marshal(jaxbElement, writer);
+        writer.writeEndElement();
+        writer.writeEndDocument();
+        writer.flush();
+        
+        assertTrue(baos.toString().indexOf("Hello World") > 0);
+        assertTrue(baos.toString().indexOf("</root>") > 0);
+    }
+    
+   
+}