Categories
Java

Java + LetsEncrypt certificate giving SunCertPathBuilderException

During testing some java code i have for doing a check against check.torproject.org i got an exception is have not seen before:

PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

After digging around i realised that the site in question has started using certificates from Lets Encrypt.

Java keeps their known certificate providers bundled with the installation, so if your JRE/JDK installation is not quite up to date, it will be as simple as to simply upgrade to the latest release. (Anything >= Oracle Java 8u101 has Lets Encrypt root cert bundled)

Categories
PHP Ubuntu

Adding SSH support to PHP on Ubuntu

I have previously written a post on how to add SSH support to PHP, but that post is old, and it has now become even easier to get it up and running. And therefore making it much easier to auto upgrade WordPress via SSH. (automatic, yay!)

As root, do the following:

1: apt-get install libssh2-1-dev libssh2-php

2: Check that is installed: php -m |grep ssh2

3: Restart apache: service apache2 restart

And you should now have SSH support in PHP.

Categories
Development Java

Java: How to get access to ClassLoader from static function

If you need access to the ClassLoader from a static function, for example in order to access a file inside your jar. You can get hold of it simply bu calling “YourClassname.class.getClassLoader()” 🙂

Categories
Development Java

GWT: Getting rid of iframe borders in IE8

IE8 defaults to displaying a frame border on iframes, this can be overridden by using the IFrameElement class.

Example:

IFrameElement.as(yourFrameClass.getElement()).setFrameBorder(0);
Categories
Mobile & Gadgets Web development

How to make iframes scrollbable on iPad (even in GWT)

I am currently working on a GWT app that some places uses iframes. When i tested this on a iPad, i noticed that it was not possible to scroll the contents, even with the two fingers swipe trick.

This required a lot of testing, googling, failing and then some more testing.

Somebody solved this by setting parent elements of the iframe, to the iframe`s size, this did not give the wanted behavior. But what i did notice was that there was a lot of pointing towards the CSS rule: “-webkit-overflow-scrolling”. I tried this too, but it did not “just work”.

After some testing, i made it work when i added the CSS rule for almost all parent elements for that iframe. With the 3 parents of the iframe corrected, the ipad started working as expected. Yay!

-webkit-overflow-scrolling: touch;

But then, i got to the next problem. All the HTML elements that were hidden because of overflow, started disappearing, shrinking, getting cut in half, and other “fancy stuff”.

Luckily, there is a CSS fix for that too:

*:not(html) {
-webkit-transform: translate3d(0, 0, 0);
}

tl;tr: iPad gets correct iframe scrolling with two lines of CSS.

PS: This is verified on iPad3.

Categories
Development Java

java.io.file renameTo return false

Had a issue today where a java function which moves files stopped working. I realised that Java`s io.file.renameTo only throws Exceptions for some scenarios. For some errors, it will only return false when something goes wrong.

Only getting true/false on a rather vital operation is rather silly, so my “fix” was to move over to a library from Apache, aka FileUtils.

So now i simply do this: FileUtils.moveFile(oldFile, newFile);

That function actually throws exceptions when something fails 🙂

Categories
Development Linux

MRTG: ERROR: CFG Error in “Interval”: should be at least 5 Minutes (unless you use rrdtool)

Just setup MRTG the other day. And due to having some old switches to monitor, i chose to run the MRTG cron every minute, in order to be able to read traffic above 100Mbit. But even when i had specified rrdtool in the server config, i got these error messages:

ERROR: CFG Error in "Interval": should be at least 5 Minutes 
(unless you use rrdtool) at /usr/bin/../lib64/mrtg2/MRTG_lib.pm line 739 

The solution was pretty simple. Simply add the following line in mrtg.cfg:

Logformat: rrdtool
Interval: 1
Categories
Development

Ubuntu: ImportError: No module named BeautifulSoup

When trying to run a python script on Ubuntu, which require BeutilfulSoup. You will need the following package: python-beautifulsoup

Install it by doing:

apt-get install python-beautifulsoup
Categories
Development Java

GWT: “For security purposes, this type will not be serialized.”

The full error message you can get is: “Foo was not included in the set of types which can be serialized by this SerializationPolicy or its Class object could not be loaded. For security purposes, this type will not be serialized.”

This is normally caused by using a non-serializable class, which can happen if your class does not implement serializable or if you have forgotten to add a empty constructor.

Categories
Development Java

Java: Converting long to double

While Integers has to be parsed from a String, doubles can simply be casted:

String bar = "9.99";
Double foo = (double)bar;
Categories
Java

EXT GWT: Adding onClick to Labels

I had a issue where i needed to add a click handler for labels in EXT GWT, the solution i came up with was as follows

theLabel.addListener(Events.OnClick, new Listener() {
@Override
public void handleEvent(BaseEvent be) {
    // TODO Auto-generated method stub
}});

 

Categories
Java

Guice: java.lang.IllegalStateException: No SessionHandler or SessionManager

One reason for this error would be that you should inject the session object directly, not via constructor:

So instead of:

@Singleton
public class Foo {

@Inject public Foo(HttpServletSession s) {
this.session = s  }
}

do this:

@Singleton
public class Foo{

@Inject Provider<HttpServletSession> session;

}

And it should work much better 🙂