Author: keith
Date: Wed Jan 16 22:17:21 2008
New Revision: 12378

Log:

Moving more logic to secured service.



Modified:
   
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
   
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
   trunk/mashup/java/modules/www/js/services.js

Modified: 
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
==============================================================================
--- 
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
   (original)
+++ 
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
   Wed Jan 16 22:17:21 2008
@@ -16,15 +16,131 @@
 package org.wso2.mashup.admin.service;
 
 import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
 import org.wso2.javascript.rhino.JavaScriptEngineConstants;
+import org.wso2.wsas.ServerManager;
 
 import java.io.File;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
 
 public class MashupAdminService {
 
+    public Boolean saveServiceSource(String path, String modifiedSource) {
+        boolean success = false;
+
+        try {
+
+            String[] pathContents = path.split("/");
+
+            // Extracting the service author from the path.
+            // Not using the registry here on purpose to allow saving the 
service source even when it's undeployed.
+            String author = pathContents[2];
+
+            //todo Add verification and validation routines to ensure only the 
author of the service and admins can write.
+
+            //Extracting the real path from the registry path provided
+            path = "";
+            for (int x = 2; x < pathContents.length; x++) {
+                path = path + "/" + pathContents[x];
+            }
+
+            ServerManager serverManager = ServerManager.getInstance();
+            ConfigurationContext configContext = serverManager.configContext;
+
+            File serviceJs = new 
File(configContext.getRealPath(configContext.getContextRoot()) +
+                    "/scripts/" + path + ".js");
+
+            //Writing the file with the source provided
+            BufferedWriter out = new BufferedWriter(new FileWriter(serviceJs));
+            out.write(modifiedSource);
+            out.flush();
+            out.close();
+            success = true;
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return Boolean.valueOf(success);
+    }
+
+    public Boolean saveUiSource(String path, String modifiedSource) {
+        boolean success = false;
+
+        try {
+
+            //Extracting the real path from the registry path provided
+            String[] pathContents = path.split("/");
+            path = "";
+            for (int x = 2; x < pathContents.length; x++) {
+                path = path + "/" + pathContents[x];
+            }
+
+            String serviceName = pathContents[pathContents.length - 1];
+
+            ServerManager serverManager = ServerManager.getInstance();
+            ConfigurationContext configContext = serverManager.configContext;
+
+            File wwwDir =
+                    new 
File(configContext.getRealPath(configContext.getContextRoot()) +
+                            "/scripts/" + path + ".resources/www");
+
+            if (!wwwDir.exists()) {
+                wwwDir.mkdirs();
+            }
+
+            //Getting the html file
+            File uiHtmlFile = new File(wwwDir, "index.htm");
+
+            if (!uiHtmlFile.exists()) {
+                uiHtmlFile = new File(wwwDir, "index.html");
+            }
+
+            //Writing the file with the source provided
+            BufferedWriter out = new BufferedWriter(new 
FileWriter(uiHtmlFile));
+            out.write(modifiedSource);
+            out.flush();
+            out.close();
+            success = true;
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return Boolean.valueOf(success);
+    }
+
+    public Boolean redeployService(String serviceName) {
+        boolean success = false;
+
+        MessageContext currentMessageContext = 
MessageContext.getCurrentMessageContext();
+        AxisConfiguration configuration =
+                currentMessageContext.getAxisService().getAxisConfiguration();
+
+        try {
+            AxisService mashupService = configuration.getService(serviceName);
+
+            Parameter serviceJSParameter = mashupService
+                    .getParameter(JavaScriptEngineConstants.SERVICE_JS);
+
+            if (serviceJSParameter != null && serviceJSParameter.getValue() != 
null) {
+                File serviceJS = (File) serviceJSParameter.getValue();
+                long time = System.currentTimeMillis();
+                serviceJS.setLastModified(time);
+                success = true;
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+        return Boolean.valueOf(success);
+    }
+
     public Boolean deleteService(String serviceName) {
         boolean success = false;
 

Modified: 
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
==============================================================================
--- 
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
       (original)
+++ 
trunk/mashup/java/modules/coreservices/servicemetadatalister/src/org/wso2/mashup/coreservices/servicemetadatalister/ServiceMetaDataListerService.java
       Wed Jan 16 22:17:21 2008
@@ -215,172 +215,10 @@
     }
 
 
-    public Boolean saveServiceSource(String path, String modifiedSource) {
-        boolean success = false;
-
-        try {
-
-            String[] pathContents = path.split("/");
-
-            // Extracting the service author from the path.
-            // Not using the registry here on purpose to allow saving the 
service source even when it's undeployed.
-            String author = pathContents[2];
-
-            //todo Add verification and validation routines to ensure only the 
author of the service and admins can write.
-
-            //Extracting the real path from the registry path provided
-            path = "";
-            for (int x = 2; x < pathContents.length; x++) {
-                path = path + "/" + pathContents[x];
-            }
-
-            ServerManager serverManager = ServerManager.getInstance();
-            ConfigurationContext configContext = serverManager.configContext;
-
-            File serviceJs = new 
File(configContext.getRealPath(configContext.getContextRoot()) +
-                    "/scripts/" + path + ".js");
-
-            //Writing the file with the source provided
-            BufferedWriter out = new BufferedWriter(new FileWriter(serviceJs));
-            out.write(modifiedSource);
-            out.flush();
-            out.close();
-            success = true;
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        return Boolean.valueOf(success);
-    }
-
-    public Boolean saveUiSource(String path, String modifiedSource) {
-        boolean success = false;
-
-        try {
-
-            //Extracting the real path from the registry path provided
-            String[] pathContents = path.split("/");
-            path = "";
-            for (int x = 2; x < pathContents.length; x++) {
-                path = path + "/" + pathContents[x];
-            }
-
-            String serviceName = pathContents[pathContents.length - 1];
-
-            ServerManager serverManager = ServerManager.getInstance();
-            ConfigurationContext configContext = serverManager.configContext;
-
-            File wwwDir =
-                    new 
File(configContext.getRealPath(configContext.getContextRoot()) +
-                            "/scripts/" + path + ".resources/www");
-
-            if (!wwwDir.exists()) {
-                wwwDir.mkdirs();
-            }
-
-            //Getting the html file
-            File uiHtmlFile = new File(wwwDir, "index.htm");
-
-            if (!uiHtmlFile.exists()) {
-                uiHtmlFile = new File(wwwDir, "index.html");
-            }
-
-            //Writing the file with the source provided
-            BufferedWriter out = new BufferedWriter(new 
FileWriter(uiHtmlFile));
-            out.write(modifiedSource);
-            out.flush();
-            out.close();
-            success = true;
-
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        return Boolean.valueOf(success);
-    }
-
-    public Boolean redeployService(String serviceName) {
-        boolean success = false;
-
-        MessageContext currentMessageContext = 
MessageContext.getCurrentMessageContext();
-        AxisConfiguration configuration =
-                currentMessageContext.getAxisService().getAxisConfiguration();
-
-        try {
-            AxisService mashupService = configuration.getService(serviceName);
-
-            Parameter serviceJSParameter = mashupService
-                    .getParameter(JavaScriptEngineConstants.SERVICE_JS);
-
-            if (serviceJSParameter != null && serviceJSParameter.getValue() != 
null) {
-                File serviceJS = (File) serviceJSParameter.getValue();
-                long time = System.currentTimeMillis();
-                serviceJS.setLastModified(time);
-                success = true;
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-
-        return Boolean.valueOf(success);
-    }
-
-    public Boolean deleteService(String serviceName) {
-        boolean success = false;
-
-        MessageContext currentMessageContext = 
MessageContext.getCurrentMessageContext();
-        AxisConfiguration configuration =
-                currentMessageContext.getAxisService().getAxisConfiguration();
-
-        try {
-            AxisService mashupService = configuration.getService(serviceName);
-
-            Parameter serviceJSParameter = mashupService
-                    .getParameter(JavaScriptEngineConstants.SERVICE_JS);
-            Parameter serviceResourcesDir =
-                    
mashupService.getParameter(JavaScriptEngineConstants.RESOURCES_FOLDER);
-
-            if (serviceJSParameter != null && serviceJSParameter.getValue() != 
null) {
-                File serviceJS = (File) serviceJSParameter.getValue();
-                File serviceReources = (File) serviceResourcesDir.getValue();
-                success = serviceJS.delete();
-
-                //On successful deletion of the service, deleting the 
resources directory
-                if (success) {
-                    success = deleteDir(serviceReources);
-                }
-            }
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-
-        return Boolean.valueOf(success);
-    }
-
-
-    private static boolean deleteDir(File dir) {
-        if (dir.isDirectory()) {
-            String[] children = dir.list();
-            for (int i = 0; i < children.length; i++) {
-                boolean success = deleteDir(new File(dir, children[i]));
-                if (!success) {
-                    return false;
-                }
-            }
-        }
-
-        // The directory is now empty so delete it
-        return dir.delete();
-    }
-
-
     public String isPossibleToCreate(String servicePath) {
         return MashupUtils.isPossibleToCreateService(servicePath);
     }
 
-
     public SharingDataService[] getSharableServices() {
 
         SharingDataService[] retServiceArray = null;
@@ -422,7 +260,6 @@
         return retServiceArray;
     }
 
-
     public Service[] getFaultyServices() {
         Hashtable faulties =
                 MashupUtils.getFaultyServices();      // enumerate all the 
contents of the hashtable

Modified: trunk/mashup/java/modules/www/js/services.js
==============================================================================
--- trunk/mashup/java/modules/www/js/services.js        (original)
+++ trunk/mashup/java/modules/www/js/services.js        Wed Jan 16 22:17:21 2008
@@ -333,14 +333,14 @@
  */
 wso2.mashup.services.saveServiceSource = function (path, modifiedSource, 
callback, params) {
 
-    var callURL = serverURL + "/" + "ServiceMetaDataLister" + "/" ;
+    var callURL = serverURL + "/" + "MashupAdminService" + "/" ;
 
     var serviceSource = "<![CDATA[" + modifiedSource + "]]>";
 
-    var body_xml = '<req:saveServiceSourceOpRequest 
xmlns:req="http://servicemetadatalister.coreservices.mashup.wso2.org/xsd";>\n' +
+    var body_xml = '<req:saveServiceSource 
xmlns:req="http://service.admin.mashup.wso2.org/xsd";>\n' +
                    ' <req:path>' + path + '</req:path>\n' +
                    ' <req:modifiedSource>' + serviceSource + 
'</req:modifiedSource>\n' +
-                   ' </req:saveServiceSourceOpRequest>\n';
+                   ' </req:saveServiceSource>\n';
 
     new wso2.wsf.WSRequest(callURL, "saveServiceSource", body_xml, callback, 
params, wso2.mashup.services.defaultErrHandler);
 };
@@ -353,14 +353,14 @@
  * @param {callback} params    Parameters to be set in the callback
  */
 wso2.mashup.services.saveUiSource = function (path, modifiedSource, callback, 
params) {
-    var callURL = serverURL + "/" + "ServiceMetaDataLister" + "/" ;
+    var callURL = serverURL + "/" + "MashupAdminService" + "/" ;
 
     var serviceSource = "<![CDATA[" + modifiedSource + "]]>";
 
-    var body_xml = '<req:saveUiSourceOpRequest 
xmlns:req="http://servicemetadatalister.coreservices.mashup.wso2.org/xsd";>\n' +
+    var body_xml = '<req:saveUiSource 
xmlns:req="http://service.admin.mashup.wso2.org/xsd";>\n' +
                    ' <req:path>' + path + '</req:path>\n' +
                    ' <req:modifiedSource>' + serviceSource + 
'</req:modifiedSource>\n' +
-                   ' </req:saveUiSourceOpRequest>\n';
+                   ' </req:saveUiSource>\n';
 
     new wso2.wsf.WSRequest(callURL, "saveUiSource", body_xml, callback, 
params, wso2.mashup.services.defaultErrHandler);
 };
@@ -386,11 +386,11 @@
  * @param {callback} callback User-defined callback function or object
  */
 wso2.mashup.services.reDeployService = function (serviceName, callback) {
-    var callURL = serverURL + "/" + "ServiceMetaDataLister" + "/" ;
+    var callURL = serverURL + "/" + "MashupAdminService" + "/" ;
 
-    var body_xml = '<req:redeployServiceOpRequest 
xmlns:req="http://servicemetadatalister.coreservices.mashup.wso2.org/xsd";>\n' +
+    var body_xml = '<req:redeployService 
xmlns:req="http://service.admin.mashup.wso2.org/xsd";>\n' +
                    ' <req:serviceName>' + serviceName + '</req:serviceName>\n' 
+
-                   ' </req:redeployServiceOpRequest>\n';
+                   ' </req:redeployService>\n';
 
     new wso2.wsf.WSRequest(callURL, "redeployService", body_xml, callback, "", 
wso2.mashup.services.defaultErrHandler);
 };

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to