[Registry-dev] svn commit r6701 - in trunk/registry/java/modules: core/src/main/java/org/wso2/registry core/src/main/java/org/wso2/registry/inmemory core/src/main/java/org/wso2/registry/servlet core/src/main/java/org/wso2/registry/servlet/actions webapps/conf

svn at wso2.org svn at wso2.org
Thu Aug 30 02:46:15 PDT 2007


Author: deepal
Date: Thu Aug 30 02:45:49 2007
New Revision: 6701

Modified:
   trunk/registry/java/modules/core/src/main/java/org/wso2/registry/Constants.java
   trunk/registry/java/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistryProvider.java
   trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
   trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/actions/GetResourceActionProcessor.java
   trunk/registry/java/modules/webapps/conf/web.xml
Log:
WOW , now we have working rest support for directory listing 

Modified: trunk/registry/java/modules/core/src/main/java/org/wso2/registry/Constants.java
==============================================================================
--- trunk/registry/java/modules/core/src/main/java/org/wso2/registry/Constants.java	(original)
+++ trunk/registry/java/modules/core/src/main/java/org/wso2/registry/Constants.java	Thu Aug 30 02:45:49 2007
@@ -32,4 +32,11 @@
     public static final String SESSION_PROPERTY = "SessionObject";
     public static final String TAG_REGISTRY = "/registry";
     public static final String ACTION = "action";
+
+
+    // Directory listing
+    public static final String DIRECTORY ="directory";
+    public static final String FILE ="file";
+    public static final String ATT_NAME ="name";
+
 }

Modified: trunk/registry/java/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistryProvider.java
==============================================================================
--- trunk/registry/java/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistryProvider.java	(original)
+++ trunk/registry/java/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistryProvider.java	Thu Aug 30 02:45:49 2007
@@ -57,6 +57,7 @@
 
     public InMemoryRegistryProvider() {
         Directory root = new Directory();
+        root.setPath(Constants.ROOT_PATH);
         registry.put(Constants.ROOT_PATH, root);
     }
 

Modified: trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
==============================================================================
--- trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java	(original)
+++ trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java	Thu Aug 30 02:45:49 2007
@@ -21,9 +21,9 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.wso2.registry.Actions;
 import org.wso2.registry.Constants;
 import org.wso2.registry.RegistryContext;
-import org.wso2.registry.Actions;
 import org.wso2.registry.engine.RegistrySessionContext;
 import org.wso2.registry.i18n.Messages;
 
@@ -45,6 +45,9 @@
 
     private RegistryContext registryContext = null;
 
+    //To store the conetxt path
+    private String contextRoot = null;
+
     public void init(ServletConfig config) throws ServletException {
         super.init(config);
 
@@ -66,31 +69,37 @@
     protected void doPost(HttpServletRequest httpServletRequest,
                           HttpServletResponse httpServletResponse)
             throws ServletException, IOException {
+        initContextRoot(httpServletRequest);
         super.doPost(httpServletRequest, httpServletResponse);
     }
 
     protected void doPut(HttpServletRequest httpServletRequest,
                          HttpServletResponse httpServletResponse)
             throws ServletException, IOException {
+        initContextRoot(httpServletRequest);
         super.doPut(httpServletRequest, httpServletResponse);
     }
 
     protected void doDelete(HttpServletRequest httpServletRequest,
                             HttpServletResponse httpServletResponse)
             throws ServletException, IOException {
+        initContextRoot(httpServletRequest);
         super.doDelete(httpServletRequest, httpServletResponse);
     }
 
     protected void doGet(HttpServletRequest request,
                          HttpServletResponse response)
             throws ServletException, IOException {
+        initContextRoot(request);
         RegistrySessionContext registrySessionContext = getRegistrySessionContext(request);
         //TODO : Need to add user validation and user managment code here
         // At the moment we do not consider about the user
         //First need to check whether user is valid
         String uri = request.getRequestURI();
-        String path = uri.substring(Constants.TAG_REGISTRY.length(), uri.length());
-
+        String path = uri.substring((contextRoot + Constants.TAG_REGISTRY).length(), uri.length());
+        if (path != null && path.length() == 0) {
+            path = Constants.ROOT_PATH;
+        }
         Map params = new Utils().getParameters(request.getQueryString());
         String action = (String) params.get(Constants.ACTION);
         if (action == null) {
@@ -113,4 +122,21 @@
         }
         return registrySessionContextContext;
     }
+
+    /**
+     * To find the name of the war , so getting that from the request context path
+     *
+     * @param req
+     */
+    public void initContextRoot(HttpServletRequest req) {
+        if (contextRoot != null && contextRoot.trim().length() != 0) {
+            return;
+        }
+        String contextPath = req.getContextPath();
+        //handling ROOT scenario, for servlets in the default (root) context, this method returns ""
+        if (contextPath != null && contextPath.length() == 0) {
+            contextPath = "/";
+        }
+        this.contextRoot = contextPath;
+    }
 }

