-
Notifications
You must be signed in to change notification settings - Fork 20
16. 404 page
JakeHoward edited this page Jul 16, 2015
·
1 revision
When Utterlyidle can't find a binding that matches your HTTP request, it generates a default match failure page with a 404 response code and a list of suggestions. It's a very useful feature e.g when you misspelled a query param name. If you want to exclude some bindings from showing up in the suggestions list, you can use a @Hidden annotation or a hidden() method on a DSL binding. When you put your application on a public web you may want to disable the default match failure page.
Here's the code for the custom MatchFailure renderer:
import com.googlecode.utterlyidle.MatchFailure;
import com.googlecode.utterlyidle.Renderer;
import com.googlecode.utterlyidle.handlers.RenderingResponseHandler;
import com.googlecode.utterlyidle.handlers.ResponseHandlers;
import com.googlecode.utterlyidle.modules.ResponseHandlersModule;
import static com.googlecode.totallylazy.Predicates.*;
import static com.googlecode.utterlyidle.handlers.HandlerRule.entity;
import static com.googlecode.utterlyidle.handlers.RenderingResponseHandler.renderer;
public class MatchFailureModule implements ResponseHandlersModule {
@Override
public ResponseHandlers addResponseHandlers(ResponseHandlers handlers) throws Exception {
handlers.add(where(entity(), is(instanceOf(MatchFailure.class))), customFailureRenderer());
return handlers;
}
private RenderingResponseHandler<Object> customFailureRenderer() {
return renderer(new Renderer<Object>() {
@Override
public String render(Object value) throws Exception {
return "404 - Not Found";
}
});
}
}