generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 23
Fix protocol initialization for AwsRestJson1Protocol #1023
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e5ec5c9
Fix protocol initialization for AwsRestJson1Protocol
yasmewad d044d00
Remove tautological protocol tests per review feedback
yasmewad 3094452
Update aws/server/aws-server-restjson/src/main/java/software/amazon/s…
yasmewad 6ab7a29
Merge branch 'main' into fix-rest-json
sugmanue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ public ShapeId getProtocolId() { | |
| } | ||
|
|
||
| @Override | ||
| public int priority() { | ||
| public int precision() { | ||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,5 +15,5 @@ public interface ServerProtocolProvider { | |
|
|
||
| ShapeId getProtocolId(); | ||
|
|
||
| int priority(); | ||
| int precision(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
With the RestJson protocol, all operations are required to have the HTTP trait, so this situation should not arise in the first place.
On that note, I don’t think this addresses the root cause of the problem, it only treats a symptom.
In my opinion, the correct fix is to make the protocol resolver filter and initialize only the providers that are actually required, based on the protocol traits declared on the service.
Uh oh!
There was an error while loading. Please reload this page.
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.
That's a fair callout. I looked into protocol-level filtering first but hit some blockers.
ProtocolResolver gets instantiated with the Server and supports multiple services simultaneously. Consider serviceA with restJson1 and rpcv2Cbor, and serviceB with only rpcv2Cbor. We'd still need handlers for both protocols loaded. Filtering at the constructor level wouldn't work for this case.
I tried implementing filtering anyway and ran into the TraitKey issue. ProtocolTestProtocolProvider provides a ShapeId but no trait class to construct a TraitKey from. Also not sure if protocol traits are even available in the schema at that point since some example services don't define protocols explicitly.
To unblock the issue and open up further discussion, and going through the options with Manuel, I decided to make HTTP_TRAIT retrieval defensive. This lets handlers instantiate even when services don't use restJson1 or have HTTP traits.
My understanding is that the server needs to be aware of all protocol handlers on the classpath to select the appropriate one at runtime. I think changing this pattern could be challenging, though I might be missing something.
In my opinion, the cleanest solution would be adding a filterCandidateServices method to ServerProtocolProvider. Each provider could implement its own filtering logic based on the wire protocol selection spec instead of failing during construction.
What do you think about that approach?
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.
Merging this and will continue the discussion offline.