-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Class cast exception in Notification Class #108
Comments
I face a similar issue
|
@martijndwars can you help on this? To make sure whether it's on my side or lib's side, I've created an example Node script that runs web-push Node implementation. I applied the same keys, credentials etc. that I use in Java. In Node everything runs just fine. In Java, I'm getting this error:
Here's a (simplified) Java code that I'm using:
|
I am also facing the same issue. @matewka did you find any solution? Thanks |
@debabratapatra unfortunately not. I've abandoned this feature temporarily in my project. |
Hi @debabratapatra @matewka I have solved this issue. Apologies for long and delayed answer but this will solve your problem. So the problem is because of 2 different class loaders. The class cast exception that you see is because one class is loaded probably from a local jar, while the other is loaded from somewhere in your dependency tree. To avoid this problem, what I had to do was write a lot of Java Reflection. Do the following:
Here's a ReflectionUtil class that I wrote, you can reuse the same:
Now, rewrite the webpush-java/src/main/java/nl/martijndwars/webpush/Utils.java class as follows:
Do similar changes to all other classes wherever required ( or whichever place you get ClassNotFound exception). Remember, do not add dependency in your pom for bouncycastle, otherwise you'll again run into this. The JVM will get confused between which class to load. |
@iyashsoni Thank you for responding and sharing your solution. I had to use older version of webpush to make it working. Here is my solution.
|
I am using library version 5.0.2
I get the following error
org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey cannot be cast to org.bouncycastle.jce.interfaces.ECPublicKey
when I try and instantiate the Notification class at runtime.In my setup, as we are bundling the entire server in a war file, due to re-bundling, signature breaks for bouncycastle libs, So I'm using a custom class loader to accommodate Subscription class cryptographic operations.
But in the Notification Class, there is a cast as below:
This is from org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey to org.bouncycastle.jce.interfaces.ECPublicKey, which is a valid cast. But for some reason it gives me error at run time saying it is invalid.
We have added compile dependency in our project pom to avoid build issues due to missing bouncycastle lib, as we are only loading it through reflection.
@martijndwars, Can you help please?
Please let me know if you need additional info.
Thanks
The text was updated successfully, but these errors were encountered: