2017-03-02 67 views
0

我正在JBoss Fuse內開發一個代碼優先的SOAP服務。我用輸入和輸出類定義了一個接口my.endpoint.Interface。 wsdl生成良好,服務正在運行。端點由調用我的駱駝路由的CXF處理。在駱駝路由中的CXF SOAP端點中啓用XML驗證

版本:
的JBoss 6.2.1保險絲
Apache的駱駝2.15.1
的Apache 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?


我沒有找出指定XSD CxfEndpointConfigurer接口:

<!-- 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] 

回答

0

如果您的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端點到Exchange身體設置爲實際的SOAP體:你可以到以下幾點:

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

此時,交易所的主體已經被解散到POJO。是否有一些配置可以告訴CXF在驗證之後不要解組並自行完成? –

+0

我明白了。是的,你可以將dataFormat屬性設置爲「PAYLOAD」,我會更新我的答案。 – noMad17

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> 

這應該也適用於代碼第一。