Skip to content


Browse files Browse the repository at this point in the history
provides a default route to handle 404 response in prod mode
The factory was listing all the existing endpoints if no route was
found for a request. By defining this new route, which match all
kind of request, we will bypass the `RestxMainRouterFactory`.
This route is only activated in "prod" mode, as the listing might
be useful during development.
  • Loading branch information
a-peyrard committed Feb 10, 2016
1 parent e0e01e5 commit fce9d8d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions restx-core/src/main/java/restx/security/
@@ -1,12 +1,26 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import restx.RestxContext;
import restx.RestxHandler;
import restx.RestxHandlerMatch;
import restx.RestxRequest;
import restx.RestxRequestMatch;
import restx.RestxResponse;
import restx.RestxRoute;
import restx.StdRestxRequestMatch;
import restx.WebException;
import restx.common.RestxConfig;
import restx.config.SettingsKey;
import restx.factory.AutoStartable;
import restx.factory.Module;
import restx.factory.Provides;
import restx.factory.When;
import restx.http.HttpStatus;

import javax.inject.Named;
Expand Down Expand Up @@ -65,4 +79,23 @@ public int sessionsLimit() {
public EntryCacheManager guavaCacheManager() {
return new GuavaEntryCacheManager();

@Provides(priority = 100000)
@When(name = "restx.mode", value = "prod")
public RestxRoute productionNotFoundHandler() {
return new RestxRoute() {
public Optional<RestxHandlerMatch> match(RestxRequest req) {
return Optional.of(new RestxHandlerMatch(
new StdRestxRequestMatch("*", req.getRestxPath()),
new RestxHandler() {
public void handle(RestxRequestMatch match, RestxRequest req, RestxResponse resp, RestxContext ctx) throws IOException {
throw new WebException(HttpStatus.NOT_FOUND);

0 comments on commit fce9d8d

Please sign in to comment.