-
Notifications
You must be signed in to change notification settings - Fork 858
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adds an interceptor to replace params-to-body stage and applies it to… #1566
Conversation
{ | ||
"type": "bugfix", | ||
"category": "AWS SDK for Java v2", | ||
"description": "Removes query protocol specific stage from request pipeline and performs functionality when creating HTTP request" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this a more clear/concise description of the 'bug', so that when people read this in the future and aren't able to cross-reference your PR notes they are not missing too much context. Maybe focus on what behavior it fixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
@@ -519,6 +519,10 @@ public boolean isXmlProtocol() { | |||
protocol == Protocol.REST_XML; | |||
} | |||
|
|||
public boolean isQueryProtocol() { | |||
return protocol == Protocol.EC2 || protocol == Protocol.QUERY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: Can we follow the style of the other methods in this class, keep each check on a separate line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix
@@ -177,6 +180,16 @@ private MethodSpec finalizeServiceConfigurationMethod() { | |||
.addCode("interceptors = $T.mergeLists(interceptors, config.option($T.EXECUTION_INTERCEPTORS));\n", | |||
CollectionUtils.class, SdkClientOption.class); | |||
|
|||
if (model.getMetadata().isQueryProtocol()) { | |||
builder.addStatement("$T<$T> protocolInterceptors = $T.singletonList(new $T())", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use poet's ParamaterizedTypeName here instead of parameterizing by hand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like this?
TypeName listType = ParameterizedTypeName.get(List.class, ExecutionInterceptor.class);
builder.addStatement("$T protocolInterceptors = $T.singletonList(new $T())",
listType,
Collections.class,
QueryParametersToBodyInterceptor.class);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly
codegen/src/main/java/software/amazon/awssdk/codegen/poet/builder/BaseClientBuilderClass.java
Show resolved
Hide resolved
* - It is a POST request | ||
* - There is no content stream provider | ||
* - There are query parameters to transfer | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<p>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix
...software/amazon/awssdk/protocols/query/interceptor/QueryParametersToBodyInterceptorTest.java
Outdated
Show resolved
Hide resolved
.executionContext(executionContext) | ||
.originalRequest(NoopTestRequest.builder().build()) | ||
.build(); | ||
public final class Context implements software.amazon.awssdk.core.interceptor.Context.ModifyHttpRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do have to do this maybe a slightly less generic name that gives the reader a clue as to why we had to do this (eg: ContextWithNoRequest or whatever)
public WireMockRule wireMock = new WireMockRule(0); | ||
|
||
private ProtocolQueryClient client; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: extraneous linebreak
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix
} | ||
|
||
private void verifyResponseMetadata() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Extraneous linebreak
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix
.withRequestBody(containing("Version=")) | ||
.withRequestBody(containing("IdempotencyToken=test"))); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Extraneous linebreak
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix
4011c62
to
e2f1de5
Compare
… every query protocol service through codegen
e2f1de5
to
8befe5f
Compare
Codecov Report
@@ Coverage Diff @@
## master #1566 +/- ##
============================================
+ Coverage 75.53% 75.54% +0.01%
Complexity 638 638
============================================
Files 896 896
Lines 28073 28086 +13
Branches 2217 2217
============================================
+ Hits 21205 21218 +13
Misses 5848 5848
Partials 1020 1020
Continue to review full report at Codecov.
|
Kudos, SonarCloud Quality Gate passed! 0 Bugs |
…1e1408a02 Pull request: release <- staging/84c53abd-3119-4856-9c90-c161e1408a02
… every query protocol service through codegen
Description
MoveParametersToBodyStage.java
that analyses every HTTP request passing through and based on certain conditions, moves them to the body instead.modifyHTTPRequest
interceptor hook. The interceptor is added to the interceptor chain for every service identified as a Query protocol service, through codegen.Motivation and Context
The change is directly motivated by a bug fix, PR 1187, which caused services not using this protocol to pass the conditions and erroneously move its params to the body.
It's also a change in the right direction from an architectural point of view, moving this too-unspecific check and protocol specific functionality from the general codepath shared by all services to the protocol layer.
Solution alternatives
Moving this HTTP request back in the request pipeline to the client handler where the HTTP request is created/marshalled, there were two possible solutions considered.
Approach 1: Adapt marshalling
This is the preferred approach since the protocol marshaller should do protocol specific work and it was the first approach. However, the protocol marshaller is not aware of any content streaming provider, which makes the content streaming code execution path not work; the protocol marshaller would move parameters to the body even though the wrapping streaming marshaller has a content stream provider. It may be possible to explore further avenues of the codegen making the protocol marshaller aware of the content streaming provider.
Approach 2: Create a protocol specific interceptor
This PR presents approach 2, where the HTTP request modification is done through an interceptor and the HTTP request modification hook, applied directly after marshalling. This interceptor is added to any client builder identified as needing it (Query protocol).
The condition to determine that relationship may have to be modified, since some protocols are inter-related.
Testing
mvn clean install
Types of changes
Checklist
mvn install
succeedsLicense