Routing error in case controller and package have the same names
alniks opened this issue · comments
One more case, which causes error after recent updates. This time we have a package and route of the same name:
package app.controllers.api;
import org.javalite.activeweb.AppController;
import org.javalite.activeweb.annotations.POST;
public class TestController extends AppController {
@POST
public void index() {
respond("TestController#index");
}
}
package app.controllers;
import org.javalite.activeweb.AppController;
public class ApiController extends AppController {
public void index() {
respond("ApiController#index");
}
}
package app.config;
import app.controllers.ApiController;
import org.javalite.activeweb.AbstractRouteConfig;
import org.javalite.activeweb.AppContext;
public class RouteConfig extends AbstractRouteConfig {
public void init(AppContext appContext) {
route("/api").to(ApiController.class).action("index").get();
}
}
$ curl http://localhost:8888/api
system error: You defined a controller package 'api', but this request does not specify controller name
@alniks I was able to reproduce this issue. However, this philosophical discussion. You defined a controller api
and a package api
. The framework detects the package first, and assumes that you forgot to provide a controller, meaning your URI is incomplete. It stops processing then, and is not even trying to find a controller. IMHO, the behavior is correct.
Thoughts?
I pushed the commit that replicates this issue, you can clone, switch to that branch and see the same for yourself: https://github.com/javalite/activeweb/tree/issue_400
@ipolevoy The main thing is that recent updates broke application that worked before and they may do so to multiple others. I don't know why our application has such configuration - it was done long ago, but it worked. It might as well be done to avoid initial bug.
The current implementation still fails for this request (with a slash at the end):
$ curl http://localhost:8888/api/
Even if we have a route.
@yanchevsky , so the idea is that if you have:
- Custom route:
route("/api").to("AnyController.class").action("index");
and have a package app.controllers.api/*
and call:
curl http://localhost:8080/api/
then the specified custom route is not working with a message:
system error: You defined a controller package 'api', but did not specify controller name
The commit on this branch I pushed is hacky, it fixed this problem, but broke other tests.
@yanchevsky I believe this issue is actually fixed but not yet closed, is this correct?
@ipolevoy yes. we have tests for this issue.
perfect, closing