Author: keith
Date: Tue Jan 15 10:42:12 2008
New Revision: 12290

Log:

Adding faulty services into the registry. Part fix for Mashup-503. Need to fix 
up the UI now.



Modified:
   trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
   
trunk/mashup/java/modules/javascriptdeployer/src/org/wso2/mashup/deployer/JSDeployer.java

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java
==============================================================================
--- trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
(original)
+++ trunk/mashup/java/modules/core/src/org/wso2/mashup/MashupConstants.java     
Tue Jan 15 10:42:12 2008
@@ -97,4 +97,6 @@
     public static final String MASHUP_ADMIN_SERVICEIC = "MashupAdminServiceUT";
     public static final String USER_LOGGED_IN = "UserLoggedIn";
     public static final String INITIAL_SETUP_COMPLETE = 
"initial_setup_complete";
+
+    public static final String FAULTY_MASHUP = "faulty_mashup";
 }

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 15 10:42:12 2008
@@ -185,6 +185,9 @@
             if (serviceStatus.startsWith("Error:")) {
                 
axisConfig.getFaultyServices().put(deploymentFileData.getFile().getAbsolutePath(),
                                                    serviceStatus);
+                populateRegistry(deploymentFileData, "This Service is Faulty. 
Reason : " + serviceStatus,
+                        
DescriptionBuilder.getShortFileName(deploymentFileData.getName()), true);
+
             }
         }
     }
@@ -270,18 +273,12 @@
             // we get the filename without the extension
             String shortFileName = 
DescriptionBuilder.getShortFileName(currentFile.getName());
 
-            // Get the realm and the registry
-            JDBCRegistry registry =
-                    (JDBCRegistry) 
configCtx.getAxisConfiguration().getParameterValue(
-                            RegistryConstants.REGISTRY);
-            Realm realm = (Realm) 
configCtx.getAxisConfiguration().getParameterValue(
-                    RegistryConstants.REGISTRY_REALM);
-
             AxisService axisService = new AxisService();
 
             // org.wso2.javascript.rhino.JavaScriptReceiver needs this to load 
the javascript file
+            File file = currentFile.getFile();
             Parameter serviceJSParameter = new 
Parameter(JavaScriptEngineConstants.SERVICE_JS,
-                                                         
currentFile.getFile());
+                    file);
             axisService.addParameter(serviceJSParameter);
 
             // Mashup UI uses this information to differentiate services when 
listing them.
@@ -301,7 +298,7 @@
 
             // Creating the service.resources dir
             // For more details see 
http://www.wso2.org/wiki/display/mashup/scripts+folder+structure+and+deployment
-            File parentDir = currentFile.getFile().getParentFile();
+            File parentDir = file.getParentFile();
             File resourcesDir = new File(parentDir, shortFileName + 
".resources");
             resourcesDir.mkdir();
             // Add a reference to the resources folder, as this is quite 
usefull in the runtime
@@ -327,7 +324,7 @@
             JavaScriptEngineUtils.loadGlobalPropertyObjects(engine, configCtx
                     .getAxisConfiguration());
             FileInputStream fileInputStream;
-            fileInputStream = new FileInputStream(currentFile.getFile());
+            fileInputStream = new FileInputStream(file);
             // load the service java script file 
             engine.evaluate(new BufferedReader(new 
InputStreamReader(fileInputStream)));
 
@@ -343,8 +340,10 @@
             String name = serviceAnnotationParser.getServiceName();
             MashupUtils.validateName(name, "ServiceName");
 
+            Realm realm = (Realm) 
configCtx.getAxisConfiguration().getParameterValue(
+                    RegistryConstants.REGISTRY_REALM);
             // Infer the username (The owner of this service)
-            String username = inferUserName(currentFile.getFile(), realm, 
name);
+            String username = inferUserName(file, realm, name);
 
             //create a service group per service.
             // ServiceGroup name and axisservice name will be of the form 
username-serviceName
@@ -432,13 +431,44 @@
 
             // We are putting the service into the registry here
 
+            String path = populateRegistry(currentFile, 
axisService.getDocumentation(), name, false);
+            //Storing the registry path as a service parameter, to be used at 
undeployment time
+            //to remove the service from registry
+            Parameter myRegistryPath = new 
Parameter(MashupConstants.REGISTRY_MASHUP_PATH, path);
+            axisService.addParameter(myRegistryPath);
+
+            ArrayList serviceList = new ArrayList();
+            serviceList.add(axisService);
+            return serviceList;
+        } catch (FileNotFoundException e) {
+            throw new DeploymentException("JS Service File Not Found", e);
+        } catch (IOException e) {
+            throw new DeploymentException(e);
+        } catch (SchedulerException e) {
+            throw new DeploymentException("Failed to initiate the functin 
scheduler", e);
+        }
+    }
+
+    private String populateRegistry(DeploymentFileData currentFile, String 
documentation, String name, boolean faulty)
+            throws DeploymentException {
+
+        try {
+            Realm realm = (Realm) 
configCtx.getAxisConfiguration().getParameterValue(
+                        RegistryConstants.REGISTRY_REALM);
+            File file = currentFile.getFile();
+            // Infer the username (The owner of this service)
+            String username = inferUserName(file, realm, name);
+
+            // Get the realm and the registry
+            JDBCRegistry registry =
+                    (JDBCRegistry) 
configCtx.getAxisConfiguration().getParameterValue(
+                            RegistryConstants.REGISTRY);
             SecureRegistry secureRegistry = new SecureRegistry(username, 
registry, realm);
 
             // create a content resource
             Resource resource1 = new Resource();
 
             resource1.setAuthorUserName(username);
-            File file = currentFile.getFile();
             FileInputStream fis = new FileInputStream(file);
             FileChannel fc = fis.getChannel();
             byte[] data =
@@ -446,32 +476,23 @@
             ByteBuffer bb = ByteBuffer.wrap(data);
             fc.read(bb);
             resource1.setContent(data);
-            resource1.setDescription(axisService.getDocumentation());
+            resource1.setDescription(documentation);
             resource1.setMediaType(MashupConstants.MASHUP_MEDIA_TYPE);
+            if (faulty) {
+                resource1.setProperty(MashupConstants.FAULTY_MASHUP, "true");
+            }
             // store it in a non existence path
             String path1 = "/mashups/" + username + "/" + name;
             secureRegistry.put(path1, resource1);
 
-            //Storing the registry path as a service parameter, to be used at 
undeployment time
-            //to remove the service from registry
-            Parameter myRegistryPath = new 
Parameter(MashupConstants.REGISTRY_MASHUP_PATH, path1);
-            axisService.addParameter(myRegistryPath);
-
             AccessControlAdmin ac = realm.getAccessControlAdmin();
             ac.authorizeUser(username, path1, UserManagerConstants.EDIT);
             ac.authorizeUser(username, path1, UserManagerConstants.DELETE);
-
-            ArrayList serviceList = new ArrayList();
-            serviceList.add(axisService);
-            return serviceList;
-        } catch (FileNotFoundException e) {
-            throw new DeploymentException("JS Service File Not Found", e);
-        } catch (IOException e) {
-            throw new DeploymentException(e);
-        } catch (SchedulerException e) {
-            throw new DeploymentException("Failed to initiate the functin 
scheduler", e);
+            return path1;
         } catch (RegistryException e) {
             throw new DeploymentException(e);
+        } catch (IOException e) {
+            throw new DeploymentException(e);
         } catch (UserManagerException e) {
             throw new DeploymentException(e);
         }

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

Reply via email to