java.lang.NoSuchMethodException: sun.misc.Unsafe.defineClass

Upgrading from JDK8 to 17+ caused jaxb to run into this errors at run time. Solution remove older Jaxb jars and replace with newer jars that still provide “xml.bind”. When replacing try with 2.3.X jar versions as they still maintain the old sun class path, 3.XX jars have switched to the jarkarta class path which will mean updating some of your project imports and dependencies.

Remove any of the below libs

implementation group:'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
implementation group:'com.sun.xml.bind',name:'jaxb-impl', version: '2.3.0'
implementation group:'com.sun.xml.bind',name:'jaxb-core', version: '2.3.0'
    

replace with

implementation group: 'jakarta.xml.bind', name: 'jakarta.xml.bind-api', version: '2.3.3'
implementation group: 'org.glassfish.jaxb', name: 'jaxb-runtime', version: '2.3.3'

No appropriate protocol

I saw this error message once I updated to JDK 11 when trying to send emails initially I didn’t have time to figure out a long term solution so I took a shortcut and removed Tls 1.0 from blocked algorithms in the java.security file. (I know that was a bad move but I was on a time crunch so I wasn’t thinking clearly 🙂 )
Things were ok for a while until an update of JDK replaced my update to java.security file, at this point I figured I would have to keep repeating this dance every few months or get a long term solution.

I use apache commons library to send email and by default it uses < TLS v1.2 and JDK 11+ supports > TLS v1.2. The permanent fix just turned out to be specifying TLS version to be used and my app was able to get back to sending emails without any issues and this time it was future proofed from future update breakage due to JDK updates. Below are the parmeter updates needed.

#Method 1 adding a system property
System.setProperty("mail.smtp.ssl.protocols", "TLSv1.2");
System.setProperty("mail.pop3s.ssl.protocols", "TLSv1.2");
#Method 2 setting value in a property file
spring.mail.properties.mail.smtp.ssl.protocols=TLSv1.2
spring.mail.properties.mail.pop3s.ssl.protocols=TLSv1.2

I went with Method #2 as it allows easier management of properties but every bodies use case is different so you can go with whatever works for your situation.

Angular2: Property binding ngFor not used by any directive on an embedded template

Just brushing up on some Angular2 and run into this error it didn’t make sense since I was using a tutorial from the official angular site. It turns out the language is changing faster that the documentation can keep up with :). The cause for the error was using # with ngFor instead of let so instead of *ngFor="#Item of Items" do *ngFor="let Item of Items" My previous angular2 apps are locked to earlier versions of angular thats why I hadn’t run into this issue, but this time around I was starting a new project with the latest angular2 version.

Converting selinium code to headless tests with PhantomJS

The word test here is used ambiguously as I use selenium for more than just UI tests, it makes a great tool for browser automation which I use it for this purpose a lot. While writing your browser automation most of the time it’s easier to do it in browser mode by using the firefox or chrome driver so that you can visually inspect the HTML. Once you are done writing the code and finished testing sometimes you would prefer to switch it to headless mode so that it can be run without having a UI, at which point you are likely to tryout PhantomJS driver and your fully tested code starts throwing all sorts of errors like “Element not found” or “Stale Element Exception”. If all this errors go away if you switch back to chrome or firefox driver then the likeliest cause of your troubles is you might need to add delays in most places where you have the browser loading new data compared to the other browser drivers.
To me this seemed a bit counter intuitive at first as I though headless mode should run faster therefore requiring even less time to load UI changes, but I guess it might actually take a little longer since all the browser rendering is being done is software only. Just thought to put this out there as I have run into the issue a few times.

Useful Git commands

Sometimes when using apps checked out from Git an update might break something so it’s good to know a few git commands. Move to root of the app folder you had checked out to perform git commands.

git log
This command will list all the commits so you can see at which commit you are and pick the one before yours and copy the commit hashcode it will be a long string.

git checkout hashcode
With ‘hashcode’ being the commit hashcode copied from the log. This command will move/revert your app/code to the commit you specified. Just restart your app after that to run it with the new code.

git checkout master
This command will move your code to the master branch from development. Do this if you want your app to be more stable Alpha/Developement branches break now and then as people checkin new code. They have the benefit of getting new features before the stable branch if you don’t mind having something break now and then which is ok with me 🙂

Python IMAP search and SMTP with Gmail

Recently I had a need to search through my gmail and fwd some emails on a daily basis. I checked out Gmails rest interface but it was a bit of an overkill for what I was doing. So I settled on just plain IMAP and SMTP. The main idea was search through my inbox using several search parameters, get all the emails that match the pattern and fwd them to a list of emails. So I wrote a script to do this and had cron call the script at the end of the day. I put up the source in github for anyone interested.

Update enom dynamic IP address

I have been using LqConsulting for about five years now to register my domain, if you are a linux user and you have used Linuxquestions to get some issues resolved consider using this registrar as it it is owned by the same person.

Back to the point this registrar currently uses enom to register your domains, which offers DyDns services and you can get a list from both places on the clients you can use to update your Dynamic IP. The problem comes with configuration, I like most people who rum linux to host personal websites have never setup one of this Dydns clients before and the help I got from my registrar was not very helpful. So for sometime as you can see from this post I was using a script to notify me when my ip changed and i would log in to my registrar and update my IP manually, this is not a very ideal way of doing it. Am not trying to bash my registrar here they provide me with a great service, they are a small shop and the main part is they do a lot for linux users, this being a personal site I was not loosing any sleep or money due to my site going down as a result of my IP changing.

But life is about convenience so I finally crawled the net and was able to find configuration info for ddclient with enom services, straight away I setup ddclient in my Centos box, and life was great anytime my ip changed I would get an email notification and my registrar would be updated automatically. The problem with life is once you have gone forward it’s hard to go back so when I updated my Centos box to the next version it came with a new version of ddclient which would not take the patch to make it work with enom but it also did not work with enom even though it was supposed to support it. So I could go back to manually updating my IP or get another client that would work with enom, I ended up putting together this python script to update my IP changes and to also send me an email whenever my dynamic IP changed. This is my first ever python code, I have worked with other languages and it was a real pleasure to see how simple python makes some tasks that would take a lot more coding in other languages I have used. Most of the code is made up of different pieces i found around the net so I can’t claim to have done it all by myself. So in the spirit of others before me am putting it out there to help anyone else who might need it feel free to use as you please and change it to your liking. If it works for you or not let me know but it is not a requirement.

HTTPService get with parameters

I was trying to put together a simple HTTPService Get service and most of the tutorials online did not work for me, as most of them are get calls without parameters and I needed to pass 2 to 3 arguments with my get call. Below is sample code for my get call.

[cc lang=”actionscript3″]

private function getListings():void
{
var params:Object = new Object;
params[“Input”] = txtInput.text;
params[“Index”] = new String(cmbSample.selectedIndex);
GetMyListing.send(params);
}
[/cc]
How does this work
When the HTTPService executes it will convert the above call to

http://localhost/rs/client/listing?Input=sometxt&Index=sometxt

This way am not having to do a post call just to send two parameters.