Author: tyrell
Date: Fri Jul 11 09:42:04 2008
New Revision: 19148
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=19148

Log:
Fixing MASHUP-901

Modified:
   trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java

Modified: 
trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/core/src/org/wso2/mashup/utils/MashupUtils.java?rev=19148&r1=19147&r2=19148&view=diff
==============================================================================
--- 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   
Fri Jul 11 09:42:04 2008
@@ -481,9 +481,9 @@
 
         return serviceUiSource;
     }
-    
 
-     /**
+
+    /**
      * Reads a given JS service's Google Gadget UI source directly from the 
physical file. This ensures the availability
      * of the service UI source even when the service is faulty and not 
deployed.
      *
@@ -543,8 +543,10 @@
             ConfigurationContext configurationContext =
                     
ConfigurationContextFactory.createConfigurationContextFromFileSystem(
                             wso2wsasHome + File.separator + 
MashupConstants.WORK_DIRECTORY +
-                            File.separator + MashupConstants.REPO_DIRECTORY, 
wso2wsasHome + File.separator +
-                            MashupConstants.CONF_DIRECTORY + File.separator + 
MashupConstants.ALT_AXIS2);
+                                    File.separator + 
MashupConstants.REPO_DIRECTORY,
+                            wso2wsasHome + File.separator +
+                                    MashupConstants.CONF_DIRECTORY + 
File.separator +
+                                    MashupConstants.ALT_AXIS2);
             ServiceClient client = new ServiceClient(configurationContext, 
null);
             client.engageModule(MashupConstants.RAMPART);
             client.engageModule(MashupConstants.ADDRESSING);
@@ -600,8 +602,10 @@
             ConfigurationContext configurationContext =
                     
ConfigurationContextFactory.createConfigurationContextFromFileSystem(
                             wso2wsasHome + File.separator + 
MashupConstants.WORK_DIRECTORY +
-                                    File.separator + 
MashupConstants.REPO_DIRECTORY, wso2wsasHome + File.separator +
-                                    MashupConstants.CONF_DIRECTORY + 
File.separator + MashupConstants.ALT_AXIS2);
+                                    File.separator + 
MashupConstants.REPO_DIRECTORY,
+                            wso2wsasHome + File.separator +
+                                    MashupConstants.CONF_DIRECTORY + 
File.separator +
+                                    MashupConstants.ALT_AXIS2);
             RPCServiceClient client = new 
RPCServiceClient(configurationContext, null);
             client.engageModule(MashupConstants.RAMPART);
             client.engageModule(MashupConstants.ADDRESSING);
@@ -997,12 +1001,32 @@
         resource1.setMediaType(mediaType);
         if (faulty) {
             resource1.setProperty(MashupConstants.FAULTY_MASHUP, "true");
+        } else {
+            // Checking whether we have a duplicate registry entry fix for 
MASHUP-901
+            try {
+                ServerManager serverManager = ServerManager.getInstance();
+                ConfigurationContext configContext = 
serverManager.configContext;
+
+                Hashtable faulties = 
configContext.getAxisConfiguration().getFaultyServices();
+
+                Iterator iterator = faulties.keySet().iterator();
+
+                while (iterator.hasNext()) {
+                    if (iterator.next().equals(file.getAbsolutePath())) {
+                        faulties.remove(file.getAbsolutePath());
+                        // Removing from the registry
+                        userRegistry.delete(inferPathFromFileName(username, 
file.getName()));
+                    }
+                }
+            } catch (NullPointerException e) {
+                // Sometimes at the very first startup a NPE is thrown 
swallowing it since it cures itself in the next startup
+            }
         }
 
-        //Setting the service js file path and resources directory path
+        // Setting the service js file path and resources directory path
         resource1.setProperty(serviceType, file.getAbsolutePath());
 
-        //Setting the MD5 of the content
+        // Setting the MD5 of the content
         resource1.setProperty(MashupConstants.CONTENT_MD5, 
MashupUtils.calculateFileMD5(file));
 
         File resourcesDir = new File(currentFile.getFile().getParent(), 
DescriptionBuilder
@@ -1014,6 +1038,10 @@
         userRegistry.put(path1, resource1);
     }
 
+    public static String inferPathFromFileName(String userName, String 
fileName) {
+        return "/mashups/" + userName + "/" + fileName.substring(0, 
fileName.indexOf("."));
+    }
+
     public static String inferUserName(File file, UserRealm realm, String 
serviceName)
             throws MashupFault {
         String username = file.getParentFile().getName();
@@ -1068,17 +1096,17 @@
         }
 
         TransportInDescription httpTransport = 
configuration.getTransportIn("http");
-            Parameter parameter = httpTransport.getParameter("proxyPort");
-            String port = "";
-            if (parameter != null) {
-                String value = (String) parameter.getValue();
-                if (!"80".equals(value)) {
-                    port = ":" + value;
-                }
-            } else {
-                port = ":" + serverManager.getHttpPort();
+        Parameter parameter = httpTransport.getParameter("proxyPort");
+        String port = "";
+        if (parameter != null) {
+            String value = (String) parameter.getValue();
+            if (!"80".equals(value)) {
+                port = ":" + value;
             }
-            return "http://"; + serverName + port;
+        } else {
+            port = ":" + serverManager.getHttpPort();
+        }
+        return "http://"; + serverName + port;
     }
 
     /**
@@ -1147,7 +1175,7 @@
     }
 
     public static KeyStore getUserKeyStore(String userName) throws MashupFault 
{
-             FileInputStream ksIn = null;
+        FileInputStream ksIn = null;
         BufferedInputStream ksbufin = null;
         OutputStream os = null;
         String keyStoreName = userName + MashupConstants.KEY_STORE_SUFFIX;
@@ -1197,7 +1225,7 @@
         }
     }
 
-   /**
+    /**
      * Gets all certificates from a user's keystore
      *
      * @param userName The name of the user
@@ -1287,7 +1315,8 @@
     /**
      * Given a HTTPMethod and a target this utility method fetches the 
resource for you. It will
      * take care of setting the user keyStore and stuff when the url is https.
-     * @param method The HTTP Method instance
+     *
+     * @param method    The HTTP Method instance
      * @param targetURL - The target URL to invoke
      * @return The statusCode as an int
      * @throws IOException Thrown in case any exception occurrs
@@ -1345,6 +1374,7 @@
 
     /**
      * Cleans HTML input based on a set of pre-configured policies, returning 
the cleaned HTML content.
+     *
      * @param htmlContent The raw HTML entered by the user.
      * @return Safe HTML for storing in registry.
      */
@@ -1354,7 +1384,7 @@
         try {
             org.owasp.validator.html.Policy policy =
                     org.owasp.validator.html.Policy.getInstance(wso2wsasHome + 
File.separator +
-                    "conf" + File.separator +"antisamy-mashup-1.0.xml");
+                            "conf" + File.separator + 
"antisamy-mashup-1.0.xml");
             AntiSamy as = new AntiSamy();
             CleanResults cr = as.scan(htmlContent, policy);
             cleanHtml = cr.getCleanHTML();
@@ -1391,7 +1421,7 @@
             // parameters to the service ServiceName string, service file name,
             // dataHandler of the bundled archive
             Object[] parameters = new Object[] { serviceName };
-            Class[] result = new Class[] { SecurityScenarioDO[].class};
+            Class[] result = new Class[] { SecurityScenarioDO[].class };
             Object[] objects = serviceClient.invokeBlocking(operation, 
parameters, result);
             return (SecurityScenarioDO[]) objects[0];
         } catch (AxisFault axisFault) {
@@ -1401,6 +1431,7 @@
 
     /**
      * Calculates the period for which the 'remember me' cookie has to be 
retained.
+     *
      * @param rememberForever Whether to remember for an extended period or 
the default time span.
      * @return time to remember, in seconds.
      */

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

Reply via email to