Skip to content

incorrect request mapping #779

@ArtemBudnikov

Description

@ArtemBudnikov

Request mapping only takes into account the number of path chunks (the number of slashes in the url) when finding the corresponding java method to call. It means that the two urls like
"/services/test/projects/1/files/2" and "/services/test/projects/1/images/3" are mapped to the same method. I created a simple test :

public class Test {
	@RequestMapping("/projects/{projectId}/files/{fileId}")
	public String test1(@PathVariable("projectId") int projectId, @PathVariable("fileId") int fileId) {
		return "test1";
	}

	@RequestMapping("/projects/{projectId}/images/{imageId}")
	public String test2(@PathVariable("projectId") int projectId, @PathVariable("imageId") int imageId) {
		return "test2";
	}
	public static void main(String[] args) {
		final ManagedServiceBuilder managedServiceBuilder = ManagedServiceBuilder.managedServiceBuilder().setRootURI("/services").setPort(2334);
		managedServiceBuilder.addEndpointService("test", new Test());

		EndpointServerBuilder builder = managedServiceBuilder.getEndpointServerBuilder();
		ServiceEndpointServer server = builder.build();
		server.startServer();

		HttpClient tmService = HttpClientBuilder.httpClientBuilder().setHost("localhost").setPort(2334).build();
		tmService.startClient();

		System.out.println(tmService.get("/services/test/projects/1/files/2"));
		System.out.println(tmService.get("/services/test/projects/1/images/3"));

	}
}

If you run the test, you'll get:

HttpTextResponse(code:200contentType:application/json
body:
"test1"
)
HttpTextResponse(code:200contentType:application/json
body:
"test1"
)

The first method is called in both cases, which is incorrect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions