can anyone point me how to view my custom 404 page. I googled and tried implementing ExceptionMapper<RuntimeException>
but this did not work fully. I'm using 0.8.1 version
My Exception mapper:
public class RuntimeExceptionMapper implements ExceptionMapper<NotFoundException> {
@Override
public Response toResponse(NotFoundException exception) {
Response defaultResponse = Response.status(Status.OK)
.entity(JsonUtils.getErrorJson("default response"))
.build();
return defaultResponse;
}
}
This only works on incorrect APIs and not on resource calls
My Setup :
@Override
public void initialize(Bootstrap<WebConfiguration> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/webapp", "/", "index.html"));
}
@Override
public void run(WebConfiguration configuration, Environment environment) throws Exception {
environment.jersey().register(RuntimeExceptionMapper.class);
((AbstractServerFactory) configuration.getServerFactory()).setJerseyRootPath("/api/*");
// Registering Resources
environment.jersey().register(new AuditResource(auditDao));
....
}
Now,
http://localhost:8080/api/rubish
goes through overridden ExceptionMapper method
http://localhost:8080/rubish.html
results in default 404 page
How do i setup so that whenever unknown pages are requested dropwizard will show up a custom 404 page
I refereed this link for the exception mapper