Skip to content

spring-boot: Using @Topic annotation reads the path from methods' @PostMapping, ignoring class-level @RequestMapping #694

Description

@ittays

Expected Behavior

When annotating a controller with @RequestMapping and a method with @PostMapping actual HTTP path is the combination of both.

So, when annotating the method with @Topic I expect it to map the topic with the full path.

Actual Behavior

The topic is mapped with a truncated path, which is only the @PostMapping value.
Publishing to the topic constantly fail, as path not found.

Steps to Reproduce the Problem

Create a controller and start the app:

@Controller
@RequestMapping(value = "/v1")
public class MyController {
    @Topic(pubsubName = "pubsub", name = "my-topic")
    @PostMapping("foo")
    public void foo(@RequestBody(required = false) CloudEvent<String> cloudEvent) {
        log.trace("{}", cloudEvent.getData());
    }
}

Publish with dapr publish --publish-app-id myapp --pubsub pubsub --topic my-topic --data hello-world.

Observe sidecar error: "non-retriable error returned from app while processing pub/sub event 9d8b9f70-9985-4665-8ce8-1d63a7935977: {\"timestamp\":1645712855614,\"status\":404,\"error\":\"Not Found\",\"message\":\"No message available\",\"path\":\"/foo\"}. status code returned: 404".

Error referrs to "path": "/foo", but actual path is /v1/foo.

The code that can be improved is on https://github.com/dapr/java-sdk/blob/master/sdk-springboot/src/main/java/io/dapr/springboot/DaprBeanPostProcessor.java

Release Note

RELEASE NOTE: FIX Topic annotation handles class-level @RequestMapping

Activity

  1. artursouza commented on Feb 24, 2022

    @artursouza
    Contributor

    Thanks for reporting this bug with such level of detail.

  2. mukundansundar commented on Mar 1, 2022

    @mukundansundar
    Contributor

    Currently the post processor only supports one value from the PostMapping annotation. In the scenario that there are multiple routes that is processed by the same method/controller, only the first value/path is taken into account. I think we can enhance the post processor such that all paths specified within PostMapping annotation are taken into consideration and not only the first path as it is now.

    cc @artursouza thoughts ?

  3. artursouza commented on Mar 3, 2022

    @artursouza
    Contributor

    Agreed.

  4. DeepanshuA commented on Mar 3, 2022

    @DeepanshuA
    Contributor

    Assigning this to myself. Please feel free to re-assign if someone has already started work on this.

  5. DeepanshuA commented on Mar 3, 2022

    @DeepanshuA
    Contributor

    /assign

  6. ittays commented on Mar 21, 2022

    @ittays
    Author

    Well done! 🌟

  7. added this to the v1.5 milestone on Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions