Hello,
I've just tried a short-cut to return the representation after a PUT:
calling get(variant), but it doesn't work as if it was doing a direct
GET. I'm not sure if it's a just a bad idea or if we should try to make
it work.
The test case looks like this:
public MyClass extends ServerResource {
@Get("xml")
public Document toXml() {
return ...;
}
public Representation put(Representation input, Variant variant) {
// Do something with input.
return get(variant);
}
}
The problem with this approach is that 'variant' is not an instance of
'VariantInfo', so in ServerResource.get(Variant), doHandle isn't called:
if (variant instanceof VariantInfo) {
result = doHandle(((VariantInfo) variant).getAnnotationInfo(),
variant);
} else {
setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
}
To make get(variant) from a variant that's not a VariantInfo, something
like the following patch could work. I'm just not sure if it's worth
doing it this way. Any thoughts?
Best wishes,
Bruno.
diff --git
a/modules/org.restlet/src/org/restlet/resource/ServerResource.java
b/modules/org.restlet/src/org/restlet/resource/ServerResource.java
index 1dfee23..39dd86d 100644
--- a/modules/org.restlet/src/org/restlet/resource/ServerResource.java
+++ b/modules/org.restlet/src/org/restlet/resource/ServerResource.java
@@ -635,9 +635,31 @@ public abstract class ServerResource extends
UniformResource {
protected Representation get(Variant variant) throws
ResourceException {
Representation result = null;
+ VariantInfo variantInfo = null;
+
if (variant instanceof VariantInfo) {
- result = doHandle(((VariantInfo) variant).getAnnotationInfo(),
- variant);
+ variantInfo = (VariantInfo) variant;
+ } else {
+ List<Variant> annoVariants = null;
+ for (AnnotationInfo annotationInfo : getAnnotations()) {
+ if (Method.GET.equals(annotationInfo.getRestletMethod())) {
+ annoVariants = annotationInfo.getResponseVariants(null,
+ getMetadataService(), getConverterService());
+ if (annoVariants != null) {
+ for (Variant v : annoVariants) {
+ if (v.isCompatible(variant)) {
+ variantInfo = new VariantInfo(variant,
+ annotationInfo);
+ break;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (variantInfo != null) {
+ result = doHandle(variantInfo.getAnnotationInfo(), variant);
} else {
setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
}
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2419000