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
[SCB-292] chassis support standard parameter validation #627
Conversation
*/ | ||
package org.apache.servicecomb.swagger.invocation.extension; | ||
|
||
public abstract class AbstractProducerInvokeExtension implements ProducerInvokeExtension { |
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 we always define empty abstract class?
i think it's useless.
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.
Agreed. Java now supports defaults for interface, and no need empty abstract class any more
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.
Fixed
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.
Can you provide some integration tests to show the user how to use this feature?
@@ -37,6 +37,14 @@ | |||
<artifactId>swagger-generator-jaxrs</artifactId> | |||
<scope>test</scope> | |||
</dependency> | |||
<dependency> |
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.
Indention
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.
fixed
@@ -134,6 +137,11 @@ public void testGetOrCreateProducer() throws Exception { | |||
|
|||
SwaggerProducerOperation producerOperation = operationMeta.getExtData(Const.PRODUCER_OPERATION); | |||
|
|||
List<ProducerInvokeExtension> producerInvokeExtenstionList = |
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 need to set this manually?
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.
Fixed
@@ -22,5 +22,9 @@ | |||
public interface ExceptionToResponseConverter<T extends Throwable> { | |||
Class<T> getExceptionClass(); | |||
|
|||
default int getOrder() { |
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.
interface definition default to 100,
so strange
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.
Fixed
|
||
public int getOrder(); | ||
|
||
<T> void beforeMethodInvoke(SwaggerInvocation invocation, SwaggerProducerOperation producerOperation, |
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.
add comments
args in invocation is contract args, this is not always equals to producer method args
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.
Fixed
Default.class); | ||
if (violations.size() > 0) { | ||
LOGGER.warn("Parameter validation failed : " + violations.toString()); | ||
throw new ConstraintViolationException(violations.toString(), violations); |
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.
so strange that first and second parameter have the same information
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.
Fixed.
|
||
@Override | ||
public int getOrder() { | ||
return 100; |
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.
default to 100 is not enough.
order rule is: smaller order have high priority
so what will happened in ExceptionToResponseConverters when developers custom their own ConstraintViolationException converter?
had remind you this yesterday......
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.
When user custom exception with higher order , it will override the default behavior, user can customize the error codes, message ..etc.The same is tested.
@@ -1,5 +1,5 @@ | |||
/* | |||
* Licensed to the Apache Software Foundation (ASF) under one or more | |||
* Licensed to the Apache Software Foundation (ASF) under one or more |
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.
Formatting
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.
Fixed
demo/demo-validator/pom.xml
Outdated
<parent> | ||
<groupId>org.apache.servicecomb.demo</groupId> | ||
<artifactId>demo-parent</artifactId> | ||
<version>1.0.0-m2-SNAPSHOT</version> |
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.
Formatting. Suggest to show blanks in your IDE to check if file is correctly indented
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.
fixed
</dependencies> | ||
|
||
<properties> | ||
<demo.main>org.apache.servicecomb.demo.jaxrs.client.JaxrsClient</demo.main> |
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.
Class name should be ValidatorClient
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.
fixed
import org.apache.servicecomb.demo.TestMgr; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
public class CodeFirstRestTemplateValidator extends CodeFirstRestTemplate { |
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.
This class seems useless
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.
fixed
</dependencies> | ||
|
||
<properties> | ||
<demo.main>org.apache.servicecomb.demo.jaxrs.server.JaxrsServer</demo.main> |
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.
wrong class name
params.put("a", "5"); | ||
params.put("b", "3"); | ||
boolean isExcep = false; | ||
try { |
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 better to validate the returned status code also.
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.
fixed
template.postForObject(cseUrlPrefix + "add", params, Integer.class); | ||
} catch (InvocationException e) { | ||
isExcep = true; | ||
TestMgr.check(490, e.getStatus().getStatusCode()); |
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.
can we got the correct validate message?
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.
Fixed
Student.class); | ||
} catch (InvocationException e) { | ||
isExcep = true; | ||
TestMgr.check(490, e.getStatus().getStatusCode()); |
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.
490 error code exposes that consumer logic got some bad encapsulation. Maybe we need to find out the cause or leave a comment here and submit an improvement issue to fix 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.
Fixed
need to resolve the problem that consumer can not get validate message. |
@@ -179,6 +180,8 @@ private static void testValidatorAddFail(RestTemplate template, String cseUrlPre | |||
} catch (InvocationException e) { | |||
isExcep = true; | |||
TestMgr.check(400, e.getStatus().getStatusCode()); | |||
TestMgr.check(Status.BAD_REQUEST, e.getReasonPhrase()); | |||
TestMgr.check(true, e.getErrorData().toString().contains("ConstraintViolationImpl")); |
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 use contains logic, not verity the full message
TestMgr.check(400, e.getStatus().getStatusCode()); | ||
TestMgr.check(Status.BAD_REQUEST, e.getReasonPhrase()); | ||
TestMgr.check( | ||
"CommonExceptionData [message=[ConstraintViolationImpl{interpolatedMessage='must be greater than or equal to 20', propertyPath=add.arg1, rootBeanClass=class org.apache.servicecomb.demo.jaxrs.server.Validator, messageTemplate='{javax.validation.constraints.Min.message}'}]]", |
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.
so strange that use exception.toString to be the message.
infact only interpolatedMessage/propertyPath/rootBeanClass is useful
we can use json to express this.
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'll submit a new PR for this minor problem and merge this one. https://issues.apache.org/jira/browse/SCB-496
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 about test case......
root cause is that developer use exception.toString to be response information.
Follow this checklist to help us incorporate your contribution quickly and easily:
[SCB-XXX] Fixes bug in ApproximateQuantiles
, where you replaceSCB-XXX
with the appropriate JIRA issue.mvn clean install
to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.