Author: tyrell
Date: Tue Jan 22 04:35:03 2008
New Revision: 12677

Log:

Changing mashup editor and backend services to take the service js file path 
from the registry first and fallback to the manual method on exceptions only.

Modified:
   
trunk/mashup/java/modules/admin/service/src/org/wso2/mashup/admin/service/MashupAdminService.java
   trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
   
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java

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
   Tue Jan 22 04:35:03 2008
@@ -45,14 +45,12 @@
 public class MashupAdminService {
 
     public Boolean saveServiceSource(String path, String modifiedSource) 
throws MashupFault {
-        boolean success;
+        boolean success = false;
 
         try {
 
             String[] pathContents = path.split("/");
 
-            //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++) {
@@ -62,8 +60,19 @@
             ServerManager serverManager = ServerManager.getInstance();
             ConfigurationContext configContext = serverManager.configContext;
 
-            File serviceJs = new 
File(configContext.getRealPath(configContext.getContextRoot()) +
-                    "/scripts/" + path + ".js");
+            //First try to get the file path from registry
+            File serviceJs;
+            JDBCRegistry registry =
+                    (JDBCRegistry) 
configContext.getAxisConfiguration().getParameterValue(
+                            RegistryConstants.REGISTRY);
+            try {
+                serviceJs = new File(
+                        
registry.get(path).getProperty(JavaScriptEngineConstants.SERVICE_JS));
+            } catch (RegistryException e) {
+                //If the service is not in registry, let's figure out the path 
manually
+                serviceJs = new 
File(configContext.getRealPath(configContext.getContextRoot()) +
+                        "/scripts/" + path + ".js");
+            }
 
             //Writing the file with the source provided
             BufferedWriter out = new BufferedWriter(new FileWriter(serviceJs));
@@ -82,7 +91,7 @@
     }
 
     public Boolean saveUiSource(String path, String modifiedSource) throws 
MashupFault {
-        boolean success;
+        boolean success = false;
 
         try {
 
@@ -96,9 +105,20 @@
             ServerManager serverManager = ServerManager.getInstance();
             ConfigurationContext configContext = serverManager.configContext;
 
-            File wwwDir =
-                    new 
File(configContext.getRealPath(configContext.getContextRoot()) +
-                            "/scripts/" + path + ".resources/www");
+            File wwwDir;
+            //Trying to get the resources directory path from the registry
+            JDBCRegistry registry =
+                    (JDBCRegistry) 
configContext.getAxisConfiguration().getParameterValue(
+                            RegistryConstants.REGISTRY);
+            try {
+                wwwDir = new File(
+                        
registry.get(path).getProperty(JavaScriptEngineConstants.RESOURCES_FOLDER) +
+                                "/www");
+            } catch (RegistryException e) {
+                //If the service is not in registry, let's figure out the path 
manually
+                wwwDir = new 
File(configContext.getRealPath(configContext.getContextRoot()) +
+                        "/scripts/" + path + ".resources/www");
+            }
 
             if (!wwwDir.exists()) {
                 wwwDir.mkdirs();
@@ -154,7 +174,8 @@
         return Boolean.valueOf(success);
     }
 
-    public Boolean setServiceDocumentation(String serviceName, String 
documentation) throws MashupFault {
+    public Boolean setServiceDocumentation(String serviceName, String 
documentation)
+            throws MashupFault {
         boolean success;
 
         MessageContext currentMessageContext = 
MessageContext.getCurrentMessageContext();
@@ -189,11 +210,14 @@
             success = true;
 
         } catch (AxisFault axisFault) {
-            throw new MashupFault("Cannot change service documentation of 
service " + serviceName, axisFault);
+            throw new MashupFault("Cannot change service documentation of 
service " + serviceName,
+                                  axisFault);
         } catch (ServiceNotFoundException e) {
-            throw new MashupFault("Cannot change service documentation of 
service " + serviceName, e);
+            throw new MashupFault("Cannot change service documentation of 
service " + serviceName,
+                                  e);
         } catch (RegistryException e) {
-            throw new MashupFault("Cannot change service documentation of 
service " + serviceName, e);
+            throw new MashupFault("Cannot change service documentation of 
service " + serviceName,
+                                  e);
         }
 
 
@@ -233,17 +257,20 @@
             persistenceMgr.updateService(serviceDO);
 
         } catch (AxisFault axisFault) {
-            throw new MashupFault("Cannot change operation documentation of " 
+ operationName + " in service " +
-                    serviceName, axisFault);
+            throw new MashupFault(
+                    "Cannot change operation documentation of " + 
operationName + " in service " +
+                            serviceName, axisFault);
         } catch (ServiceNotFoundException e) {
-            throw new MashupFault("Cannot change operation documentation of " 
+ operationName + " in service " +
-                    serviceName, e);
+            throw new MashupFault(
+                    "Cannot change operation documentation of " + 
operationName + " in service " +
+                            serviceName, e);
         }
 
         return Boolean.valueOf(success);
     }
 
-    public Boolean changeOperationStatus(String serviceName, String 
operationName, boolean status) throws MashupFault {
+    public Boolean changeOperationStatus(String serviceName, String 
operationName, boolean status)
+            throws MashupFault {
         boolean success = false;
 
         MessageContext currentMessageContext = 
MessageContext.getCurrentMessageContext();
@@ -263,8 +290,9 @@
             }
 
         } catch (AxisFault axisFault) {
-            throw new MashupFault("Cannot change operation status of " + 
operationName + " in service " + serviceName,
-                    axisFault);
+            throw new MashupFault("Cannot change operation status of " + 
operationName +
+                    " in service " + serviceName,
+                                  axisFault);
         }
 
         return Boolean.valueOf(success);

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java   
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java   
Tue Jan 22 04:35:03 2008
@@ -45,6 +45,10 @@
 import org.wso2.wsas.ServerManager;
 import org.wso2.wsas.persistence.PersistenceManager;
 import org.wso2.wsas.persistence.dataobject.ServiceUserDO;
+import org.wso2.registry.jdbc.JDBCRegistry;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.RegistryException;
+import org.wso2.javascript.rhino.JavaScriptEngineConstants;
 
 import javax.management.*;
 import javax.xml.stream.XMLStreamException;
@@ -310,17 +314,20 @@
         String serviceSource = "The specified mashup was not found on the 
server.";
 
         //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];
-        }
-
         ServerManager serverManager = ServerManager.getInstance();
         ConfigurationContext configContext = serverManager.configContext;
 
-        File serviceJs = new 
File(configContext.getRealPath(configContext.getContextRoot()) +
-                "/scripts/" + path + ".js");
+        JDBCRegistry registry =
+                (JDBCRegistry) 
configContext.getAxisConfiguration().getParameterValue(
+                        RegistryConstants.REGISTRY);
+
+        File serviceJs = null;
+        try {
+            serviceJs = new File(
+                    
registry.get(path).getProperty(JavaScriptEngineConstants.SERVICE_JS));
+        } catch (RegistryException e) {
+            log.error("Failed to read mashup from disk.", e);
+        }
 
         try {
             if (serviceJs.exists()) {
@@ -337,7 +344,7 @@
                 serviceSource = fileData.toString();
             }
         } catch (IOException e) {
-            log.error("Failed to read mashup from disk.");
+            log.error("Failed to read mashup from disk.", e);
         }
 
         return serviceSource;
@@ -355,22 +362,22 @@
         String serviceUiSource =
                 "The custom UI code for the specified mashup was not found on 
the server.";
 
-        //Extracting the real path from the registry path provided
+        //Extracting the service name from the 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];
+        String serviceName = pathContents[3];
 
+        //Extracting the real path from the registry path provided
         ServerManager serverManager = ServerManager.getInstance();
         ConfigurationContext configContext = serverManager.configContext;
-
-        File serviceUiFile = new 
File(configContext.getRealPath(configContext.getContextRoot()) +
-                "/scripts/" + path + ".resources/www/index.html");
-
+        JDBCRegistry registry =
+                (JDBCRegistry) 
configContext.getAxisConfiguration().getParameterValue(
+                        RegistryConstants.REGISTRY);
         try {
+            File serviceUiFile =
+                    new File(registry.get(path)
+                            
.getProperty(JavaScriptEngineConstants.RESOURCES_FOLDER) +
+                            "/www/index.html");
+
             if (serviceUiFile.exists()) {
 
                 StringBuffer fileData = new StringBuffer(1000);
@@ -384,8 +391,10 @@
 
                 serviceUiSource = fileData.toString();
             } else {
-                serviceUiFile = new 
File(configContext.getRealPath(configContext.getContextRoot()) +
-                        "/scripts/" + path + ".resources/www/index.htm");
+                serviceUiFile =
+                        new File(registry.get(path)
+                                
.getProperty(JavaScriptEngineConstants.RESOURCES_FOLDER) +
+                                "/www/index.htm");
 
                 if (serviceUiFile.exists()) {
 
@@ -402,7 +411,9 @@
                 }
             }
         } catch (IOException e) {
-            log.error("Failed to read the mashup's custom ui from disk.");
+            log.error("Failed to read the mashup's custom ui from disk.", e);
+        } catch (RegistryException e) {
+            log.error("Failed to read the mashup's custom ui from disk.", e);
         }
 
         return serviceUiSource;
@@ -575,8 +586,20 @@
         ServerManager serverManager = ServerManager.getInstance();
         ConfigurationContext configContext = serverManager.configContext;
 
-        File serviceJs = new 
File(configContext.getRealPath(configContext.getContextRoot()) +
-                "/scripts/" + decodedServicePath + ".js");
+        //Checking for the file in registry
+        File serviceJs;
+        JDBCRegistry registry =
+                (JDBCRegistry) 
configContext.getAxisConfiguration().getParameterValue(
+                        RegistryConstants.REGISTRY);
+        try {
+            serviceJs = new File(
+                    registry.get(decodedServicePath).getProperty(
+                            JavaScriptEngineConstants.SERVICE_JS));
+        } catch (RegistryException e) {
+            //If the service is not in registry, let's figure out the path 
manually
+            serviceJs = new 
File(configContext.getRealPath(configContext.getContextRoot()) +
+                    "/scripts/" + decodedServicePath + ".js");
+        }
 
         if (serviceJs.exists()) {
             success = "A service with the name you specified (" + serviceName +

Modified: 
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
==============================================================================
--- 
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
   (original)
+++ 
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java
   Tue Jan 22 04:35:03 2008
@@ -455,7 +455,12 @@
             if (faulty) {
                 resource1.setProperty(MashupConstants.FAULTY_MASHUP, "true");
             }
+
+            //Setting the service js file path and resources directory path
             resource1.setProperty(JavaScriptEngineConstants.SERVICE_JS, 
file.getAbsolutePath());
+            File resourcesDir = new File(currentFile.getFile().getParent(), 
DescriptionBuilder.getShortFileName(currentFile.getName()) + ".resources");
+            resource1.setProperty(JavaScriptEngineConstants.RESOURCES_FOLDER, 
resourcesDir.getAbsolutePath());
+
             // store it in a non existence path
             String path1 = "/mashups/" + username + "/" + name;
             secureRegistry.put(path1, resource1);

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

Reply via email to