Fedora 26 Install Guest Additions (VirtualBox)

sudo dnf update kernel*

sudo dnf install dkms kernel-devel

Insert VirtualBox guest additions

cd /run/media/username/VBOXADDITIONS_xxx/

sudo ./VBoxLinuxAdditions.run



[JAX-RS] Some good auth resources








Eclipse remote debug (with ant example)

Sometimes you cannot start your program from within eclipse to be able to debug it. Or even worse, you run your application on a remote server where you don’t have the sources or the ability to debug it on that machine. In this case you can use the remote debug capability of the JVM. For this:

1. Start your program with these VM arguments:


If your application is started as an Ant task then:

<java dir="${running.dir}" jar="${jar.location}" fork="true" failonerror="true" >
         <jvmarg value="-Xdebug" />
 <jvmarg value="-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9000" />

For address, specify the port you know is open and can be accessed from outside.

2. In eclipse open the project which contains the sources and click Debug -> Debug Configurations. Double click to create new debug configuration.
Set the correct Connection Properties: Host (the target host) and Port the port you specified earlier.

3. Click apply and debug…

[SOLVED] Eclipse create new class slow in Fedora

If you’re having problems with eclipse under Fedora, then it might be due to GTK3. So start eclipse like:

./eclipse --launcher.GTK_version 2

It must also work from eclipse.ini, but you need to make sure to put 2 in the next line:


Thanks to this person:

[WTF] Criteria API

This is the best representation of what I want to say about JPA criteria API:


EntityManager em = ...;
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Pet> cq = cb.createQuery(Pet.class);
Root<Pet> pet = cq.from(Pet.class);
TypedQuery<Pet> q = em.createQuery(cq);
List<Pet> allPets = q.getResultList();

The equivalent JPQL query is:


The equivalent SQL query is:


Clearly SQL is too simple and boring. You really need a bullshit API to produce a simple SQL query. Of course this will ease maintenance, improve performance, reduce code, prevent bugs, speed up development by a factor of 10 and reduce your project cost by 99% at least. A classic case of overengineering.

Java EE 7 WebSocket example

1. Createa a Java EE Web application called MyWebSocket for example.
2. In index.html:

<!DOCTYPE html>
        <title>Start Page</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script language="javascript">
            var ws;
            function connect() {
                ws = new WebSocket("ws://localhost:8080/MyWebSocket/sockOne");
                ws.onmessage = onMessage;
            function onMessage(evt) {
                var dataarr = evt.data;
                document.getElementById("valueElement").innerHTML = dataarr;
            window.addEventListener("load", connect, false);
        <h1>Hello World!</h1>
        <b>Value: </b>
        <b id="valueElement">no data yet</b>

2. Create a class Called WebSocketEndpoint. Here the most important annotations are @ServerEndpoint, @OnOpen, @OnClose and @OnError, in these methods you put whatever you want to get executed when these events happen:

package com.vvirlan.websocket;

import java.io.IOException;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

 * @author vvirlan
public class WebSocketEndpoint {

    private static final Logger LOGGER = Logger.getLogger("WebSocketEndpoint");
    private static Queue<Session> sessionQueue = new ConcurrentLinkedQueue<>();

    public static void send(double number) {
        String toSend = String.format("%f", number);
        try {
            for (Session session : sessionQueue) {
                LOGGER.log(Level.INFO, "Sent: {0}", toSend);
        } catch (IOException e) {
            LOGGER.log(Level.SEVERE, e.toString());

    public void openConnection(Session session) {
        LOGGER.log(Level.INFO, "Connection opened");

    public void closeConnection(Session session) {
        LOGGER.log(Level.INFO, "Connection closed");

    public void error(Session session, Throwable th) {
        LOGGER.log(Level.WARNING, "Connection errorred");
        LOGGER.log(Level.WARNING, th.toString());


3. The bean which will produce our fake data. It gets injected a TimerService as a @Resource and when @Timeout happens it invokes the send method of our endpoint:

package com.vvirlan.websocket;

import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.ejb.Timeout;
import javax.ejb.TimerConfig;
import javax.ejb.TimerService;

 * @author vvirlan
 * Generates a double every second and calls the endpoint for updating the clients
public class GeneratorBean {
    @Resource TimerService timerService;
    private Random random;
    private volatile double number = 777.0;
    private static final Logger logger = Logger.getLogger("GeneratorBean");
    public void init() {
        logger.log(Level.INFO, "Initializing EJB");
        random = new Random();
        timerService.createIntervalTimer(1000, 1000, new TimerConfig());
    public void timeout() {
        number = 1.5 * (random.nextInt(100));

JSF simple ajax example

Here is a simple AJAX example in JSF (run on Glassfish).
Just to note: for sending the value to the bean you use the execute attribute of f:ajax, and for displaying the output from the beans’s getter, you use the render attribute.

1. pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">






2. The xhtml page:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
        <title>Facelet Title</title>
        Hello from Facelets
            <h:inputText id="msg" value="#{myBean.text}"/>
        <h:commandButton id="submit" value="Submit">
            <f:ajax event="click"  execute="msg" render="outText"/>
            <h:outputText value="The message: #{myBean.text}" id="outText">

3. The Bean:

package com.mycompany.ajaxtest;

import java.io.Serializable;
import javax.enterprise.inject.Model;

 * @author vvirlan
public class MyBean implements Serializable {
    private String text = "defaullt";
    public void message() {
        System.out.println("The message "+text);

    public String getText() {
        System.out.println("getText message "+text);
        return text;

    public void setText(String text) {
        System.out.println("setText message "+text);
        this.text = text;