2

私は、ColdFusion で Braintree の統合に取り組んできました。Braintree は CF を直接サポートしていませんが、Java ライブラリを提供しており、これまでに行ったことはすべてうまく機能しています...今まで. 一部のオブジェクト (特に検索機能) には、CF からアクセスできないメソッドが含まれているようです。これは、「is」や「contains」などの CF 予約語であるためだと思われます。これを回避する方法はありますか?

<cfscript>
gate = createObject( "java", "com.braintreegateway.BraintreeGateway" ).init(env,merchant.getMerchantAccountId(), merchant.getMerchantAccountPublicSecret(),merchant.getMerchantAccountPrivateSecret());
req = createObject( "java","com.braintreegateway.CustomerSearchRequest").id().is("#user.getUserId()#");
customer = gate.customer().search(req);
</cfscript>

スローされたエラー: 無効な CFML コンストラクト ... ColdFusion は次のテキストを見ていました: is

4

3 に答える 3

6

これは、CFコンパイラのバグを表しています。is()CFには、またはのいずれかと呼ばれるメソッドを定義できないという規則はありませんthis()。実際、基本的な状況では、どちらも呼び出すことに問題はありません。このコードは次のことを示しています。

<!--- Junk.cfc --->
<cfcomponent>
    <cffunction name="is">
        <cfreturn true>
    </cffunction>
    <cffunction name="contains">
        <cfreturn true>
    </cffunction>
</cfcomponent>

<!--- test.cfm --->
<cfset o = new Junk()>

<cfoutput>
    #o.is()#<br />
    #o.contains()#<br />
</cfoutput>

これは-予想通り-出力:

true
true

ただし、init()メソッドをJunk.cfcに導入すると、問題が発生します。

<cffunction name="init">
    <cfreturn this>
</cffunction>

次に、それに応じてtest.cfmを調整します。

#o.init().is()#<br />
#o.init().contains()#<br />

これにより、コンパイラエラーが発生します。

4行目の19列目に無効なCFMLコンストラクトが見つかりました。

ColdFusionは次のテキストを見ていました。

[...]

coldfusion.compiler.ParseException:4行目の19列目に無効なCFMLコンストラクトが見つかりました。

at coldfusion.compiler.cfml40.generateParseException(cfml40.java:12135)

[等]

o.init().is()うまくいけば大丈夫ではないという正当な理由はありませんo.is()

バグを報告することをお勧めします。投票します。

回避策として、メソッドチェーンではなく、中間値を使用する場合は問題ありません。

于 2012-07-06T07:48:58.450 に答える
1

おそらく、Java Reflection APIを使用して、オブジェクトでis()メソッドを呼び出すことができます。

また、アドビに電話をかけて、アドビが修正するか、独自の回避策を提供するかを確認します。'is'という独自のメソッドまたは変数の定義を禁止することは理解できますが、ここでそれを呼び出そうとしても安全です。

于 2012-07-06T04:55:51.153 に答える
0

これがこの問題の解決策です。少なくとも、起動して実行するための修正。

このコードを試してください。

<cfscript>
    //Get our credentials here, this is a custom private function I have, so your mileage may vary
    credentials = getCredentials();

    //Supply the credentials for the gateway    
    gateway = createObject("java", "com.braintreegateway.BraintreeGateway" ).init(credentials.type, credentials.merchantId, credentials.publicKey, credentials.privateKey);

    //Setup the customer search object  
    customerSearch = createObject("java", "com.braintreegateway.CustomerSearchRequest").id();

    //can't chain the methods here for the contains, since it's a reserved word in cf.  lame.
    customerSearchRequest = customerSearch.contains(arguments.customerId);

    //Build the result here
    result = gateway.customer().search(customerSearchRequest);
</cfscript>
于 2013-11-05T22:31:04.950 に答える