Ever had one of those days where you have tried to...
# cfml-general
m
Ever had one of those days where you have tried to do one thing, all day, and failed so much that you don't even know what you have tried and failed with any more? (and I know it is simple) I am trying to use the Amazon Pay Java jar, instantiating the object in CF, and I can't even find the methods - even though I can see them right on the screen in the cfdump! Doesn't help much that the only java I have ever used was in the core of Java either.. Message: com.amazon.pay.api.WebstoreClient.<init>() Type: java.lang.NoSuchMethodException Detail: An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. If the class has a constructor that accepts an argument, you must call the constructor explicitly using the init(args) method. Error : com.amazon.pay.api.WebstoreClient or AmazonPayClient <cfset wsClient=createObject('java', 'com.amazon.pay.api.WebstoreClient')> <cfset butSig=wsClient.generateButtonSignature(initVars)> <cfset apClient=createObject('java', 'com.amazon.pay.api.AmazonPayClient')> <cfset butSig=apClient.generateButtonSignature(initVars)>
😂 1
w
did you try explicitly adding a call to .init() ? createObject does NOT automatically call init(). what happens if you change to:
Copy code
<cfset wsClient=createObject('java', 'com.amazon.pay.api.WebstoreClient').init()>
obviously i don't know if there are arguments you must pass to init, but their docs should say i imagine
m
Yes, tried it - Class not found: com.amazon.pay.api.WebstoreClient .init()
This should freakin be simple! even tried this - with this result.. Detail: Either there are no methods with the specified method name and argument types or the setRegion 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. Message: The setRegion method was not found.
<cfset oPayConfiguration = createObject("java", "com.amazon.pay.api.PayConfiguration")>
<cftry>
<cfset oPayConfiguration.setRegion("your region here")>
<cfset oPayConfiguration.setPrivateKey("your private key here")>
<cfset oPayConfiguration.setEnvironmenet("environment sandbox here")>
<cfcatch type="any">
<cfdump var="#cfcatch#" abort="true">
</cfcatch>
</cftry>
<cfset oAmazonPayClient = createObject("java", "com.amazon.pay.api.AmazonPayClient")>
<cfset oAmazonPayClient.init(oPayConfiguration)>
<cfset payload = ""{\"storeId\":\"amzn1.application-oa2-client.xxxxx\",\"webCheckoutDetails\":{\"checkoutReviewReturnUrl\":\"<https://example.com/review.html>\"}}"">
<cfset signature = oAmazonPayClient.generateButtonSignature(payload)
w
you have a link to the docs?
w
sorry to sound like a broken record, but the few references i've found searching led me to examples that include the init like so:
Copy code
<cfset oPayConfiguration = createObject("java", "com.amazon.pay.api.PayConfiguration").init()>
did you try with PayConfiguration like that?
not the same issue you're having, but here's one reference i found: https://stackoverflow.com/questions/66037089/bouncycastleprovider-not-found-by-jar-on-lucee
anyway, i'm not helping, hopefully someone with more java knowledge will chime in
m
I have, when I add init(), I get the error. If I leave Init off, I can cfdump. When I can CFdump, and see the methods, I can't access them.
w
if you instantiate it (and leave off init) are you able to call any of the getters without error?
m
Copy code
<cfset oPayConfiguration.setRegion("US")> gets me - The setRegion method was not found.
well, damn, the getters work - though they are blank (obviously)
w
which cf/java version?
m
2016 and 1.8.0_112
w
does setMaxRetries(1) also error?
setRegion appears to want a very specific data type, i wonder if simply passing a string like "US" causes it to try and find an overloaded method which takes a string but it can't find it and yields that error
m
nope, an I see where you are going... I need to instatiate this - com.amazon.pay.api.types.Region to setRegion('US')
w
right
so max retries was ok?
m
ALL DAMN DAY!
w
takes an unambiguouus int as an argument
m
Yes, works just fine and getRegion() gives it back..
TY, you have an Amazon Wish list?
w
yes, the only thing on it though is my heartfelt wish to never have to implement Amazon Pay
m
LOL. I think now it will be WAY easier.. I might actually get it done is this pans out..
w
remember, you are the only thing standing between amazon and world domination
good luck
m
well, I only code, I don't write the rqmts..
It is days like today that I miss popping over a cubicle wall and saying, "hey, got a minute?"
w
LEAVE ME ALONE CAN'T YOU SEE I'M BUSY
m
You can't be, I hear they block FB at work now
w
asdpfoidsfu tunnelling vpn adfswoeiueo