-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix(http): fix java.lang.IllegalStateException: STREAMED #5367
fix(http): fix java.lang.IllegalStateException: STREAMED #5367
Conversation
1. Optimized Util getAddress method 2. add `GetBrokerageServletTest` test case 3. add `GetRewardServletTest` test case
@@ -499,6 +500,12 @@ public static byte[] getAddress(HttpServletRequest request) throws Exception { | |||
byte[] address = null; | |||
String addressParam = "address"; | |||
String addressStr = request.getParameter(addressParam); | |||
|
|||
if (APPLICATION_FORM_URLENCODED.equals(request.getContentType()) |
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.
It's not clear. Is this the only scene?
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.
It is recommended to make a clear distinction between GET, POST (application/json, application/x-www-form-urlencoded)
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.
There is no need to add other types of content types, and these types are supported even if other types of judgments are not explicitly added.
With the addition of parameter checks, if the uploaded parameter is an illegal parameter, an error will be returned. request:
expected Result:
Otherwise, normal parameter requests for |
1. add parameter checking methods
if (HttpMethod.GET.toString().toUpperCase() .equalsIgnoreCase(method)) { | ||
value = request.getParameter(key); | ||
if (StringUtils.isBlank(value)) { | ||
throw new IllegalArgumentException("Invalid request parameter"); |
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.
Need to keep compatibility
} | ||
if (keyValue[0].equals("address")) { | ||
return keyValue[1]; | ||
} |
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.
Need to keep compatibility
@forfreeday Is there any progress on this PR? |
@halibobo1205 |
return jsonObject.getString(key); | ||
} | ||
} else if (APPLICATION_FORM_URLENCODED.toLowerCase().contains(contentType)) { | ||
return getParam(getRequestValue(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.
Why not just use request.getParameter(addressParam)
?
if (keyValue.length == 1) { | ||
continue; | ||
} | ||
if (keyValue[0].equals("address")) { |
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.
BTW, Why is it limited to address
? getParam
seems to be a generic method.
@halibobo1205 |
@forfreeday Why does |
@halibobo1205 |
@forfreeday I really don't get it. @tomatoishealthy Please take a look. |
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.
For historical reasons, this logic does not have a unit test.
Better add comprehensive unit tests for all situations after changing the whole logic of the param extraction to make sure all the new logic works well, such as: good requests for both form&json
Codecov Report
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. @@ Coverage Diff @@
## develop #5367 +/- ##
==========================================
Coverage 60.95% 60.96%
- Complexity 9247 9253 +6
==========================================
Files 840 840
Lines 50064 50081 +17
Branches 5578 5584 +6
==========================================
+ Hits 30517 30530 +13
Misses 17146 17146
- Partials 2401 2405 +4
... and 8 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
String content = (String) result.get("Error"); | ||
Assert.assertNull(content); | ||
} catch (UnsupportedEncodingException e) { | ||
e.printStackTrace(); |
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.
Assert.fail(); is a good choice
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.
I'm not expecting an exception to be thrown; the end result of this use case is a normal return of the
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.
Does it mean that even if an UnsupportedEncodingException is thrown, it's still normal?
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.
Using a statement when pointing out a problem is a good way to respond; if you use a rhetorical question, I can't be sure of your intentions and it doesn't help to accurately describe the problem.
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.
The point of this use case is not to test for the UnsupportedEncodingException, but rather to determine the value of null.
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.
Assert.fail()
is added where it is not possible to reach in the expectation, once it is reached, indicates that the test has failed, the result is not as expected.
String content = (String) result.get("Error"); | ||
Assert.assertNull(content); | ||
} catch (UnsupportedEncodingException e) { | ||
e.printStackTrace(); |
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.
Please test all cases of checkGetParam.
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.
checkGetParam
is business-independent and does not need to be validated.
addressStr = jsonObject.getString(addressParam); | ||
} | ||
} | ||
String addressStr = checkGetParam(request, addressParam); |
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.
getParam
or checkAndGetParam
?
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.
Use checkGetParam
as the method name, because there are some checking judgments
} | ||
|
||
@After | ||
public void deleteDatabase() { |
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.
BaseTest
has already done the release.
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, it can be dispensed with here
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.
LGTM
What does this PR do?
GetBrokerageServletTest
test caseGetRewardServletTest
test caseWhy are these changes required?
Fix incorrect interface returns, add test cases
This PR has been tested by:
Follow up
Extra details