【问题标题】:Enable XML validation in CXF SOAP endpoint inside Camel route在 Camel 路由内的 CXF SOAP 端点中启用 XML 验证
【发布时间】:2017-03-02 17:18:53
【问题描述】:

我正在 JBoss Fuse 中开发代码优先的 SOAP 服务。我用输入和输出类定义了一个接口my.endpoint.Interface。 wsdl 生成良好并且服务正在运行。端点由调用我的 Camel 路由的 CXF 处理。

版本:
JBoss Fuse 6.2.1
Apache Camel 2.15.1
阿帕奇 CXF 3.0.4

这是我的包的配置:

<blueprint>

    <cxf:cxfEndpoint id="myEndpoint"
         address="/my/"
         serviceClass="my.endpoint.Interface">
    </cxf:cxfEndpoint>

    <camelContext>

        <route>
            <from uri="cxf:bean:myEndpoint" />
            <to uri="bean:doProcess" />
        </route>

    </camelContext>

</blueprint>

我想使用 XSD 对传入的负载应用 XML 验证。

如何在这种特定环境中配置 CXF?


我没找到在哪里指定XSDCxfEndpointConfigurer接口:

<!-- blueprint file -->
<from uri="cxf:bean:myEndpoint?cxfEndpointConfigurer=configurer" />

// java file
@Override
public void configureServer(Server server) {
    // where do I set XSD in here?
}

在蓝图文件中配置cxfEndpoint 会在运行时引发异常

<cxf:cxfEndpoint id="readingsEndpoint"
                 address="/readings/"
                 serviceClass="my.endpoint.Interface">
    <cxf:schemaLocations>
        <schemaLocation>classpath:my/endpoint/schema1.xsd</schemaLocation>
    </cxf:schemaLocations>
</cxf:cxfEndpoint>

不起作用,引发以下异常:

Unable to start blueprint container for bundle my.bundle/0.0.0.SNAPSHOT
java.lang.NullPointerException
    at org.apache.aries.blueprint.container.RecipeBuilder.getValue(RecipeBuilder.java:355)[23:org.apache.aries.blueprint.core:1.4.4]
    at org.apache.aries.blueprint.container.RecipeBuilder.getValue(RecipeBuilder.java:334)[23:org.apache.aries.blueprint.core:1.4.4]
    at org.apache.aries.blueprint.container.RecipeBuilder.createBeanRecipe(RecipeBuilder.java:278)[23:org.apache.aries.blueprint.core:1.4.4]
    at org.apache.aries.blueprint.container.RecipeBuilder.createRecipe(RecipeBuilder.java:110)[23:org.apache.aries.blueprint.core:1.4.4]
    at org.apache.aries.blueprint.container.RecipeBuilder.createRepository(RecipeBuilder.java:93)[23:org.apache.aries.blueprint.core:1.4.4]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.getRepository(BlueprintContainerImpl.java:481)[23:org.apache.aries.blueprint.core:1.4.4]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:328)[23:org.apache.aries.blueprint.core:1.4.4]
    at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:269)[23:org.apache.aries.blueprint.core:1.4.4]
    at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:294)[23:org.apache.aries.blueprint.core:1.4.4]
    at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:263)[23:org.apache.aries.blueprint.core:1.4.4]
    at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:253)[23:org.apache.aries.blueprint.core:1.4.4]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[17:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[17:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[17:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[17:org.apache.aries.util:1.1.0]
    at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[17:org.apache.aries.util:1.1.0]
    at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1127)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.util.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:696)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.util.EventDispatcher.fireBundleEvent(EventDispatcher.java:484)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4429)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2100)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.Felix.updateBundle(Felix.java:2412)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.felix.framework.BundleImpl.update(BundleImpl.java:994)[org.apache.felix.framework-4.4.1.jar:]
    at org.apache.karaf.shell.dev.watch.BundleWatcher.run(BundleWatcher.java:120)[43:org.apache.karaf.shell.dev:2.4.0.redhat-621084]
    at java.lang.Thread.run(Thread.java:745)[:1.8.0_101]

【问题讨论】:

    标签: apache-camel cxf jbossfuse


    【解决方案1】:

    在我的合同优先设置中,我在蓝图上下文中启用架构验证,如下所示:

    <cxf:cxfEndpoint id="cxfEndpoint" address="http://0.0.0.0:${cxf.port}/${application-path}" serviceClass="my.generated.service.Class" >
        <cxf:properties>
            <entry key="schema-validation-enabled" value="true" />
        </cxf:properties>
    </cxf:cxfEndpoint>
    

    这应该同样适用于代码。

    【讨论】:

      【解决方案2】:

      如果您的 XSD 与 WSDL 是分开的,即不同的文件,您可以使用验证器组件。

      <camelContext>
      
          <route>
              <from uri="cxf:bean:myEndpoint" />
              <to uri="validator:my/endpoint/schema1.xsd" />
              <to uri="bean:doProcess" />
          </route>
      
      </camelContext>
      

      您可能还应该使用 doTry/doCatch 将其括起来,或者将错误处理程序添加到您的路由或上下文中。

      要配置 cxf-endpoint 以将 Exchange 主体设置为实际的 soap:body,您可以如下:

      <cxf:cxfEndpoint id="readingsEndpoint"
                   address="/readings/"
                   serviceClass="my.endpoint.Interface">
          <cxf:properties>
              <entry key="dataFormat" value="PAYLOAD"/>
          </cxf:properties>
      </cxf:cxfEndpoint>
      

      【讨论】:

      • 此时,Exchange 的主体已被解组为 POJO。是否有一些配置告诉 CXF 不要解组并在验证后自己做?
      • 我明白了。是的,您可以将 dataFormat-property 设置为“PAYLOAD”,我会更新我的答案。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-16
      • 1970-01-01
      相关资源
      最近更新 更多