Hello,
I'm quite surprised also. I've just tried your resource (I send you the
complete test code) and it works with the current snapshot of Restlet 1.1.
Could you tell us more about your classpath?
Best regards,
Thierry Boileau
> Yes, thank you. Here is my test case. I apologize for not attaching it in
> my original message. It is essentially taken directly from the "first
> resource" tutorial yet stripped down to attempt to get it working, so I do
> not save an item or return a truly new identifier.
>
> The text is below and the exact .java file is attached to this post.
>
> I really don't understand what is wrong. I am following the examples
> closely, the rest of my code runs correctly, GET works correctly, and I
> recently did a fresh install of Windows and Eclipse, and a fresh clean setup
> for my current app in Eclipse with all of the required external JARs. So I
> am surprised by running into this problem. I have 10 resources working fine
> with GET and this is the first time I have tried to use POST. So i know my
> app is basically working otherwise.
>
> I can see from my console trace that the POST request is well formed (and can
> verify that via Firebug too on the sending end). I know the route to the
> resource is working properly because I tried adding to this resource the code
> for handling GET requests, and that worked perfectly as one would expect.
>
> So I am somewhat at a loss for direction. Thank you for all advice.
>
>
> public class DiscoveryResource extends Resource {
>
> public DiscoveryResource(Context context, Request request, Response
> response) {
> super(context, request, response);
> setModifiable(true);
> getVariants().add(new Variant(MediaType.TEXT_PLAIN));
> }
>
> public void acceptRepresentation(Representation entity)
> throws ResourceException {
> Form form = new Form(entity);
> String data = form.getFirstValue("data");
> getResponse().setStatus(Status.SUCCESS_CREATED);
> Representation rep = new StringRepresentation("POST succeeded",
> MediaType.TEXT_PLAIN);
>
> rep.setIdentifier(getRequest().getResourceRef().getIdentifier());
> getResponse().setEntity(rep);
> }
> }
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2418431package testPost;
import org.restlet.Application;
import org.restlet.Client;
import org.restlet.Component;
import org.restlet.Context;
import org.restlet.Restlet;
import org.restlet.Router;
import org.restlet.data.Form;
import org.restlet.data.MediaType;
import org.restlet.data.Protocol;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.data.Status;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.ResourceException;
import org.restlet.resource.StringRepresentation;
import org.restlet.resource.Variant;
public class DiscoveryResource extends Resource {
public static void main(String[] args) throws Exception {
Component c = new Component();
c.getServers().add(Protocol.HTTP, 8182);
Application a = new Application() {
@Override
public Restlet createRoot() {
Router router = new Router();
router.attach("/test", DiscoveryResource.class);
return router;
}
};
c.getDefaultHost().attach(a);
c.start();
Client client = new Client(Protocol.HTTP);
Form form = new Form();
form.add("data", "This is a test");
Response response = client.post("http://localhost:8182/test", form.getWebRepresentation());
System.out.println(response.getStatus());
if (response.getStatus().isSuccess()) {
response.getEntity().write(System.out);
}
c.stop();
}
public DiscoveryResource(Context context, Request request, Response response) {
super(context, request, response);
setModifiable(true);
getVariants().add(new Variant(MediaType.TEXT_PLAIN));
}
public void acceptRepresentation(Representation entity)
throws ResourceException {
Form form = new Form(entity);
String data = form.getFirstValue("data");
getResponse().setStatus(Status.SUCCESS_CREATED);
Representation rep = new StringRepresentation("POST succeeded => "
+ data, MediaType.TEXT_PLAIN);
rep.setIdentifier(getRequest().getResourceRef().getIdentifier());
getResponse().setEntity(rep);
}
}