2012-08-06 75 views
0

我們使用一些org.apache類作爲實現Web服務的WS Security的一部分。ColdFusion/Java - 「未找到構建方法」

variables.paths = arrayNew(1); 
variables.paths[1] = getDirectoryFromPath(getCurrentTemplatePath()) & "lib\wss4j-1.5.8.jar"; 
variables.paths[2] = getDirectoryFromPath(getCurrentTemplatePath()) & "lib\xmlsec-1.4.2.jar"; 
variables.loader = createObject("component","lib.javaloader.JavaLoader").init(loadPaths=variables.paths,loadColdFusionClassPath=true); 
variables.WSConstantsObj = loader.create("org.apache.ws.security.WSConstants"); 
variables.messageClass = loader.create("org.apache.ws.security.message.WSSecUsernameToken"); 
variables.secHeaderClass = loader.create("org.apache.ws.security.message.WSSecHeader"); 

以下代碼:

<cfset var msg = getMessage()> 

生產:

enter image description here

以下代碼:

<cfset var secHeader = getSecHeader()> 

生產:

enter image description here

下面的代碼:

<cfset var env = soapEnv.getDocumentElement()> 

生產:

enter image description here

env.getOwnerDocument() 

產生了巨大的結構(過大,包括在這裏),您可以view here

然而,下面的代碼:

<cfset e = msg.build(env.GetOwnerDocument(),secHeader)> 

引發錯誤:

The build method was not found. 
Either there are no methods with the specified method name and argument types or the build method is overloaded with argument types that ColdFusion cannot decipher reliably. ColdFusion found 0 methods that match the provided arguments. If this is a Java object and you verified that the method exists, use the javacast function to reduce ambiguity. 

然而生成()方法肯定存在,按照在所述第一屏幕截圖中的黃色亮點。

錯誤消息提到「...使用Javacast函數來減少歧義」。如果這是問題,我將如何應用此解決方案?

+0

所有這些紅讓我眼睛流血:( – 2012-08-06 03:41:29

+0

你已經cfdumped除了什麼env.GetOwnerDocument()實際返回的東西。你可以嘗試嗎?如果由於某種原因它返回NULL或意想不到的東西,它肯定會導致問題 – 2012-08-06 03:51:39

+1

等等...你在env.GetOwnerDocument()中使用大寫G嗎? – 2012-08-06 03:56:27

回答

0

這不是「build()」不存在,而是您的簽名不正確。該2個參數用於構建方法是:

env.GetOwnerDocument(),secHeader 

我們知道這secHeader是類

org.apache.ws.security.message.WSSecHeader 

因爲你的cfdump表示之多。

則可能意味着「env.GetOwnerDocument」沒有返回的類的對象

org.w3c.dom.Document 

它可以返回錯誤或一個原始或另一個類。實例化envGetOwnerDocumet()並將其轉儲出來並檢查該類。我認爲這是搞砸方法簽名。無論如何,這是我最好的猜測。

+0

我錯過了其他評論...看起來像Barnyr和傑森D已經爲你覆蓋了這個。對不起:) – 2012-08-06 14:15:55

+0

謝謝馬克。 Jason迴應說org.apache.xerces.dom.DeferredDocumentImpl確實實現了org.w3c.dom.Document。我提供的envGetOwnerDocument()的轉儲在這裏提供:http://www.china-buy.com/tga/index.cfm?viewDump – user460114 2012-08-06 20:38:26

+0

是的,我寫了我的評論後看到了。我不知道它是否正確實施?我認爲最有可能成爲候選人。你能直接實例化一個org.w3c.dom.Document類並使用它嗎?還是必須擁有xerces課程? – 2012-08-07 13:09:38