jax-rs - 自定义 ConstraintValidatior 在 JAX-RS 中执行两次
问题描述
在验证提供给的解决方案时,是否有办法在使用 JAX-RS 时将变量放入自定义 ConstraintValidator?我注意到它isValid
被调用了两次,我怀疑这是正确的。
我可以在我尝试过的两个 WLP 中重现问题:
- Java HotSpot(TM) 64 位服务器 VM 上的 WebSphere Application Server 19.0.0.2/wlp-1.0.25.cl190220190222-1311,版本 1.8.0_161-b12 (en_US)
- Java HotSpot(TM) 64 位服务器 VM 版本 1.8.0_161-b12 上的 WebSphere Application Server 19.0.0.5/wlp-1.0.28.cl190520190522-2227 (en_US)
服务器.xml
<featureManager>
<feature>jaxrs-2.1</feature>
<feature>localConnector-1.0</feature>
<feature>transportSecurity-1.0</feature>
<feature>beanValidation-2.0</feature>
<feature>jaxrsClient-2.1</feature>
<feature>cdi-2.0</feature>
</featureManager>
在代码中找不到任何解释双重验证的内容。
堆栈转储显示这发生在同一个线程中。第一个验证堆栈片段:
.....
ValidatorImpl.validateParameters(T, Method, Object[], Class<?>...) line: 224
BeanValidationProvider.validateParameters(T, Method, Object[]) line: 113
GeneratedMethodAccessor593.invoke(Object, Object[]) line: not available
Method.invoke(Object, Object...) line: not available
LibertyJaxRsInvoker.callValidationMethod(String, Object[], Object) line: 371
LibertyJaxRsInvoker.invoke(Exchange, Object, Method, List<Object>) line: 254
LibertyJaxRsInvoker(JAXRSInvoker).invoke(Exchange, Object, Object) line: 205
.....
几毫秒后的第二个验证堆栈片段:
....
ValidatorImpl.validateParameters(T, Method, Object[], Class<?>...) line: 224
ValidationInterceptor.validateMethodInvocation(InvocationContext) line: 66
GeneratedMethodAccessor662.invoke(Object, Object[]) line: not available
Method.invoke(Object, Object...) line: not available
SimpleInterceptorInvocation$SimpleMethodInvocation.invoke(InvocationContext) line: 73
InterceptorMethodHandler.executeAroundInvoke(Object, Method, Method, Object[], InterceptorMethodHandler$CachedInterceptionChain, InterceptionDecorationContext$Stack) line: 84
InterceptorMethodHandler.executeInterception(Object, Method, Method, Object[], InterceptionType, InterceptionDecorationContext$Stack) line: 72
InterceptorMethodHandler.invoke(InterceptionDecorationContext$Stack, Object, Method, Method, Object[]) line: 56
CombinedInterceptorAndDecoratorStackMethodHandler.invoke(InterceptionDecorationContext$Stack, Object, Method, Method, Object[], boolean, boolean) line: 79
CombinedInterceptorAndDecoratorStackMethodHandler.invoke(InterceptionDecorationContext$Stack, Object, Method, Method, Object[]) line: 68
CustomerResource$Proxy$_$$_WeldSubclass.postCustomer(Customer) line: not available
CustomerResource$Proxy$_$$_WeldClientProxy.postCustomer(Customer) line: not available
GeneratedMethodAccessor661.invoke(Object, Object[]) line: not available
Method.invoke(Object, Object...) line: not available
LibertyJaxRsServerFactoryBean.performInvocation(Exchange, Object, Method, Object[]) line: 652
LibertyJaxRsInvoker.performInvocation(Exchange, Object, Method, Object[]) line: 160
LibertyJaxRsInvoker(AbstractInvoker).invoke(Exchange, Object, Method, List<Object>) line: 96
LibertyJaxRsInvoker.invoke(Exchange, Object, Method, List<Object>) line: 273
LibertyJaxRsInvoker(JAXRSInvoker).invoke(Exchange, Object, Object) line: 205
....
验证不应该只调用一次吗?
解决方案
推荐阅读
- sql - 更新后 Wikidata 查询抛出 StackOverflowError
- c# - UWP 可以写入下载文件夹中多种类型的文件,但不能对 SQLite db 文件执行相同操作
- android - 如何将带有降价语法的文本共享到电报?
- python - 在数据框中创建新列
- html - Get_Template_Part 部分未显示 CSS
- python - 有什么方法可以轻松交换字符串中的两个字符?
- android - 活动转换 API 调用意图
- javascript - 使用 Express 将 BigQuery 流式传输到前端
- google-cloud-platform - 气流 trigger_rule=none_failed 不起作用
- c# - 使用 lambda 更改变量值时遇到错误