1

I am getting NullPointerException for httpClient in the code mentioned below:

@Introspected
public class CustomEventHandler extends MicronautRequestHandler<Map<String, Object>, APIGatewayV2HTTPResponse> {

    private static final Logger LOGGER = LoggerFactory.getLogger(CustomEventHandler.class);

    @Inject
    @Client("/")
    public final RxHttpClient httpClient;

    @Override
    public APIGatewayV2HTTPResponse execute(Map<String, Object> input) {
        String result = httpClient.toBlocking()
                .retrieve(HttpRequest
                        .GET("http://test-api.com"));

        final TestDto testDto;
        try {
            testDto = new ObjectMapper().readValue(result, TestDto.class);
            return APIGatewayV2HTTPResponse.builder().withStatusCode(HttpStatus.SC_OK)
                    .withBody(testDto.toString())
                    .build();
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return APIGatewayV2HTTPResponse.builder().withStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR)
                .build();
    }
}
tmarwen
  • 15,750
  • 5
  • 43
  • 62
user3769960
  • 91
  • 1
  • 5

1 Answers1

0

Check this example how to use the client on serverless functions

https://guides.micronaut.io/micronaut-function-aws-lambda/guide/index.html#writingTheApp

IEE1394
  • 1,181
  • 13
  • 33