You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/11/26 03:50:20 UTC
[GitHub] weichao666 commented on a change in pull request #1004: [SCB-925]
Springmvc, when have defaultValue, required should be false,
when param not exist, should check isRequired
weichao666 commented on a change in pull request #1004: [SCB-925] Springmvc, when have defaultValue, required should be false, when param not exist, should check isRequired
URL: https://github.com/apache/servicecomb-java-chassis/pull/1004#discussion_r236115451
##########
File path: common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/param/CookieProcessorCreator.java
##########
@@ -35,33 +38,41 @@
public static final String PARAMTYPE = "cookie";
public static class CookieProcessor extends AbstractParamProcessor {
- public CookieProcessor(String paramPath, JavaType targetType, Object defaultValue) {
- super(paramPath, targetType, defaultValue);
+ public CookieProcessor(String paramPath, JavaType targetType, Object defaultValue, boolean required) {
+ super(paramPath, targetType, defaultValue, required);
}
@Override
public Object getValue(HttpServletRequest request) throws Exception {
Cookie[] cookies = request.getCookies();
- if (cookies == null) {
- return null;
+ Object value = null;
+ if (cookies == null || cookies.length == 0) {
+ value = checkRequiredAndDefaultValue(value);
+ return convertValue(value, targetType);
}
- String value = null;
for (Cookie cookie : cookies) {
if (paramPath.equals(cookie.getName())) {
value = cookie.getValue();
- if (value == null) {
- Object defaultValue = getDefaultValue();
- if (defaultValue != null) {
- value = defaultValue.toString();
- }
- }
}
}
-
+ if (value == null) {
+ value = checkRequiredAndDefaultValue(value);
+ }
return convertValue(value, targetType);
}
+ private Object checkRequiredAndDefaultValue(Object value) {
+ if (isRequired()) {
+ throw new InvocationException(Status.BAD_REQUEST, "Parameter is not valid, required is true");
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services