Is it possible to enable schema validation for inbound or outbound xml only in Apache CXF 2.5.2?

杀马特。学长 韩版系。学妹 提交于 2019-12-04 19:20:39

Since Apache CXF 3.0 this is sort of possible. You can't disable the validation on an in/outbound basis, but you can ignore the validation errors selectively (so you're still getting the performance hit).

You configure reader (inbound) & writer (outbound) validation event handlers in the CXF configuration.

<jaxws:properties>
    <!-- Validation of the SOAP Message--> 
    <entry key="schema-validation-enabled" value="true" />

    <entry key="jaxb-reader-validation-event-handler">
        <bean class="com.example.cxf.InboundValidationEventHandler" />
    </entry>

    <entry key="jaxb-writer-validation-event-handler">
        <bean class="com.example.cxf.OutboundValidationEventHandler" />
    </entry>
</jaxws:properties>

Create the ValidationEventHandlers like this and return true. Returning true informs CXF to ignore a single validation error and continue validation.

package com.example.cxf;

import javax.xml.bind.ValidationEvent;
import javax.xml.bind.ValidationEventHandler;

public class InboundValidationEventHandler implements ValidationEventHandler {

    public boolean handleEvent(ValidationEvent event) {
        String message = event.getMessage();
        Throwable t = event.getLinkedException();

        System.out.println("Ignoring Inbound Validation EVENT : " +  message);

        // ignore
        return true;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!