Author: chathura
Date: Sat Dec 15 02:05:57 2007
New Revision: 11156

Log:


Integrated the wsdl media type support.



Added:
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/WSDLMediaTypeHandler.java
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceHandler.java
Modified:
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/RegistryConstants.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java
   
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/utils/WSDLFileProcessor.java
   
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
   trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/RegistryConstants.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/RegistryConstants.java
  (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/RegistryConstants.java
  Sat Dec 15 02:05:57 2007
@@ -79,6 +79,9 @@
     public static final String RATING_MEDIA_TYPE = "rating";
     public static final String TAG_MEDIA_TYPE = "tag";
 
+    // built in media types
+
+    public static final String WSDL_MEDIA_TYPE = "wsdl/xml";
     public static final String SYNPASE_REPOSITORY_MEDIA_TYPE = "synapse-repo";
     public static final String SYNAPSE_CONF_COLLECTION_MEDIA_TYPE = 
"synapse-conf";
     public static final String SYNAPSE_SEQUENCE_COLLECTION_MEDIA_TYPE = 
"synapse-sequences";

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java
   (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/MediaTypeManager.java
   Sat Dec 15 02:05:57 2007
@@ -28,6 +28,7 @@
 import org.wso2.registry.jdbc.mediatypes.builtin.DefaultMediaTypeHandler;
 import org.wso2.registry.jdbc.mediatypes.builtin.SQLQueryMediaTypeHandler;
 import 
org.wso2.registry.jdbc.mediatypes.builtin.SynapseRepositoryMediaTypeHandler;
+import org.wso2.registry.jdbc.mediatypes.builtin.WSDLMediaTypeHandler;
 import org.wso2.usermanager.Realm;
 
 import java.sql.Connection;
@@ -66,6 +67,10 @@
                 new SynapseRepositoryMediaTypeHandler(connectionFactory, 
realm, this);
         mediaTypeHandlers.put(
                 RegistryConstants.SYNPASE_REPOSITORY_MEDIA_TYPE, 
synRepoMediaTypeHandler);
+
+        MediaTypeHandler wsdlMediaTypeHandler =
+                new WSDLMediaTypeHandler(connectionFactory, realm, this);
+        mediaTypeHandlers.put(RegistryConstants.WSDL_MEDIA_TYPE, 
wsdlMediaTypeHandler);
     }
 
     public Resource get(String path) throws RegistryException {
@@ -162,7 +167,7 @@
         return (MediaTypeHandler) mediaTypeHandlers.get(mediaType);
     }
 
-    public MediaTypeHandler getDefaultMediaTypeHandler() {
+    public DefaultMediaTypeHandler getDefaultMediaTypeHandler() {
         return defaultMediaTypeHandler;
     }
 

Added: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/WSDLMediaTypeHandler.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/WSDLMediaTypeHandler.java
       Sat Dec 15 02:05:57 2007
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry.jdbc.mediatypes.builtin;
+
+import org.wso2.registry.jdbc.mediatypes.MediaTypeHandler;
+import org.wso2.registry.jdbc.mediatypes.MediaTypeManager;
+import org.wso2.registry.jdbc.mediatypes.builtin.utils.WSDLFileProcessor;
+import org.wso2.registry.jdbc.ConnectionFactory;
+import org.wso2.registry.Resource;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.usermanager.Realm;
+
+public class WSDLMediaTypeHandler extends MediaTypeHandler {
+
+    WSDLFileProcessor wsdlFileProcessor;
+
+    public WSDLMediaTypeHandler(ConnectionFactory connectionFactory,
+                             Realm realm,
+                             MediaTypeManager mediaTypeManager) {
+
+        super(connectionFactory, realm, mediaTypeManager);
+
+        wsdlFileProcessor = new 
WSDLFileProcessor(mediaTypeManager.getDefaultMediaTypeHandler());
+
+    }
+
+    public Resource get(String path, Resource rawArtifact) throws 
RegistryException {
+        return null;  //To change body of implemented methods use File | 
Settings | File Templates.
+    }
+
+    public boolean put(String path, Resource resource) throws 
RegistryException {
+
+        String wsdlURL = resource.getProperty("fetchURL");
+        wsdlFileProcessor.saveWSDLFileToRegistry(wsdlURL, getParentPath(path));
+        
+        return true;  //To change body of implemented methods use File | 
Settings | File Templates.
+    }
+
+    public boolean delete(String path) throws RegistryException {
+        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
+    }
+
+    public boolean putChild(String childPath, Resource resource) throws 
RegistryException {
+        return false;  //To change body of implemented methods use File | 
Settings | File Templates.
+    }
+
+    private static String getParentPath(String childPath) {
+
+        if (childPath.equals(RegistryConstants.ROOT_PATH)) {
+            return null;
+        }
+
+        int parentPathLength = 
childPath.lastIndexOf(RegistryConstants.PATH_SEPARATOR);
+
+        if (parentPathLength == 0) {
+            return RegistryConstants.ROOT_PATH;
+        }
+
+        String parentPath = childPath.substring(0, parentPathLength);
+        return parentPath;
+    }
+}

Modified: 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/utils/WSDLFileProcessor.java
==============================================================================
--- 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/utils/WSDLFileProcessor.java
    (original)
+++ 
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/mediatypes/builtin/utils/WSDLFileProcessor.java
    Sat Dec 15 02:05:57 2007
@@ -22,6 +22,10 @@
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
+import org.wso2.registry.jdbc.mediatypes.builtin.DefaultMediaTypeHandler;
+import org.wso2.registry.Resource;
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.RegistryException;
 
 import javax.wsdl.Types;
 import javax.wsdl.Definition;
@@ -44,20 +48,42 @@
     public static final String IMPORT_TAG = "import";
     public static final String INCLUDE_TAG = "include";
 
+    DefaultMediaTypeHandler defaultMediaTypeHandler;
+
+    public WSDLFileProcessor(DefaultMediaTypeHandler defaultMediaTypeHandler) {
+        this.defaultMediaTypeHandler = defaultMediaTypeHandler;
+    }
+
     /**
      * saves a wsdl file including its imports and imported schemas.
      *
      * @param location
      * @throws WSDLException
      */
-    public void saveWSDLFileToRegistry(String location)
-            throws WSDLException {
-        WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader();
+    public void saveWSDLFileToRegistry(String location, String 
registryBasePath)
+            throws RegistryException {
+        WSDLReader wsdlReader = null;
+
+        try {
+            wsdlReader = WSDLFactory.newInstance().newWSDLReader();
+        } catch (WSDLException e) {
+            String msg = "Could not initiate the wsdl reader. Caused by: " + 
e.getMessage();
+            throw new RegistryException(msg);
+        }
+
         wsdlReader.setFeature("javax.wsdl.importDocuments", true);
-        Definition wsdlDefinition = wsdlReader.readWSDL(location);
+        Definition wsdlDefinition = null;
+
+        try {
+            wsdlDefinition = wsdlReader.readWSDL(location);
+        } catch (WSDLException e) {
+            String msg = "Could not read the wsdl at location " + location + 
". Caused by: " + e.getMessage();
+            throw new RegistryException(msg);
+        }
+
         Map processedWSDLMap = new HashMap();
         calculateWSDLNamesAndChangeTypes(wsdlDefinition, processedWSDLMap, new 
HashMap(), new HashSet());
-        saveWSDLFileToRegistry(wsdlDefinition, processedWSDLMap, new 
HashSet());
+        saveWSDLFileToRegistry(wsdlDefinition, processedWSDLMap, new 
HashSet(), registryBasePath);
     }
 
     /**
@@ -144,7 +170,8 @@
 
     public void saveWSDLFileToRegistry(Definition wsdlDefinition,
                                        Map processedWSDLMap,
-                                       Set visitedWSDLs) {
+                                       Set visitedWSDLs,
+                                       String registryBasePath) throws 
RegistryException {
         // first we have to process the imports and change the
         // schema locations suite for the registry
         Iterator iter = wsdlDefinition.getImports().values().iterator();
@@ -160,7 +187,7 @@
                 Definition innerDefinition = wsdlImport.getDefinition();
                 if 
(!visitedWSDLs.contains(innerDefinition.getDocumentBaseURI())) {
                     // we have not process this wsdl file earlier
-                    saveWSDLFileToRegistry(innerDefinition, processedWSDLMap, 
visitedWSDLs);
+                    saveWSDLFileToRegistry(innerDefinition, processedWSDLMap, 
visitedWSDLs, registryBasePath);
                 }
                 // set the import location according to the new location
                 wsdlImport.setLocationURI((String) processedWSDLMap.get(
@@ -171,15 +198,23 @@
         // after processing the defintions save this to the registry
         // TODO: save this to the registry for the moment save this to the
         // folder and omit any exception occurs.
-        String fileNameToSave = (String) 
processedWSDLMap.get(wsdlDefinition.getDocumentBaseURI());
+        String importedResourceName = (String) 
processedWSDLMap.get(wsdlDefinition.getDocumentBaseURI());
         try {
             WSDLWriter wsdlWriter = WSDLFactory.newInstance().newWSDLWriter();
             ByteArrayOutputStream byteArrayOutputStream = new 
ByteArrayOutputStream();
-            wsdlWriter.writeWSDL(wsdlDefinition, new 
FileOutputStream("repository/" + fileNameToSave));
+            wsdlWriter.writeWSDL(wsdlDefinition, byteArrayOutputStream);
+            byte[] wsdlResourceContent = byteArrayOutputStream.toByteArray();
+
+            // create a resource this wsdlResourceContent and put it to the 
registry with the name importedResourceName (in some path)
+
+            String wsdlPath = registryBasePath + 
RegistryConstants.PATH_SEPARATOR + importedResourceName;
+            Resource wsdlResource = new Resource();
+            wsdlResource.setContent(wsdlResourceContent);
+            defaultMediaTypeHandler.put(wsdlPath, wsdlResource);
+
+            //wsdlWriter.writeWSDL(wsdlDefinition, new 
FileOutputStream("repository/" + importedResourceName));
         } catch (WSDLException e) {
             e.printStackTrace();
-        } catch (FileNotFoundException e) {
-            e.printStackTrace();
         }
     }
 

Modified: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
==============================================================================
--- 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   (original)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/ControllerServlet.java
   Sat Dec 15 02:05:57 2007
@@ -305,6 +305,16 @@
                 response.sendRedirect("/wso2registry/web" + path);
                 //forwardToResources(request, response, path);
 
+            } else if (command.equals("/fetchResource")) {
+
+                try {
+                    ResourceHandler.fetchURLResource(request);
+                } catch (RegistryException e) {
+                    setErrorMessage(request, e.getMessage());
+                }
+
+                response.sendRedirect("/wso2registry/web" + path);
+
             } else if (command.equals("/addResource")) {
 
                 handleFileUpload(request, response);

Added: 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceHandler.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/ResourceHandler.java
     Sat Dec 15 02:05:57 2007
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.registry.web.actions;
+
+import org.wso2.registry.RegistryConstants;
+import org.wso2.registry.Resource;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.jdbc.JDBCRegistry;
+import org.wso2.registry.web.ConsoleConstants;
+import org.wso2.registry.secure.SecureRegistry;
+import org.wso2.usermanager.Realm;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.ServletContext;
+
+public class ResourceHandler {
+
+    public static void fetchURLResource(HttpServletRequest request) throws 
RegistryException {
+
+        String parentPath = request.getParameter("path");
+        String resourceName = request.getParameter("filename");
+        String resourcePath = parentPath + RegistryConstants.PATH_SEPARATOR + 
resourceName;
+
+        String fetchURL = request.getParameter("fetchURL");
+        String mediaType = request.getParameter("mediaType");
+
+        Resource resource = new Resource();
+        resource.setProperty("fetchURL", fetchURL);
+        resource.setMediaType(mediaType);
+
+        SecureRegistry userRegistry = getUserRegistry(request);
+        userRegistry.put(resourcePath, resource);
+    }
+
+    private static SecureRegistry getUserRegistry(HttpServletRequest request)
+            throws RegistryException {
+
+        SecureRegistry userRegistry =
+                (SecureRegistry) 
request.getSession().getAttribute(ConsoleConstants.USER_REGISTRY);
+
+        if (userRegistry == null) {
+
+            // user is not logged in. create a annoymous userRegistry for the 
user.
+
+            ServletContext context =
+                    request.getSession().getServletContext();
+
+            JDBCRegistry jdbcRegistry =
+                    (JDBCRegistry) 
context.getAttribute(RegistryConstants.REGISTRY);
+
+            Realm realm = (Realm) request.getSession().getServletContext().
+                    getAttribute(RegistryConstants.REGISTRY_REALM);
+
+            SecureRegistry secureRegistry = new SecureRegistry(
+                    RegistryConstants.ANONYMOUS_USER, "guest", jdbcRegistry, 
realm);
+
+            request.getSession().setAttribute(ConsoleConstants.USER_REGISTRY, 
secureRegistry);
+
+            userRegistry = secureRegistry;
+        }
+
+        return userRegistry;
+    }
+}

Modified: trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js   
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/js/common.js   Sat Dec 
15 02:05:57 2007
@@ -248,7 +248,7 @@
 }
 
 function loadMediaTypes() {
-    
+
     if (mediaTypeMap == null) {
         fillMediaTypes();
     }
@@ -287,3 +287,46 @@
 
     document.getElementById('resourceMediaType').value = mediaType;
 }
+
+function fillResourceDetailsForURLs() {
+
+    var filepath = document.getElementById('fetchURLID').value;
+
+    var filename = "";
+    filename = filepath.substring(filepath.lastIndexOf('/') + 1, 
filepath.length);
+
+    document.getElementById('resourceName').value = filename;
+    var extension = filename.substring(filename.lastIndexOf("?") + 1, 
filename.length);
+    if (extension.indexOf("=") > 0) {
+        extension = extension.substring(0, extension.lastIndexOf("="));
+    }
+
+    var mediaType = "";
+    if (extension.length > 0) {
+        mediaType = getMediaType(extension);
+        if (mediaType == undefined) {
+            mediaType = "";
+        }
+    }
+
+    document.getElementById('resourceMediaType').value = mediaType;
+}
+
+/**
+ * We want to submit this form to differnt urls based on how the resource 
content is given.
+ */
+function submitResourceAddForm() {
+
+    var rForm = document.forms["resourceupload"];
+
+    var fetchURL = document.getElementById("fetchURLID").value;
+    if (fetchURL != null && fetchURL.length > 0) {
+        rForm.enctype = "application/x-www-form-urlencoded";
+        rForm.action = "/wso2registry/system/fetchResource";
+    } else {
+        rForm.enctype = "multipart/form-data";
+        rForm.action = "/wso2registry/system/addResource";
+    }
+
+    rForm.submit();
+}

Modified: 
trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp
==============================================================================
--- trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp 
(original)
+++ trunk/registry/modules/webapps/src/main/webapp/admin/registry-resources.jsp 
Sat Dec 15 02:05:57 2007
@@ -191,7 +191,15 @@
                                <input type="hidden" name="path" 
value="<%=details.getPath()%>"/>
                        
                                <table width="100%"  border="0" cellspacing="0" 
cellpadding="0">
-                                   <tr>
+                        <tr>
+                                       <td width="100" valign="top">Fetch 
content from URL</td>
+                                       <td><input id="fetchURLID" type="text" 
name="fetchURL" style="margin-bottom:10px;" 
onchange="fillResourceDetailsForURLs()"/></td>
+                                   </tr>
+                        <tr>
+                                       <td valign="top">Import content from 
file</td>
+                                       <td><input id="resourceFile" 
type="file" name="upload" onchange="fillResourceDetails()"/></td>
+                                   </tr>
+                        <tr>
                                        <td width="100" valign="top">Name</td>
                        
                                        <td><input id="resourceName" 
type="text" name="filename" style="margin-bottom:10px;"/></td>
@@ -206,12 +214,8 @@
                                        <td><textarea name="description" 
class="normal-textarea"></textarea></td>
                                    </tr>
                                    <tr>
-                                       <td valign="top">File</td>
-                                       <td><input id="resourceFile" 
type="file" name="upload" onchange="fillResourceDetails()"/></td>
-                                   </tr>
-                                   <tr>
                                        <td>&nbsp;</td>
-                                       <td><input type="submit" class="button" 
value="Add" style="margin-top:10px;" onclick="showHide('add-resource-div')"/> 
<input type="submit" class="button" value="Cancel" style="margin-top:10px;" 
onclick="showHide('add-resource-div')"/></td>
+                                       <td><input type="button" class="button" 
value="Add" style="margin-top:10px;" 
onclick="submitResourceAddForm();showHide('add-resource-div')"/> <input 
type="submit" class="button" value="Cancel" style="margin-top:10px;" 
onclick="showHide('add-resource-div')"/></td>
                                    </tr>
                                </table>
                            </form>

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

Reply via email to