1

我在下面提到的代码中得到NullPointerException了:httpClient

@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();
    }
}
4

1 回答 1

0

检查此示例如何在无服务器功能上使用客户端

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

于 2021-04-15T20:14:06.117 回答