Skip to content
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

Merged
merged 3 commits into from
Jan 9, 2020

Conversation

cenedhryn
Copy link
Contributor

… every query protocol service through codegen

Description

  • In the request pipeline, there is a Stage class MoveParametersToBodyStage.java that analyses every HTTP request passing through and based on certain conditions, moves them to the body instead.
  • This functionality (move params to body) is specific for the Query protocol
  • This change moves the code to an interceptor attached to the 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
  • ran integration tests for iot, rds, ec2, protocol-tests

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed
  • A short description of the change has been added to the CHANGELOG
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

{
"type": "bugfix",
"category": "AWS SDK for Java v2",
"description": "Removes query protocol specific stage from request pipeline and performs functionality when creating HTTP request"
Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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())",
Copy link
Contributor

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.

Copy link
Contributor Author

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);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, exactly

* - It is a POST request
* - There is no content stream provider
* - There are query parameters to transfer
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<p>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix

.executionContext(executionContext)
.originalRequest(NoopTestRequest.builder().build())
.build();
public final class Context implements software.amazon.awssdk.core.interceptor.Context.ModifyHttpRequest {
Copy link
Contributor

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;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: extraneous linebreak

Copy link
Contributor Author

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() {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Extraneous linebreak

Copy link
Contributor Author

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")));
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Extraneous linebreak

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix

@cenedhryn cenedhryn force-pushed the salande/unsupported-payloads-interceptor branch from 4011c62 to e2f1de5 Compare January 9, 2020 21:40
… every query protocol service through codegen
@cenedhryn cenedhryn force-pushed the salande/unsupported-payloads-interceptor branch from e2f1de5 to 8befe5f Compare January 9, 2020 22:07
@codecov-io
Copy link

codecov-io commented Jan 9, 2020

Codecov Report

Merging #1566 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             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
Flag Coverage Δ Complexity Δ
#unittests 75.54% <100%> (+0.01%) 638 <0> (ø) ⬇️
Impacted Files Coverage Δ Complexity Δ
...n/awssdk/codegen/lite/regions/RegionGenerator.java 100% <100%> (ø) 0 <0> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 314ef90...a5bca3d. Read the comment docs.

@cenedhryn cenedhryn merged commit 308c95a into master Jan 9, 2020
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 9, 2020

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@cenedhryn cenedhryn deleted the salande/unsupported-payloads-interceptor branch March 18, 2020 17:04
aws-sdk-java-automation added a commit that referenced this pull request Jul 26, 2021
…1e1408a02

Pull request: release <- staging/84c53abd-3119-4856-9c90-c161e1408a02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants