axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntha...@apache.org
Subject svn commit: r648320 - in /webservices/axis2/trunk/java/modules: jaxws-integration/test/org/apache/axis2/jaxws/sample/ jaxws-integration/test/org/apache/axis2/jaxws/sample/mtom/ jaxws/src/org/apache/axis2/datasource/jaxb/ jaxws/src/org/apache/axis2/jaxw...
Date Tue, 15 Apr 2008 16:37:16 GMT
Author: nthaker
Date: Tue Apr 15 09:37:08 2008
New Revision: 648320

URL: http://svn.apache.org/viewvc?rev=648320&view=rev
Log:
Axis2-3740

Added:
    webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleMTOMThresholdService.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/config/MTOMConfigurator.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
    webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java

Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java?rev=648320&r1=648319&r2=648320&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/MtomSampleTests.java
Tue Apr 15 09:37:08 2008
@@ -27,6 +27,7 @@
 import org.apache.axis2.jaxws.TestLogger;
 import org.apache.axis2.jaxws.framework.AbstractTestCase;
 import org.apache.axis2.jaxws.provider.DataSourceImpl;
+import org.apache.axis2.util.Utils;
 import org.test.mtom.ImageDepot;
 import org.test.mtom.ObjectFactory;
 import org.test.mtom.SendImage;
@@ -66,6 +67,8 @@
         "http://localhost:6060/axis2/services/MtomSampleService.MtomSampleMTOMEnableServicePort";
     private static final String URL_ENDPOINT_MTOMDEFAULT = 
         "http://localhost:6060/axis2/services/MtomSampleService.MtomSampleMTOMDefaultServicePort";
+    private static final String URL_ENDPOINT_MTOMTHRESHOLD = 
+        "http://localhost:6060/axis2/services/MtomSampleService.MtomSampleMTOMThresholdServicePort";
     
     
     private static final String IMAGE_DIR = System.getProperty("basedir",".")+"/"+"test-resources"+File.separator+"image";
  
@@ -631,6 +634,63 @@
         assertNotNull(response);
         assertNotNull(response.getOutput().getImageData());
         */
+    }
+    /*
+     * Enable attachment Optimization but call an endpoint with @MTOM(enable=true, Threshold
= 99000)
+     */
+    
+    public void testSendImage_setMTOMThreshold() throws Exception {
+        TestLogger.logger.debug("----------------------------------");
+        TestLogger.logger.debug("test: " + getName());
+        System.out.println("testSendImage_setMTOMThreshold()");
+        String imageResourceDir = IMAGE_DIR;
+        
+        //Create a DataSource from an image 
+        File file = new File(imageResourceDir+File.separator+"test.jpg");
+        ImageInputStream fiis = new FileImageInputStream(file);
+        Image image = ImageIO.read(fiis);
+        DataSource imageDS = new DataSourceImpl("image/jpeg","test.jpg",image);
+        
+        //Create a DataHandler with the String DataSource object
+        DataHandler dataHandler = new DataHandler(imageDS);
+        
+        //Store the data handler in ImageDepot bean
+        ImageDepot imageDepot = new ObjectFactory().createImageDepot();
+        imageDepot.setImageData(dataHandler);
+        
+        SendImage request = new ObjectFactory().createSendImage();
+        request.setInput(imageDepot);
+        
+        //Create the necessary JAXBContext
+        JAXBContext jbc = JAXBContext.newInstance("org.test.mtom");
+        //Setting Threshold to send request Inline
+        int threshold = 100000;
+        MTOMFeature mtom21 = new MTOMFeature(true, threshold);
+        // Create the JAX-WS client needed to send the request
+        Service service = Service.create(QNAME_SERVICE);
+        service.addPort(QNAME_PORT, SOAPBinding.SOAP11HTTP_BINDING, URL_ENDPOINT_MTOMTHRESHOLD);
+        Dispatch<Object> dispatch = service.createDispatch(QNAME_PORT, jbc, Mode.PAYLOAD,
mtom21);
+        
+        List cids = null;
+        SendImageResponse response = null;
+        try {
+            JAXBAttachmentUnmarshallerMonitor.setMonitoring(true);
+            response = (SendImageResponse) dispatch.invoke(request);
+            
+            // The cids are collected in the monitor.  We will check
+            // this to make sure the response mtom is not inlined
+            cids = JAXBAttachmentUnmarshallerMonitor.getBlobCIDs();
+        } finally {
+            JAXBAttachmentUnmarshallerMonitor.setMonitoring(false);
+        }
+        
+        
+        assertNotNull(response);
+        assertNotNull(response.getOutput().getImageData());
+        
+        //There shold be no cid as attachment should be inlined.
+        int numCIDs = (cids == null) ? 0 : cids.size();
+        assertTrue("Expected one attachment inlined:" + numCIDs, numCIDs == 0);
     }
     
 }

Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleMTOMThresholdService.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleMTOMThresholdService.java?rev=648320&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleMTOMThresholdService.java
(added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/mtom/MtomSampleMTOMThresholdService.java
Tue Apr 15 09:37:08 2008
@@ -0,0 +1,64 @@
+package org.apache.axis2.jaxws.sample.mtom;
+
+import java.awt.Image;
+import java.io.InputStream;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.imageio.ImageIO;
+import javax.jws.WebService;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.soap.MTOM;
+
+import org.apache.axis2.datasource.jaxb.JAXBAttachmentUnmarshallerMonitor;
+import org.apache.axis2.jaxws.TestLogger;
+import org.apache.axis2.jaxws.provider.DataSourceImpl;
+import org.test.mtom.ImageDepot;
+import org.test.mtom.ObjectFactory;
+/**
+ * Endpoint with MTOM enabled and Threshold set to size bigger than the attachment size.
+ * The response from Server should have attachments inlined.
+ */
+@WebService(serviceName="MtomSampleService",
+	    endpointInterface="org.apache.axis2.jaxws.sample.mtom.MtomSample")
+@MTOM(enabled=true, threshold=99000)
+public class MtomSampleMTOMThresholdService implements MtomSample {
+
+    public ImageDepot sendImage(ImageDepot input) {
+        TestLogger.logger.debug("MtomSampleMTOMEnableService [new sendImage request received]");
+        DataHandler data = input.getImageData();
+
+        TestLogger.logger.debug("[contentType] " + data.getContentType());
+        ImageDepot output = (new ObjectFactory()).createImageDepot();
+        Image image = null;
+        
+        resetAttachmentUnmarshallingMonitor();
+        try {
+            InputStream stream = (InputStream) data.getContent();
+            image = ImageIO.read(stream);
+            
+            DataSource imageDS = new DataSourceImpl("image/jpeg", "test.jpg", image);
+            DataHandler handler = new DataHandler(imageDS);
+            output.setImageData(handler);
+        }
+        catch (Exception e) {
+            throw new WebServiceException(e);
+        }
+        return output;
+    }
+
+    public ImageDepot sendText(byte[] input) {
+        TestLogger.logger.debug("[new sendText request received]");
+        return null;
+    }
+
+    /**
+     * Reset the monitor so that we can determine if an
+     * attachment is unmarshalled on the response.
+     */
+    private void resetAttachmentUnmarshallingMonitor() {
+        if (JAXBAttachmentUnmarshallerMonitor.isMonitoring()) {
+            JAXBAttachmentUnmarshallerMonitor.clear();
+        }
+    }
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java?rev=648320&r1=648319&r2=648320&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBAttachmentMarshaller.java
Tue Apr 15 09:37:08 2008
@@ -23,6 +23,7 @@
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
 import org.apache.axiom.om.impl.llom.OMTextImpl;
+import org.apache.axis2.Constants;
 import org.apache.axis2.Constants.Configuration;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.transport.http.HTTPConstants;
@@ -82,8 +83,7 @@
         if (log.isDebugEnabled()){ 
             log.debug("isXOPPackage returns " + value);
         }
-        return value;
-
+        return value;        
     }
 
     
@@ -109,7 +109,7 @@
                       "{" + namespace + "}" + localPart);
         }
         
-        String cid;
+        String cid = null;
         
             try {
                 // Create MIME Body Part
@@ -119,9 +119,14 @@
                 
                 //Create a data source for the MIME Body Part
                 MimePartDataSource mpds = new MimePartDataSource(mbp);
+                long dataLength =data.length;
+                Integer value = (Integer)msgContext.getProperty(Constants.Configuration.MTOM_THRESHOLD);
+                int optimizedThreshold = (value!=null)?value.intValue():0;
                 
-                DataHandler dataHandler = new DataHandler(mpds);
-                cid = addDataHandler(dataHandler);
+                if(optimizedThreshold==0 || dataLength > optimizedThreshold){
+                	DataHandler dataHandler = new DataHandler(mpds);
+                	cid = addDataHandler(dataHandler);
+                }
                 
                 // Add the content id to the mime body part
                 mbp.setHeader(HTTPConstants.HEADER_CONTENT_ID, cid);
@@ -173,10 +178,12 @@
         // even if the attachment is SWAREF ?)
         if (writer instanceof MTOMXMLStreamWriter) {
             textNode = new OMTextImpl(dh, null);
-            cid = textNode.getContentID();
-            ((MTOMXMLStreamWriter) writer).writeOptimized(textNode);
-            // Remember the attachment on the message.
-            addDataHandler(dh, cid);
+        	if(((MTOMXMLStreamWriter) writer).isOptimizedThreshold(textNode)){
+        		cid = textNode.getContentID();
+        		((MTOMXMLStreamWriter) writer).writeOptimized(textNode);
+        		// Remember the attachment on the message.
+        		addDataHandler(dh, cid);
+        	}        	
         }
         
         if (log.isDebugEnabled()){ 

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/config/MTOMConfigurator.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/config/MTOMConfigurator.java?rev=648320&r1=648319&r2=648320&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/config/MTOMConfigurator.java
(original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/client/config/MTOMConfigurator.java
Tue Apr 15 09:37:08 2008
@@ -19,6 +19,8 @@
 
 package org.apache.axis2.jaxws.client.config;
 
+import org.apache.axis2.Constants;
+import org.apache.axis2.description.Parameter;
 import org.apache.axis2.jaxws.ExceptionFactory;
 import org.apache.axis2.jaxws.binding.SOAPBinding;
 import org.apache.axis2.jaxws.core.MessageContext;
@@ -68,49 +70,22 @@
             // Enable MTOM
             requestMsg.setMTOMEnabled(true);
             
-            
             if (threshold <= 0) {
                 if (log.isDebugEnabled()) {
                     log.debug("Enabling MTOM with no threshold.");
                 }             
-            }
-            else if (attachmentIDs != null) {
-                // REVIEW This processing will be moved to axiom.
-                // DISABLING FOR NOW
-                /*
-            	long size = 0L;
-            	
-            	for (String attachmentID : attachmentIDs) {
-            	    DataHandler dh = requestMsg.getDataHandler(attachmentID);
-        			
-            	    if (dh != null) {
-            	        DataSource ds = dh.getDataSource();
-            	        InputStream is = null;
-                    	
-            	        try {
-            	            is = ds.getInputStream();
-            	            size += is.available();
-            	        }
-            	        catch (Exception e) {
-            	            throw ExceptionFactory.
-                              makeWebServiceException(Messages.getMessage("mtomAttachErr"),
e);
-                    	}
-                    	finally {
-                    	    try {
-                    	        if (is != null)
-                    	            is.close();
-                    	    }
-                    	    catch (Exception e) {
-                    	        //Nothing to do.
-                    	    }
-                    	}
-            	    }
-            	}
-            	
-            	if (size > threshold) {
-            	    requestMsg.setMTOMEnabled(true);
+            }else{
+                if(log.isDebugEnabled()){
+                	log.debug("MTOM Threshold Value ="+threshold);
                 }
-                */
+                
+                //set MTOM threshold value on message context.
+                //Once MTOM threshold is set on message context it will be
+                //read by SOAPMessageFormatter.writeTo() while writing the attachment
+                //SOAPMessageFormatter will further propogate the threshold value to
+                //Axiom.OMOutputFormat. JAXBAttachmentUnmarshaller will then make 
+                //decision if the attachment should be inlined or optimized.  
+                messageContext.setProperty(Constants.Configuration.MTOM_THRESHOLD, new Integer(threshold));
             }
         }
         else {

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java?rev=648320&r1=648319&r2=648320&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
(original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/SOAPMessageFormatter.java
Tue Apr 15 09:37:08 2008
@@ -26,9 +26,11 @@
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.description.Parameter;
 import org.apache.axis2.transport.MessageFormatter;
 import org.apache.axis2.transport.http.util.URLTemplatingUtil;
 import org.apache.axis2.util.JavaUtils;
+import org.apache.axis2.util.Utils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -52,6 +54,15 @@
             log.debug("  isDoingSWA=" + format.isDoingSWA());
         }
         OMElement element = msgCtxt.getEnvelope();
+        
+        int optimizedThreshold = Utils.getMtomThreshold(msgCtxt);       
+        if(optimizedThreshold > 0){
+        	if(log.isDebugEnabled()){
+        		log.debug("Setting MTOM optimized Threshold Value on OMOutputFormat");
+        	}
+        	format.setOptimizedThreshold(optimizedThreshold);
+        }	        
+
         try {
             if (!(format.isOptimized()) & format.isDoingSWA()) {
                 StringWriter bufferedSOAPBody = new StringWriter();

Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java?rev=648320&r1=648319&r2=648320&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/Utils.java Tue Apr
15 09:37:08 2008
@@ -540,4 +540,21 @@
             });
         }
     }
+    
+    public static int getMtomThreshold(MessageContext msgCtxt){
+    	Integer value = null;         
+        if(!msgCtxt.isServerSide()){                
+	        value = (Integer)msgCtxt.getProperty(Constants.Configuration.MTOM_THRESHOLD);	 
      
+        }else{
+        	Parameter param = msgCtxt.getParameter(Constants.Configuration.MTOM_THRESHOLD);
+        	if(param!=null){
+        		value = (Integer)param.getValue();       		        		
+        	}        	        	
+        }
+        int threshold = (value!=null)?value.intValue():0;
+        if(log.isDebugEnabled()){
+        	log.debug("MTOM optimized Threshold value ="+threshold);
+        }
+        return threshold;
+    }
 }



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


Mime
View raw message