Author: glen
Date: Mon Jan 21 15:28:16 2008
New Revision: 12660
Log:
* Refactor configuration mechanics so servlet-dependent stuff is isolated, and
we can use the configurationProcessor in other contexts.
* Make registry/config/RegistryConfigurationProcessor methods static, since it
keeps no state.
* Introduce CoreRegistry, and pull get/put/delete up to that interface.
* Flesh out APPTests a little more
* Some code cleanup and spelling corrections
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/CoreRegistry.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/RegistryConstants.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPTests.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/VersionTest.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AbstractRegistryAction.java
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AddCollectionAction.java
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/AdminUtil.java
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/CoreRegistry.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/CoreRegistry.java
Mon Jan 21 15:28:16 2008
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2007, 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;
+
+public interface CoreRegistry {
+ /**
+ * Returns the resource in the given path.
+ *
+ * @param path Path of the resource. e.g. /project1/server/deployment.xml
+ * @return Resource instance
+ * @throws org.wso2.registry.RegistryException is thrown if the resource
is not in the registry
+ */
+ Resource get(String path) throws RegistryException;
+
+ /**
+ * Check whether a resource exist in the given path
+ *
+ * @param path Path of the resource to be checked
+ * @return true if a resource exist in the given path, false otherwise.
+ * @throws org.wso2.registry.RegistryException if an error occurs
+ */
+ boolean resourceExists(String path) throws RegistryException;
+
+ /**
+ * Adds or updates resources in the registry. If there is no resource in
the given path,
+ * resource is added. If a resource already exist in the given path, it
will be replaced with
+ * the new resource.
+ *
+ * @param suggestedPath the path which we'd like to use for the new
resource.
+ * @param resource Resource instance for the new resource
+ * @return the actual path that the server chose to use for our Resource
+ * @throws org.wso2.registry.RegistryException
+ */
+ String put(String suggestedPath, Resource resource) throws
RegistryException;
+
+ /**
+ * Deletes the resource in the given path. If the path refers to a
directory, all child
+ * resources of the directory will also be deleted.
+ *
+ * @param path Path of the resource to be deleted.
+ * @throws RegistryException
+ * is thrown depending on the implementation.
+ */
+ void delete(String path) throws RegistryException;
+}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
==============================================================================
--- trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
(original)
+++ trunk/registry/modules/core/src/main/java/org/wso2/registry/Registry.java
Mon Jan 21 15:28:16 2008
@@ -23,35 +23,7 @@
import java.util.Map;
/** API for the Registry. Java applications should use this API to access the
registry. */
-public interface Registry {
-
- /**
- * Returns the resource in the given path.
- *
- * @param path Path of the resource. e.g. /project1/server/deployment.xml
- * @return Resource instance
- * @throws RegistryException is thrown if the resource is not in the
registry
- */
- Resource get(String path) throws RegistryException;
-
- /**
- * Check whether a resource exist in the given path
- *
- * @param path Path of the resource to be checked
- * @return true if a resource exist in the given path, false otherwise.
- * @throws RegistryException if an error occurs
- */
- boolean resourceExists(String path) throws RegistryException;
-
- /**
- * Adds or updates resources in the registry. If there is no resource in
the given path,
- * resource is added. If a resource already exist in the given path, it
will be replaced with
- * the new resource.
- *
- * @param suggestedPath
- * @param resource Resource instance for the new resource @throws
org.wso2.registry.RegistryException
- */
- String put(String suggestedPath, Resource resource) throws
RegistryException;
+public interface Registry extends CoreRegistry {
/**
* Creates a resource in the suggested path (which may be altered) by
fetching the resource
@@ -59,9 +31,8 @@
*
* @param suggestedPath Path to add the new resource. Although this path
is specified by the
* caller of the method, resource may not be actually added to this path.
- *
* @param sourceURL URL to fetch the resource content
- * @param mediaType
+ * @param mediaType media type of the remote resource
* @return Actual path to which the resource is added
* @throws RegistryException
*/
@@ -159,7 +130,8 @@
* Adds a comment to a resource.
*
* @param resourcePath Path of the resource to add the comment.
- * @param comment Comment instance for the new comment.
+ * @param comment Comment instance for the new comment.
+ * @return the path of the new comment.
* @throws RegistryException is thrown if a resource does not exist in the
given path.
*/
String addComment(String resourcePath, Comment comment) throws
RegistryException;
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
Mon Jan 21 15:28:16 2008
@@ -33,7 +33,6 @@
public static final String STATUS_MESSAGE_NAME = "edit_status";
public static final String REGISTRY_CONFIG_PATH = "registry.config.path";
- public static final String REGISTRY_CONFIG = "registry.config";
public static final String REGISTRY_CONTEXT = "registry.context";
/**
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.java
Mon Jan 21 15:28:16 2008
@@ -123,9 +123,9 @@
if (lastUpdatedUSer != null){
resource.setLastUpdaterUserName(lastUpdatedUSer);
}
- String mediaTyep = feed.getSimpleExtension(new QName("mediaType"));
- if (mediaTyep !=null) {
- resource.setMediaType(mediaTyep);
+ String mediaType = feed.getSimpleExtension(new QName("mediaType"));
+ if (mediaType !=null) {
+ resource.setMediaType(mediaType);
}
String parentPath = feed.getSimpleExtension(new QName("parentPath"));
if (parentPath !=null ){
@@ -210,7 +210,7 @@
entry.setAttributeValue(key, (String) properties.get(key));
}
}
- entry.addSimpleExtension(new QName("mediaType")
,resource.getMediaType());
+ entry.addSimpleExtension(new QName("mediaType"),
resource.getMediaType());
entry.addSimpleExtension(new QName("parentPath") ,
resource.getParentPath());
if (resource.isDirectory()) {
entry.addSimpleExtension(new QName("directory"), "true");
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryConfigurationProcessor.java
Mon Jan 21 15:28:16 2008
@@ -22,61 +22,42 @@
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.wso2.registry.RegistryException;
-import org.wso2.registry.secure.HSQLDBInitializer;
-import org.wso2.registry.jdbc.hsql.DBUtils;
-import org.wso2.registry.jdbc.utils.RegistryDataSource;
import org.wso2.registry.i18n.Messages;
-import javax.servlet.ServletConfig;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
-import java.util.HashMap;
import java.util.Iterator;
-import java.util.Map;
-import java.sql.Connection;
-import java.sql.SQLException;
public class RegistryConfigurationProcessor {
-
- private static final Log log =
LogFactory.getLog(RegistryConfigurationProcessor.class);
+ public static void populateRegistryConfig(String filename, RegistryContext
context)
+ throws RegistryException {
+ try {
+ populateRegistryConfig(new FileInputStream(filename), context);
+ } catch (FileNotFoundException e) {
+ throw new RegistryException(e.getMessage(), e);
+ }
+ }
/**
- * This method will read the registry.xml and using the data given in the
file registry
- * configuration will be populated. And if the xmlLocation is null then it
will use the one in
- * the class path.
+ * Read XML configuration from the passed InputStream, or from the
classpath.
*
- * @param xmlLocation Location of registry.xml
- * @param servletConfig the active servlet configuration
- * @throws org.wso2.registry.RegistryException
- * : if something went wrong
+ * @param in an InputStream containing XML data, or null.
+ * @param registryContext the RegistryContext to populate
+ * @throws RegistryException if there's a problem
*/
- public void populateRegistryConfig(
- String xmlLocation, ServletConfig servletConfig, RegistryContext
registryContext)
+ public static void populateRegistryConfig(InputStream in, RegistryContext
registryContext)
throws RegistryException {
-
- InputStream in;
- if (xmlLocation != null) {
- try {
- in = new FileInputStream(xmlLocation);
- } catch (FileNotFoundException e) {
- throw new RegistryException(e.getMessage());
- }
- } else {
- in =
servletConfig.getServletContext().getResourceAsStream("/WEB-INF/registry.xml");
- if (in == null) {
- in =
Thread.currentThread().getContextClassLoader().getResourceAsStream(
- "org/wso2/registry/servlet/registry.xml");
- }
- if (in == null) {
- throw new
RegistryException(Messages.getMessage("inputstream.null",
- "org/wso2/servlet/registry.xml"));
- }
+ if (in == null) {
+ in =
Thread.currentThread().getContextClassLoader().getResourceAsStream(
+ "org/wso2/registry/servlet/registry.xml");
+ }
+ if (in == null) {
+ throw new RegistryException(Messages.getMessage("inputstream.null",
+
"org/wso2/servlet/registry.xml"));
}
try {
StAXOMBuilder buillder = new StAXOMBuilder(in);
@@ -93,70 +74,35 @@
throw new
RegistryException(Messages.getMessage("dbname.null"));
}
dataBaseConfiguration.setConfigName(dbName);
+ OMElement dataSource = dbconfig.getFirstChildWithName(new
QName("dataSource"));
+ if (dataSource != null) {
+
dataBaseConfiguration.setDataSourceName(dataSource.getText());
- if (dbName.equals("sample")) {
+ } else {
-
dataBaseConfiguration.setDbUrl(getDBURL(servletConfig));
-
dataBaseConfiguration.setDriverName("org.hsqldb.jdbcDriver");
- dataBaseConfiguration.setUserName("sa");
- dataBaseConfiguration.setPassWord("");
-
- // create the in-process database
-
- RegistryDataSource dataSource;
- try {
- dataSource = new RegistryDataSource(
- dataBaseConfiguration.getDbUrl(),
- dataBaseConfiguration.getDriverName(),
- dataBaseConfiguration.getUserName(),
- dataBaseConfiguration.getPassWord());
-
- DBUtils dbUtils = new DBUtils();
- Connection conn = dataSource.getConnection();
- dbUtils.initializeDatabase(conn);
- conn.close();
-
- HSQLDBInitializer dbInitializer = new
HSQLDBInitializer();
- dbInitializer.createHSQLTables(dataSource);
-
- } catch (SQLException e) {
- dataBaseConfiguration.setConfigName("in-memory");
- log.info("Unable to create the sample DB , so
crated in-memory");
-// throw new RegistryException(msg);
+ OMElement userName =
dbconfig.getFirstChildWithName(new QName("userName"));
+ if (userName != null) {
+
dataBaseConfiguration.setUserName(userName.getText());
}
- } else {
+ OMElement password =
dbconfig.getFirstChildWithName(new QName("password"));
+ if (password != null) {
+
dataBaseConfiguration.setPassWord(password.getText());
+ }
- OMElement dataSource =
dbconfig.getFirstChildWithName(new QName("dataSource"));
- if (dataSource != null) {
-
dataBaseConfiguration.setDataSourceName(dataSource.getText());
-
- } else {
-
- OMElement userName =
dbconfig.getFirstChildWithName(new QName("userName"));
- if (userName != null) {
-
dataBaseConfiguration.setUserName(userName.getText());
- }
-
- OMElement password =
dbconfig.getFirstChildWithName(new QName("password"));
- if (password != null) {
-
dataBaseConfiguration.setPassWord(password.getText());
- }
-
- OMElement url = dbconfig.getFirstChildWithName(new
QName("url"));
- if (url != null) {
- dataBaseConfiguration.setDbUrl(url.getText());
- }
-
- OMElement driverName =
- dbconfig.getFirstChildWithName(new
QName("driverName"));
- if (driverName != null) {
-
dataBaseConfiguration.setDriverName(driverName.getText());
- }
+ OMElement url = dbconfig.getFirstChildWithName(new
QName("url"));
+ if (url != null) {
+ dataBaseConfiguration.setDbUrl(url.getText());
+ }
+
+ OMElement driverName =
+ dbconfig.getFirstChildWithName(new
QName("driverName"));
+ if (driverName != null) {
+
dataBaseConfiguration.setDriverName(driverName.getText());
}
}
- registryContext.getDbconfgigMap().put(dbName,
dataBaseConfiguration);
+ registryContext.addDBConfig(dbName, dataBaseConfiguration);
}
OMElement currentConfigElement =
@@ -167,8 +113,8 @@
}
String currentConfigName = currentConfigElement.getText();
- DataBaseConfiguration currentConfiguration =
(DataBaseConfiguration)
-
registryContext.getDbconfgigMap().get(currentConfigName);
+ DataBaseConfiguration currentConfiguration =
+ registryContext.getDBConfig(currentConfigName);
registryContext.setDefaultDataBaseConfiguration(currentConfiguration);
// process media type handler config
@@ -235,10 +181,10 @@
}
}
- public OMElement getRegistryConfigAsXML(RegistryContext registryContext) {
+ public static OMElement getRegistryConfigAsXML(RegistryContext
registryContext) {
OMFactory factory = OMAbstractFactory.getOMFactory();
- OMElement root = factory.createOMElement("wso2regsitry", null);
+ OMElement root = factory.createOMElement("wso2registry", null);
if (registryContext.getDefaultDataBaseConfiguration() != null) {
OMElement currrentConfigElement =
factory.createOMElement("currentConfig", null);
@@ -246,7 +192,7 @@
root.addChild(currrentConfigElement);
}
- Iterator values =
registryContext.getDbconfgigMap().values().iterator();
+ Iterator values = registryContext.getDBConfigNames();
while (values.hasNext()) {
DataBaseConfiguration dataBaseConfiguration =
(DataBaseConfiguration)values.next();
OMElement config = factory.createOMElement("dbconfig", null);
@@ -267,12 +213,4 @@
}
return root;
}
-
- private String getDBURL(ServletConfig config) {
- String webinf = config.getServletContext().getRealPath("/WEB-INF");
- if(webinf == null || "".equals(webinf)) {
- webinf = System.getProperty("basedir") + "/target";
- }
- return "jdbc:hsqldb:" + webinf + "/sample/sample-db;shutdown=true";
- }
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/config/RegistryContext.java
Mon Jan 21 15:28:16 2008
@@ -16,19 +16,38 @@
package org.wso2.registry.config;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ArrayList;
+import org.wso2.registry.jdbc.utils.RegistryDataSource;
+import org.wso2.registry.jdbc.hsql.DBUtils;
+import org.wso2.registry.secure.HSQLDBInitializer;
+import org.wso2.registry.RegistryException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.*;
+import java.sql.Connection;
+import java.sql.SQLException;
public class RegistryContext {
+ public interface RegURLSupplier {
+ public String getURL();
+ }
+
+ private static final Log log = LogFactory.getLog(RegistryContext.class);
+ private RegURLSupplier urlSupplier;
private DataBaseConfiguration defaultDataBaseConfiguration = null;
- private Map dbconfgigMap = new HashMap();
+ private Map dbConfigs = new HashMap<String, DataBaseConfiguration>();
private List mediaTypeHandlers = new ArrayList();
private List urlHandlers = new ArrayList();
private List queryProcessors = new ArrayList();
+ public RegistryContext() {
+ }
+
+ public RegistryContext(RegURLSupplier urlSupplier) {
+ this.urlSupplier = urlSupplier;
+ }
+
public DataBaseConfiguration getDefaultDataBaseConfiguration() {
return defaultDataBaseConfiguration;
}
@@ -37,12 +56,49 @@
this.defaultDataBaseConfiguration = defaultDataBaseConfiguration;
}
- public Map getDbconfgigMap() {
- return dbconfgigMap;
+ public Iterator<String> getDBConfigNames() {
+ return dbConfigs.keySet().iterator();
}
- public void setDbconfgigMap(Map dbconfgigMap) {
- this.dbconfgigMap = dbconfgigMap;
+ public DataBaseConfiguration getDBConfig(String dbName) {
+ DataBaseConfiguration dataBaseConfiguration =
(DataBaseConfiguration)dbConfigs.get(dbName);
+ if (dbName.equals("sample")) {
+ String dbURL = "jdbc:hsqldb:" + getBasePath() +
"/sample/sample-db;shutdown=true";
+ dataBaseConfiguration.setDbUrl(dbURL);
+ dataBaseConfiguration.setDriverName("org.hsqldb.jdbcDriver");
+ dataBaseConfiguration.setUserName("sa");
+ dataBaseConfiguration.setPassWord("");
+
+ // create the in-process database
+
+ RegistryDataSource dataSource;
+ try {
+ dataSource = new RegistryDataSource(
+ dataBaseConfiguration.getDbUrl(),
+ dataBaseConfiguration.getDriverName(),
+ dataBaseConfiguration.getUserName(),
+ dataBaseConfiguration.getPassWord());
+
+ DBUtils dbUtils = new DBUtils();
+ Connection conn = dataSource.getConnection();
+ dbUtils.initializeDatabase(conn);
+ conn.close();
+
+ HSQLDBInitializer dbInitializer = new HSQLDBInitializer();
+ dbInitializer.createHSQLTables(dataSource);
+ } catch (SQLException e) {
+ dataBaseConfiguration.setConfigName("in-memory");
+ log.info("Unable to create the sample DB, so created
in-memory");
+ } catch (RegistryException e) {
+ dataBaseConfiguration = null;
+ }
+ }
+
+ return dataBaseConfiguration;
+ }
+
+ public void addDBConfig(String name, DataBaseConfiguration config) {
+ dbConfigs.put(name, config);
}
public List getMediaTypeHandlers() {
@@ -80,4 +136,15 @@
public void addQueryProcessor(QueryProcessorConfiguration
queryProcessorConfiguration) {
queryProcessors.add(queryProcessorConfiguration);
}
+
+ private String getBasePath() {
+ String basePath = null;
+ if (urlSupplier != null) {
+ basePath = urlSupplier.getURL();
+ }
+ if (basePath == null) {
+ basePath = System.getProperty("basedir") + "/target";
+ }
+ return basePath;
+ }
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/inmemory/InMemoryRegistry.java
Mon Jan 21 15:28:16 2008
@@ -312,4 +312,5 @@
throw new
UnsupportedOperationException(Messages.getMessage("unsupported.exception",
"Logs"));
}
+
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/jdbc/JDBCRegistry.java
Mon Jan 21 15:28:16 2008
@@ -26,7 +26,6 @@
import org.wso2.registry.i18n.Messages;
import org.wso2.registry.jdbc.dao.*;
import org.wso2.registry.jdbc.mediatypes.MediaTypeManager;
-import org.wso2.registry.jdbc.queries.QueryProcessor;
import org.wso2.registry.jdbc.queries.QueryProcessorManager;
import org.wso2.registry.jdbc.realm.RegistryRealm;
import org.wso2.registry.jdbc.urlhandlers.URLHandlerManager;
@@ -234,8 +233,10 @@
* the new resource. Implementations may use a concurrency control method
to prevent concurrency
* issues.
*
- * @param suggestedPath
- * @param resource Resource instance for the new resource @throws
org.wso2.registry.RegistryException
+ * @param suggestedPath the path which we'd like to use for the new
resource.
+ * @param resource Resource instance for the new resource
+ * @return the actual path that the server chose to use for our Resource
+ * @throws org.wso2.registry.RegistryException
*/
public synchronized String put(String suggestedPath, Resource resource)
throws RegistryException {
suggestedPath = preparePath(suggestedPath);
@@ -1057,4 +1058,5 @@
return logEntries;
}
+
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/secure/SecureRegistry.java
Mon Jan 21 15:28:16 2008
@@ -67,7 +67,6 @@
Realm userRealm;
try {
-
userRealm = new AuthorizingRealm();
AuthorizingRealmConfig config = (AuthorizingRealmConfig)userRealm
.getRealmConfiguration();
@@ -626,4 +625,5 @@
return (LogEntry[]) authorizedEnListList.
toArray(new LogEntry[authorizedEnListList.size()]);
}
+
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/servlet/RegistryServlet.java
Mon Jan 21 15:28:16 2008
@@ -57,25 +57,32 @@
//To store the context path
private String contextRoot = null;
- private String configPath;
- private RegistryConfigurationProcessor registryConfigurationProcessor;
- public void init(ServletConfig config) throws ServletException {
+ public void init(final ServletConfig config) throws ServletException {
super.init(config);
+ System.out.println("Initializing RegistryServlet...");
RegistryRealm registryRealm;
Registry coreRegistry;
try {
// read the registry.xml file from the configured location. if not
configured, read the
// default registry.xml file bundled with the webapp.
- configPath =
config.getInitParameter(RegistryConstants.REGISTRY_CONFIG_PATH);
+ String configPath =
config.getInitParameter(RegistryConstants.REGISTRY_CONFIG_PATH);
- RegistryContext registryContext = new RegistryContext();
+ RegistryContext registryContext = new RegistryContext(
+ new RegistryContext.RegURLSupplier() {
+ public String getURL() {
+ return
config.getServletContext().getRealPath("/WEB-INF");
+ }
+ });
System.getProperties().put(RegistryConstants.REGISTRY_CONTEXT,
registryContext);
- registryConfigurationProcessor = new
RegistryConfigurationProcessor();
- registryConfigurationProcessor.populateRegistryConfig(configPath,
config, registryContext);
- config.getServletContext().
- setAttribute(RegistryConstants.REGISTRY_CONFIG,
registryConfigurationProcessor);
+ if (configPath != null) {
+
RegistryConfigurationProcessor.populateRegistryConfig(configPath,
registryContext);
+ } else {
+ RegistryConfigurationProcessor.populateRegistryConfig(
+
config.getServletContext().getResourceAsStream("/WEB-INF/registry.xml"),
+ registryContext);
+ }
DataBaseConfiguration dbConfiguration =
registryContext.getDefaultDataBaseConfiguration();
String dbType = System.getProperty("in-memory");
@@ -271,7 +278,7 @@
//}
}
- private void setErrorMessage(HttpServletRequest request, String message) {
- request.getSession().setAttribute(RegistryConstants.ERROR_MESSAGE,
message);
- }
+// private void setErrorMessage(HttpServletRequest request, String message)
{
+// request.getSession().setAttribute(RegistryConstants.ERROR_MESSAGE,
message);
+// }
}
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPTests.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPTests.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPTests.java
Mon Jan 21 15:28:16 2008
@@ -36,6 +36,7 @@
String BASEURL = "http://localhost:" + PORT + "/wso2registry/atom/";
RegistryServer server = new RegistryServer();
+ HttpClient client = new HttpClient();
public void setUp() throws Exception {
server.setPort(Integer.parseInt(PORT));
@@ -56,12 +57,11 @@
// Note - every URL below is rooted at our Registry's atom root
// GET the root - empty dir
- HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(buildURL(""));
int responseCode = client.executeMethod(method);
assertEquals(200, responseCode);
- byte [] response = method.getResponseBody();
+ method.getResponseBody();
// GET /d1 - 404
method = new GetMethod(buildURL("d1"));
@@ -75,35 +75,74 @@
assertEquals(404, responseCode);
// POST / with d1 content
- PostMethod writeMethod = new PostMethod(buildURL(""));
String atomContent =
"<feed></feed>";
- StringRequestEntity myRequest = new StringRequestEntity(atomContent);
- writeMethod.setRequestEntity(myRequest);
- client.executeMethod(writeMethod);
-
- // GET /d1 - empty dir
+ String location = doPost("", atomContent, "d1");
+ assertNotNull(location);
+ //assertEquals("correct header value", location);
+
+ // GET /d1 - empty dir (but not 404!)
+ method = new GetMethod(buildURL("d1"));
+ responseCode = client.executeMethod(method);
+ assertEquals(200, responseCode);
+
// GET /d1;tags - empty tags (or 404?)
+ method = new GetMethod(buildURL("d1;tags"));
+ responseCode = client.executeMethod(method);
+ assertEquals(200, responseCode);
// POST / with no slug - text file
+ String textContent = "hi there here's some text";
+ location = doPost("", textContent, null);
+ assertNotNull(location);
+
// GET /<newname> -
+ method = new GetMethod(buildURL(location));
+ responseCode = client.executeMethod(method);
+ assertEquals(200, responseCode);
+ // We should have here an Atom entry pointing to the actual media.
Parse
+ // that out and get the media URL, then GET that and make sure the
content
+ // is kosher.
// POST /d1 with bad slug "&test?"
// Should return /d1/test (sanitized name)
+ //assertEquals("d1/test", location);
+
// GET /d1/test - content
// POST /d1 with existing slug "test"
// Should return /d1/test2 (edited name)
+ assertFalse("test".equals(location));
+
// GET /d1/test2 - content
// Tags
// GET /d1/test;tags - empty tags (or 404?)
+
// POST /d1/test;tags tag=blue
+
// GET /d1/test;tags - "blue"
// Ratings
// Comments
}
+
+ private String doPost(String url, String content, String slug) throws
Exception {
+ PostMethod writeMethod = new PostMethod(url);
+ if (slug != null)
+ writeMethod.addRequestHeader("Slug", slug);
+ StringRequestEntity myRequest = new StringRequestEntity(content);
+ writeMethod.setRequestEntity(myRequest);
+ int responseCode = client.executeMethod(writeMethod);
+ assertEquals(200, responseCode);
+
+ // Get the location header
+ String location = writeMethod.getResponseHeader("Location").getValue();
+ assertNotNull(location);
+
+ // Parse out result path
+ return location;
+ }
}
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/VersionTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/VersionTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/VersionTest.java
Mon Jan 21 15:28:16 2008
@@ -31,15 +31,16 @@
try {
if (registry == null) {
server.start();
- registry = new RemoteRegistry(new
URL("http://localhost:8080/wso2registry/atom"), "admin", "admin");
+ registry = new RemoteRegistry(new
URL("http://localhost:8081/wso2registry/atom"),
+ "admin", "admin");
}
} catch (Exception e) {
fail("Failed to initialize the registry.");
}
}
- public void testResourceRestore() throws RegistryException {
-
+ public void testResourceRestore() throws RegistryException {
+
Resource r1 = new Resource();
r1.setContent("Content1");
registry.put("/wso2/wsas/v1/r1/resource1", r1);
@@ -92,248 +93,252 @@
}
- public void testDeletedResourceRestore(){
+ public void testDeletedResourceRestore() {
Resource r1 = new Resource();
- String content="this is my content";
+ String content = "this is my content";
r1.setContent(content.getBytes());
- String path="/c10/c11/r1";
- try{
- registry.put(path, r1);
- } catch (RegistryException e){
+ String path = "/c10/c11/r1";
+ try {
+ registry.put(path, r1);
+ } catch (RegistryException e) {
fail("Failed to put test resources to" + path);
}
/*read the resource*/
- Resource r4= new Resource();
- try{
- r4=registry.get(path);
- }catch (RegistryException e){
+ Resource r4 = new Resource();
+ try {
+ r4 = registry.get(path);
+ } catch (RegistryException e) {
fail("Failed to read content from the file");
}
-
-// System.out.println("File content:" + new String((byte[])
r4.getContent()));
+// System.out.println("File content:" + new String((byte[])
r4.getContent()));
/*delete the resource*/
- try{
+ try {
registry.delete(path);
- }catch (RegistryException e){
+ } catch (RegistryException e) {
fail("Failed to delete the resource at" + path);
}
-
+
/*try to read deleted resource*/
- boolean deleted= false;
- Resource r2= new Resource();
- try{
- r2=registry.get(path);
- }catch (RegistryException e){
- if(r2.getContent()==null){
- deleted=true;
+ boolean deleted = false;
+ Resource r2 = new Resource();
+ try {
+ r2 = registry.get(path);
+ } catch (RegistryException e) {
+ if (r2.getContent() == null) {
+ deleted = true;
}
//fail("Failed to read content from the deleted resource");
}
-
- assertTrue("Resource not deleted",deleted);
+
+ assertTrue("Resource not deleted", deleted);
/*restore delted resource*/
- try{
+ try {
registry.restoreVersion("/c10/c11?v=1");
- }catch(RegistryException e){
+ } catch (RegistryException e) {
fail("Couldn't restore the version");
}
-
+
/*read restored version*/
- Resource r3= new Resource();
- try{
- r3=registry.get(path);
- }catch (RegistryException e){
+ Resource r3 = new Resource();
+ try {
+ r3 = registry.get(path);
+ } catch (RegistryException e) {
fail("Failed to read content from the resotered file");
}
// System.out.println("File content:" + new String((byte[])
r4.getContent()));
// System.out.println("File content:" + new String((byte[])
r1.getContent()));
// System.out.println("File content:" + new String((byte[])
r3.getContent()));
- assertEquals("Restored file content is not matching",new
String((byte[]) r1.getContent()),new String((byte[]) r3.getContent()));
-
+ assertEquals("Restored file content is not matching", new
String((byte[])r1.getContent()),
+ new String((byte[])r3.getContent()));
+
}
- public void testUpdatedResourceRestore(){
+ public void testUpdatedResourceRestore() {
Resource r1 = new Resource();
- String content="this is my content new";
+ String content = "this is my content new";
r1.setContent(content.getBytes());
- String path="/c20/c21/r1";
- try{
- registry.put(path, r1);
- } catch (RegistryException e){
+ String path = "/c20/c21/r1";
+ try {
+ registry.put(path, r1);
+ } catch (RegistryException e) {
fail("Failed to put test resources to" + path);
}
/*read the resource*/
- Resource r4= new Resource();
- try{
- r4=registry.get(path);
- }catch (RegistryException e){
+ Resource r4 = new Resource();
+ try {
+ r4 = registry.get(path);
+ } catch (RegistryException e) {
fail("Failed to read content from the file");
}
- System.out.println("File content get:" + new String((byte[])
r4.getContent()));
- System.out.println("File content put:" + new String((byte[])
r1.getContent()));
- assertEquals("File content is not Equal", new String((byte[])
r1.getContent()), new String((byte[]) r4.getContent()));
+ System.out.println("File content get:" + new
String((byte[])r4.getContent()));
+ System.out.println("File content put:" + new
String((byte[])r1.getContent()));
+ assertEquals("File content is not Equal", new
String((byte[])r1.getContent()),
+ new String((byte[])r4.getContent()));
/*update the resource*/
Resource r5 = new Resource();
- String content_update="this is my content updated";
- r5.setContent(content_update.getBytes());
- String path_updated="/c20/c21/r1";
- try{
- registry.put(path_updated, r5);
- } catch (RegistryException e){
+ String content_update = "this is my content updated";
+ r5.setContent(content_update.getBytes());
+ String path_updated = "/c20/c21/r1";
+ try {
+ registry.put(path_updated, r5);
+ } catch (RegistryException e) {
fail("Failed to put test resources to" + path_updated);
}
/*read the resource*/
- Resource r6= new Resource();
- try{
- r6=registry.get(path);
- }catch (RegistryException e){
+ Resource r6 = new Resource();
+ try {
+ r6 = registry.get(path);
+ } catch (RegistryException e) {
fail("Failed to read content from the file");
}
- System.out.println("File content updated expected:" + new
String((byte[]) r5.getContent()));
- System.out.println("File content updated actual:" + new
String((byte[]) r6.getContent()));
-
+ System.out.println("File content updated expected:" + new
String((byte[])r5.getContent()));
+ System.out.println("File content updated actual:" + new
String((byte[])r6.getContent()));
/*restore delted resource*/
- try{
+ try {
registry.restoreVersion("/c20/c21?v=1");
- }catch(RegistryException e){
+ } catch (RegistryException e) {
fail("Couldn't restore the version");
}
/*read restored version*/
- Resource r3= new Resource();
- try{
- r3=registry.get(path);
- }catch (RegistryException e){
+ Resource r3 = new Resource();
+ try {
+ r3 = registry.get(path);
+ } catch (RegistryException e) {
fail("Failed to read content from the resotered file");
}
- System.out.println("File content:" + new String((byte[])
r1.getContent()));
- System.out.println("File content:" + new String((byte[])
r4.getContent()));
- System.out.println("File content:" + new String((byte[])
r5.getContent()));
- System.out.println("File content:" + new String((byte[])
r6.getContent()));
- System.out.println("File content:" + new String((byte[])
r3.getContent()));
- assertEquals("Restored file content is not matching",new
String((byte[]) r1.getContent()),new String((byte[]) r3.getContent()));
+ System.out.println("File content:" + new
String((byte[])r1.getContent()));
+ System.out.println("File content:" + new
String((byte[])r4.getContent()));
+ System.out.println("File content:" + new
String((byte[])r5.getContent()));
+ System.out.println("File content:" + new
String((byte[])r6.getContent()));
+ System.out.println("File content:" + new
String((byte[])r3.getContent()));
+ assertEquals("Restored file content is not matching", new
String((byte[])r1.getContent()),
+ new String((byte[])r3.getContent()));
}
- public void testReadfromVersionsPage(){
+ public void testReadfromVersionsPage() {
Resource r1 = new Resource();
- String content="this is my content new";
+ String content = "this is my content new";
r1.setContent(content.getBytes());
- String path="/c22/c23/r1";
- try{
+ String path = "/c22/c23/r1";
+ try {
registry.put(path, r1);
registry.put(path, r1);
registry.put(path, r1);
- } catch (RegistryException e){
+ } catch (RegistryException e) {
fail("Failed to put test resources to" + path);
}
/*read the resource*/
- String path_versions="/c22/c23/r1?v=2";
+ String path_versions = "/c22/c23/r1?v=2";
- Resource r4= new Resource();
- try{
- r4=registry.get(path_versions);
+ Resource r4 = new Resource();
+ try {
+ r4 = registry.get(path_versions);
- }catch (RegistryException e){
+ } catch (RegistryException e) {
fail("Failed to read content from the file");
}
- System.out.println("File content get:" + new String((byte[])
r4.getContent()));
- System.out.println("File content put:" + new String((byte[])
r1.getContent()));
- assertEquals("File content is not Equal", new String((byte[])
r1.getContent()), new String((byte[]) r4.getContent()));
+ System.out.println("File content get:" + new
String((byte[])r4.getContent()));
+ System.out.println("File content put:" + new
String((byte[])r1.getContent()));
+ assertEquals("File content is not Equal", new
String((byte[])r1.getContent()),
+ new String((byte[])r4.getContent()));
- String[] strarr= null;
- try{
- strarr=registry.getVersions("/c22/c23/r1");
+ String[] strarr = null;
+ try {
+ strarr = registry.getVersions("/c22/c23/r1");
- }catch (RegistryException e){
+ } catch (RegistryException e) {
fail("Failed to read content from the file");
}
- for(int i=0;i<strarr.length;i++){
+ for (int i = 0; i < strarr.length; i++) {
System.out.println(strarr[i]);
- if(strarr[i].equals(path_versions)){
- Resource r6= new Resource();
- try{
- r6=registry.get(strarr[i]);
- }catch (RegistryException e){
+ if (strarr[i].equals(path_versions)) {
+ Resource r6 = new Resource();
+ try {
+ r6 = registry.get(strarr[i]);
+ } catch (RegistryException e) {
fail("Failed to read content from the file");
}
- System.out.println("File content get:" + new String((byte[])
r6.getContent()));
- System.out.println("File content put:" + new String((byte[])
r1.getContent()));
- assertEquals("File content is not Equal", new String((byte[])
r1.getContent()), new String((byte[]) r6.getContent()));
+ System.out.println("File content get:" + new
String((byte[])r6.getContent()));
+ System.out.println("File content put:" + new
String((byte[])r1.getContent()));
+ assertEquals("File content is not Equal", new
String((byte[])r1.getContent()),
+ new String((byte[])r6.getContent()));
break;
}
}
}
- public void testDeletedCollectionRestore(){
+ public void testDeletedCollectionRestore() {
Resource r1 = new Resource();
- String content="this is my content";
+ String content = "this is my content";
r1.setContent(content.getBytes());
- String path="/c25/c26/c27/r1";
- try{
- registry.put(path, r1);
- } catch (RegistryException e){
+ String path = "/c25/c26/c27/r1";
+ try {
+ registry.put(path, r1);
+ } catch (RegistryException e) {
fail("Failed to put test resources to" + path);
}
/*read the resource*/
- Resource r4= new Resource();
- try{
- r4=registry.get(path);
- }catch (RegistryException e){
+ Resource r4 = new Resource();
+ try {
+ r4 = registry.get(path);
+ } catch (RegistryException e) {
fail("Failed to read content from the file");
}
- System.out.println("File content:" + new String((byte[])
r4.getContent()));
- assertEquals("File content is not Equal",new String((byte[])
r1.getContent()),new String((byte[]) r4.getContent()));
+ System.out.println("File content:" + new
String((byte[])r4.getContent()));
+ assertEquals("File content is not Equal", new
String((byte[])r1.getContent()),
+ new String((byte[])r4.getContent()));
/*delete the collection*/
- String collection_path="/c25/c26";
+ String collection_path = "/c25/c26";
- try{
+ try {
registry.delete(collection_path);
- }catch (RegistryException e){
+ } catch (RegistryException e) {
fail("Failed to delete the collection at" + collection_path);
}
/*try to read deleted resource*/
- boolean deleted= false;
- Resource r2= new Resource();
- try{
- r2=registry.get(path);
- }catch (RegistryException e){
- if(r2.getContent()==null){
- deleted=true;
+ boolean deleted = false;
+ Resource r2 = new Resource();
+ try {
+ r2 = registry.get(path);
+ } catch (RegistryException e) {
+ if (r2.getContent() == null) {
+ deleted = true;
}
//fail("Failed to read content from the deleted resource");
}
- assertTrue("Collection not deleted.",deleted);
+ assertTrue("Collection not deleted.", deleted);
/*restore delted collection*/
/*
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
Mon Jan 21 15:28:16 2008
@@ -96,8 +96,8 @@
Resource r1 = new Resource();
r1.setAuthorUserName("Author R1");
- byte[] r1content = "R1 content".getBytes();
- r1.setContent(r1content);
+ String r1content = "R1 content";
+ r1.setContent(r1content.getBytes());
try {
registry.put("/d1/r1", r1);
@@ -109,7 +109,7 @@
try {
d1 = registry.get("/d1");
} catch (RegistryException e) {
- fail("parent directory was not cerated.");
+ fail("parent directory was not created.");
}
assertTrue("/d1 should be a collection.", d1.isDirectory());
@@ -133,8 +133,8 @@
fail("resource was not stored.");
}
- assertEquals("Resource content is not stored correctly.",
- new String((byte[]) r1.getContent()), new String((byte[])
r1f.getContent()));
+ assertEquals("Resource content is not stored correctly.", r1content,
+ new String((byte[])r1f.getContent()));
try {
registry.delete("/d1");
Modified:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AbstractRegistryAction.java
==============================================================================
---
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AbstractRegistryAction.java
(original)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AbstractRegistryAction.java
Mon Jan 21 15:28:16 2008
@@ -19,7 +19,6 @@
import org.wso2.registry.Registry;
import org.wso2.registry.RegistryConstants;
import org.wso2.registry.RegistryException;
-import org.wso2.registry.jdbc.JDBCRegistry;
import org.wso2.registry.jdbc.realm.RegistryRealm;
import org.wso2.registry.secure.SecureRegistry;
import org.wso2.registry.web.ConsoleConstants;
Modified:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AddCollectionAction.java
==============================================================================
---
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AddCollectionAction.java
(original)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/actions/AddCollectionAction.java
Mon Jan 21 15:28:16 2008
@@ -34,7 +34,7 @@
setRequest(request);
- String path = "";
+ String path;
if (parentPath.equals(RegistryConstants.ROOT_PATH)) {
path = RegistryConstants.ROOT_PATH + collectionName;
Modified:
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/AdminUtil.java
==============================================================================
---
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/AdminUtil.java
(original)
+++
trunk/registry/modules/webapps/src/main/java/org/wso2/registry/web/utils/AdminUtil.java
Mon Jan 21 15:28:16 2008
@@ -18,27 +18,12 @@
import org.wso2.registry.web.beans.AdminBean;
import org.wso2.registry.web.UIConstants;
-import org.wso2.registry.config.RegistryConfigurationProcessor;
import org.wso2.registry.config.DataBaseConfiguration;
-import org.wso2.registry.RegistryConstants;
-import org.wso2.registry.Registry;
import org.wso2.registry.RegistryException;
-import org.wso2.registry.secure.SecureRegistry;
-import org.wso2.registry.jdbc.utils.RegistryDataSource;
-import org.wso2.registry.jdbc.realm.RegistryRealm;
-import org.wso2.registry.jdbc.realm.InMemoryRegistryRealm;
-import org.wso2.registry.jdbc.InMemoryJDBCRegistry;
-import org.wso2.registry.jdbc.JDBCRegistry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
-import javax.servlet.ServletContext;
-import javax.sql.DataSource;
-import javax.naming.Context;
-import javax.naming.InitialContext;
-import javax.naming.NamingException;
-import java.util.Map;
import java.io.IOException;
public class AdminUtil {
@@ -48,7 +33,7 @@
//RegistryConfigurationProcessor regConfiguration =
(RegistryConfigurationProcessor) request.getSession().
//
getServletContext().getAttribute(RegistryConstants.REGISTRY_CONFIG);
//
- ////Map dbConfigs = regConfiguration.getDbconfgigMap();
+ ////Map dbConfigs = regConfiguration.getDBConfigMap();
//
//AdminBean adminBean = new AdminBean();
////adminBean.setDbConfigs(dbConfigs);
@@ -57,11 +42,8 @@
return null;
}
- public static void addDBURLBasedConfiguration(HttpServletRequest request,
HttpServletResponse response) {
-
- RegistryConfigurationProcessor regConfiguration =
(RegistryConfigurationProcessor) request.getSession().
-
getServletContext().getAttribute(RegistryConstants.REGISTRY_CONFIG);
-
+ public static void addDBURLBasedConfiguration(HttpServletRequest request,
+ HttpServletResponse
response) {
String configName = request.getParameter("configName");
String dbURL = request.getParameter("dbURL");
String driverName = request.getParameter("driverName");
@@ -87,12 +69,6 @@
}
public static void removeDBConfiguration(HttpServletRequest request,
HttpServletResponse response) {
-
- RegistryConfigurationProcessor regConfiguration =
(RegistryConfigurationProcessor) request.getSession().
-
getServletContext().getAttribute(RegistryConstants.REGISTRY_CONFIG);
-
-
//regConfiguration.removeDataBaseConfiguration(request.getParameter("config"));
-
try {
request.getRequestDispatcher(UIConstants.ADMIN_JSP).forward(request, response);
} catch (ServletException e) {
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev