[mashup-dev] svn commit r4610 - in trunk/mashup/java/modules/coreservices/sharingservice: META-INF src/org/wso2/mashup/share/service

svn at wso2.org svn at wso2.org
Sun Jul 1 22:59:59 PDT 2007


Author: thilina
Date: Sun Jul  1 22:58:32 2007
New Revision: 4610

Modified:
   trunk/mashup/java/modules/coreservices/sharingservice/META-INF/services.xml
   trunk/mashup/java/modules/coreservices/sharingservice/src/org/wso2/mashup/share/service/MashupSharingService.java
Log:
adding mashup service downloading ability

Modified: trunk/mashup/java/modules/coreservices/sharingservice/META-INF/services.xml
==============================================================================
--- trunk/mashup/java/modules/coreservices/sharingservice/META-INF/services.xml	(original)
+++ trunk/mashup/java/modules/coreservices/sharingservice/META-INF/services.xml	Sun Jul  1 22:58:32 2007
@@ -1,5 +1,9 @@
 <serviceGroup>
 	<service name="MashupSharingService">
+		<description>This service facilitates the sharing of Mashup services between servers.</description>
 		<parameter name="ServiceClass">org.wso2.mashup.share.service.MashupSharingService</parameter>
+		<operation name="getMashup">
+			<parameter name="enableMTOM">true</parameter>
+		</operation>
 	</service>
 </serviceGroup>
\ No newline at end of file

Modified: trunk/mashup/java/modules/coreservices/sharingservice/src/org/wso2/mashup/share/service/MashupSharingService.java
==============================================================================
--- trunk/mashup/java/modules/coreservices/sharingservice/src/org/wso2/mashup/share/service/MashupSharingService.java	(original)
+++ trunk/mashup/java/modules/coreservices/sharingservice/src/org/wso2/mashup/share/service/MashupSharingService.java	Sun Jul  1 22:58:32 2007
@@ -18,7 +18,6 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.net.URL;
 
 import javax.activation.DataHandler;
 
@@ -26,12 +25,16 @@
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.MessageContext;
 import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.Parameter;
 import org.apache.axis2.engine.AxisConfiguration;
+import org.wso2.javascript.rhino.JavaScriptEngineConstants;
+import org.wso2.mashup.MashupFault;
+import org.wso2.mashup.utils.DownloadServiceResponse;
 import org.wso2.mashup.utils.MashupArchiveManupulator;
 
 /**
- * This allows the other mashup services to share their Mashup services with
- * this server. Mashups are uploaded as a bundled archive using MTOM.
+ * This service facilitates the sharing of Mashup services deplyoed in this server with other Mashup servers. 
+ * Mashups are uploaded and downloaded as bundled archives using MTOM.
  */
 public class MashupSharingService {
 
@@ -53,8 +56,11 @@
      * @throws FileNotFoundException
      * @throws IOException
      */
-    public boolean shareMashup(String serviceName, String fileName, DataHandler dataHandler)
+    public void shareMashup(String serviceName, String fileName, DataHandler dataHandler)
             throws FileNotFoundException, IOException {
+        if (dataHandler == null) {
+            throw new MashupFault("Cannot read the uploaded Mashup Service.");
+        }
         MessageContext messageContext = MessageContext.getCurrentMessageContext();
         AxisConfiguration axisConfiguration = messageContext.getConfigurationContext()
                 .getAxisConfiguration();
@@ -62,25 +68,8 @@
             throw new AxisFault(
                     "A Service with a same name already exists in the remote Mashup Server.");
         }
-        URL repository = axisConfiguration.getRepository();
-        if (repository != null && dataHandler != null) {
-            // Access the scripts deployment folder
-            File repo = new File(repository.getFile());
-            File scriptsFolder = new File(repo, "scripts");
-
-            // Checking whether a file with the same name exists
-            File file = new File(scriptsFolder, fileName);
-            if (file.exists()) {
-                throw new AxisFault(
-                        "A Service JavaScript file with the same name already exists in the remote Mashup Server.");
-            }
-            MashupArchiveManupulator archiveManupulator = new MashupArchiveManupulator();
-            // Extract the uploaded mashup archive to the scripts folder.
-            archiveManupulator.extractFromStream(dataHandler.getInputStream(), scriptsFolder
-                    .getAbsolutePath());
-            return true;
-        }
-        return false;
+        MashupArchiveManupulator archiveManupulator = new MashupArchiveManupulator();
+        archiveManupulator.deploySharedService(fileName, dataHandler, axisConfiguration);
     }
 
     /**
@@ -90,13 +79,21 @@
      * @return DataHandler containing an archived Mashup Service
      * @throws IOException
      */
-    public DataHandler getMashupService(String serviceName) throws IOException {
+    public DownloadServiceResponse getMashup(String serviceName) throws IOException {
         ConfigurationContext configurationContext = MessageContext.getCurrentMessageContext()
                 .getConfigurationContext();
         AxisConfiguration axisConfiguration = configurationContext.getAxisConfiguration();
         AxisService service = axisConfiguration.getService(serviceName);
+        if(service==null){
+            throw new MashupFault("Requested Mashup service cannot be found in the remote Mashup server.");
+        }
         MashupArchiveManupulator mashupArchiveManupulator = new MashupArchiveManupulator();
-        return mashupArchiveManupulator.createMashupArchiveDataHandler(service,
-                configurationContext);
+        DataHandler mashupServiceDataHandler = mashupArchiveManupulator
+                .createMashupArchiveDataHandler(service, configurationContext);
+        Parameter serviceJSParameter = service.getParameter(JavaScriptEngineConstants.SERVICE_JS);
+        // We do not need to check for Null or whether this is a file as we have
+        // already checked it inside the createMashupArchiveDataHandler method.
+        File serviceJS = (File) serviceJSParameter.getValue();
+        return new DownloadServiceResponse(serviceJS.getName(), mashupServiceDataHandler);
     }
 }




More information about the Mashup-dev mailing list