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

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions