feat(apigatewayv2): add WebSocket API support, Update ops, Route/Integration Responses, Models, and Tagging (#682)

Closes #526

Add 27 new API Gateway v2 operations (21 → 48 total):

- WebSocket protocol: CreateApi with WEBSOCKET, wss:// endpoints,
  routeSelectionExpression validation, routeResponseSelectionExpression
- Update operations: UpdateApi, UpdateRoute, UpdateIntegration,
  UpdateAuthorizer, UpdateStage, UpdateDeployment
- Route Responses: full CRUD (5 ops)
- Integration Responses: full CRUD (5 ops)
- Models: full CRUD (5 ops)
- Tagging: TagResource, UntagResource, GetTags
This commit is contained in:
Dixit R Jain authored and GitHub committed 2026-05-02 07:53:13 -05:00
1 parent 0b5f9e183e
commit 8fe2bf4c97
29 files changed
+6179 -16

No files matched your search

@@ -11,7 +11,10 @@ import io.github.hectorvent.floci.services.apigatewayv2.model.Api;
import io.github.hectorvent.floci.services.apigatewayv2.model.Authorizer;
import io.github.hectorvent.floci.services.apigatewayv2.model.Deployment;
import io.github.hectorvent.floci.services.apigatewayv2.model.Integration;
import io.github.hectorvent.floci.services.apigatewayv2.model.IntegrationResponse;
import io.github.hectorvent.floci.services.apigatewayv2.model.Model;
import io.github.hectorvent.floci.services.apigatewayv2.model.Route;
import io.github.hectorvent.floci.services.apigatewayv2.model.RouteResponse;
import io.github.hectorvent.floci.services.apigatewayv2.model.Stage;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
@@ -104,7 +107,7 @@ public class ApiGatewayController {
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
IntegrationResponse ir = service.putIntegrationResponse(region, apiId, resourceId, httpMethod, statusCode, request);
io.github.hectorvent.floci.services.apigateway.model.IntegrationResponse ir = service.putIntegrationResponse(region, apiId, resourceId, httpMethod, statusCode, request);
return Response.status(201).entity(toIntegrationResponseNode(ir).toString()).type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
@@ -830,6 +833,20 @@ public class ApiGatewayController {
return Response.noContent().build();
}
@PATCH
@Path("/v2/apis/{apiId}")
public Response updateApi(@Context HttpHeaders headers, @PathParam("apiId") String apiId, String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
Api updatedApi = v2Service.updateApi(region, apiId, request);
return Response.ok(toV2ApiNode(updatedApi).toString()).type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@POST
@Path("/v2/apis/{apiId}/routes")
public Response createRoute(@Context HttpHeaders headers, @PathParam("apiId") String apiId, String body) {
@@ -870,6 +887,23 @@ public class ApiGatewayController {
return Response.noContent().build();
}
@PATCH
@Path("/v2/apis/{apiId}/routes/{routeId}")
public Response updateRoute(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("routeId") String routeId,
String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
Route updatedRoute = v2Service.updateRoute(region, apiId, routeId, request);
return Response.ok(toV2RouteNode(updatedRoute).toString()).type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@POST
@Path("/v2/apis/{apiId}/integrations")
public Response createIntegration(@Context HttpHeaders headers, @PathParam("apiId") String apiId, String body) {
@@ -910,6 +944,168 @@ public class ApiGatewayController {
return Response.noContent().build();
}
@PATCH
@Path("/v2/apis/{apiId}/integrations/{integrationId}")
public Response updateV2Integration(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("integrationId") String integrationId,
String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
Integration integration = v2Service.updateIntegration(region, apiId, integrationId, request);
return Response.ok(toV2IntegrationNode(integration).toString())
.type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
// ──────────────────────────── Route Responses (v2) ────────────────────────────
@POST
@Path("/v2/apis/{apiId}/routes/{routeId}/routeresponses")
public Response createRouteResponse(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("routeId") String routeId,
String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
RouteResponse rr = v2Service.createRouteResponse(region, apiId, routeId, request);
return Response.status(201).entity(toV2RouteResponseNode(rr).toString()).type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@GET
@Path("/v2/apis/{apiId}/routes/{routeId}/routeresponses/{routeResponseId}")
public Response getRouteResponse(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("routeId") String routeId,
@PathParam("routeResponseId") String routeResponseId) {
String region = regionResolver.resolveRegion(headers);
return Response.ok(toV2RouteResponseNode(v2Service.getRouteResponse(region, apiId, routeId, routeResponseId)).toString())
.type(MediaType.APPLICATION_JSON).build();
}
@GET
@Path("/v2/apis/{apiId}/routes/{routeId}/routeresponses")
public Response getRouteResponses(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("routeId") String routeId) {
String region = regionResolver.resolveRegion(headers);
List<RouteResponse> routeResponses = v2Service.getRouteResponses(region, apiId, routeId);
ObjectNode root = objectMapper.createObjectNode();
ArrayNode items = root.putArray("items");
routeResponses.forEach(rr -> items.add(toV2RouteResponseNode(rr)));
return Response.ok(root.toString()).type(MediaType.APPLICATION_JSON).build();
}
@PATCH
@Path("/v2/apis/{apiId}/routes/{routeId}/routeresponses/{routeResponseId}")
public Response updateRouteResponse(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("routeId") String routeId,
@PathParam("routeResponseId") String routeResponseId,
String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
RouteResponse rr = v2Service.updateRouteResponse(region, apiId, routeId, routeResponseId, request);
return Response.ok(toV2RouteResponseNode(rr).toString()).type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@DELETE
@Path("/v2/apis/{apiId}/routes/{routeId}/routeresponses/{routeResponseId}")
public Response deleteRouteResponse(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("routeId") String routeId,
@PathParam("routeResponseId") String routeResponseId) {
String region = regionResolver.resolveRegion(headers);
v2Service.deleteRouteResponse(region, apiId, routeId, routeResponseId);
return Response.noContent().build();
}
// ──────────────────────────── Integration Responses (v2) ────────────────────────────
@POST
@Path("/v2/apis/{apiId}/integrations/{integrationId}/integrationresponses")
public Response createIntegrationResponse(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("integrationId") String integrationId,
String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
IntegrationResponse ir = v2Service.createIntegrationResponse(region, apiId, integrationId, request);
return Response.status(201).entity(toV2IntegrationResponseNode(ir).toString()).type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@GET
@Path("/v2/apis/{apiId}/integrations/{integrationId}/integrationresponses/{integrationResponseId}")
public Response getIntegrationResponse(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("integrationId") String integrationId,
@PathParam("integrationResponseId") String integrationResponseId) {
String region = regionResolver.resolveRegion(headers);
return Response.ok(toV2IntegrationResponseNode(v2Service.getIntegrationResponse(region, apiId, integrationId, integrationResponseId)).toString())
.type(MediaType.APPLICATION_JSON).build();
}
@GET
@Path("/v2/apis/{apiId}/integrations/{integrationId}/integrationresponses")
public Response getIntegrationResponses(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("integrationId") String integrationId) {
String region = regionResolver.resolveRegion(headers);
List<IntegrationResponse> integrationResponses = v2Service.getIntegrationResponses(region, apiId, integrationId);
ObjectNode root = objectMapper.createObjectNode();
ArrayNode items = root.putArray("items");
integrationResponses.forEach(ir -> items.add(toV2IntegrationResponseNode(ir)));
return Response.ok(root.toString()).type(MediaType.APPLICATION_JSON).build();
}
@PATCH
@Path("/v2/apis/{apiId}/integrations/{integrationId}/integrationresponses/{integrationResponseId}")
public Response updateIntegrationResponse(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("integrationId") String integrationId,
@PathParam("integrationResponseId") String integrationResponseId,
String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
IntegrationResponse ir = v2Service.updateIntegrationResponse(region, apiId, integrationId, integrationResponseId, request);
return Response.ok(toV2IntegrationResponseNode(ir).toString()).type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@DELETE
@Path("/v2/apis/{apiId}/integrations/{integrationId}/integrationresponses/{integrationResponseId}")
public Response deleteIntegrationResponse(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("integrationId") String integrationId,
@PathParam("integrationResponseId") String integrationResponseId) {
String region = regionResolver.resolveRegion(headers);
v2Service.deleteIntegrationResponse(region, apiId, integrationId, integrationResponseId);
return Response.noContent().build();
}
@POST
@Path("/v2/apis/{apiId}/authorizers")
public Response createV2Authorizer(@Context HttpHeaders headers, @PathParam("apiId") String apiId, String body) {
@@ -950,6 +1146,24 @@ public class ApiGatewayController {
return Response.noContent().build();
}
@PATCH
@Path("/v2/apis/{apiId}/authorizers/{authorizerId}")
public Response updateV2Authorizer(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("authorizerId") String authorizerId,
String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
Authorizer authorizer = v2Service.updateAuthorizer(region, apiId, authorizerId, request);
return Response.ok(toV2AuthorizerNode(authorizer).toString())
.type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@POST
@Path("/v2/apis/{apiId}/stages")
public Response createV2Stage(@Context HttpHeaders headers, @PathParam("apiId") String apiId, String body) {
@@ -990,6 +1204,24 @@ public class ApiGatewayController {
return Response.noContent().build();
}
@PATCH
@Path("/v2/apis/{apiId}/stages/{stageName}")
public Response updateV2Stage(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("stageName") String stageName,
String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
Stage stage = v2Service.updateStage(region, apiId, stageName, request);
return Response.ok(toV2StageNode(stage).toString())
.type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@POST
@Path("/v2/apis/{apiId}/deployments")
public Response createV2Deployment(@Context HttpHeaders headers, @PathParam("apiId") String apiId, String body) {
@@ -1030,6 +1262,127 @@ public class ApiGatewayController {
return Response.noContent().build();
}
@PATCH
@Path("/v2/apis/{apiId}/deployments/{deploymentId}")
public Response updateV2Deployment(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("deploymentId") String deploymentId,
String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
Deployment deployment = v2Service.updateDeployment(region, apiId, deploymentId, request);
return Response.ok(toV2DeploymentNode(deployment).toString())
.type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
// ──────────────────────────── Models (v2) ────────────────────────────
@POST
@Path("/v2/apis/{apiId}/models")
public Response createV2Model(@Context HttpHeaders headers, @PathParam("apiId") String apiId, String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
Model model = v2Service.createModel(region, apiId, request);
return Response.status(201).entity(toV2ModelNode(model).toString()).type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@GET
@Path("/v2/apis/{apiId}/models")
public Response getV2Models(@Context HttpHeaders headers, @PathParam("apiId") String apiId) {
String region = regionResolver.resolveRegion(headers);
List<Model> models = v2Service.getModels(region, apiId);
ObjectNode root = objectMapper.createObjectNode();
ArrayNode items = root.putArray("items");
models.forEach(m -> items.add(toV2ModelNode(m)));
return Response.ok(root.toString()).type(MediaType.APPLICATION_JSON).build();
}
@GET
@Path("/v2/apis/{apiId}/models/{modelId}")
public Response getV2Model(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("modelId") String modelId) {
String region = regionResolver.resolveRegion(headers);
return Response.ok(toV2ModelNode(v2Service.getModel(region, apiId, modelId)).toString()).type(MediaType.APPLICATION_JSON).build();
}
@PATCH
@Path("/v2/apis/{apiId}/models/{modelId}")
public Response updateV2Model(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("modelId") String modelId,
String body) {
String region = regionResolver.resolveRegion(headers);
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
Model model = v2Service.updateModel(region, apiId, modelId, request);
return Response.ok(toV2ModelNode(model).toString()).type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@DELETE
@Path("/v2/apis/{apiId}/models/{modelId}")
public Response deleteV2Model(@Context HttpHeaders headers,
@PathParam("apiId") String apiId,
@PathParam("modelId") String modelId) {
String region = regionResolver.resolveRegion(headers);
v2Service.deleteModel(region, apiId, modelId);
return Response.noContent().build();
}
// ──────────────────────────── Tagging (v2) ────────────────────────────
@POST
@Path("/v2/tags/{resourceArn: .+}")
public Response tagResource(@Context HttpHeaders headers,
@PathParam("resourceArn") String resourceArn,
String body) {
try {
@SuppressWarnings("unchecked")
Map<String, Object> request = objectMapper.readValue(body, Map.class);
@SuppressWarnings("unchecked")
Map<String, String> tags = (Map<String, String>) request.get("tags");
v2Service.tagResource(resourceArn, tags);
return Response.status(201).entity("{}").type(MediaType.APPLICATION_JSON).build();
} catch (IOException e) {
throw new AwsException("BadRequestException", e.getMessage(), 400);
}
}
@DELETE
@Path("/v2/tags/{resourceArn: .+}")
public Response untagResource(@Context HttpHeaders headers,
@PathParam("resourceArn") String resourceArn,
@QueryParam("tagKeys") List<String> tagKeys) {
v2Service.untagResource(resourceArn,
tagKeys != null ? tagKeys : java.util.Collections.emptyList());
return Response.noContent().build();
}
@GET
@Path("/v2/tags/{resourceArn: .+}")
public Response getTagsForResource(@Context HttpHeaders headers,
@PathParam("resourceArn") String resourceArn) {
Map<String, String> tags = v2Service.getTags(resourceArn);
ObjectNode root = objectMapper.createObjectNode();
ObjectNode tagsNode = root.putObject("tags");
tags.forEach(tagsNode::put);
return Response.ok(root.toString()).type(MediaType.APPLICATION_JSON).build();
}
// ──────────────────────────── Helpers ────────────────────────────
private ObjectNode toApiNode(RestApi api) {
@@ -1087,7 +1440,7 @@ public class ApiGatewayController {
return node;
}
private ObjectNode toIntegrationResponseNode(IntegrationResponse r) {
private ObjectNode toIntegrationResponseNode(io.github.hectorvent.floci.services.apigateway.model.IntegrationResponse r) {
ObjectNode node = objectMapper.createObjectNode();
node.put("statusCode", r.statusCode());
node.put("selectionPattern", r.selectionPattern());
@@ -1198,6 +1551,14 @@ public class ApiGatewayController {
node.put("protocolType", api.getProtocolType());
node.put("apiEndpoint", api.getApiEndpoint());
node.put("createdDate", java.time.Instant.ofEpochMilli(api.getCreatedDate()).toString());
if (api.getRouteSelectionExpression() != null) node.put("routeSelectionExpression", api.getRouteSelectionExpression());
if (api.getDescription() != null) node.put("description", api.getDescription());
if (api.getApiKeySelectionExpression() != null) node.put("apiKeySelectionExpression", api.getApiKeySelectionExpression());
if (api.getTags() != null && !api.getTags().isEmpty()) {
ObjectNode tagsNode = objectMapper.createObjectNode();
api.getTags().forEach(tagsNode::put);
node.set("tags", tagsNode);
}
return node;
}
@@ -1207,6 +1568,7 @@ public class ApiGatewayController {
node.put("routeKey", r.getRouteKey());
node.put("authorizationType", r.getAuthorizationType());
if (r.getTarget() != null) node.put("target", r.getTarget());
if (r.getRouteResponseSelectionExpression() != null) node.put("routeResponseSelectionExpression", r.getRouteResponseSelectionExpression());
return node;
}
@@ -1260,4 +1622,53 @@ public class ApiGatewayController {
return node;
}
private ObjectNode toV2RouteResponseNode(RouteResponse rr) {
ObjectNode node = objectMapper.createObjectNode();
node.put("routeResponseId", rr.getRouteResponseId());
node.put("routeResponseKey", rr.getRouteResponseKey());
if (rr.getRouteId() != null) node.put("routeId", rr.getRouteId());
if (rr.getModelSelectionExpression() != null) node.put("modelSelectionExpression", rr.getModelSelectionExpression());
if (rr.getResponseModels() != null) {
ObjectNode models = objectMapper.createObjectNode();
rr.getResponseModels().forEach(models::put);
node.set("responseModels", models);
}
if (rr.getResponseParameters() != null) {
ObjectNode params = objectMapper.createObjectNode();
rr.getResponseParameters().forEach(params::put);
node.set("responseParameters", params);
}
return node;
}
private ObjectNode toV2IntegrationResponseNode(IntegrationResponse ir) {
ObjectNode node = objectMapper.createObjectNode();
node.put("integrationResponseId", ir.getIntegrationResponseId());
node.put("integrationResponseKey", ir.getIntegrationResponseKey());
if (ir.getIntegrationId() != null) node.put("integrationId", ir.getIntegrationId());
if (ir.getContentHandlingStrategy() != null) node.put("contentHandlingStrategy", ir.getContentHandlingStrategy());
if (ir.getTemplateSelectionExpression() != null) node.put("templateSelectionExpression", ir.getTemplateSelectionExpression());
if (ir.getResponseTemplates() != null) {
ObjectNode templates = objectMapper.createObjectNode();
ir.getResponseTemplates().forEach(templates::put);
node.set("responseTemplates", templates);
}
if (ir.getResponseParameters() != null) {
ObjectNode params = objectMapper.createObjectNode();
ir.getResponseParameters().forEach(params::put);
node.set("responseParameters", params);
}
return node;
}
private ObjectNode toV2ModelNode(Model m) {
ObjectNode node = objectMapper.createObjectNode();
node.put("modelId", m.getModelId());
node.put("name", m.getName());
if (m.getSchema() != null) node.put("schema", m.getSchema());
if (m.getDescription() != null) node.put("description", m.getDescription());
if (m.getContentType() != null) node.put("contentType", m.getContentType());
return node;
}
}
@@ -33,27 +33,51 @@ public class ApiGatewayV2JsonHandler {
case "CreateApi" -> handleCreateApi(request, region);
case "GetApis" -> handleGetApis(region);
case "GetApi" -> handleGetApi(request, region);
case "UpdateApi" -> handleUpdateApi(request, region);
case "DeleteApi" -> handleDeleteApi(request, region);
case "CreateRoute" -> handleCreateRoute(request, region);
case "GetRoute" -> handleGetRoute(request, region);
case "GetRoutes" -> handleGetRoutes(request, region);
case "UpdateRoute" -> handleUpdateRoute(request, region);
case "DeleteRoute" -> handleDeleteRoute(request, region);
case "CreateIntegration" -> handleCreateIntegration(request, region);
case "GetIntegration" -> handleGetIntegration(request, region);
case "GetIntegrations" -> handleGetIntegrations(request, region);
case "UpdateIntegration" -> handleUpdateIntegration(request, region);
case "CreateAuthorizer" -> handleCreateAuthorizer(request, region);
case "GetAuthorizer" -> handleGetAuthorizer(request, region);
case "GetAuthorizers" -> handleGetAuthorizers(request, region);
case "DeleteAuthorizer" -> handleDeleteAuthorizer(request, region);
case "UpdateAuthorizer" -> handleUpdateAuthorizer(request, region);
case "CreateStage" -> handleCreateStage(request, region);
case "GetStage" -> handleGetStage(request, region);
case "GetStages" -> handleGetStages(request, region);
case "DeleteStage" -> handleDeleteStage(request, region);
case "UpdateStage" -> handleUpdateStage(request, region);
case "CreateDeployment" -> handleCreateDeployment(request, region);
case "GetDeployment" -> handleGetDeployment(request, region);
case "GetDeployments" -> handleGetDeployments(request, region);
case "DeleteDeployment" -> handleDeleteDeployment(request, region);
case "UpdateDeployment" -> handleUpdateDeployment(request, region);
case "DeleteIntegration" -> handleDeleteIntegration(request, region);
case "CreateRouteResponse" -> handleCreateRouteResponse(request, region);
case "GetRouteResponse" -> handleGetRouteResponse(request, region);
case "GetRouteResponses" -> handleGetRouteResponses(request, region);
case "UpdateRouteResponse" -> handleUpdateRouteResponse(request, region);
case "DeleteRouteResponse" -> handleDeleteRouteResponse(request, region);
case "CreateIntegrationResponse" -> handleCreateIntegrationResponse(request, region);
case "GetIntegrationResponse" -> handleGetIntegrationResponse(request, region);
case "GetIntegrationResponses" -> handleGetIntegrationResponses(request, region);
case "UpdateIntegrationResponse" -> handleUpdateIntegrationResponse(request, region);
case "DeleteIntegrationResponse" -> handleDeleteIntegrationResponse(request, region);
case "CreateModel" -> handleCreateModel(request, region);
case "GetModel" -> handleGetModel(request, region);
case "GetModels" -> handleGetModels(request, region);
case "UpdateModel" -> handleUpdateModel(request, region);
case "DeleteModel" -> handleDeleteModel(request, region);
case "TagResource" -> handleTagResource(request, region);
case "UntagResource" -> handleUntagResource(request, region);
case "GetTags" -> handleGetTags(request, region);
default -> JsonErrorResponseUtils.createUnknownOperationErrorResponse(action);
};
} catch (AwsException e) {
@@ -89,6 +113,14 @@ public class ApiGatewayV2JsonHandler {
return Response.noContent().build();
}
private Response handleUpdateApi(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
Api api = service.updateApi(region, apiId, map);
return Response.ok(toApiNode(api).toString()).build();
}
// ──────────────────────────── Authorizer ────────────────────────────
private Response handleCreateAuthorizer(JsonNode request, String region) {
@@ -121,6 +153,15 @@ public class ApiGatewayV2JsonHandler {
return Response.noContent().build();
}
private Response handleUpdateAuthorizer(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String authorizerId = request.path("AuthorizerId").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
Authorizer auth = service.updateAuthorizer(region, apiId, authorizerId, map);
return Response.ok(toAuthorizerNode(auth).toString()).build();
}
// ──────────────────────────── Route ────────────────────────────
private Response handleCreateRoute(JsonNode request, String region) {
@@ -153,6 +194,15 @@ public class ApiGatewayV2JsonHandler {
return Response.noContent().build();
}
private Response handleUpdateRoute(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String routeId = request.path("RouteId").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
Route route = service.updateRoute(region, apiId, routeId, map);
return Response.ok(toRouteNode(route).toString()).build();
}
// ──────────────────────────── Integration ────────────────────────────
private Response handleCreateIntegration(JsonNode request, String region) {
@@ -178,6 +228,15 @@ public class ApiGatewayV2JsonHandler {
return Response.ok(root.toString()).build();
}
private Response handleUpdateIntegration(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String integrationId = request.path("IntegrationId").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
Integration integration = service.updateIntegration(region, apiId, integrationId, map);
return Response.ok(toIntegrationNode(integration).toString()).build();
}
// ──────────────────────────── Stage ────────────────────────────
private Response handleCreateStage(JsonNode request, String region) {
@@ -210,6 +269,15 @@ public class ApiGatewayV2JsonHandler {
return Response.noContent().build();
}
private Response handleUpdateStage(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String stageName = request.path("StageName").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
Stage stage = service.updateStage(region, apiId, stageName, map);
return Response.ok(toStageNode(stage).toString()).build();
}
// ──────────────────────────── Deployment ────────────────────────────
private Response handleCreateDeployment(JsonNode request, String region) {
@@ -242,6 +310,15 @@ public class ApiGatewayV2JsonHandler {
return Response.noContent().build();
}
private Response handleUpdateDeployment(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String deploymentId = request.path("DeploymentId").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
Deployment deployment = service.updateDeployment(region, apiId, deploymentId, map);
return Response.ok(toDeploymentNode(deployment).toString()).build();
}
private Response handleDeleteIntegration(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String integrationId = request.path("IntegrationId").asText();
@@ -249,6 +326,166 @@ public class ApiGatewayV2JsonHandler {
return Response.noContent().build();
}
// ──────────────────────────── Route Response ────────────────────────────
private Response handleCreateRouteResponse(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String routeId = request.path("RouteId").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
RouteResponse rr = service.createRouteResponse(region, apiId, routeId, map);
return Response.status(201).entity(toRouteResponseNode(rr).toString()).build();
}
private Response handleGetRouteResponse(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String routeId = request.path("RouteId").asText();
String routeResponseId = request.path("RouteResponseId").asText();
return Response.ok(toRouteResponseNode(service.getRouteResponse(region, apiId, routeId, routeResponseId)).toString()).build();
}
private Response handleGetRouteResponses(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String routeId = request.path("RouteId").asText();
List<RouteResponse> routeResponses = service.getRouteResponses(region, apiId, routeId);
ObjectNode root = objectMapper.createObjectNode();
ArrayNode items = root.putArray("Items");
routeResponses.forEach(rr -> items.add(toRouteResponseNode(rr)));
return Response.ok(root.toString()).build();
}
private Response handleUpdateRouteResponse(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String routeId = request.path("RouteId").asText();
String routeResponseId = request.path("RouteResponseId").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
RouteResponse rr = service.updateRouteResponse(region, apiId, routeId, routeResponseId, map);
return Response.ok(toRouteResponseNode(rr).toString()).build();
}
private Response handleDeleteRouteResponse(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String routeId = request.path("RouteId").asText();
String routeResponseId = request.path("RouteResponseId").asText();
service.deleteRouteResponse(region, apiId, routeId, routeResponseId);
return Response.noContent().build();
}
// ──────────────────────────── Integration Response ────────────────────────────
private Response handleCreateIntegrationResponse(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String integrationId = request.path("IntegrationId").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
IntegrationResponse ir = service.createIntegrationResponse(region, apiId, integrationId, map);
return Response.status(201).entity(toIntegrationResponseNode(ir).toString()).build();
}
private Response handleGetIntegrationResponse(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String integrationId = request.path("IntegrationId").asText();
String integrationResponseId = request.path("IntegrationResponseId").asText();
return Response.ok(toIntegrationResponseNode(service.getIntegrationResponse(region, apiId, integrationId, integrationResponseId)).toString()).build();
}
private Response handleGetIntegrationResponses(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String integrationId = request.path("IntegrationId").asText();
List<IntegrationResponse> integrationResponses = service.getIntegrationResponses(region, apiId, integrationId);
ObjectNode root = objectMapper.createObjectNode();
ArrayNode items = root.putArray("Items");
integrationResponses.forEach(ir -> items.add(toIntegrationResponseNode(ir)));
return Response.ok(root.toString()).build();
}
private Response handleUpdateIntegrationResponse(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String integrationId = request.path("IntegrationId").asText();
String integrationResponseId = request.path("IntegrationResponseId").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
IntegrationResponse ir = service.updateIntegrationResponse(region, apiId, integrationId, integrationResponseId, map);
return Response.ok(toIntegrationResponseNode(ir).toString()).build();
}
private Response handleDeleteIntegrationResponse(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String integrationId = request.path("IntegrationId").asText();
String integrationResponseId = request.path("IntegrationResponseId").asText();
service.deleteIntegrationResponse(region, apiId, integrationId, integrationResponseId);
return Response.noContent().build();
}
// ──────────────────────────── Model ────────────────────────────
private Response handleCreateModel(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
Model model = service.createModel(region, apiId, map);
return Response.status(201).entity(toModelNode(model).toString()).build();
}
private Response handleGetModel(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String modelId = request.path("ModelId").asText();
return Response.ok(toModelNode(service.getModel(region, apiId, modelId)).toString()).build();
}
private Response handleGetModels(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
List<Model> models = service.getModels(region, apiId);
ObjectNode root = objectMapper.createObjectNode();
ArrayNode items = root.putArray("Items");
models.forEach(m -> items.add(toModelNode(m)));
return Response.ok(root.toString()).build();
}
private Response handleUpdateModel(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String modelId = request.path("ModelId").asText();
@SuppressWarnings("unchecked")
Map<String, Object> map = toLowerCamelCase(objectMapper.convertValue(request, Map.class));
Model model = service.updateModel(region, apiId, modelId, map);
return Response.ok(toModelNode(model).toString()).build();
}
private Response handleDeleteModel(JsonNode request, String region) {
String apiId = request.path("ApiId").asText();
String modelId = request.path("ModelId").asText();
service.deleteModel(region, apiId, modelId);
return Response.noContent().build();
}
// ──────────────────────────── Tagging ────────────────────────────
private Response handleTagResource(JsonNode request, String region) {
String resourceArn = request.path("ResourceArn").asText();
Map<String, String> tags = objectMapper.convertValue(
request.path("Tags"), new com.fasterxml.jackson.core.type.TypeReference<Map<String, String>>() {});
service.tagResource(resourceArn, tags);
return Response.ok("{}").build();
}
private Response handleUntagResource(JsonNode request, String region) {
String resourceArn = request.path("ResourceArn").asText();
List<String> tagKeys = new java.util.ArrayList<>();
request.path("TagKeys").forEach(n -> tagKeys.add(n.asText()));
service.untagResource(resourceArn, tagKeys);
return Response.noContent().build();
}
private Response handleGetTags(JsonNode request, String region) {
String resourceArn = request.path("ResourceArn").asText();
Map<String, String> tags = service.getTags(resourceArn);
ObjectNode root = objectMapper.createObjectNode();
ObjectNode tagsNode = root.putObject("Tags");
tags.forEach(tagsNode::put);
return Response.ok(root.toString()).build();
}
// ──────────────────────────── Serializers ────────────────────────────
private ObjectNode toApiNode(Api api) {
@@ -258,6 +495,19 @@ public class ApiGatewayV2JsonHandler {
node.put("ProtocolType", api.getProtocolType());
node.put("ApiEndpoint", api.getApiEndpoint());
node.put("CreatedDate", api.getCreatedDate() / 1000.0);
if (api.getRouteSelectionExpression() != null) {
node.put("RouteSelectionExpression", api.getRouteSelectionExpression());
}
if (api.getDescription() != null) {
node.put("Description", api.getDescription());
}
if (api.getApiKeySelectionExpression() != null) {
node.put("ApiKeySelectionExpression", api.getApiKeySelectionExpression());
}
if (api.getTags() != null && !api.getTags().isEmpty()) {
ObjectNode tagsNode = node.putObject("Tags");
api.getTags().forEach(tagsNode::put);
}
return node;
}
@@ -290,6 +540,9 @@ public class ApiGatewayV2JsonHandler {
node.put("AuthorizationType", r.getAuthorizationType());
if (r.getAuthorizerId() != null) node.put("AuthorizerId", r.getAuthorizerId());
if (r.getTarget() != null) node.put("Target", r.getTarget());
if (r.getRouteResponseSelectionExpression() != null) {
node.put("RouteResponseSelectionExpression", r.getRouteResponseSelectionExpression());
}
return node;
}
@@ -321,6 +574,61 @@ public class ApiGatewayV2JsonHandler {
return node;
}
private ObjectNode toRouteResponseNode(RouteResponse rr) {
ObjectNode node = objectMapper.createObjectNode();
node.put("RouteResponseId", rr.getRouteResponseId());
node.put("RouteResponseKey", rr.getRouteResponseKey());
if (rr.getRouteId() != null) {
node.put("RouteId", rr.getRouteId());
}
if (rr.getModelSelectionExpression() != null) {
node.put("ModelSelectionExpression", rr.getModelSelectionExpression());
}
if (rr.getResponseModels() != null) {
ObjectNode responseModels = node.putObject("ResponseModels");
rr.getResponseModels().forEach(responseModels::put);
}
if (rr.getResponseParameters() != null) {
ObjectNode responseParameters = node.putObject("ResponseParameters");
rr.getResponseParameters().forEach(responseParameters::put);
}
return node;
}
private ObjectNode toIntegrationResponseNode(IntegrationResponse ir) {
ObjectNode node = objectMapper.createObjectNode();
node.put("IntegrationResponseId", ir.getIntegrationResponseId());
node.put("IntegrationResponseKey", ir.getIntegrationResponseKey());
if (ir.getIntegrationId() != null) {
node.put("IntegrationId", ir.getIntegrationId());
}
if (ir.getContentHandlingStrategy() != null) {
node.put("ContentHandlingStrategy", ir.getContentHandlingStrategy());
}
if (ir.getTemplateSelectionExpression() != null) {
node.put("TemplateSelectionExpression", ir.getTemplateSelectionExpression());
}
if (ir.getResponseTemplates() != null) {
ObjectNode responseTemplates = node.putObject("ResponseTemplates");
ir.getResponseTemplates().forEach(responseTemplates::put);
}
if (ir.getResponseParameters() != null) {
ObjectNode responseParameters = node.putObject("ResponseParameters");
ir.getResponseParameters().forEach(responseParameters::put);
}
return node;
}
private ObjectNode toModelNode(Model m) {
ObjectNode node = objectMapper.createObjectNode();
node.put("ModelId", m.getModelId());
node.put("Name", m.getName());
if (m.getSchema() != null) node.put("Schema", m.getSchema());
if (m.getDescription() != null) node.put("Description", m.getDescription());
if (m.getContentType() != null) node.put("ContentType", m.getContentType());
return node;
}
/**
* Converts PascalCase map keys to lowerCamelCase so the service layer's
* field lookups work regardless of whether the request arrived via the
@@ -27,6 +27,9 @@ public class ApiGatewayV2Service {
private final StorageBackend<String, Authorizer> authorizerStore;
private final StorageBackend<String, Deployment> deploymentStore;
private final StorageBackend<String, Stage> stageStore;
private final StorageBackend<String, RouteResponse> routeResponseStore;
private final StorageBackend<String, IntegrationResponse> integrationResponseStore;
private final StorageBackend<String, Model> modelStore;
private final RegionResolver regionResolver;
@Inject
@@ -43,6 +46,12 @@ public class ApiGatewayV2Service {
new TypeReference<>() {});
this.stageStore = storageFactory.create("apigatewayv2", "apigatewayv2-stages.json",
new TypeReference<>() {});
this.routeResponseStore = storageFactory.create("apigatewayv2", "apigatewayv2-routeresponses.json",
new TypeReference<>() {});
this.integrationResponseStore = storageFactory.create("apigatewayv2", "apigatewayv2-integrationresponses.json",
new TypeReference<>() {});
this.modelStore = storageFactory.create("apigatewayv2", "apigatewayv2-models.json",
new TypeReference<>() {});
this.regionResolver = regionResolver;
}
@@ -51,16 +60,46 @@ public class ApiGatewayV2Service {
public Api createApi(String region, Map<String, Object> request) {
String name = (String) request.get("name");
String protocolType = (String) request.getOrDefault("protocolType", "HTTP");
String routeSelectionExpression = (String) request.get("routeSelectionExpression");
String description = (String) request.get("description");
String apiKeySelectionExpression = (String) request.get("apiKeySelectionExpression");
if ("WEBSOCKET".equals(protocolType) && (routeSelectionExpression == null || routeSelectionExpression.isBlank())) {
throw new AwsException("BadRequestException",
"RouteSelectionExpression is required for WEBSOCKET protocol", 400);
}
// Apply AWS defaults
if (apiKeySelectionExpression == null) {
apiKeySelectionExpression = "$request.header.x-api-key";
}
if ("HTTP".equals(protocolType) && routeSelectionExpression == null) {
routeSelectionExpression = "${request.method} ${request.path}";
}
Api api = new Api();
api.setApiId(shortId(10));
api.setName(name);
api.setProtocolType(protocolType);
api.setCreatedDate(System.currentTimeMillis());
api.setApiEndpoint(String.format("https://%s.execute-api.%s.amazonaws.com", api.getApiId(), region));
api.setRouteSelectionExpression(routeSelectionExpression);
api.setDescription(description);
api.setApiKeySelectionExpression(apiKeySelectionExpression);
if ("WEBSOCKET".equals(protocolType)) {
api.setApiEndpoint(String.format("wss://%s.execute-api.%s.amazonaws.com", api.getApiId(), region));
} else {
api.setApiEndpoint(String.format("https://%s.execute-api.%s.amazonaws.com", api.getApiId(), region));
}
@SuppressWarnings("unchecked")
Map<String, String> tags = (Map<String, String>) request.get("tags");
if (tags != null) {
api.setTags(tags);
}
apiStore.put(apiKey(region, api.getApiId()), api);
LOG.infov("Created HTTP API: {0} ({1}) in {2}", api.getName(), api.getApiId(), region);
LOG.infov("Created {0} API: {1} ({2}) in {3}", protocolType, api.getName(), api.getApiId(), region);
return api;
}
@@ -79,6 +118,31 @@ public class ApiGatewayV2Service {
apiStore.delete(apiKey(region, apiId));
}
public Api updateApi(String region, String apiId, Map<String, Object> request) {
Api api = getApi(region, apiId);
if (request.containsKey("name") && request.get("name") != null) {
api.setName((String) request.get("name"));
}
if (request.containsKey("description") && request.get("description") != null) {
api.setDescription((String) request.get("description"));
}
if (request.containsKey("routeSelectionExpression") && request.get("routeSelectionExpression") != null) {
api.setRouteSelectionExpression((String) request.get("routeSelectionExpression"));
}
if (request.containsKey("apiKeySelectionExpression") && request.get("apiKeySelectionExpression") != null) {
api.setApiKeySelectionExpression((String) request.get("apiKeySelectionExpression"));
}
if (request.containsKey("tags")) {
@SuppressWarnings("unchecked")
Map<String, String> tags = (Map<String, String>) request.get("tags");
api.setTags(tags);
}
apiStore.put(apiKey(region, apiId), api);
return api;
}
// ──────────────────────────── Authorizer CRUD ────────────────────────────
public Authorizer createAuthorizer(String region, String apiId, Map<String, Object> request) {
@@ -88,9 +152,14 @@ public class ApiGatewayV2Service {
auth.setName((String) request.get("name"));
auth.setAuthorizerType((String) request.get("authorizerType"));
@SuppressWarnings("unchecked")
List<String> identitySource = (List<String>) request.get("identitySource");
auth.setIdentitySource(identitySource);
Object identitySourceRaw = request.get("identitySource");
if (identitySourceRaw instanceof String s) {
auth.setIdentitySource(List.of(s));
} else if (identitySourceRaw instanceof List<?>) {
@SuppressWarnings("unchecked")
List<String> identitySource = (List<String>) identitySourceRaw;
auth.setIdentitySource(identitySource);
}
@SuppressWarnings("unchecked")
Map<String, Object> jwtConfig = (Map<String, Object>) request.get("jwtConfiguration");
@@ -121,6 +190,39 @@ public class ApiGatewayV2Service {
authorizerStore.delete(authorizerKey(region, apiId, authorizerId));
}
public Authorizer updateAuthorizer(String region, String apiId, String authorizerId,
Map<String, Object> request) {
Authorizer auth = getAuthorizer(region, apiId, authorizerId);
if (request.containsKey("name") && request.get("name") != null) {
auth.setName((String) request.get("name"));
}
if (request.containsKey("authorizerType") && request.get("authorizerType") != null) {
auth.setAuthorizerType((String) request.get("authorizerType"));
}
if (request.containsKey("identitySource") && request.get("identitySource") != null) {
Object identitySourceRaw = request.get("identitySource");
if (identitySourceRaw instanceof String s) {
auth.setIdentitySource(List.of(s));
} else if (identitySourceRaw instanceof List<?>) {
@SuppressWarnings("unchecked")
List<String> identitySource = (List<String>) identitySourceRaw;
auth.setIdentitySource(identitySource);
}
}
if (request.containsKey("jwtConfiguration") && request.get("jwtConfiguration") != null) {
@SuppressWarnings("unchecked")
Map<String, Object> jwtConfig = (Map<String, Object>) request.get("jwtConfiguration");
@SuppressWarnings("unchecked")
List<String> audience = (List<String>) jwtConfig.get("audience");
String issuer = (String) jwtConfig.get("issuer");
auth.setJwtConfiguration(new Authorizer.JwtConfiguration(audience, issuer));
}
authorizerStore.put(authorizerKey(region, apiId, authorizerId), auth);
return auth;
}
// ──────────────────────────── Route CRUD ────────────────────────────
public Route createRoute(String region, String apiId, Map<String, Object> request) {
@@ -131,6 +233,7 @@ public class ApiGatewayV2Service {
route.setAuthorizationType((String) request.getOrDefault("authorizationType", "NONE"));
route.setAuthorizerId((String) request.get("authorizerId"));
route.setTarget((String) request.get("target"));
route.setRouteResponseSelectionExpression((String) request.get("routeResponseSelectionExpression"));
routeStore.put(routeKey(region, apiId, route.getRouteId()), route);
return route;
@@ -151,6 +254,29 @@ public class ApiGatewayV2Service {
routeStore.delete(routeKey(region, apiId, routeId));
}
public Route updateRoute(String region, String apiId, String routeId, Map<String, Object> request) {
Route route = getRoute(region, apiId, routeId);
if (request.containsKey("routeKey") && request.get("routeKey") != null) {
route.setRouteKey((String) request.get("routeKey"));
}
if (request.containsKey("authorizationType") && request.get("authorizationType") != null) {
route.setAuthorizationType((String) request.get("authorizationType"));
}
if (request.containsKey("authorizerId") && request.get("authorizerId") != null) {
route.setAuthorizerId((String) request.get("authorizerId"));
}
if (request.containsKey("target") && request.get("target") != null) {
route.setTarget((String) request.get("target"));
}
if (request.containsKey("routeResponseSelectionExpression") && request.get("routeResponseSelectionExpression") != null) {
route.setRouteResponseSelectionExpression((String) request.get("routeResponseSelectionExpression"));
}
routeStore.put(routeKey(region, apiId, routeId), route);
return route;
}
/**
* Finds the best matching route for the given HTTP method and path.
* Priority: exact match > path-template match > $default.
@@ -229,6 +355,24 @@ public class ApiGatewayV2Service {
integrationStore.delete(integrationKey(region, apiId, integrationId));
}
public Integration updateIntegration(String region, String apiId, String integrationId,
Map<String, Object> request) {
Integration integration = getIntegration(region, apiId, integrationId);
if (request.containsKey("integrationType") && request.get("integrationType") != null) {
integration.setIntegrationType((String) request.get("integrationType"));
}
if (request.containsKey("integrationUri") && request.get("integrationUri") != null) {
integration.setIntegrationUri((String) request.get("integrationUri"));
}
if (request.containsKey("payloadFormatVersion") && request.get("payloadFormatVersion") != null) {
integration.setPayloadFormatVersion((String) request.get("payloadFormatVersion"));
}
integrationStore.put(integrationKey(region, apiId, integrationId), integration);
return integration;
}
// ──────────────────────────── Stage CRUD ────────────────────────────
public Stage createStage(String region, String apiId, Map<String, Object> request) {
@@ -260,6 +404,22 @@ public class ApiGatewayV2Service {
stageStore.delete(stageKey(region, apiId, stageName));
}
public Stage updateStage(String region, String apiId, String stageName,
Map<String, Object> request) {
Stage stage = getStage(region, apiId, stageName);
if (request.containsKey("deploymentId") && request.get("deploymentId") != null) {
stage.setDeploymentId((String) request.get("deploymentId"));
}
if (request.containsKey("autoDeploy") && request.get("autoDeploy") != null) {
stage.setAutoDeploy(Boolean.parseBoolean(String.valueOf(request.get("autoDeploy"))));
}
stage.setLastUpdatedDate(System.currentTimeMillis());
stageStore.put(stageKey(region, apiId, stageName), stage);
return stage;
}
// ──────────────────────────── Deployment CRUD ────────────────────────────
public Deployment createDeployment(String region, String apiId, Map<String, Object> request) {
@@ -306,6 +466,259 @@ public class ApiGatewayV2Service {
deploymentStore.delete(deploymentKey(region, apiId, deploymentId));
}
public Deployment updateDeployment(String region, String apiId, String deploymentId,
Map<String, Object> request) {
Deployment deployment = getDeployment(region, apiId, deploymentId);
if (request.containsKey("description") && request.get("description") != null) {
deployment.setDescription((String) request.get("description"));
}
deploymentStore.put(deploymentKey(region, apiId, deploymentId), deployment);
return deployment;
}
// ──────────────────────────── Route Response CRUD ────────────────────────────
public RouteResponse createRouteResponse(String region, String apiId, String routeId, Map<String, Object> request) {
getApi(region, apiId);
getRoute(region, apiId, routeId);
RouteResponse rr = new RouteResponse();
rr.setRouteResponseId(shortId(8));
rr.setRouteId(routeId);
rr.setRouteResponseKey((String) request.get("routeResponseKey"));
rr.setModelSelectionExpression((String) request.get("modelSelectionExpression"));
@SuppressWarnings("unchecked")
Map<String, String> responseModels = (Map<String, String>) request.get("responseModels");
rr.setResponseModels(responseModels);
@SuppressWarnings("unchecked")
Map<String, String> responseParameters = (Map<String, String>) request.get("responseParameters");
rr.setResponseParameters(responseParameters);
routeResponseStore.put(routeResponseKey(region, apiId, routeId, rr.getRouteResponseId()), rr);
return rr;
}
public RouteResponse getRouteResponse(String region, String apiId, String routeId, String routeResponseId) {
return routeResponseStore.get(routeResponseKey(region, apiId, routeId, routeResponseId))
.orElseThrow(() -> new AwsException("NotFoundException", "Route response not found", 404));
}
public List<RouteResponse> getRouteResponses(String region, String apiId, String routeId) {
String prefix = region + "::" + apiId + "::" + routeId + "::";
return routeResponseStore.scan(k -> k.startsWith(prefix));
}
public RouteResponse updateRouteResponse(String region, String apiId, String routeId, String routeResponseId, Map<String, Object> request) {
RouteResponse rr = getRouteResponse(region, apiId, routeId, routeResponseId);
if (request.containsKey("routeResponseKey") && request.get("routeResponseKey") != null) {
rr.setRouteResponseKey((String) request.get("routeResponseKey"));
}
if (request.containsKey("modelSelectionExpression") && request.get("modelSelectionExpression") != null) {
rr.setModelSelectionExpression((String) request.get("modelSelectionExpression"));
}
if (request.containsKey("responseModels") && request.get("responseModels") != null) {
@SuppressWarnings("unchecked")
Map<String, String> responseModels = (Map<String, String>) request.get("responseModels");
rr.setResponseModels(responseModels);
}
if (request.containsKey("responseParameters") && request.get("responseParameters") != null) {
@SuppressWarnings("unchecked")
Map<String, String> responseParameters = (Map<String, String>) request.get("responseParameters");
rr.setResponseParameters(responseParameters);
}
routeResponseStore.put(routeResponseKey(region, apiId, routeId, routeResponseId), rr);
return rr;
}
public void deleteRouteResponse(String region, String apiId, String routeId, String routeResponseId) {
getRouteResponse(region, apiId, routeId, routeResponseId);
routeResponseStore.delete(routeResponseKey(region, apiId, routeId, routeResponseId));
}
// ──────────────────────────── Integration Response CRUD ────────────────────────────
public IntegrationResponse createIntegrationResponse(String region, String apiId, String integrationId, Map<String, Object> request) {
getApi(region, apiId);
getIntegration(region, apiId, integrationId);
IntegrationResponse ir = new IntegrationResponse();
ir.setIntegrationResponseId(shortId(8));
ir.setIntegrationId(integrationId);
ir.setIntegrationResponseKey((String) request.get("integrationResponseKey"));
ir.setContentHandlingStrategy((String) request.get("contentHandlingStrategy"));
ir.setTemplateSelectionExpression((String) request.get("templateSelectionExpression"));
@SuppressWarnings("unchecked")
Map<String, String> responseTemplates = (Map<String, String>) request.get("responseTemplates");
ir.setResponseTemplates(responseTemplates);
@SuppressWarnings("unchecked")
Map<String, String> responseParameters = (Map<String, String>) request.get("responseParameters");
ir.setResponseParameters(responseParameters);
integrationResponseStore.put(integrationResponseKey(region, apiId, integrationId, ir.getIntegrationResponseId()), ir);
return ir;
}
public IntegrationResponse getIntegrationResponse(String region, String apiId, String integrationId, String integrationResponseId) {
return integrationResponseStore.get(integrationResponseKey(region, apiId, integrationId, integrationResponseId))
.orElseThrow(() -> new AwsException("NotFoundException", "Integration response not found", 404));
}
public List<IntegrationResponse> getIntegrationResponses(String region, String apiId, String integrationId) {
String prefix = region + "::" + apiId + "::" + integrationId + "::";
return integrationResponseStore.scan(k -> k.startsWith(prefix));
}
public IntegrationResponse updateIntegrationResponse(String region, String apiId, String integrationId, String integrationResponseId, Map<String, Object> request) {
IntegrationResponse ir = getIntegrationResponse(region, apiId, integrationId, integrationResponseId);
if (request.containsKey("integrationResponseKey") && request.get("integrationResponseKey") != null) {
ir.setIntegrationResponseKey((String) request.get("integrationResponseKey"));
}
if (request.containsKey("contentHandlingStrategy") && request.get("contentHandlingStrategy") != null) {
ir.setContentHandlingStrategy((String) request.get("contentHandlingStrategy"));
}
if (request.containsKey("templateSelectionExpression") && request.get("templateSelectionExpression") != null) {
ir.setTemplateSelectionExpression((String) request.get("templateSelectionExpression"));
}
if (request.containsKey("responseTemplates") && request.get("responseTemplates") != null) {
@SuppressWarnings("unchecked")
Map<String, String> responseTemplates = (Map<String, String>) request.get("responseTemplates");
ir.setResponseTemplates(responseTemplates);
}
if (request.containsKey("responseParameters") && request.get("responseParameters") != null) {
@SuppressWarnings("unchecked")
Map<String, String> responseParameters = (Map<String, String>) request.get("responseParameters");
ir.setResponseParameters(responseParameters);
}
integrationResponseStore.put(integrationResponseKey(region, apiId, integrationId, integrationResponseId), ir);
return ir;
}
public void deleteIntegrationResponse(String region, String apiId, String integrationId, String integrationResponseId) {
getIntegrationResponse(region, apiId, integrationId, integrationResponseId);
integrationResponseStore.delete(integrationResponseKey(region, apiId, integrationId, integrationResponseId));
}
// ──────────────────────────── Model CRUD ────────────────────────────
public Model createModel(String region, String apiId, Map<String, Object> request) {
getApi(region, apiId);
Model model = new Model();
model.setModelId(shortId(10));
model.setName((String) request.get("name"));
model.setSchema((String) request.get("schema"));
model.setDescription((String) request.get("description"));
model.setContentType((String) request.get("contentType"));
modelStore.put(modelKey(region, apiId, model.getModelId()), model);
return model;
}
public Model getModel(String region, String apiId, String modelId) {
return modelStore.get(modelKey(region, apiId, modelId))
.orElseThrow(() -> new AwsException("NotFoundException", "Model not found", 404));
}
public List<Model> getModels(String region, String apiId) {
String prefix = region + "::" + apiId + "::";
return modelStore.scan(k -> k.startsWith(prefix));
}
public Model updateModel(String region, String apiId, String modelId, Map<String, Object> request) {
Model model = getModel(region, apiId, modelId);
if (request.containsKey("name") && request.get("name") != null) {
model.setName((String) request.get("name"));
}
if (request.containsKey("schema") && request.get("schema") != null) {
model.setSchema((String) request.get("schema"));
}
if (request.containsKey("description") && request.get("description") != null) {
model.setDescription((String) request.get("description"));
}
if (request.containsKey("contentType") && request.get("contentType") != null) {
model.setContentType((String) request.get("contentType"));
}
modelStore.put(modelKey(region, apiId, modelId), model);
return model;
}
public void deleteModel(String region, String apiId, String modelId) {
getModel(region, apiId, modelId);
modelStore.delete(modelKey(region, apiId, modelId));
}
// ──────────────────────────── Standalone Tagging ────────────────────────────
/**
* Parses an API Gateway v2 resource ARN and returns a two-element array
* [region, apiId]. Throws BadRequestException if the ARN is malformed.
*
* Expected format: arn:aws:apigateway:{region}::/apis/{apiId}
*/
private String[] parseArn(String resourceArn) {
if (resourceArn == null || resourceArn.isBlank()) {
throw new AwsException("BadRequestException", "ResourceArn must not be blank", 400);
}
String[] parts = resourceArn.split(":");
if (parts.length < 6) {
throw new AwsException("BadRequestException",
"Invalid ResourceArn format: " + resourceArn, 400);
}
String region = parts[3];
String resource = parts[5]; // e.g. "/apis/abc1234567"
int lastSlash = resource.lastIndexOf('/');
if (lastSlash < 0 || lastSlash == resource.length() - 1) {
throw new AwsException("BadRequestException",
"Cannot extract apiId from ResourceArn: " + resourceArn, 400);
}
String apiId = resource.substring(lastSlash + 1);
return new String[]{region, apiId};
}
public void tagResource(String resourceArn, Map<String, String> tags) {
String[] parsed = parseArn(resourceArn);
String region = parsed[0];
String apiId = parsed[1];
Api api = getApi(region, apiId);
if (tags != null && !tags.isEmpty()) {
if (api.getTags() == null) {
api.setTags(new java.util.HashMap<>());
}
api.getTags().putAll(tags);
}
apiStore.put(apiKey(region, apiId), api);
}
public void untagResource(String resourceArn, List<String> tagKeys) {
String[] parsed = parseArn(resourceArn);
String region = parsed[0];
String apiId = parsed[1];
Api api = getApi(region, apiId);
if (tagKeys != null && api.getTags() != null) {
tagKeys.forEach(k -> api.getTags().remove(k));
}
apiStore.put(apiKey(region, apiId), api);
}
public Map<String, String> getTags(String resourceArn) {
String[] parsed = parseArn(resourceArn);
String region = parsed[0];
String apiId = parsed[1];
Api api = getApi(region, apiId);
Map<String, String> tags = api.getTags();
return (tags != null) ? new java.util.HashMap<>(tags) : java.util.Collections.emptyMap();
}
// ──────────────────────────── Key helpers ────────────────────────────
private String apiKey(String region, String apiId) {
@@ -332,6 +745,18 @@ public class ApiGatewayV2Service {
return region + "::" + apiId + "::" + deploymentId;
}
private String routeResponseKey(String region, String apiId, String routeId, String routeResponseId) {
return region + "::" + apiId + "::" + routeId + "::" + routeResponseId;
}
private String integrationResponseKey(String region, String apiId, String integrationId, String integrationResponseId) {
return region + "::" + apiId + "::" + integrationId + "::" + integrationResponseId;
}
private String modelKey(String region, String apiId, String modelId) {
return region + "::" + apiId + "::" + modelId;
}
private static String shortId(int length) {
return UUID.randomUUID().toString().replace("-", "").substring(0, length);
}
@@ -15,6 +15,9 @@ public class Api {
private String apiEndpoint;
private long createdDate;
private Map<String, String> tags = new HashMap<>();
private String routeSelectionExpression;
private String description;
private String apiKeySelectionExpression;
public Api() {}
@@ -35,4 +38,13 @@ public class Api {
public Map<String, String> getTags() { return tags; }
public void setTags(Map<String, String> tags) { this.tags = tags; }
public String getRouteSelectionExpression() { return routeSelectionExpression; }
public void setRouteSelectionExpression(String routeSelectionExpression) { this.routeSelectionExpression = routeSelectionExpression; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public String getApiKeySelectionExpression() { return apiKeySelectionExpression; }
public void setApiKeySelectionExpression(String apiKeySelectionExpression) { this.apiKeySelectionExpression = apiKeySelectionExpression; }
}
@@ -0,0 +1,40 @@
package io.github.hectorvent.floci.services.apigatewayv2.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.Map;
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public class IntegrationResponse {
private String integrationResponseId;
private String integrationResponseKey;
private String integrationId;
private String contentHandlingStrategy;
private String templateSelectionExpression;
private Map<String, String> responseTemplates;
private Map<String, String> responseParameters;
public IntegrationResponse() {}
public String getIntegrationResponseId() { return integrationResponseId; }
public void setIntegrationResponseId(String integrationResponseId) { this.integrationResponseId = integrationResponseId; }
public String getIntegrationResponseKey() { return integrationResponseKey; }
public void setIntegrationResponseKey(String integrationResponseKey) { this.integrationResponseKey = integrationResponseKey; }
public String getIntegrationId() { return integrationId; }
public void setIntegrationId(String integrationId) { this.integrationId = integrationId; }
public String getContentHandlingStrategy() { return contentHandlingStrategy; }
public void setContentHandlingStrategy(String contentHandlingStrategy) { this.contentHandlingStrategy = contentHandlingStrategy; }
public String getTemplateSelectionExpression() { return templateSelectionExpression; }
public void setTemplateSelectionExpression(String templateSelectionExpression) { this.templateSelectionExpression = templateSelectionExpression; }
public Map<String, String> getResponseTemplates() { return responseTemplates; }
public void setResponseTemplates(Map<String, String> responseTemplates) { this.responseTemplates = responseTemplates; }
public Map<String, String> getResponseParameters() { return responseParameters; }
public void setResponseParameters(Map<String, String> responseParameters) { this.responseParameters = responseParameters; }
}
@@ -0,0 +1,31 @@
package io.github.hectorvent.floci.services.apigatewayv2.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.quarkus.runtime.annotations.RegisterForReflection;
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public class Model {
private String modelId;
private String name;
private String schema;
private String description;
private String contentType;
public Model() {}
public String getModelId() { return modelId; }
public void setModelId(String modelId) { this.modelId = modelId; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getSchema() { return schema; }
public void setSchema(String schema) { this.schema = schema; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description; }
public String getContentType() { return contentType; }
public void setContentType(String contentType) { this.contentType = contentType; }
}
@@ -11,6 +11,7 @@ public class Route {
private String authorizationType; // NONE, AWS_IAM, CUSTOM, JWT
private String authorizerId;
private String target; // integrations/{integrationId}
private String routeResponseSelectionExpression;
public Route() {}
@@ -28,4 +29,7 @@ public class Route {
public String getTarget() { return target; }
public void setTarget(String target) { this.target = target; }
public String getRouteResponseSelectionExpression() { return routeResponseSelectionExpression; }
public void setRouteResponseSelectionExpression(String routeResponseSelectionExpression) { this.routeResponseSelectionExpression = routeResponseSelectionExpression; }
}
@@ -0,0 +1,36 @@
package io.github.hectorvent.floci.services.apigatewayv2.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.Map;
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public class RouteResponse {
private String routeResponseId;
private String routeResponseKey;
private String routeId;
private String modelSelectionExpression;
private Map<String, String> responseModels;
private Map<String, String> responseParameters;
public RouteResponse() {}
public String getRouteResponseId() { return routeResponseId; }
public void setRouteResponseId(String routeResponseId) { this.routeResponseId = routeResponseId; }
public String getRouteResponseKey() { return routeResponseKey; }
public void setRouteResponseKey(String routeResponseKey) { this.routeResponseKey = routeResponseKey; }
public String getRouteId() { return routeId; }
public void setRouteId(String routeId) { this.routeId = routeId; }
public String getModelSelectionExpression() { return modelSelectionExpression; }
public void setModelSelectionExpression(String modelSelectionExpression) { this.modelSelectionExpression = modelSelectionExpression; }
public Map<String, String> getResponseModels() { return responseModels; }
public void setResponseModels(Map<String, String> responseModels) { this.responseModels = responseModels; }
public Map<String, String> getResponseParameters() { return responseParameters; }
public void setResponseParameters(Map<String, String> responseParameters) { this.responseParameters = responseParameters; }
}