[ 
https://issues.apache.org/jira/browse/SCB-925?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16698451#comment-16698451
 ] 

ASF GitHub Bot commented on SCB-925:
------------------------------------

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:
[email protected]


> Springmvc, when have defaultValue, required should be false
> -----------------------------------------------------------
>
>                 Key: SCB-925
>                 URL: https://issues.apache.org/jira/browse/SCB-925
>             Project: Apache ServiceComb
>          Issue Type: Bug
>          Components: Java-Chassis
>            Reporter: WeiChao
>            Assignee: WeiChao
>            Priority: Major
>             Fix For: java-chassis-1.1.0
>
>




--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to