Skip to content
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

Merged
merged 14 commits into from Apr 16, 2018

Conversation

acsukesh
Copy link
Contributor

@acsukesh acsukesh commented Mar 29, 2018

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Make sure there is a JIRA issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a JIRA issue. Your pull request should address just this issue, without pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SCB-XXX] Fixes bug in ApproximateQuantiles, where you replace SCB-XXX with the appropriate JIRA issue.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will be performed on your pull request automatically.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

@coveralls
Copy link

coveralls commented Mar 29, 2018

Coverage Status

Coverage increased (+0.06%) to 87.459% when pulling ad8c7dc on acsukesh:master into ae28a9f on apache:master.

*/
package org.apache.servicecomb.swagger.invocation.extension;

public abstract class AbstractProducerInvokeExtension implements ProducerInvokeExtension {
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Copy link
Contributor

@liubao68 liubao68 left a 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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indention

Copy link
Contributor Author

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 =
Copy link
Contributor

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?

Copy link
Contributor Author

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() {
Copy link
Contributor

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

Copy link
Contributor Author

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,
Copy link
Contributor

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

Copy link
Contributor Author

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);
Copy link
Contributor

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

Copy link
Contributor Author

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;
Copy link
Contributor

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......

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

<parent>
<groupId>org.apache.servicecomb.demo</groupId>
<artifactId>demo-parent</artifactId>
<version>1.0.0-m2-SNAPSHOT</version>
Copy link
Contributor

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

Copy link
Contributor Author

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>
Copy link
Contributor

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

Copy link
Contributor Author

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class seems useless

Copy link
Contributor Author

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>
Copy link
Contributor

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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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());
Copy link
Contributor

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?

Copy link
Contributor Author

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());
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@wujimin
Copy link
Contributor

wujimin commented Apr 12, 2018

need to resolve the problem that consumer can not get validate message.
and then merge this PR.

@@ -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"));
Copy link
Contributor

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}'}]]",
Copy link
Contributor

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.

Copy link
Contributor

@liubao68 liubao68 Apr 16, 2018

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

Copy link
Contributor

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.

@liubao68 liubao68 merged commit 01c377c into apache:master Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants