|
Mail sent on the 09/10 and
apparently lost. --- Hello Kenji, I'm a little surprised by the fact that the Filter#afterHandle method does not work as expected. What kind of filter are you suspecting to fail? Anyway, I send you a sample code containing 3 classes: an application, a resource and a filter. The application puts the filter as its own root restlet, thus the afterHandle method of the filter is called after all methods. Please feel free to detail your need, I may have missed something. Best regards, Thierry Boileau -- Restlet ~ Core developer ~ http://www.restlet.org Noelios Technologies ~ Co-founder ~ http://www.noelios.com Hi, I'm trying to hook the end of POST calls, and I've tried these :Filter#afterHandle Handler#handleXxx Application#handle Works fine for GET requests, but for POST requests, these get called before response data is sent to the browser. Is there any way to hook the point when response data is sent? Thanks, Kenji Tayama |
package 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.Protocol;
import org.restlet.resource.StringRepresentation;
public class TestApplication extends Application {
public static void main(String[] args) throws Exception {
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8182);
component.getDefaultHost()
.attachDefault(
new TestApplication(component.getContext()
.createChildContext()));
component.start();
Client client = new Client(Protocol.HTTP);
client.post("http://localhost:8182/", new StringRepresentation("test"));
component.stop();
}
public TestApplication(Context context) {
super(context);
}
@Override
public Restlet createRoot() {
Router router = new Router(getContext());
router.attachDefault(TestResource.class);
// Filter all requests handled by the application.
return new TestFilter(getContext(), router);
}
}
package testPost;
import org.restlet.Context;
import org.restlet.Filter;
import org.restlet.Restlet;
import org.restlet.data.Request;
import org.restlet.data.Response;
public class TestFilter extends Filter {
public TestFilter(Context context, Restlet next) {
super(context, next);
}
@Override
protected void afterHandle(Request request, Response response) {
// TODO Auto-generated method stub
super.afterHandle(request, response);
}
@Override
protected int beforeHandle(Request request, Response response) {
// TODO Auto-generated method stub
return super.beforeHandle(request, response);
}
@Override
protected int doHandle(Request request, Response response) {
// TODO Auto-generated method stub
return super.doHandle(request, response);
}
}
package testPost;
import org.restlet.Context;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.ResourceException;
import org.restlet.resource.StringRepresentation;
public class TestResource extends Resource {
/**
* Handle post calls
*/
@Override
public void acceptRepresentation(Representation entity)
throws ResourceException {
getResponse().setEntity(new StringRepresentation("ok"));
}
public TestResource(Context context, Request request, Response response) {
super(context, request, response);
setModifiable(true);
}
}

