serverless-java-container
serverless-java-container copied to clipboard
Add static factory methods to ApiGatewayRequestIdentity and AwsProxyRequestContext
Issue #, if available: issue #1495
Description of changes:
This PR resolves issue #1495 by implementing static factory methods for both ApiGatewayRequestIdentity and AwsProxyRequestContext classes.
Implemented Changes
-
Added
getApiGatewayRequestIdentity()toApiGatewayRequestIdentityclass:- Creates an instance with realistic default values based on typical API Gateway requests
- Sets appropriate values for all fields (including userAgent and sourceIp)
- Null values for fields that typically don't have defaults
-
Added
getApiGatewayRequestIdentity(String sourceIp)toApiGatewayRequestIdentityclass:- Allows specifying a custom source IP while keeping other defaults
-
Added
getAwsProxyRequestContext()toAwsProxyRequestContextclass:- Creates an instance with realistic default values from API Gateway
- Sets appropriate values for all fields
- Uses the default ApiGatewayRequestIdentity
-
Added
getAwsProxyRequestContext(String httpMethod)toAwsProxyRequestContextclass:- Allows specifying a custom HTTP method while keeping other defaults
Benefits
- Simplifies testing and priming implementations by providing easy-to-use factory methods
- Reduces boilerplate code needed to set up these objects
- Follows a similar approach to the one in reference implementation (AmazonAPIGatewayPrimingResource)
Questions for Maintainers
- Is the naming convention
getAwsProxyRequestContext()andgetApiGatewayRequestIdentity()preferred, or would you prefer a different naming pattern likebuilder()orof()? - Are there specific default values for certain fields that you'd like to change?
- Would additional overloaded methods with different parameters be useful?
I've tested these changes locally and they work as expected.
By submitting this pull request
- [x] I confirm that my contribution is made under the terms of the Apache 2.0 license.
- [x] I confirm that I've made a best effort attempt to update all relevant documentation.