是否可以通过编程方式控制set-jaxb-validation-event-handler? [英] Is it possible to control set-jaxb-validation-event-handler programmatically?
问题描述
在CXF SOAP Web服务中,我使用以下注释禁用xsd验证:
In a CXF SOAP webservice, I'm using the following annotations to disable the xsd validation:
@EndpointProperties({
@EndpointProperty(key = "set-jaxb-validation-event-handler", value = "false")
})
我希望在运行时控制验证(根据从数据库中检索到的设置的值来启用/禁用该验证)。我的问题是:是否可以在运行时禁用/启用此处理程序?也许是通过编写自定义事件处理程序而不使用此属性?
I would like the validation to controlled at runtime (enable/disable it, based on the value of a setting retrieved from a database). My question is: is it possible to disable/enable this handler at runtime? Maybe by writing a custom event handler and not using this property at all?
谢谢。
编辑:,一个选项是不使用 set-jaxb-validation-handler
禁用验证,而是子类 ValidationEventHandler 。如此处所述,然后我将检查数据库在 handleEvent
中设置并根据其值返回。
an option would be not to disable the validation with set-jaxb-validation-handler
, and rather subclass ValidationEventHandler. As explained here, I would then check the database setting in handleEvent
and return according to its value.
但是这种方法仍有一些缺点:首先,此Web服务配置有注释,我似乎找不到找到应用<$的方法。 c $ c> ValidationEventHandler 带有注释(相同的问题:如何在使用批注时在JAXB unmarshaller上设置自定义ValidationEventHandler )。
But there are still a few downsides with this approach: first, this webservice is configured with annotations, and I can't seem to find a way to apply a ValidationEventHandler
with annotations (same question as: How to set custom ValidationEventHandler on JAXB unmarshaller when using annotations).
其次,这意味着将进行验证即使我不需要它也执行了;这样我就会失去任何性能上的好处。
Secondly, it means that the validation will be performed even if I don't need it; I would then lose any performance benefit.
实际上这并不完全适合我的需求,因此我仍然愿意接受任何建议。
It doesn't in fact exactly suit my needs, so I'm still open to any suggestion.
推荐答案
我终于找到了一个可行的解决方案。
I finally found a working solution.
当我在JBoss EAP上运行CXF时6.0中,我在standalone.xml中的webservices子系统中添加了以下配置:
As I'm running CXF on JBoss EAP 6.0, I added the following configuration to the webservices subsytem in standalone.xml:
<subsystem xmlns="urn:jboss:domain:webservices:1.2">
<!-- ... -->
<endpoint-config name="myconfig">
<property name="set-jaxb-validation-event-handler" value="false"/>
</endpoint-config>
<!-- ...-->
</subsystem>
SEI实现的以下注释:
And the following annotation to the SEI implementation:
@org.jboss.ws.api.annotation.EndpointConfig(configName = "myconfig")
这是相关的Maven依赖项:
This is the related Maven dependency:
<dependency>
<groupId>org.jboss.ws</groupId>
<artifactId>jbossws-api</artifactId>
<version>1.0.1.Final</version>
<scope>provided</scope>
</dependency>
如果要更改属性值,我们仍然需要重新启动服务器,但这要少一些邪恶。
We still need a restart of the server if we want to change the property value, but it's a lesser evil.
这篇关于是否可以通过编程方式控制set-jaxb-validation-event-handler?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!