Skip to content

Commit

Permalink
[#2034] move create validator to init to use injected spring bean
Browse files Browse the repository at this point in the history
  • Loading branch information
wujimin committed Jul 6, 2020
1 parent f51e0e4 commit 15396af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
Expand Up @@ -143,8 +143,8 @@ private Factory buildFactory(Class<? extends Filter> filterClass, FilterMeta met
private Filter createFilter(Class<? extends Filter> filterClass) {
try {
Filter filter = filterClass.newInstance();
filter.init(engine);
injectSpringBean(filter);
filter.init(engine);
return filter;
} catch (Exception e) {
throw new IllegalStateException("failed to create filter.", e);
Expand Down
Expand Up @@ -30,6 +30,7 @@
import javax.validation.groups.Default;

import org.apache.servicecomb.core.Invocation;
import org.apache.servicecomb.core.SCBEngine;
import org.apache.servicecomb.core.filter.Filter;
import org.apache.servicecomb.core.filter.FilterMeta;
import org.apache.servicecomb.core.filter.FilterNode;
Expand All @@ -51,9 +52,10 @@ public class ParameterValidatorFilter implements Filter {

private static final String ENABLE_EL = "servicecomb.filters.validation.useResourceBundleMessageInterpolator";

private final ExecutableValidator validator;
private ExecutableValidator validator;

public ParameterValidatorFilter() {
@Override
public void init(SCBEngine engine) {
validator = createValidatorFactory()
.getValidator().forExecutables();
}
Expand All @@ -66,7 +68,7 @@ protected ValidatorFactory createValidatorFactory() {
.buildValidatorFactory();
}

private AbstractMessageInterpolator messageInterpolator() {
protected AbstractMessageInterpolator messageInterpolator() {
if (useResourceBundleMessageInterpolator()) {
return new ResourceBundleMessageInterpolator();
}
Expand Down
Expand Up @@ -42,6 +42,7 @@
import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -93,6 +94,11 @@ public void op(@NotNull(message = "not null") String query, @Valid Model model)
@Mocked
SwaggerProducerOperation operation;

@BeforeClass
public static void beforeClass() throws Exception {
filter.init(null);
}

@Before
public void setUp() throws Exception {
new Expectations() {
Expand Down

0 comments on commit 15396af

Please sign in to comment.