quarkusio/quarkus · error · IllegalStateException
Missing HTTP method in request event
Error message
Missing HTTP method in request event
What it means
LambdaHttpHandler.nettyDispatch converts the API Gateway V2 HTTP event into a Netty request and requires request.requestContext.http.method. API Gateway v2 always supplies it, so a missing method means the event wasn't a valid HTTP API payload — the handler throws IllegalStateException.
Source
Thrown at extensions/amazon-lambda-http/runtime/src/main/java/io/quarkus/amazon/lambda/http/LambdaHttpHandler.java:191
if (!future.isDone())
future.completeExceptionally(new RuntimeException("Connection closed"));
}
}
private APIGatewayV2HTTPResponse nettyDispatch(InetSocketAddress clientAddress, APIGatewayV2HTTPEvent request,
Context context)
throws Exception {
QuarkusHttpHeaders quarkusHeaders = new QuarkusHttpHeaders();
quarkusHeaders.setContextObject(Context.class, context);
quarkusHeaders.setContextObject(APIGatewayV2HTTPEvent.class, request);
quarkusHeaders.setContextObject(APIGatewayV2HTTPEvent.RequestContext.class, request.getRequestContext());
HttpMethod httpMethod = null;
if (request.getRequestContext() != null && request.getRequestContext().getHttp() != null
&& request.getRequestContext().getHttp().getMethod() != null) {
httpMethod = HttpMethod.valueOf(request.getRequestContext().getHttp().getMethod());
}
if (httpMethod == null) {
throw new IllegalStateException("Missing HTTP method in request event");
}
DefaultHttpRequest nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1,
httpMethod, ofNullable(request.getRawQueryString())
.filter(q -> !q.isEmpty()).map(q -> request.getRawPath() + '?' + q).orElse(request.getRawPath()),
quarkusHeaders);
if (request.getHeaders() != null) { //apparently this can be null if no headers are sent
for (Map.Entry<String, String> header : request.getHeaders().entrySet()) {
if (header.getValue() != null) {
// Some header values have commas in them and we don't want to
// split them up into multiple header values.
if (COMMA_HEADERS.contains(header.getKey().toLowerCase(Locale.ROOT))) {
nettyRequest.headers().add(header.getKey(), header.getValue());
} else {
for (String val : header.getValue().split(","))
nettyRequest.headers().add(header.getKey(), val);
}
}
}View on GitHub (pinned to e1c734241f)
Solutions
- Invoke via a real API Gateway HTTP API (v2) so requestContext.http.method is populated
- If using ALB or REST API (v1) payloads, use the quarkus-amazon-lambda-rest extension instead of lambda-http
- Fix test event JSON to include requestContext.http.method
- Verify the trigger type matches the handler (v2 HTTP API events only)
Example fix
// before
{"rawPath":"/x"} // no requestContext
// after
{"rawPath":"/x","requestContext":{"http":{"method":"GET"}}} Defensive patterns
Strategy: validation
Validate before calling
if (event.getRequestContext() == null || event.getRequestContext().getHttp() == null
|| event.getRequestContext().getHttp().getMethod() == null) {
throw new IllegalArgumentException("Event is not an API Gateway v2 HTTP payload");
} Type guard
boolean isV2HttpEvent(APIGatewayV2HTTPEvent e) {
return e != null && e.getRequestContext() != null
&& e.getRequestContext().getHttp() != null
&& e.getRequestContext().getHttp().getMethod() != null;
} Try / catch
try { handler.handleRequest(event, ctx); } catch (IllegalStateException e) { LOGGER.error("Non-HTTP event routed to HTTP Lambda"); } Prevention
- Test with payloads captured from real API Gateway v2
- Use quarkus-amazon-lambda-rest for ALB/REST API (v1) events
- Validate local test event JSON includes requestContext.http.method
When it happens
Trigger: Invoking the Lambda with an event whose requestContext.http.method is null or whose requestContext/http object is absent — e.g. testing with a hand-crafted event, ALB-style payloads, or non-HTTP invocations (direct invoke, other trigger sources).
Common situations: Local tests sending minimal/malformed JSON events; routing a custom-resource or scheduled event to an HTTP-mode Lambda; using REST API (v1) payloads with the v2 handler extension; ALB events lacking requestContext.http.
Related errors
- You must override this method or IdentityProvider.authentica
- should have comma
- bad input
- aws context not set
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/c3ec99edd5c33be7.
Report an issue: GitHub.