Posts

Showing posts from 2014

Glassfish - Exception in creating message-driven bean container (NullPointerException)

This may happen every now and then if you killed the appserver and JMS was left in locked state. You can try to resolve it by deleting the file glassfish4/glassfish/domains/domain1/imq/instances/imqbroker/lock.

Secure file transfer with Java and Versile

Just made an example of how to transfer a file over a secure and authenticated connection in pure Java - without having to use additional technology like ssh/scp. Versile has all you need for creating a secure and authenticated connection, and you'll decide what files you want to expose - nothing more - nothing less.This is the file server (include versile.jar in your classpath - and create a file called "personregister.txt" in the working directory): package versileexample; import java.io.File; import java.io.FileNotFoundException; import java.io.RandomAccessFile; import java.security.interfaces.RSAPublicKey; import java.util.logging.Level; import java.util.logging.Logger; import org.versile.Versile; import org.versile.common.auth.VAuth; import org.versile.common.auth.VCredentials; import org.versile.common.auth.VPrivateCredentials; import org.versile.common.peer.VInetSocketPeer; import org.versile.common.peer.VPeer; import org.ver…

Converting from linear to logarithmic scale

A simple function useful to plot a logarithmic scale. Just provide it with the min and max values of the scale and the value you want to convert - and you'll get in return a value as it should be positioned on a logarithmic scale in the given range.
public double toLogScale(double min, double max,double val) { double logmin = Math.log(min); double logmax = Math.log(max); double logscale = (Math.log(val)-logmin) / (logmax-logmin); return min+(max-min)*logscale; }

Ubuntu desktop in the cloud accessible with VNC

To create a Ubuntu desktop on Amazon EC2 that can be accessed by VNC I did the following steps:

1. Create 64-bit Ubuntu server instance
2. Install ubuntu desktop:

sudo apt-get install ubuntu-desktop

3. Install x11vnc

sudo apt-get install x11vnc

4. Install xvfb

sudo apt-get install xvfb

5. Configure x11vnc

sudo nano /etc/init/x11vnc.conf
start on login-session-start script /usr/bin/x11vnc -xkb -auth /var/run/lightdm/root/:0 -noxrecord -noxfixes -noxdamage -rfbauth /etc/x11vnc.pass -forever -bg -rfbport 5900 -o /var/log/x11vnc.log end script
And you should also set a password for your vnc sessions:


sudo x11vnc -storepasswd /etc/x11vnc.pass
6. Configure X server to use xvfb:

(Add the xserver-command line)

sudo nano /etc/lightdm/lightdm.conf
[SeatDefaults] greeter-session=unity-greeter user-session=ubuntu xserver-command=/etc/X11/xinit/xserverrc
(Replace the exec line)

sudo nano /etc/X11/xinit/xserverrc #!/bin/sh #exec /usr/bin/X -nolisten tcp "$@" exec Xv…

Exporting Kendo UI GRID to Excel with Java

This is a simple method of creating an Excel export function on your Kendo UI grid with a Java EE server.
JS function to trigger Excel export In your web-page with the grid - insert this JS function. You should create a button or similar that calls this when you want to perform the export from the UI.
function exportGridToExcel() { var grid = $("#grid").data("kendoGrid"); var currentPage = grid.dataSource.page(); var allPages = new Array(); for(var n=1;n<=grid.dataSource.totalPages();n++) { grid.dataSource.page(n); var view = grid.dataSource.view(); for(var x=0;x<view.length;x++) { allPages.push(view[x]); } } $("#excelExportGridData").val(JSON.stringify({"rows": allPages, "cols": grid.columns})); $("#exportToExcelForm").submit(); grid.dataSource.page(currentPage); } Hidden form and iframe You also need a …