简体   繁体   中英

Is it possible to control set-jaxb-validation-event-handler programmatically?

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?

Thanks.

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

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.

Yes, it is possible.

MyService service = new MyService();
MyServiceInterface port = service.getMyServicePort();
BindingProvider bindingProvider = (BindingProvider) port;
bindingProvider.getRequestContext().put(
    "set-jaxb-validation-event-handler", Boolean.FALSE);

I finally found a working solution.

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>

And the following annotation to the SEI implementation:

@org.jboss.ws.api.annotation.EndpointConfig(configName = "myconfig")

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.

For the people trying to configure that on the bus level, the following worked for me:

<cxf:bus id="soapClientCxfBus" bus="soapClientCxfBus" >
    <cxf:properties>
        <entry key="set-jaxb-validation-event-handler" value="false" />
    </cxf:properties>
</cxf:bus>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM