カスタム検証ハンドラーの意味がわかりません。
検証エラー処理を変更する場合は、 javax.xml.bind.ValidationEventHandlerを実装するクラスを作成できます。
たとえば、このアプローチを使用して、最初に発生したエラーで JAXB が例外をスローしないようにしました。私のカスタム イベント ハンドラーは、致命的ではないすべての検証エラーを収集し、受信メッセージ全体を検証した後に適切な例外をスローしました。
ValidationEventHandler の使用例
カスタム検証イベント ハンドラーを使用するには、jaxb-validation-event-handler プロパティを追加する必要があります。
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
<jaxws:endpoint id="HTTPEndpoint"
implementor="org.dpytel.servicemix.cxf.wsdlfirst.PersonImpl" address="/PersonService"
wsdlLocation="wsdl/person.wsdl" endpointName="e:soap" serviceName="s:PersonService"
xmlns:e="http://servicemix.apache.org/samples/wsdl-first" xmlns:s="http://servicemix.apache.org/samples/wsdl-first">
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
<entry key="jaxb-validation-event-handler">
<bean class="org.dpytel.servicemix.cxf.wsdlfirst.MyCustomHandler"></bean>
</entry>
</jaxws:properties>
</jaxws:endpoint>
</beans>
Camel CXF エンドポイント構成:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://camel.apache.org/schema/cxf
http://camel.apache.org/schema/cxf/camel-cxf.xsd">
<cxf:cxfEndpoint id="personEndpoint" address="/person"
serviceClass="org.apache.servicemix.samples.wsdl_first.Person"
wsdlURL="wsdl/person.wsdl">
<cxf:properties>
<entry key="schema-validation-enabled" value="true" />
<entry key="jaxb-validation-event-handler">
<bean class="org.dpytel.servicemix.camel.MyCustomHandler" />
</entry>
</cxf:properties>
</cxf:cxfEndpoint>
</beans>
検証エラーを無効にし、検証メッセージのみをログに記録するハンドラーの例:
import java.util.logging.Logger;
import javax.xml.bind.ValidationEvent;
import javax.xml.bind.ValidationEventHandler;
public class MyCustomHandler implements ValidationEventHandler {
private Logger logger = Logger.getLogger(this.getClass().getCanonicalName());
public boolean handleEvent(ValidationEvent event) {
logger.severe("Error: " + event.getMessage());
return true;
}
}
一部の検証エラーにより、CXF がハンドラーの呼び出しをスキップすることに注意してください ( DataReaderImpl.WSUIDValidationHandler.handleEvent(...)の詳細を参照してください)。エラー メッセージに「:Id」文字列が含まれている場合、または次のエラーのいずれかである場合、ハンドラーはスキップされます。
- cvc-type.3.1.1
- cvc-type.3.2.2
- cvc-complex-type.3.1.1
- cvc-complex-type.3.2.2
(率直に言って、これは CXF の汚いハックのように思えます。問題がある場合は、CXF チームにバグを報告します)。
さらにエラー処理のカスタマイズが必要な場合は、おそらく独自のInterceptorを作成することを検討する必要があります。おそらく、このような検証を実行するのに最適なフェーズは、(PRE/USER/POST)_LOGICAL のいずれかです。