Modified: trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/actions/GetResourceActionProcessor.java
==============================================================================
--- trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/actions/GetResourceActionProcessor.java	(original)
+++ trunk/registry/java/modules/core/src/main/java/org/wso2/registry/servlet/actions/GetResourceActionProcessor.java	Thu Aug 30 02:45:49 2007
@@ -19,8 +19,13 @@
 
 package org.wso2.registry.servlet.actions;
 
+import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.wso2.registry.Constants;
 import org.wso2.registry.Registry;
+import org.wso2.registry.RegistryException;
 import org.wso2.registry.engine.RegistrySessionContext;
 import org.wso2.registry.resources.Directory;
 import org.wso2.registry.resources.Resource;
@@ -56,7 +61,10 @@
             OutputStream out = response.getOutputStream();
             if (resource instanceof Directory) {
                 Directory directory = (Directory) resource;
-                String[] childPaths = directory.getChildNames();
+                response.setContentType("text/xml");
+                OMElement directoryElement = createDirectoyElement(directory, registrySessionContext, null);
+                directoryElement.serialize(out);
+                out.flush();
             } else {
                 Object object = resource.getObject();
                 if (object instanceof OMElement) {
@@ -76,4 +84,51 @@
         }
         return true;
     }
+
+    private OMElement createDirectoyElement(Directory directory, RegistrySessionContext context, OMFactory factory) {
+        if (factory == null) {
+            factory = OMAbstractFactory.getOMFactory();
+        }
+        OMNamespace ns = factory.createOMNamespace("", "");
+        OMElement directoryElement = factory.createOMElement(Constants.DIRECTORY, ns);
+        //TODO , need to substring that to get only the last part
+        directoryElement.addAttribute(Constants.ATT_NAME, directory.getPath(), ns);
+        String[] childNames = directory.getChildNames();
+        for (int i = 0; i < childNames.length; i++) {
+            String childName = childNames[i];
+            try {
+                Resource resource = registry.get(childName, context);
+                if (resource instanceof Directory) {
+                    OMElement childElement = factory.createOMElement(Constants.DIRECTORY, ns);
+                    childElement.addAttribute(Constants.ATT_NAME, childName, ns);
+                    directoryElement.addChild(childElement);
+                } else {
+                    OMElement fileElement = factory.createOMElement(Constants.FILE, ns);
+                    fileElement.addAttribute(Constants.ATT_NAME, childName, ns);
+                    directoryElement.addChild(fileElement);
+                }
+            } catch (RegistryException e) {
+                //we do not need to consider this
+                continue;
+            }
+
+        }
+        return directoryElement;
+    }
+
+    public static void main(String[] args) throws Exception {
+        OMFactory factory = OMAbstractFactory.getOMFactory();
+        OMNamespace ns = factory.createOMNamespace("", "");
+        OMElement directoryElement = factory.createOMElement(Constants.DIRECTORY, ns);
+        //TODO , need to substring that to get only the last part
+        directoryElement.addAttribute(Constants.ATT_NAME, "dd", ns);
+        String childNames[] = new String[]{"a", "b", "c"};
+        for (int i = 0; i < childNames.length; i++) {
+            String childName = childNames[i];
+            OMElement fileElement = factory.createOMElement(Constants.FILE, ns);
+            fileElement.addAttribute(Constants.ATT_NAME, childName, ns);
+            directoryElement.addChild(fileElement);
+        }
+        directoryElement.serialize(System.out);
+    }
 }

Modified: trunk/registry/java/modules/webapps/conf/web.xml
==============================================================================
--- trunk/registry/java/modules/webapps/conf/web.xml	(original)
+++ trunk/registry/java/modules/webapps/conf/web.xml	Thu Aug 30 02:45:49 2007
@@ -11,7 +11,7 @@
 
      <servlet-mapping>
         <servlet-name>RegistryServlet</servlet-name>
-        <url-pattern>/registry</url-pattern>
+        <url-pattern>/registry/*</url-pattern>
     </servlet-mapping>
 
     <filter>



More information about the Registry-dev mailing list