Author: aparfonov
Date: 2010-06-21 08:41:26 -0400 (Mon, 21 Jun 2010)
New Revision: 2670
Modified:
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java
Log:
EXOJCR-713 :
Modified:
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java
===================================================================
---
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java 2010-06-21
12:20:03 UTC (rev 2669)
+++
ws/trunk/exo.ws.rest.core/src/main/java/org/exoplatform/services/rest/impl/RequestDispatcher.java 2010-06-21
12:41:26 UTC (rev 2670)
@@ -126,11 +126,11 @@
}
/**
- * Get last element from path parameters. This element will be used as request
- * path for child resources.
+ * Get last element from path parameters. This element will be used as
+ * request path for child resources.
*
* @param parameterValues See
- * {@link ApplicationContextImpl#getParameterValues()}
+ * {@link ApplicationContextImpl#getParameterValues()}
* @return last element from given list or empty string if last element is
* null
*/
@@ -141,18 +141,18 @@
}
/**
- * Process resource methods, sub-resource methods and sub-resource locators to
- * find the best one for serve request.
+ * Process resource methods, sub-resource methods and sub-resource locators
+ * to find the best one for serve request.
*
* @param request See {@link GenericContainerRequest}
* @param response See {@link GenericContainerResponse}
* @param context See {@link ApplicationContextImpl}
* @param resourceFactory the root resource factory or resource factory which
- * was created by previous sub-resource locator
+ * was created by previous sub-resource locator
* @param resource instance of resource class
* @param requestPath request path, it is relative path to the base URI or
- * other resource which was called before (one of sub-resource
- * locators)
+ * other resource which was called before (one of sub-resource
+ * locators)
*/
private void dispatch(GenericContainerRequest request, GenericContainerResponse
response,
ApplicationContext context, ObjectFactory<AbstractResourceDescriptor>
resourceFactory, Object resource,
@@ -322,14 +322,15 @@
}
/**
- * Compare two sub-resources. One of it is {@link SubResourceMethodDescriptor}
- * and other one id {@link SubResourceLocatorDescriptor}. First compare
- * UriPattern, see {@link UriPattern#URIPATTERN_COMPARATOR}. NOTE URI
- * comparator compare UriPattrens for descending sorting. So it it return
- * negative integer then it minds SubResourceMethodDescriptor has higher
- * priority by UriPattern comparison. If comparator return positive integer
- * then SubResourceLocatorDescriptor has higher priority. And finally if zero
- * was returned then UriPattern is equals, in this case
+ * Compare two sub-resources. One of it is
+ * {@link SubResourceMethodDescriptor} and other one id
+ * {@link SubResourceLocatorDescriptor}. First compare UriPattern, see
+ * {@link UriPattern#URIPATTERN_COMPARATOR}. NOTE URI comparator compare
+ * UriPattrens for descending sorting. So it it return negative integer then
+ * it minds SubResourceMethodDescriptor has higher priority by UriPattern
+ * comparison. If comparator return positive integer then
+ * SubResourceLocatorDescriptor has higher priority. And finally if zero was
+ * returned then UriPattern is equals, in this case
* SubResourceMethodDescriptor must be selected.
*
* @param srmd See {@link SubResourceMethodDescriptor}
@@ -414,7 +415,7 @@
if (rmds == null || rmds.size() == 0)
{
response.setResponse(Response.status(405).header("Allow",
HeaderHelper.convertToString(rmm.getAllow()))
- .build());
+ .entity("Method not
allowed.").type(MediaType.TEXT_PLAIN).build());
return false;
}
MediaType contentType = request.getMediaType();
@@ -435,7 +436,8 @@
if (methods.isEmpty())
{
-
response.setResponse(Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).build());
+
response.setResponse(Response.status(Response.Status.UNSUPPORTED_MEDIA_TYPE).entity(
+ "Media type " + contentType + " is not
supported.").type(MediaType.TEXT_PLAIN).build());
return false;
}
@@ -477,7 +479,8 @@
return true;
}
- response.setResponse(Response.status(Response.Status.NOT_ACCEPTABLE).build());
+
response.setResponse(Response.status(Response.Status.NOT_ACCEPTABLE).entity("Not
Acceptable").type(
+ MediaType.TEXT_PLAIN).build());
return false;
}
@@ -489,7 +492,7 @@
* @param request See {@link GenericContainerRequest}
* @param response See {@link GenericContainerResponse}
* @param capturingValues the list for keeping template values. See
- * {@link javax.ws.rs.core.UriInfo#getPathParameters()}
+ * {@link javax.ws.rs.core.UriInfo#getPathParameters()}
* @param methods list for method resources
* @return true if at least one sub-resource method found false otherwise
*/
@@ -516,7 +519,8 @@
if (rmm == null)
{
- response.setResponse(Response.status(Status.NOT_FOUND).build());
+ response.setResponse(Response.status(Status.NOT_FOUND).entity(
+ "There is no any resources matched to request path " +
requestedPath).type(MediaType.TEXT_PLAIN).build());
return false;
}
@@ -609,7 +613,8 @@
}
// Stop here, there is no matched root resource
- throw new
WebApplicationException(Response.status(Response.Status.NOT_FOUND).build());
+ throw new
WebApplicationException(Response.status(Response.Status.NOT_FOUND).entity(
+ "There is no any resources matched to request path " +
requestPath).type(MediaType.TEXT_PLAIN).build());
}
else
{
Modified:
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java
===================================================================
---
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java 2010-06-21
12:20:03 UTC (rev 2669)
+++
ws/trunk/exo.ws.rest.core/src/test/java/org/exoplatform/services/rest/impl/method/MethodReturnTypeTest.java 2010-06-21
12:41:26 UTC (rev 2670)
@@ -30,7 +30,7 @@
/**
* Created by The eXo Platform SAS. <br/>
* Date: 20 Jan 2009
- *
+ *
* @author <a href="mailto:dmitry.kataev@exoplatform.com.ua">Dmytro
Katayev</a>
* @version $Id: ResourceReturnTypeTest.java
*/
@@ -93,7 +93,7 @@
// void Results in an empty entity body with a 204 status code.
assertEquals(204, service("GET", "/a/0", "", null,
null).getStatus());
- assertNull(service("GET", "/a/o", "", null,
null).getEntity());
+ assertNull(service("GET", "/a/0", "", null,
null).getEntity());
// Response Results in an entity body mapped from the entity property of the
// Response