Author: glen
Date: Sun Dec 23 07:00:37 2007
New Revision: 11692
Log:
* Clean up code in AtomRegistry. Introduce common method for getting a
ResponseContext from a Feed.
* Use a simpleExtension to carry the average rating in ratings feed
* Introduce ResourceNotFoundException so we can tell when to 404 (and turn 404s
into those on the client)
* Spelling fixes (SEPARATER -> SEPARATOR etc)
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/exceptions/
trunk/registry/modules/core/src/main/java/org/wso2/registry/exceptions/ResourceNotFoundException.java
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/RegistryConstants.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/RemoteRegistry.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/jdbc/mediatypes/MediaTypeManager.java
trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/APPTests.java
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
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
Sun Dec 23 07:00:37 2007
@@ -19,8 +19,9 @@
package org.wso2.registry;
-public class RegistryConstants {
+import javax.xml.namespace.QName;
+public interface RegistryConstants {
/**
* These constants are used to specify the core registry to use in the
registry server. This is
* specified as a init parameter of the Registry servlet.
@@ -131,10 +132,14 @@
public static final String PARAMETER_QUERY = "query";
public static final String PARAMETER_RESOURCE_EXIST = "resourceExists";
-
public static final String RESOURCES_JSP = "/admin/registry-resources.jsp";
public static final String RESOURCE_DETAILS_JSP =
"/admin/resources_details.jsp";
public static final String PATH_ATTR = "path";
- public static final String URL_SEPARATER = "_";
+ // Custom elements in Atom feeds and entries
+ public static final String NAMESPACE = "http://wso2.org/registry";
+ public static final QName QNAME_AVGRATING = new QName(NAMESPACE,
"AverageRating", "wso2");
+
+ // Separator used to access Registry metadata - i.e. "/resource$tags"
+ public static final String URL_SEPARATOR = "$";
}
Modified:
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
==============================================================================
---
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
(original)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/app/AtomRegistry.java
Sun Dec 23 07:00:37 2007
@@ -36,6 +36,7 @@
import org.apache.commons.logging.LogFactory;
import org.wso2.registry.Comment;
import org.wso2.registry.*;
+import org.wso2.registry.exceptions.ResourceNotFoundException;
import org.wso2.registry.i18n.Messages;
import javax.activation.MimeType;
@@ -236,14 +237,27 @@
*/
public ResponseContext getFeed(RequestContext request) {
Abdera abdera = request.getAbdera();
- AbstractResponseContext rc;
String baseURI = request.getBaseUri().toString();
String entry_id = getRealPath(request);
- String values[] = splitPath(entry_id);
- if (values.length > 1) {
+ int idx = entry_id.indexOf(RegistryConstants.URL_SEPARATOR);
+ String resourcePath = entry_id.substring(0, (idx == -1) ?
entry_id.length() : idx);
+
+ // See if the resource is there. If not, no further work is necessary
as we'll be
+ // returning a 404...
+ Resource resource;
+ try {
+ resource = registry.get(resourcePath);
+ } catch (ResourceNotFoundException e) {
+ return new EmptyResponseContext(404);
+ } catch (RegistryException e) {
+ return new EmptyResponseContext(500);
+ }
+
+ Feed feed = null;
+ if (idx > -1) {
+ String operation = entry_id.substring(idx + 1);
+
// seems like some we need to do some filtering
- String resourcePath = values[0];
- String operation = values[1];
//Checking whether the parameter is there in the operation , like
tags:foo
String parameter = null;
if (operation.indexOf(":") > 0) {
@@ -256,7 +270,7 @@
try {
String[] versions = registry.getVersions(resourcePath);
Factory factory = abdera.getFactory();
- Feed feed = factory.newFeed();
+ feed = factory.newFeed();
feed.setId("http://wso2.org/registry,atom:version");
feed.setTitle("Available versions for " + resourcePath);
feed.setSubtitle(Messages.getMessage("resource.version",
resourcePath));
@@ -266,10 +280,6 @@
createEntriesFromStringArray(versions,
request.getBaseUri().toString(),
abdera, "versionLink",
feed);
- Document<Feed> docfeed = feed.getDocument();
- rc = new BaseResponseContext<Document<Feed>>(docfeed);
- rc.setEntityTag(calculateEntityTag(docfeed.getRoot()));
- return rc;
} catch (RegistryException e) {
return new EmptyResponseContext(500);
}
@@ -277,51 +287,31 @@
// if the user [parameter] name is null then need to return
all the
// tags for the given path
if (parameter == null) {
- Feed feed = getFeedForTags(abdera, resourcePath, baseURI);
- Document<Feed> docfeed = feed.getDocument();
- rc = new BaseResponseContext<Document<Feed>>(docfeed);
- rc.setEntityTag(calculateEntityTag(docfeed.getRoot()));
- return rc;
+ feed = getFeedForTags(abdera, resourcePath, baseURI);
} else {
- // Need to return only the tags which are doen by giving
user
+ // Need to return only the tags which are doen by given
user
// TODO registry need to provide this feature
}
} else if
(RegistryConstants.PARAMETER_AVERAGE_RATINGS.equals(operation)) {
- Feed feed = getFeedForAvarageRating(abdera, resourcePath,
baseURI);
- Document<Feed> docfeed = feed.getDocument();
- rc = new BaseResponseContext<Document<Feed>>(docfeed);
- rc.setEntityTag(calculateEntityTag(docfeed.getRoot()));
- return rc;
+ feed = getRatingsFeed(abdera, resourcePath, baseURI);
} else if (RegistryConstants.PARAMETER_RATINGS.equals(operation)) {
- Feed feed = getFeedForRating(abdera, resourcePath, parameter);
- Document<Feed> docfeed = feed.getDocument();
- rc = new BaseResponseContext<Document<Feed>>(docfeed);
- rc.setEntityTag(calculateEntityTag(docfeed.getRoot()));
- return rc;
+ if (parameter != null) {
+ feed = getFeedForRating(abdera, resourcePath, parameter);
+ } else {
+ feed = getRatingsFeed(abdera, resourcePath, baseURI);
+ }
} else if (RegistryConstants.PARAMETER_COMMENTS.equals(operation))
{
- Feed feed = getFeedForComments(abdera, resourcePath);
- Document<Feed> docfeed = feed.getDocument();
- rc = new BaseResponseContext<Document<Feed>>(docfeed);
- rc.setEntityTag(calculateEntityTag(docfeed.getRoot()));
- return rc;
+ feed = getFeedForComments(abdera, resourcePath);
} else if
(RegistryConstants.PARAMETER_TAG_PATHS.equals(operation)) {
- Feed feed = getFeedForTagPaths(abdera, parameter, baseURI);
- Document<Feed> docfeed = feed.getDocument();
- rc = new BaseResponseContext<Document<Feed>>(docfeed);
- rc.setEntityTag(calculateEntityTag(docfeed.getRoot()));
- return rc;
+ feed = getFeedForTagPaths(abdera, parameter, baseURI);
} else if (RegistryConstants.PARAMETER_LOGS.equals(operation)) {
Date to = request.getDateHeader("ToDate");
Date from = request.getDateHeader("FromDate");
String action = request.getHeader("Action");
String author = request.getHeader("Author");
try {
- Feed feed = getFeedForLogs(abdera, resourcePath, from, to,
author, action);
- Document<Feed> docfeed = feed.getDocument();
- rc = new BaseResponseContext<Document<Feed>>(docfeed);
- rc.setEntityTag(calculateEntityTag(docfeed.getRoot()));
- return rc;
+ feed = getFeedForLogs(abdera, resourcePath, from, to,
author, action);
} catch (RegistryException e) {
return new EmptyResponseContext(500);
}
@@ -331,46 +321,32 @@
String parms = request.getHeader("parameters");
String[] parameters =
RemoteRegistry.decodeParametesAsString(parms);
- Resource resource = registry.executeQuery(resourcePath,
parameters);
- Feed feed = populateFeed(abdera, baseURI, resourcePath,
resource, true);
- Document<Feed> docfeed = feed.getDocument();
- rc = new BaseResponseContext<Document<Feed>>(docfeed);
- rc.setEntityTag(calculateEntityTag(docfeed.getRoot()));
- return rc;
+ resource = registry.executeQuery(resourcePath, parameters);
+ feed = populateFeed(abdera, baseURI, resourcePath,
resource, true);
} catch (RegistryException e) {
return new EmptyResponseContext(500);
}
} else if
(RegistryConstants.PARAMETER_RESOURCE_EXIST.equals(operation)) {
- Feed feed = getFeedResourceExist(abdera, resourcePath);
- Document<Feed> docfeed = feed.getDocument();
- rc = new BaseResponseContext<Document<Feed>>(docfeed);
- rc.setEntityTag(calculateEntityTag(docfeed.getRoot()));
- return rc;
+ feed = getFeedResourceExist(abdera, resourcePath);
} else {
return createErrorResponse();
}
} else {
//need to return a feed representing resource.
- if ("atom".equals(entry_id) || entry_id == null ||
"".equals(entry_id)) {
- entry_id = "/";
- }
- Document<Feed> feed;
- try {
- Resource resource = registry.get(entry_id);
- Feed feedObj = populateFeed(abdera, baseURI, entry_id,
resource, false);
- if (feedObj != null) {
- feed = feedObj.getDocument();
- rc = new BaseResponseContext<Document<Feed>>(feed);
- rc.setEntityTag(calculateEntityTag(feed.getRoot()));
- return rc;
- } else {
- return createErrorResponse();
- }
- } catch (RegistryException e) {
- return createErrorResponse();
- }
+ feed = populateFeed(abdera, baseURI, entry_id, resource, false);
}
- return null;
+
+ if (feed != null) return getResponseContextForFeed(feed);
+
+ return createErrorResponse();
+ }
+
+ private AbstractResponseContext getResponseContextForFeed(Feed feed) {
+ AbstractResponseContext rc;
+ Document<Feed> docfeed = feed.getDocument();
+ rc = new BaseResponseContext<Document<Feed>>(docfeed);
+ rc.setEntityTag(calculateEntityTag(docfeed.getRoot()));
+ return rc;
}
/**
@@ -587,7 +563,8 @@
private String getRealPath(RequestContext request) {
String path = request.getBaseUri().getPath();
String uri = request.getUri().toString();
- return uri.replaceAll(path + "atom", "");
+ uri = uri.replaceAll(path + "atom", "");
+ return (uri.length() == 0) ? "/" : uri;
}
/**
@@ -598,7 +575,7 @@
* @return String array of the splited string
*/
private String[] splitPath(String path) {
- return path.split("\\" + RegistryConstants.URL_SEPARATER);
+ return path.split("\\" + RegistryConstants.URL_SEPARATOR);
}
private EntityTag calculateEntityTag(Base base) {
@@ -634,7 +611,7 @@
feed.setId("http://wso2.org/registry:tags" + path);
feed.setTitle("Tags for " + path);
String nodeLink = baseUri + "atom" + path +
- RegistryConstants.URL_SEPARATER +
+ RegistryConstants.URL_SEPARATOR +
RegistryConstants.PARAMETER_TAGS;
feed.addLink(nodeLink);
feed.setUpdated(new Date());
@@ -653,17 +630,15 @@
}
/**
- * This method will return average rating for a give resource , text of
the feed represent the
- * avg rating value
+ * Get an Atom feed for the ratings of a given resource. This feed will
contain
+ * an extension "AverageRating", and entries for each individual rating.
*
* @param abdera : Abdera instance
* @param path : Resource path
* @param baseUri : Base URI of the regsitry
- * @return : Feed representing the avarage feed
+ * @return Feed representing the average feed
*/
- private Feed getFeedForAvarageRating(Abdera abdera,
- String path,
- String baseUri) {
+ private Feed getRatingsFeed(Abdera abdera, String path, String baseUri) {
try {
Factory factory = abdera.getFactory();
Feed feed = factory.newFeed();
@@ -671,10 +646,11 @@
feed.setId("http://wso2.org/registry:avarageRating");
feed.setTitle("Avarage Rating for the resource " + path);
String nodeLink = baseUri + "atom" + path +
- RegistryConstants.URL_SEPARATER +
+ RegistryConstants.URL_SEPARATOR +
RegistryConstants.PARAMETER_AVERAGE_RATINGS;
feed.addLink(nodeLink);
- feed.setSubtitle("" + registry.getAverageRating(path));
+ feed.addSimpleExtension(RegistryConstants.QNAME_AVGRATING,
+ "" + registry.getAverageRating(path));
return feed;
} catch (RegistryException e) {
return null;
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
Sun Dec 23 07:00:37 2007
@@ -29,6 +29,7 @@
import org.apache.commons.logging.LogFactory;
import org.wso2.registry.Comment;
import org.wso2.registry.*;
+import org.wso2.registry.exceptions.ResourceNotFoundException;
import org.wso2.registry.i18n.Messages;
import javax.xml.namespace.QName;
@@ -39,7 +40,7 @@
import java.util.List;
import java.util.Properties;
-public class RemoteRegistry implements Registry {
+public class RemoteRegistry implements Registry, RegistryConstants {
private String baseURI;
private Log log = LogFactory.getLog(RemoteRegistry.class);
@@ -59,15 +60,15 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI + path);
- if (clientResponse.getType() == Response.ResponseType.SERVER_ERROR) {
- throw new
RegistryException(Messages.getMessage("resource.not.found.warn", path));
+ if (clientResponse.getType() == Response.ResponseType.CLIENT_ERROR) {
+ throw new ResourceNotFoundException(path);
}
Document introspection =
clientResponse.getDocument();
Feed feed = (Feed) introspection.getRoot();
String state = feed.getSimpleExtension(new QName("state"));
if (state != null && state.equals("Deleted")) {
- throw new
RegistryException(Messages.getMessage("resource.not.found"));
+ throw new ResourceNotFoundException(path);
}
return createResourceFromFeed(feed, false);
}
@@ -103,7 +104,7 @@
resource.setDescription(feed.getSubtitle());
String state = feed.getSimpleExtension(new QName("state"));
if (state != null && "Deleted".equals(state)) {
- resource.setState(RegistryConstants.DELETED_STATE);
+ resource.setState(DELETED_STATE);
}
if (isDirectory != null && "true".equals(isDirectory)) {
@@ -141,8 +142,8 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI + path +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_RESOURCE_EXIST);
+ URL_SEPARATOR +
+ PARAMETER_RESOURCE_EXIST);
Document introspection =
clientResponse.getDocument();
Feed feed = (Feed) introspection.getRoot();
@@ -156,8 +157,8 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
Entry entry = abdera.getFactory().newEntry();
- if
(RegistryConstants.SQL_QUERY_MEDIA_TYPE.equals(resource.getMediaType())) {
- entry.setAttributeValue("mediaType",
RegistryConstants.SQL_QUERY_MEDIA_TYPE);
+ if (SQL_QUERY_MEDIA_TYPE.equals(resource.getMediaType())) {
+ entry.setAttributeValue("mediaType", SQL_QUERY_MEDIA_TYPE);
}
entry.setSummary(resource.getDescription());
entry.addAuthor(resource.getAuthorUserName());
@@ -208,8 +209,8 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI + path +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_VERSION);
+ URL_SEPARATOR +
+ PARAMETER_VERSION);
Document introspection =
clientResponse.getDocument();
Feed feed = (Feed) introspection.getRoot();
@@ -230,8 +231,8 @@
AbderaClient abderaClient = new AbderaClient(abdera);
Entry entry = abdera.getFactory().newEntry();
ClientResponse resp = abderaClient.put(baseURI + versionPath +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_RESTORE, entry);
+ URL_SEPARATOR +
+ PARAMETER_RESTORE, entry);
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.restoreded", versionPath));
} else {
@@ -246,8 +247,8 @@
Entry entry = abdera.getFactory().newEntry();
entry.setContent(tag);
ClientResponse resp = abderaClient.put(baseURI + resourcePath +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_TAGS, entry);
+ URL_SEPARATOR +
+ PARAMETER_TAGS, entry);
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.tagged", resourcePath));
} else {
@@ -260,8 +261,8 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_TAG_PATHS +
+ URL_SEPARATOR +
+ PARAMETER_TAG_PATHS +
":" + tag);
Document introspection =
clientResponse.getDocument();
@@ -286,8 +287,8 @@
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI +
resourcePath +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_TAGS);
+ URL_SEPARATOR +
+ PARAMETER_TAGS);
Document introspection =
clientResponse.getDocument();
Feed feed = (Feed) introspection.getRoot();
@@ -312,8 +313,8 @@
Entry entry = abdera.getFactory().newEntry();
entry.setContent(tag);
ClientResponse resp = abderaClient.put(baseURI + path +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_TAGS_REMOVED, entry);
+ URL_SEPARATOR +
+ PARAMETER_TAGS_REMOVED, entry);
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("tag.removed", path));
} else {
@@ -330,8 +331,8 @@
entry.addAuthor(comment.getCommentedUser());
entry.setContent(comment.getCommentText());
ClientResponse resp = abderaClient.put(baseURI + resourcePath +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_COMMENTS, entry);
+ URL_SEPARATOR +
+ PARAMETER_COMMENTS, entry);
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.commented", resourcePath));
} else {
@@ -344,8 +345,8 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI +
resourcePath +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_COMMENTS);
+ URL_SEPARATOR +
+ PARAMETER_COMMENTS);
Document introspection =
clientResponse.getDocument();
Element element = introspection.getRoot();
@@ -371,10 +372,10 @@
AbderaClient abderaClient = new AbderaClient(abdera);
Entry entry = abdera.getFactory().newEntry();
entry.setContent("" + rating);
- entry.setSummary(RegistryConstants.PARAMETER_RATINGS);
+ entry.setSummary(PARAMETER_RATINGS);
ClientResponse resp = abderaClient.put(baseURI + resourcePath +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_RATINGS, entry);
+ URL_SEPARATOR +
+ PARAMETER_RATINGS, entry);
if (resp.getType() == Response.ResponseType.SUCCESS) {
log.info(Messages.getMessage("resource.rated", resourcePath));
} else {
@@ -387,12 +388,10 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse = abderaClient.get(baseURI +
resourcePath +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_AVERAGE_RATINGS);
- Document introspection =
- clientResponse.getDocument();
+ URL_SEPARATOR + PARAMETER_RATINGS);
+ Document introspection = clientResponse.getDocument();
Feed feed = (Feed) introspection.getRoot();
- String floatvalue = feed.getSubtitle();
+ String floatvalue = feed.getSimpleExtension(QNAME_AVGRATING);
return Float.parseFloat(floatvalue);
}
@@ -400,9 +399,8 @@
Abdera abdera = new Abdera();
AbderaClient abderaClient = new AbderaClient(abdera);
ClientResponse clientResponse =
- abderaClient.get(baseURI + path +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_RATINGS + ":" + userName);
+ abderaClient.get(baseURI + path + URL_SEPARATOR +
+ PARAMETER_RATINGS + ":" + userName);
Document introspection =
clientResponse.getDocument();
Feed feed = (Feed) introspection.getRoot();
@@ -417,8 +415,8 @@
RequestOptions requestOptions = new RequestOptions();
requestOptions.addHeader("parameters",
encodeParametesAsString(parameters));
ClientResponse resp = abderaClient.get(baseURI + path +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_QUERY, requestOptions);
+ URL_SEPARATOR +
+ PARAMETER_QUERY, requestOptions);
Document introspection =
resp.getDocument();
Feed feed = (Feed) introspection.getRoot();
@@ -460,8 +458,7 @@
requestOptions.addHeader("Action", "" + action);
requestOptions.addHeader("Author", userName);
ClientResponse resp = abderaClient.get(baseURI + resourcePath +
- RegistryConstants.URL_SEPARATER +
- RegistryConstants.PARAMETER_LOGS, requestOptions);
+ URL_SEPARATOR + PARAMETER_LOGS, requestOptions);
Document introspection =
resp.getDocument();
Feed feed = (Feed) introspection.getRoot();
Added:
trunk/registry/modules/core/src/main/java/org/wso2/registry/exceptions/ResourceNotFoundException.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/core/src/main/java/org/wso2/registry/exceptions/ResourceNotFoundException.java
Sun Dec 23 07:00:37 2007
@@ -0,0 +1,28 @@
+/*
+ * 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.exceptions;
+
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.i18n.Messages;
+
+/**
+ * This is thrown when a requested resource cannot be located in the Registry.
+ */
+public class ResourceNotFoundException extends RegistryException {
+ public ResourceNotFoundException(String path) {
+ super(Messages.getMessage("resource.get.error", path));
+ }
+}
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
Sun Dec 23 07:00:37 2007
@@ -22,6 +22,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.registry.*;
+import org.wso2.registry.exceptions.ResourceNotFoundException;
import org.wso2.registry.i18n.Messages;
import org.wso2.registry.inmemory.comments.CommentManager;
import org.wso2.registry.inmemory.ratings.RatingsManager;
@@ -56,7 +57,7 @@
public Resource get(String path) throws RegistryException {
Resource resource = (Resource)resourceMap.get(path);
if (resource == null) {
- throw new
RegistryException(Messages.getMessage("resource.get.error", path));
+ throw new ResourceNotFoundException(path);
}
return resource;
}
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
Sun Dec 23 07:00:37 2007
@@ -22,6 +22,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.registry.*;
+import org.wso2.registry.exceptions.ResourceNotFoundException;
import org.wso2.registry.i18n.Messages;
import org.wso2.registry.jdbc.dao.*;
import org.wso2.registry.jdbc.mediatypes.MediaTypeManager;
@@ -198,15 +199,8 @@
resource = mediaTypeManager.get(path);
}
- if (resource == null) {
- String message = Messages.getMessage("artifact.get.error", path);
- throw new RegistryException(message);
- }
-
- if (resource.getState() == RegistryConstants.DELETED_STATE) {
- String msg = "Resource at path " + resource.getPath() + " does not
exists.";
- log.error(msg);
- throw new RegistryException(msg);
+ if (resource == null || resource.getState() ==
RegistryConstants.DELETED_STATE) {
+ throw new ResourceNotFoundException(path);
}
return resource;
@@ -214,11 +208,11 @@
public boolean resourceExists(String path) throws RegistryException {
- boolean resourceExist = false;
+ boolean exists = false;
Connection conn = getConnection();
try {
- resourceExist = resourceDAO.resourceExist(path, conn);
+ exists = resourceDAO.resourceExist(path, conn);
} catch (SQLException e) {
String msg = "Failed to check the exsitence of a resource at path
" + path;
log.error(msg, e);
@@ -232,7 +226,7 @@
}
}
- return resourceExist;
+ return exists;
}
/**
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
Sun Dec 23 07:00:37 2007
@@ -21,6 +21,7 @@
import org.wso2.registry.RegistryConstants;
import org.wso2.registry.RegistryException;
import org.wso2.registry.Resource;
+import org.wso2.registry.exceptions.ResourceNotFoundException;
import org.wso2.registry.i18n.Messages;
import org.wso2.registry.jdbc.JDBCRegistry;
import org.wso2.registry.jdbc.dao.VersionedResourceDAO;
@@ -81,7 +82,7 @@
Resource processedArtifact = null;
if (resource == null) {
- throw new RegistryException("No resource found at path " + path);
+ throw new ResourceNotFoundException(path);
}
if (resource.getMediaType() != null) {
Modified:
trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties
==============================================================================
---
trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties
(original)
+++
trunk/registry/modules/core/src/main/resources/org/wso2/registry/i18n/resource.properties
Sun Dec 23 07:00:37 2007
@@ -43,7 +43,7 @@
server.initalized=Registry intialized successfully.
resource.delete.error=Cannot delete non-existing resource. Resource with the
path {0} does not exist.
resource.adding.error={0} is not a collectionContent. Therefore, it is unable
to add a new resource to the path {1}
-resource.get.error=Requested resource {0} does not exist.
+resource.get.error=Resource at ''{0}'' does not exist.
delete.null.resource=Cannot delete non-existing resource {0}.
comment.on.null.artfact=Cannot comment on non-existing artfact {0}.
rate.on.null.artfact="Cannot rate on non-existing artfact {0}.
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
Sun Dec 23 07:00:37 2007
@@ -46,7 +46,7 @@
*
* TODO: WORK IN PROGRESS (Glen)
*/
-public class APPTests extends TestCase {
+public class APPTests extends TestCase implements RegistryConstants {
DefaultServiceContext abderaServiceContext;
public void setUp() throws Exception {
@@ -123,7 +123,7 @@
// GET /foo;tags - 404
// Make sure metadata indicator doesn't change error code
- method = new GetMethod(buildURL("foo;tags"));
+ method = new GetMethod(buildURL("foo" + URL_SEPARATOR + "tags"));
responseCode = client.executeMethod(method);
assertEquals(404, responseCode);
Modified:
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
==============================================================================
---
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
(original)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/JettyBasedServerTest.java
Sun Dec 23 07:00:37 2007
@@ -70,7 +70,7 @@
abderaServiceContext
.setDefaultTargetResolver(RegistryAPPTargetResolver.class.getName());
abderaServiceContext.init(getAbdera(),
getProperties(getServletConfig()));
- JDBCRegistry jdbcRegistry = null;
+ JDBCRegistry jdbcRegistry;
try {
RegistryRealm realm = new InMemoryRegistryRealm();
jdbcRegistry = new InMemoryJDBCRegistry(realm);
@@ -82,7 +82,6 @@
} catch (RegistryException e) {
e.printStackTrace();
}
- registry = jdbcRegistry;
return abderaServiceContext;
}
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev