mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(ses): read every SES v2 request body by the same rule (#6385)
Every SES v2 operation reads its body through readOptionBody, now also CreateEmailIdentity, CreateEmailTemplate, UpdateEmailTemplate, CreateCustomVerificationEmailTemplate, UpdateCustomVerificationEmailTemplate and TagResource, which read a body that is not a JSON object as one without members. Only an empty body is read as one without members; a whitespace-only body, malformed JSON and anything but whitespace after the object are a SerializationException without a message, as AWS answers them. The hand-rolled copies in the tenant, contact, account, identity, import job, send, dedicated IP, suppression and template controllers, which answered malformed JSON with a BadRequestException carrying Jackson's message, are gone, and so is the import job controller's own strict reader. The operations that answer an empty body with "Request body is required." no longer give that answer for a whitespace-only one.
This commit is contained in:
1 parent
42f5019231
commit
0acb8cd44c
17 files changed
+245
-218
No files matched your search
@@ -1,6 +1,5 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -30,7 +29,6 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBoolean;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBooleanOrFalse;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;
|
||||
|
||||
/**
|
||||
@@ -164,10 +162,7 @@ public class SesAccountController {
|
||||
public Response putAccountDetails(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
|
||||
// Parse every member first (rejecting wrong JSON types as a serialization error, the way
|
||||
// AWS does before validation), then validate the parsed values together so all constraint
|
||||
@@ -205,10 +200,6 @@ public class SesAccountController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
// AWS reports a malformed JSON body as a SerializationException, the same error type used
|
||||
// for wrong-typed members above.
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -38,8 +37,8 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.coerceBooleanOrF
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
|
||||
|
||||
/**
|
||||
* SES V2 contact-list and contact endpoints ({@code /v2/email/contact-lists}). Every operation
|
||||
@@ -71,11 +70,10 @@ public class SesContactController {
|
||||
public Response createContactList(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
if (body == null || body.isBlank()) {
|
||||
if (body == null || body.isEmpty()) {
|
||||
throw new AwsException("BadRequestException", "Request body is required.", 400);
|
||||
}
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("CreateContactList", request);
|
||||
// Read leniently; the service surfaces a missing ContactListName as the AWS Smithy
|
||||
// validation error rather than a custom "required" message.
|
||||
@@ -88,8 +86,6 @@ public class SesContactController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,10 +125,7 @@ public class SesContactController {
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("UpdateContactList", request);
|
||||
JsonNode topicsNode = request.path("Topics");
|
||||
// Treat absent or explicit-null Topics as "not provided" (keep existing), consistent
|
||||
@@ -148,8 +141,6 @@ public class SesContactController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,11 +202,10 @@ public class SesContactController {
|
||||
@PathParam("contactListName") String contactListName, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
if (body == null || body.isBlank()) {
|
||||
if (body == null || body.isEmpty()) {
|
||||
throw new AwsException("BadRequestException", "Request body is required.", 400);
|
||||
}
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("CreateContact", request);
|
||||
String emailAddress = request.path("EmailAddress").asText(null);
|
||||
List<TopicPreference> prefs = parseTopicPreferences(request.path("TopicPreferences"));
|
||||
@@ -227,8 +217,6 @@ public class SesContactController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,10 +226,7 @@ public class SesContactController {
|
||||
@PathParam("contactListName") String contactListName, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("ListContacts", request);
|
||||
Integer pageSize = intMemberOrAbsent(request, "PageSize");
|
||||
String nextToken = request.path("NextToken").asText(null);
|
||||
@@ -256,8 +241,6 @@ public class SesContactController {
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,10 +277,7 @@ public class SesContactController {
|
||||
@PathParam("emailAddress") String emailAddress, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("UpdateContact", request);
|
||||
JsonNode prefsNode = request.path("TopicPreferences");
|
||||
boolean prefsPresent = !prefsNode.isMissingNode() && !prefsNode.isNull();
|
||||
@@ -310,8 +290,6 @@ public class SesContactController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -26,8 +25,8 @@ import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
|
||||
|
||||
/**
|
||||
* SES V2 custom verification email template endpoints
|
||||
@@ -63,7 +62,7 @@ public class SesCvetController {
|
||||
public Response createCustomVerificationEmailTemplate(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
CustomVerificationEmailTemplate t = parseCvet(request);
|
||||
// Tags exist only on the create request; UpdateCustomVerificationEmailTemplate has no
|
||||
// Tags member and preserves the stored ones.
|
||||
@@ -72,8 +71,6 @@ public class SesCvetController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,14 +112,12 @@ public class SesCvetController {
|
||||
@PathParam("templateName") String templateName, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
CustomVerificationEmailTemplate t = parseCvet(objectMapper.readTree(body));
|
||||
CustomVerificationEmailTemplate t = parseCvet(readOptionBody(objectMapper, body));
|
||||
t.setTemplateName(templateName);
|
||||
sesService.updateCustomVerificationEmailTemplate(t, region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +135,6 @@ public class SesCvetController {
|
||||
}
|
||||
|
||||
private CustomVerificationEmailTemplate parseCvet(JsonNode request) {
|
||||
requireJsonObject(request);
|
||||
CustomVerificationEmailTemplate t = new CustomVerificationEmailTemplate();
|
||||
t.setTemplateName(request.path("TemplateName").asText(null));
|
||||
t.setFromEmailAddress(request.path("FromEmailAddress").asText(null));
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -33,7 +32,6 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readRequiredStringField;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
|
||||
|
||||
/**
|
||||
* SES V2 dedicated IP pool and dedicated IP endpoints ({@code /v2/email/dedicated-ip-pools} and
|
||||
@@ -65,11 +63,10 @@ public class SesDedicatedIpController {
|
||||
public Response createDedicatedIpPool(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
if (body == null || body.isBlank()) {
|
||||
if (body == null || body.isEmpty()) {
|
||||
throw new AwsException("BadRequestException", "Request body is required.", 400);
|
||||
}
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String poolName = readRequiredStringField(request, "PoolName");
|
||||
JsonNode scalingNode = request.path("ScalingMode");
|
||||
String scalingMode;
|
||||
@@ -87,8 +84,6 @@ public class SesDedicatedIpController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -37,7 +36,6 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireObjectOrAbsent;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMapMemberOrAbsent;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;
|
||||
@@ -85,7 +83,7 @@ public class SesIdentityController {
|
||||
public Response createEmailIdentity(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
JsonNode emailIdentityNode = request.path("EmailIdentity");
|
||||
if (!emailIdentityNode.isMissingNode() && !emailIdentityNode.isNull()
|
||||
&& !emailIdentityNode.isTextual()) {
|
||||
@@ -232,8 +230,6 @@ public class SesIdentityController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,8 +245,6 @@ public class SesIdentityController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,12 +270,11 @@ public class SesIdentityController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private String readPolicyBody(String body) throws JsonProcessingException {
|
||||
if (body == null || body.isBlank()) {
|
||||
private String readPolicyBody(String body) {
|
||||
if (body == null || body.isEmpty()) {
|
||||
throw new AwsException("BadRequestException", "Request body is required.", 400);
|
||||
}
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
JsonNode policyNode = request.path("Policy");
|
||||
if (policyNode.isMissingNode() || policyNode.isNull()) {
|
||||
// Verified against AWS: a missing/null required member is a Smithy validation error.
|
||||
@@ -322,9 +315,7 @@ public class SesIdentityController {
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode() : objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String origin = request.path("SigningAttributesOrigin").asText(null);
|
||||
if (!"AWS_SES".equals(origin) && !"EXTERNAL".equals(origin)) {
|
||||
throw new AwsException("BadRequestException",
|
||||
@@ -366,11 +357,10 @@ public class SesIdentityController {
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
if (body == null || body.isBlank()) {
|
||||
if (body == null || body.isEmpty()) {
|
||||
throw new AwsException("BadRequestException", "Request body is required.", 400);
|
||||
}
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
JsonNode mailFromDomainNode = request.path("MailFromDomain");
|
||||
if (mailFromDomainNode.isMissingNode()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
@@ -397,8 +387,6 @@ public class SesIdentityController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -428,30 +416,21 @@ public class SesIdentityController {
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
// An omitted or explicit-null ConfigurationSetName clears the association, as does an
|
||||
// empty body.
|
||||
String configurationSetName = null;
|
||||
if (body != null && !body.isEmpty()) {
|
||||
// Only a truly empty body is "no body". A non-empty body must be a JSON object; a
|
||||
// whitespace-only or otherwise unparseable body is a serialization error (verified
|
||||
// against real AWS: whitespace-only returns SerializationException and does not
|
||||
// clear). Within a valid object, an omitted or explicit-null ConfigurationSetName
|
||||
// clears the association (as does an empty body / {}).
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode node = request.path("ConfigurationSetName");
|
||||
if (!node.isMissingNode() && !node.isNull()) {
|
||||
if (!node.isTextual()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"ConfigurationSetName must be a JSON string.", 400);
|
||||
}
|
||||
configurationSetName = node.asText();
|
||||
JsonNode node = readOptionBody(objectMapper, body).path("ConfigurationSetName");
|
||||
if (!node.isMissingNode() && !node.isNull()) {
|
||||
if (!node.isTextual()) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"ConfigurationSetName must be a JSON string.", 400);
|
||||
}
|
||||
configurationSetName = node.asText();
|
||||
}
|
||||
sesService.setEmailIdentityConfigurationSet(emailIdentity, configurationSetName, region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectReader;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
@@ -26,9 +23,9 @@ import org.jboss.logging.Logger;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readRequiredStringField;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;
|
||||
|
||||
/**
|
||||
@@ -46,9 +43,6 @@ public class SesImportJobController {
|
||||
private final SesImportJobService importJobService;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ObjectMapper objectMapper;
|
||||
// FAIL_ON_TRAILING_TOKENS so "{...} garbage" is rejected instead of creating a job from the
|
||||
// leading object, as the JSON protocol controllers do.
|
||||
private final ObjectReader strictReader;
|
||||
|
||||
@Inject
|
||||
public SesImportJobController(SesImportJobService importJobService, RegionResolver regionResolver,
|
||||
@@ -56,7 +50,6 @@ public class SesImportJobController {
|
||||
this.importJobService = importJobService;
|
||||
this.regionResolver = regionResolver;
|
||||
this.objectMapper = objectMapper;
|
||||
this.strictReader = objectMapper.reader().with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -64,11 +57,10 @@ public class SesImportJobController {
|
||||
public Response createImportJob(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
if (body == null || body.isBlank()) {
|
||||
if (body == null || body.isEmpty()) {
|
||||
throw new AwsException("BadRequestException", "Request body is required.", 400);
|
||||
}
|
||||
JsonNode request = strictReader.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("CreateImportJob", request);
|
||||
JsonNode source = request.path("ImportDataSource");
|
||||
if (source.isMissingNode() || source.isNull()) {
|
||||
@@ -104,8 +96,6 @@ public class SesImportJobController {
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,10 +121,7 @@ public class SesImportJobController {
|
||||
public Response listImportJobs(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: strictReader.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String destinationType = stringMemberOrAbsent(request, "ImportDestinationType");
|
||||
Integer pageSize = intMemberOrAbsent(request, "PageSize");
|
||||
String nextToken = stringMemberOrAbsent(request, "NextToken");
|
||||
@@ -149,8 +136,6 @@ public class SesImportJobController {
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -41,8 +40,8 @@ import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
|
||||
|
||||
/**
|
||||
* REST JSON controller for the three SES V2 send endpoints:
|
||||
@@ -93,8 +92,7 @@ public class SesSendController {
|
||||
"Account sending is disabled.", 400);
|
||||
}
|
||||
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("SendEmail", request);
|
||||
validateTrackingOverrides(request);
|
||||
|
||||
@@ -246,8 +244,7 @@ public class SesSendController {
|
||||
"Account sending is disabled.", 400);
|
||||
}
|
||||
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("SendBulkEmail", request);
|
||||
validateTrackingOverrides(request);
|
||||
String fromEmailAddress = request.path("FromEmailAddress").asText(null);
|
||||
@@ -393,8 +390,7 @@ public class SesSendController {
|
||||
throw new AwsException("SendingPausedException",
|
||||
"Account sending is disabled.", 400);
|
||||
}
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
SesV2RequestShapes.check("SendCustomVerificationEmail", request);
|
||||
templateName = request.path("TemplateName").asText(null);
|
||||
String messageId = sesService.sendCustomVerificationEmail(
|
||||
@@ -411,8 +407,6 @@ public class SesSendController {
|
||||
"Custom verification email template <" + templateName + "> does not exist", 404);
|
||||
}
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -28,9 +27,9 @@ import org.jboss.logging.Logger;
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readRequiredStringField;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;
|
||||
|
||||
/**
|
||||
@@ -64,11 +63,10 @@ public class SesSuppressionController {
|
||||
public Response putSuppressedDestination(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
if (body == null || body.isBlank()) {
|
||||
if (body == null || body.isEmpty()) {
|
||||
throw new AwsException("BadRequestException", "Request body is required.", 400);
|
||||
}
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String emailAddress = readRequiredStringField(request, "EmailAddress");
|
||||
String reason = readRequiredStringField(request, "Reason");
|
||||
String tenantName = stringMemberOrAbsent(request, "TenantName");
|
||||
@@ -77,8 +75,6 @@ public class SesSuppressionController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -26,6 +25,7 @@ import org.jboss.logging.Logger;
|
||||
import java.util.List;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
|
||||
|
||||
/**
|
||||
@@ -59,10 +59,10 @@ public class SesTagController {
|
||||
public Response tagResource(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
if (body == null || body.isBlank()) {
|
||||
if (body == null || body.isEmpty()) {
|
||||
throw new AwsException("BadRequestException", "Request body is required.", 400);
|
||||
}
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String arn = request.path("ResourceArn").asText(null);
|
||||
List<Tag> tags = parseTagsArray(request.path("Tags"));
|
||||
if (tags == null) {
|
||||
@@ -73,8 +73,6 @@ public class SesTagController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -30,8 +29,8 @@ import java.util.List;
|
||||
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
|
||||
|
||||
/**
|
||||
* SES V2 email-template endpoints ({@code /v2/email/templates}). Talks to
|
||||
@@ -65,7 +64,7 @@ public class SesTemplateController {
|
||||
public Response createEmailTemplate(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String templateName = request.path("TemplateName").asText(null);
|
||||
if (templateName == null || templateName.isBlank()) {
|
||||
throw new AwsException("BadRequestException", "TemplateName is required.", 400);
|
||||
@@ -80,8 +79,6 @@ public class SesTemplateController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,15 +122,13 @@ public class SesTemplateController {
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
EmailTemplate template = parseTemplateContent(templateName, request.path("TemplateContent"));
|
||||
templateService.updateTemplate(template, region);
|
||||
LOG.infov("SES V2 UpdateEmailTemplate: {0}", templateName);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,11 +153,10 @@ public class SesTemplateController {
|
||||
String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
if (body == null || body.isBlank()) {
|
||||
if (body == null || body.isEmpty()) {
|
||||
throw new AwsException("BadRequestException", "Request body is required.", 400);
|
||||
}
|
||||
JsonNode request = objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
JsonNode templateDataNode = request.path("TemplateData");
|
||||
if (!templateDataNode.isMissingNode() && !templateDataNode.isNull()
|
||||
&& !templateDataNode.isTextual()) {
|
||||
@@ -177,8 +171,6 @@ public class SesTemplateController {
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
@@ -29,8 +28,8 @@ import static io.github.hectorvent.floci.services.ses.SesV2Json.filterValues;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.intMemberOrAbsent;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.parseTagsArray;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.putTimestamp;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.readOptionBody;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.remapV1Exception;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.requireJsonObject;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringArrayOrAbsent;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMapMemberOrAbsent;
|
||||
import static io.github.hectorvent.floci.services.ses.SesV2Json.stringMemberOrAbsent;
|
||||
@@ -72,10 +71,7 @@ public class SesTenantController {
|
||||
public Response createTenant(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String tenantName = stringMemberOrAbsent(request, "TenantName");
|
||||
List<Tag> tags = parseTagsArray(request.path("Tags"));
|
||||
List<String> suppressedReasons = null;
|
||||
@@ -94,8 +90,6 @@ public class SesTenantController {
|
||||
return Response.ok(tenantJson(tenant)).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,10 +98,7 @@ public class SesTenantController {
|
||||
public Response getTenant(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String tenantName = stringMemberOrAbsent(request, "TenantName");
|
||||
Tenant tenant = tenantService.getTenant(tenantName, region);
|
||||
ObjectNode result = objectMapper.createObjectNode();
|
||||
@@ -115,8 +106,6 @@ public class SesTenantController {
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,10 +114,7 @@ public class SesTenantController {
|
||||
public Response listTenants(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
Map<String, String> filter = stringMapMemberOrAbsent(request, "Filter");
|
||||
Integer pageSize = intMemberOrAbsent(request, "PageSize");
|
||||
String nextToken = stringMemberOrAbsent(request, "NextToken");
|
||||
@@ -148,8 +134,6 @@ public class SesTenantController {
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,17 +142,12 @@ public class SesTenantController {
|
||||
public Response deleteTenant(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String tenantName = stringMemberOrAbsent(request, "TenantName");
|
||||
sesService.deleteTenant(tenantName, region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,10 +159,7 @@ public class SesTenantController {
|
||||
public Response createTenantResourceAssociation(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String tenantName = stringMemberOrAbsent(request, "TenantName");
|
||||
String resourceArn = stringMemberOrAbsent(request, "ResourceArn");
|
||||
sesService.createTenantResourceAssociation(tenantName, resourceArn,
|
||||
@@ -191,8 +167,6 @@ public class SesTenantController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,10 +175,7 @@ public class SesTenantController {
|
||||
public Response deleteTenantResourceAssociation(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String tenantName = stringMemberOrAbsent(request, "TenantName");
|
||||
String resourceArn = stringMemberOrAbsent(request, "ResourceArn");
|
||||
sesService.deleteTenantResourceAssociation(tenantName, resourceArn,
|
||||
@@ -212,8 +183,6 @@ public class SesTenantController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -222,10 +191,7 @@ public class SesTenantController {
|
||||
public Response listTenantResources(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String tenantName = stringMemberOrAbsent(request, "TenantName");
|
||||
Map<String, String> filter = stringMapMemberOrAbsent(request, "Filter");
|
||||
String resourceTypeFilter = filter == null ? null : filter.get("RESOURCE_TYPE");
|
||||
@@ -245,8 +211,6 @@ public class SesTenantController {
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,10 +219,7 @@ public class SesTenantController {
|
||||
public Response listResourceTenants(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String resourceArn = stringMemberOrAbsent(request, "ResourceArn");
|
||||
Integer pageSize = intMemberOrAbsent(request, "PageSize");
|
||||
String nextToken = stringMemberOrAbsent(request, "NextToken");
|
||||
@@ -279,8 +240,6 @@ public class SesTenantController {
|
||||
return Response.ok(result).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,10 +250,7 @@ public class SesTenantController {
|
||||
public Response putTenantSuppressionAttributes(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
JsonNode request = readOptionBody(objectMapper, body);
|
||||
String tenantName = stringMemberOrAbsent(request, "TenantName");
|
||||
List<String> suppressedReasons = stringArrayOrAbsent(request, "SuppressedReasons");
|
||||
String suppressionScope = stringMemberOrAbsent(request, "SuppressionScope");
|
||||
@@ -303,8 +259,6 @@ public class SesTenantController {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
} catch (AwsException e) {
|
||||
throw remapV1Exception(e);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", null, 400);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.ses;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
@@ -113,17 +114,23 @@ final class SesV2Json {
|
||||
return !node.isMissingNode() && !node.isNull() && !node.isTextual();
|
||||
}
|
||||
|
||||
/** Parse an option PUT body into a JSON object, treating an empty body as {}. */
|
||||
/**
|
||||
* Parse a request body into a JSON object. Only an empty body reads as {}: AWS answers a
|
||||
* whitespace-only body, malformed JSON and a trailing token after the object (even a second
|
||||
* value) with a {@code SerializationException} without a message.
|
||||
*/
|
||||
static JsonNode readOptionBody(ObjectMapper objectMapper, String body) {
|
||||
try {
|
||||
JsonNode request = (body == null || body.isBlank())
|
||||
? objectMapper.createObjectNode()
|
||||
: objectMapper.readTree(body);
|
||||
requireJsonObject(request);
|
||||
return request;
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
if (body == null || body.isEmpty()) {
|
||||
return objectMapper.createObjectNode();
|
||||
}
|
||||
JsonNode request;
|
||||
try {
|
||||
request = objectMapper.reader().with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS).readTree(body);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException(SERIALIZATION_EXCEPTION, null, 400);
|
||||
}
|
||||
requireJsonObject(request);
|
||||
return request;
|
||||
}
|
||||
|
||||
/** Read an optional string member, rejecting a non-string value the way the AWS deserialization layer does. */
|
||||
|
||||
Reference in new issue
Block a user