2

I'm using this web-push java library: https://github.com/MartijnDwars/web-push

Gradle build task to compile as a jar file to be use in Coldfusion.

jar {
  baseName = 'web-push'
  version = '3.0.0'
  doFirst {
      from {
          configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
      }
  }
  exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA' 
}

So i have a functioning jar file with all the dependencies. However, when I go to send a notification I get this error.

java.lang.NoSuchMethodError: org.bouncycastle.math.ec.ECPoint.getEncoded(Z)[B

which points to the savePublicKey method in Utils.java

public static byte[] savePublicKey(ECPublicKey publicKey) {
    return publicKey.getQ().getEncoded(false);
}

Its my understanding that getEncoded is a build int java Key method. So I'm not sure if I'm getting this error because publicKey.getQ isn't a valid key or because I need to import/include a java key class.

Thanks in advance for any tips/help.

CFML Code

<cfscript>

variables.server.pubKey = 'XXXXXXXXXXX';
variables.server.priKey = 'XXXXXX';

variables.subscription = {
      "endpoint": "https://fcm.googleapis.com/fcm/send/eEmctHWg8-k:APA91bF-kzQfUv1Y1T9C3sJ3eN5zDDtyRhcDU0MyVS1XWgPIko2X7VpjeymhqDAzb-4nbg4x2SmObHk1JSITG4lmsx-40E_uNi4a_TnFavs4ICMzbeHQJzKgnuTAcQxSXDxJSBNFrzY_"
    , "keys": {
          "p256dh": "BMIWtizmL6BgkofOn6DmPq/AaDwBvh894GBHvPpH2xgg9/uNoNsvKWAfEXVxLgpaUeytb8tGryguvIAmYTDO0W8="
        , "auth": "zDH8z4GPHvW2zFXG0bf2pQ=="
    } 
}
variables.json = serializeJSON(variables.subscription);

variables.java.gson = createObject('java', 'com.google.gson.Gson', expandPath('/fw/jar/gson-2.8.0.jar'));

variables.lib               = expandPath('/fw/jar/web-push-3.0.0.jar');
variables.java.subscription = createObject('java', 'nl.martijndwars.webpush.Subscription', variables.lib);
variables.java.notification = createObject('java', 'nl.martijndwars.webpush.Notification', variables.lib);
variables.java.pushservice  = createObject('java', 'nl.martijndwars.webpush.PushService', variables.lib);

variables.java.subscription = variables.java.gson.fromJson(variables.json, variables.java.subscription.class);

variables.java.notification.init(variables.java.subscription, 'Hello, World!');

variables.java.pushservice.init(variables.server.pubKey, variables.server.priKey, "mailto:craig@thinkerventures.com");

variables.resonse = variables.java.pushservice.send(variables.java.notification);

</cfscript>

CFML Stack Trace

Full Trace: org.bouncycastle.math.ec.ECPoint.getEncoded(Z)[B 
at nl.martijndwars.webpush.Utils.savePublicKey(Utils.java:36):36 
at nl.martijndwars.webpush.HttpEce.lengthPrefix(HttpEce.java:124):124 
at nl.martijndwars.webpush.HttpEce.deriveDH(HttpEce.java:115):115 
at nl.martijndwars.webpush.HttpEce.deriveKey(HttpEce.java:55):55 
at nl.martijndwars.webpush.HttpEce.encrypt(HttpEce.java:172):172 
at nl.martijndwars.webpush.PushService.encrypt(PushService.java:92):92 
at nl.martijndwars.webpush.PushService.sendAsync(PushService.java:128):128 
at nl.martijndwars.webpush.PushService.send(PushService.java:113):113 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method):-2 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62):62 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43):43 
at java.lang.reflect.Method.invoke(Method.java:497):497 
at lucee.runtime.reflection.pairs.MethodInstance.invoke(MethodInstance.java:55):55 
at lucee.runtime.reflection.Reflector.callMethod(Reflector.java:857):857 
at lucee.runtime.reflection.Reflector.callMethod(Reflector.java:842):842 
at lucee.runtime.java.JavaObject.call(JavaObject.java:228):228 
at lucee.runtime.java.JavaObject.call(JavaObject.java:259):259 
at lucee.runtime.util.VariableUtilImpl.callFunctionWithoutNamedValues(VariableUtilImpl.java:743):743 
at lucee.runtime.PageContextImpl.getFunction(PageContextImpl.java:1593):1593 
at script.dev.push_cfm$cf.call(D:\nonprofitthrive_com\script\dev\push.cfm:38):38 
at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:954):954 
at lucee.runtime.PageContextImpl.doInclude(PageContextImpl.java:858):858 
at fw.application_fw_cfc$cf.udfCall1(D:\nonprofitthrive_com\fw\application_fw.cfc:279):279 
at fw.application_fw_cfc$cf.udfCall(D:\nonprofitthrive_com\fw\application_fw.cfc):-1 
at lucee.runtime.type.UDFImpl.implementation(UDFImpl.java:111):111 
at lucee.runtime.type.UDFImpl._call(UDFImpl.java:328):328 
at lucee.runtime.type.UDFImpl.call(UDFImpl.java:229):229 
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:642):642 
at lucee.runtime.ComponentImpl._call(ComponentImpl.java:524):524 
at lucee.runtime.ComponentImpl.call(ComponentImpl.java:1761):1761 
at lucee.runtime.listener.ModernAppListener.call(ModernAppListener.java:414):414 
at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:223):223 
at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:37):37 
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2265):2265 
at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2228):2228 
at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:456):456 
at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:47):47 
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729):729 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291):291 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206):206 
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52):52 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239):239 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206):206 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217):217 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106):106 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502):502 
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142):142 
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79):79 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88):88 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518):518 
at org.apache.coyote.ajp.AbstractAjpProcessor.process(AbstractAjpProcessor.java:844):844 
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673):673 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500):1500 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456):1456 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142):1142 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617):617 
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61):61 
at java.lang.Thread.run(Thread.java:745):745 
Craig Harshbarger
  • 1,863
  • 3
  • 18
  • 29
  • What is the full stack trace message, specifically the "caused by ..." section (if any)? Also, how are you loading the jar, via `this.javaSettings`? Could be caused by a version conflict between one of the dependencies and the built in libraries (of which bouncy castle is one). – Leigh May 12 '17 at 17:38
  • Added a stack trace but not sure if that will help since the jar is being called by coldfusion. – Craig Harshbarger May 12 '17 at 17:39
  • (Edit) CF will still show the trace in the error message (or cfcatch). That does not look like the correct trace (says hibernate?). Can you post the one for the java.lang.NoSuchMethodError: error? Also, how are you loading the jar in CF? – Leigh May 12 '17 at 17:41
  • whoops, wrong trace. Updated with the correct one. Also added my cfml – Craig Harshbarger May 12 '17 at 17:46
  • Just sample dev keys, will not be used in any real word/production envs. But I'll xxx them out. – Craig Harshbarger May 12 '17 at 17:48
  • Okay, just making sure :) Try and create instance of that class *without* the dynamic path and dump it. Do you see that method name? ie `o = createObject("java", "org.bouncycastle.math.ec.ECPoint"); writeDump(o);` (Edit) Oops, just noticed you are Lucee. I am on ACF at the moment. – Leigh May 12 '17 at 17:54
  • 1
    Yep `getEncoded` method is there. But it doesn't accept any parameters. I removed the false parameter from the `getEncoded` call and remade the jar and now it makes it past that function. Only to error on something further down the line... Thinking the library is using a different version of bouncyhouse maybe? – Craig Harshbarger May 12 '17 at 18:06
  • 1
    (Edit) That confirms Lucee is bundled with its own version of Bouncy Castle. Yes, from the error it seems like maybe that version is getting loaded instead of the newer one required by the library. Does the `variables.lib` path include the BC jar? – Leigh May 12 '17 at 18:12
  • The `web-push-3.0.0.jar` includes all its dependencies including BC. So lucee has its own and is using that instead of the classes in the web-push jar? – Craig Harshbarger May 12 '17 at 18:24
  • Luce does have its own BC. `lucee/lib/bcprov-jdk14.jar` – Craig Harshbarger May 12 '17 at 18:26
  • Sounds like a dynamic class loader issue then. Not sure why it is loading the old version, when the new version is included within the jar, but [class loaders are very picky](http://stackoverflow.com/questions/15506237/getting-coldfusion-called-web-service-to-work-with-javaloader-loaded-objects/15592095#15592095). I am more familiar with the JavaLoader/ACF's dynamic class loading. Probably unrelated to the error, but I would suggest using the same jar path for all of the createObject calls, to avoid other potential issues/conflicts. – Leigh May 12 '17 at 18:34
  • Okay thanks for your help. What do you mean by use the same jar path? the gson jar and the web-push jar are both necessary. – Craig Harshbarger May 12 '17 at 18:40
  • Some of the createObject calls are using different jar paths, ie `expandPath('/fw/jar/gson-2.8.0.jar')` versus `variables.lib`. Put all of the paths in a single variable, then use that one variable in all of the createObject calls. The different paths *might* be what is causing the problem. I remember running into something like that with Railo once. – Leigh May 12 '17 at 18:44
  • How do you do that? didn't know you could pass multiple paths into `createobject`. (edit) tried just passing in an array of paths and that seems to work. – Craig Harshbarger May 12 '17 at 18:46
  • IIRC just pass in a list. If I am reading the [Lucee docs](http://docs.lucee.org/reference/functions/createobject.html) right, you can specify a list delimiter as the fourth param, if needed. (Though apparently new Object() is preferred over createObject). – Leigh May 12 '17 at 18:50
  • I am using lucee 4 (lucee 5 has a bug in it that breaks our existing and valid code). – Craig Harshbarger May 12 '17 at 18:52
  • Did you try multiple paths? I would guess the default separator is either a comma or semi-colon. Failing that, you could always try bundling everything in a single jar, just to verify. Not ideal, but would work around any single file limitations. – Leigh May 12 '17 at 18:58
  • Yes tried multiple paths, no change. You mean bundling the gson in with the web-push jar? – Craig Harshbarger May 12 '17 at 19:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144096/discussion-between-leigh-and-craig-harshbarger). – Leigh May 12 '17 at 19:13
  • Did you find an answer? – Rama Adaikkalam Apr 18 '18 at 20:36
  • @Rama I think I ended up bundling gson in with the web-push jar. Can't really remember though, and I ended up abandoning this project for other reasons. So I never really finished it. – Craig Harshbarger Apr 19 '18 at 13:34
  • 1
    I somehow figured it. Thanks for the reply. My solution was I was using another dependency from bouncycastle where they had diff groupId bouncycastle vs org.bouncycastle, but using the same artifactId. That took my time to identify. – Rama Adaikkalam Apr 19 '18 at 20:46

0 Answers0