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

DateTime Input causing exceptions when direct invoking. #67

Open
kingkong-AI opened this issue Jun 14, 2024 · 0 comments
Open

DateTime Input causing exceptions when direct invoking. #67

kingkong-AI opened this issue Jun 14, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@kingkong-AI
Copy link
Contributor

Describe the bug

When direct invoking the reserve method, we input values, we get the mentioned exception trace. This does not happen during a postman call. It seems to be occuring by how the direct invoke input is being captured:

Screenshot 2024-06-14 at 5 24 22 PM

Controller Method:

@RestController
public class MockConcertController {

    private final Random random = new Random();

    @PostMapping("integration/splitter/concert/reserve")
    public Flux<ConcertReservationResponse> reserve(@RequestBody Flux<ConcertReservationRequest> requestFlux) {
        return requestFlux.flatMap(request -> {
            int randomPrice = calculateRandomPrice(request.getSlot());
            ConcertReservationResponse response = ConcertReservationResponse.create(
                    UUID.randomUUID(),
                    request.getCity(),
                    request.getSlot(),
                    request.getCategory(),
                    randomPrice
            );
            return Mono.just(response);
        });
    }

    private int calculateRandomPrice(LocalDateTime slot) {
        // Add randomness
        int basePrice = 100;
        int variation = random.nextInt(50);
        return basePrice + variation;
    }
}

Request Object

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor(staticName = "create")
public class ConcertReservationRequest {

    private String city;
    private LocalDateTime slot;
    private String category;
}

Response Object:

@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor(staticName = "create")
public class ConcertReservationResponse {

    private UUID reservationId;
    private String city;
    private LocalDateTime slot;
    private String category;
    private Integer price;

}

Exception Trace:

Caused by: Cannot invoke "reactor.core.publisher.Flux.flatMap(java.util.function.Function)" because "requestFlux" is null
    at org.unlogged.springwebfluxdemo.integrationpatterns.splitter.externalservices.MockConcertController.reserve(MockConcertController.java:22)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:568)
    at io.unlogged.AgentCommandExecutorImpl.lambda$executeCommandRaw$0(AgentCommandExecutorImpl.java:346)
    at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:45)
    at reactor.core.publisher.Mono.subscribe(Mono.java:4512)
    at reactor.core.publisher.Mono.subscribeWith(Mono.java:4578)
    at reactor.core.publisher.Mono.subscribe(Mono.java:4339)
    at io.unlogged.AgentCommandExecutorImpl.executeCommandRaw(AgentCommandExecutorImpl.java:379)
    at io.unlogged.AgentCommandExecutorImpl.executeCommand(AgentCommandExecutorImpl.java:477)
    at io.unlogged.command.AgentCommandServer.serve(AgentCommandServer.java:74)
    at fi.iki.elonen.NanoHTTPD$HTTPSession.execute(NanoHTTPD.java:945)
    at fi.iki.elonen.NanoHTTPD$ClientHandler.run(NanoHTTPD.java:192)
    at java.lang.Thread.run(Thread.java:840)

Reproduction steps

  1. Direct invoke the given controller. method.
  2. You will receive an exception.
  3. With postman everything works fine
    ...

Expected behavior

Correct Expected json output as received in postman:

[
    {
        "reservationId": "4da54fb5-79f7-473d-b240-4f4f342ad9a3",
        "city": "Los Angeles",
        "slot": [
            2024,
            6,
            20,
            19,
            0
        ],
        "category": "Rock",
        "price": 128
    }
]

Additional context

No response

@kingkong-AI kingkong-AI added the bug Something isn't working label Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant