Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ittays opened this issue Feb 24, 2022 · 6 comments · Fixed by #700
Assignees
Labels
kind/bug Something isn't working P1 size/XS triaged/resolved Items triaged and ready
Milestone

Comments

@ittays
Copy link

ittays commented Feb 24, 2022

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

@ittays ittays added the kind/bug Something isn't working label Feb 24, 2022
@artursouza
Copy link
Member

Thanks for reporting this bug with such level of detail.

@artursouza artursouza added P1 size/XS triaged/resolved Items triaged and ready labels Feb 24, 2022
@artursouza artursouza added this to Backlog in Dapr Roadmap via automation Feb 24, 2022
@artursouza artursouza removed this from Backlog in Dapr Roadmap Feb 24, 2022
@mukundansundar
Copy link
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 ?

@artursouza
Copy link
Member

Agreed.

@DeepanshuA
Copy link
Contributor

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

@DeepanshuA
Copy link
Contributor

/assign

@ittays
Copy link
Author

ittays commented Mar 21, 2022

Well done! 🌟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working P1 size/XS triaged/resolved Items triaged and ready
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants