是否可以仅在Apache CXF 2.5.2中为入站或出站xml启用模式验证? [英] Is it possible to enable schema validation for inbound or outbound xml only in Apache CXF 2.5.2?

查看:102
本文介绍了是否可以仅在Apache CXF 2.5.2中为入站或出站xml启用模式验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Apache CXF 2.5.2创建了一个Web服务端点,但是我在模式验证和MTOM交互方面遇到了一些问题。如果启用了MTOM和模式验证,则必须直接使用base64Binary类型,但是我试图遵循固定的规范,其中MTOM字段也具有 contentType属性。

I have created a web service endpoint using Apache CXF 2.5.2, but I am having some issues with schema validation and MTOM interacting. If I enable MTOM and schema validation I must use the base64Binary type directly, however I am trying to conform to a fixed spec where the MTOM field also has a "contentType" attribute.

<jaxws:properties>
    <entry key="mtom-enabled" value="true"/>
    <entry key="schema-validation-enabled" value="true"/>
</jaxws:properties>

是否可以仅对入站或出站消息启用模式验证?例如:

Is it possible to only enable schema validation for inbound or outbound messages? For example something like:

<entry key="schema-validation-enabled" value="inbound"/>

是否有另一种方法可以做到这一点,例如覆盖出站邮件验证?

Alternatively is there an alternate way of achieving this, such as overriding the outbound message validation?

谢谢。

推荐答案

从Apache CXF 3.0开始,这是可能的。您不能基于入站/出站禁用验证,但是可以有选择地忽略验证错误(因此仍然会影响性能)。

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>

像这样创建 ValidationEventHandlers 并返回 true 。返回 true 通知CXF忽略单个验证错误并继续验证。

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;
    }
}

这篇关于是否可以仅在Apache CXF 2.5.2中为入站或出站xml启用模式验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