This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information

Posts tagged: JVx

Power control with RaspberryPi, JVx and Vert.x

My idea was to create a programmable timer for some lamps at home. I wanted to control the timer via mobile phone (not only smartphone). I decided to use simple SMS'.

The timer app was not really a challenge and the SMS interface was also very straight forward, so I added a little bit network communication and complexity. The result:

Power control

Power control

My Hardware:

  • Raspberry Pi Model B
  • Cinterion TC65i
  • Standard table lamp
  • Solid State Relay (found here)
  • Laptop as cluster client
  • Mobile Phone :)

My software:

My first question was - Which application server should I use for my Pi? I thought that JBoss or Tomcat would be overhead and I would save resources. I decided for Vert.x and a simple socket server. I wanted to show the integration of Vert.x with JVx and so my server got a JVx application with some business logic for publishing messages.

The server "thing" was clear and for reading SMS' I wrote a simple polling app. The app reads SMS from my hardware via RS232 and forwards received SMS via JVx APIs to my server (with Vert.x' NetClient).
I didn't use the EventBus for sending messages becasue I wanted to show the seamless integration of JVx and Vert.x.

The code for forwarding messages:

MasterConnection macon = new MasterConnection(new NetSocketConnection("10.0.0.39"));
macon.setApplicationName("demo");
macon.setUserName("user");
macon.setPassword("password");
macon.setAliveInterval(-1);
macon.open();

macon.callAction("publishMessage", msg.getOriginator(), msg.getText());

The server application is a standard JVx application (only server-side). It uses a standard XmlSecurityManager without the need for a database. The "business logic" is very simple:

public Vertx getVertx()
{
    return (Vertx)get("vertx");
}

public void publishMessage(String pNr, String pMessage)
{
    System.out.println("publishMessage (" + pMessage + ")");
       
    String sNumber = pNr;

    sNumber = sNumber.substring(0, 5);

    //hide last characters
    for (int i = 5; i < pNr.length(); i++)
    {
        sNumber += "*";
    }
       
    JsonObject jsobj = new JsonObject();
    jsobj.putString("number", sNumber);
    jsobj.putString("message", pMessage);
       
    getVertx().eventBus().publish("sms.received", jsobj);
}

I made some tests with vert.x clustering and decided to implement a (very) simple JavaFX application that shows published SMS'. The application contains following code:

vertx = Vertx.newVertx(25502, "10.0.0.11");

EventBus ebus = vertx.eventBus();
ebus.registerHandler("sms.received", new Handler<Message<JsonObject>>()
{
    public void handle(final Message<JsonObject> pMessage)
    {
        Platform.runLater(new Runnable()
        {
            public void run()
            {
                try
                {
                    mdb.insert(false);
                    mdb.setValues(new String[] {"NUMBER", "MESSAGE"},
                                  new String[] {pMessage.body.getString("number"),
                                                pMessage.body.getString("message")});
                    mdb.saveSelectedRow();
                }
                catch (ModelException me)
                {
                    throw new RuntimeException(me);
                }
            }
        });
    }
});

Finally, I created a short video that shows all in action. It shows three applications on the same laptop. The first is the JavaFX application that shows published SMS. The second is the Power control (includes SMS check), started via PuTTY. The third application is the server instance, started via PuTTY. You can see a table lamp that will be turned on and off with SMS, sent from a smartphone.

Enjoy it :)


Power Control with RaspberryPi

Vert.x + JVx

Do you know vert.x?

It's like node.js but written in Java and without JavaScript limitations. It's very powerful and easy to use. I don't describe features of vert.x or tell you how it works. If you want to know more about it, you'll find everything you need on the official site.

How and why do we use vert.x?

We simply tried it out to find out how it works and if an integration with JVx makes sense. We started a simple Research project with some goals:

  • Create a simple http server that will run without an application server, e.g. on a Raspberry Pi
  • Create a simple net/socket server, also for Raspberry Pi
  • Deploy an existing JVx application (e.g. FirstApp) and connect to the new server
  • Integrate the EventBus in an existing JVx application
  • Create a simple JavaScript app (show data in a grid) with jQuery, jQueryUI and vert.x EventBus
  • Use EventBus in Cluster mode (Java IPC)

The documentation of vert.x is great and there are a lot of examples, not what we needed but good for a quick start.

It was easy to create a http and socket server. The only problem was that everything was asynchronous and JVx expected synchronous calls. The HttpConnection of JVx worked without modifications because the JDK solved everything. We didn't use the vert.x http client.

It was a little bit tricky to implement an IConnection for socket communication because the server has to know when a command ends. It only reads a stream and does not know the protocol! We didn't introduce a new protocol, instead we wrote a delimiter after each command. This worked like a charm.

After we had http and socket support, the usage of an existing JVx application was easy. We copied existing files and it worked out-of-the-box. That was as expected ;-)

What about the event bus?

With JVx we have a super fast and simple client/server communication and it's possible to send messages from the client to the server, but the client polls. It's not live!

The event bus offers more power and flexibility. We thought it would be a great benefit for JVx applications or applications written in technologies that are supported from vert.x e.g. JavaScript.

It's already possible to use JVx' REST interface from non Java applications but if you use vert.x it would be cool to use the event bus.

The EventBus support was soo easy because the API is very nice and simple. It's enough to register a handler (like a listener) for a specific address (= string). After the registration you'll receive events from the bus :)

We had some problems with clustering vert.x because we didn't read the (whole) documentation and the information was in a different place as expected. If you use vert.x embedded and start multiple applications with different Vertx instances, be sure to use free cluster (communication) ports (see manual):

-cluster-port If the cluster option has also been specified then this determines which port will be used for cluster communication with other vert.x instances. Default is 25500. If you are running more than one vert.x instance on the same host and want to cluster them, then you'll need to make sure each instance has its own cluster port to avoid port conflicts.

We had to create Vertx instances with a specific port, e.g. 25501, 25502 (for the second and third application):

Vertx vertx = Vertx.newVertx(25501, "10.0.0.11");

Without port and host, the instance is not clustered!

The last goal was a simple JavaScript application. Here is a screenshot:

JVx with Vert.x and JQuery

JVx with Vert.x and JQuery

The application connects with username and password and retrieves data from a database via business logic (standard JVx). We used an existing JVx application and wrote one html page for our JavaScript application. Here is the source code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JVx + vert.x + jQuery</title>
 
<link rel="stylesheet" type="text/css" media="screen" href="css/jquery-ui.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />

<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="http://cdn.sockjs.org/sockjs-0.2.1.min.js"></script>
<script src="js/vertxbus.js"></script>
<script type="text/javascript">
  $.jgrid.no_legacy_api = true;
  $.jgrid.useJSON = true;
</script>
<script type="text/javascript">
jQuery(document).ready(function(){
  $.jgrid.defaults = $.extend($.jgrid.defaults,{loadui:"enable"});

  jQuery("#grid").jqGrid(
  {
    datatype: "local",
    height: 400,

    colNames:['ID','PLZ-ID', 'ZIP', 'STRA-ID', 'Street', 'House #', 'Floor', 'Door #'],
    colModel:[
                {name:'ID', width:60, sorttype:"int"},
                {name:'POST_ID', hidden:true},
                {name:'POST_PLZ', width:50, align:"right", sorttype:"text"},
                {name:'STRA_ID', hidden:true},
                {name:'STRA_NAME', width:200, sorttype:"text"},        
                {name:'HAUSNUMMER', width:50, align:"right", sorttype:"int"},          
                {name:'STIEGE', width:70, align:"right", sorttype:"int"},              
                {name:'TUERNUMMER', width:60, align:"right", sorttype:"int"}
                ],
   
    multiselect: false,
    rowNum: 200,
    forceFit: true,
    loadonce: true,
    caption: "Address data"
});

eb = new vertx.EventBus("http://10.0.0.11:8080/eventbus");

eb.onopen = function()
{
    eb.send('jvx.createSession',
            {application: 'demo', username: 'rene', password: 'rene'},
            function (reply)
    {  
      eb.send('jvx.fetch',
              {sessionId: reply.sessionId, object: 'adrData'},
              function (reply2)
      {
        gdata = reply2.data;

        for(var i = 0; i <= gdata.length; i++)
       {
         jQuery("#grid").jqGrid('addRowData', i + 1, gdata[i]);
       }
     });
   });    
};

});
</script>
</head>
<body>
  <div id="GridPane">
    <table id="grid"></table>
  </div>
</body>
</html>

The authentication is hardcoded, of course. It's not a problem to show a login page, but not necessary for our project.

Summary

We have a great integration of JVx for vert.x and it's now possible to use JVx on remote hosts without application server. Simply use Vert.x as http or socket server. It's very cool to use a Raspberry Pi with JVx without Tomcat, Jetty or JBoss - it saves system resources and is cool :)

It's now possible to use JavaScript, Python, Ruby or Groovy as client technology together with vert.x and JVx. Use the power of JVx for your preferred client technology.

The EventBus is a powerful feature to enrich your rich applications :)

Our integration project is open source and free for everyone!

JVx, NTLMv2, Samba4 AD - authentication rocks!

Samba4 - what a great product!

My first samba PDC was version 3, and it took many nights until my old NT machines joined the samba domain... that was long time ago. As I heard of samba 4 and the big ideas (2005), I thought c'mon how would you do this? But Microsoft released important documentation about the protocol internas. And this helped!

... and some years later, we have a final release of Samba4.
Respect!

Yesterday, I read about a prebuilt samba image from SerNet (EnterpriseSamba) and thought I should try it out, because the installation was so easy! 20 minutes later, my Samba4 VM was up and running.

My first test with Windows XP as client was successful and today I added Vista, Win7 and Win8 to my new domain.
It was too easy :(

Of course, I had a problem with name resolving. The client machines should use the Samba4 server as primary DNS. I didn't change my DNS server but set the primary DNS on every machine/VM.

After my virtual domain environment was setup, I made tests with JVx' NTLM authentication. We added NTLMv1 support in 2008 or earlier - not sure when. We used jCIFS - what else.

We support authentication with signed, unsigned Applets (YES - Applets) and Desktop applications. It is one of the most important features for our business customers: Single Sign-On.

Our problems with the implementation were the difference between OS versions and Java versions. In Windows XP, NTLMv1 was default. Since Vista, NTLMv2 is default. Java 1.5 and newer support NTLM authentication via http automatically. Since 1.6 update ?? the authentication implementation is not so nice as it was before...

My tests with 1.5 and 1.6 <= 20 on WinXP, Vista, Win7, Win8 were successful. With 1.6 u38 and 1.7 u10 we have to use a new authentication dialog (be careful - German):

Authentication dialog

Authentication dialog

I'm not sure if this dialog is good or not, because NTLM authentication worked with e.g. 1.6 u20 without this thing. I didn't find a property to bypass this dialog. But if you check "save", the dialog does not pop up again (not perfect but our business users can handle it).

At the end of the day, we have a working solution for automatic NTLMv1 + NTLMv2 authentication for JVx with support for WinXP, Vista, Win7, Win8 and jre 1.5 up to 1.7. Thanks to samba4, an ActiveDirectory costs nothing.

It's a nice present :)

NFC/RFID for Beagleboard xm with Java

NFC reader   Based on my experience with JavaFX, Beagleboard xm, RxTx and GSM devices, I started my new research project: A simple and cheap time tracking solution.

There are hundreds of tools and hardware solutions available for time tracking, but hardware solutions are expensive and tools without hardware are not practically.

The ideal solution would use a Raspberry Pi and a RFID reader together with a simple JavaFX application. Total costs are about EUR 50,- for the hardware and software should be free :) If you need a case for your hardware and a lcd display, it would be more expensive but EUR 150,- should be the limit for a brilliant system.

I ordered my Raspberry Pi some weeks ago but it is still not available and hopefully it will arrive before Xmas? My fallback board is the Beagleboard xm.

The big question was the RFID reader/writer. Wich devices were supported, and were there any Java APIs for the communication? After a short google search I found a lot of recommendations for RFID breakout board, but it was not too cheap and I don't have an Arduino board and don't want one. I found some other boards but I decided to use PN532 NFC RFID module kit. It is still expensive but seems to be fair.

Why this RFID board?

Firstly, because of a mistake. I saw a screenshot of an example application and the frame icon was a Java icon... So I thought the application was written with Java and there must be a Java API. Not really!
The whole kit was available as developer version with a lot of accessoires like two cards, one dongle, additional cables, ....

After reading the documentation and provided information it was clear that the board was perfect for Arduino boards and the software was written in C/C++, but it was still not too expensive.

But no risk, no fun - ordered.

The delivery time was ok and after unpacking I thought it would be easy to test the included RFID cards - Plug and Play? The truth: No way.

First problem

Included cables were built for Arduino board. I kew that the connection could be a problem and ordered an USB TTL module together with the RFID baord.

The USB module has a connector with 4 pins (GND, VCC, RX, TX) and the RFID board has 4 pins (GND, VDD, RX/SDA, TX/SDL). It was not a big problem to connect the right pins after it was clear that the included standard cable will not work.

Solved.

Second problem

The RFID reader supports 3 different modes (HSU, I2C, SPI). The default mode was I2C because of the Arduino support. But in order to support my Beagleboard, HSU was needed. The board has no jumpers and you must solder a little bit to, but with the right tools it's easy.

Solved.

Third problem

No Arduino board, no chance to test the RFID board? Not really.
There is a great open source project with the name libnfc. It has read/write and diagnostic tools and runs on Linux and should run on Windows too. I compiled libnfc on my Ubuntu VM and had the problem that the nfc-list tool reported a timeout after connecting - but the RFID board was found.
Hm...

It was easy to compile libnfc on Ubuntu - after installing some dependencies - so I thought it should be easy to compile it on my Beagleboard xm? It was a bad idea and I spent some extra hours... but it worked.

How? I can't remember every single step, but try following:

Dependencies:

opkg install cc
opkg install gcc-dev
opkg install task-native-sdk
opkg install libusb-1.0-0 libusb-1.0-dev
opkg install libusb-0.1-4 libusb-0.1-dev
opkg install udev-dev
opkg install autoconf

You need following source packages:

pcsc-lite.1.7.0
libnfc-1.5.1

(Newer versions or different version combinations did not work because libraries were not available for my distribution. But this versions are good enough for tests.)

Start with pcsclite:

./bootstrap
./configure --disable-libhal
make install

Copy /usr/local/include/PCSC directory to /usr/include and /usr/local/lib/pkgconfig/libpcsclite.pc to /usr/lib/pkconfig/

Next, compile libnfc:

./configure --with-drivers=pn532_uart,pn53x_usb --enable-serial-autoprobe --enable-debug
make install

If you get the exception similar to ln: symbol not found -lusb, create a symbolic link:

cd /lib
ln -s libusb-0.1.so.4.4.4 libusb.so

Test, in your libnfc directory:

cd utils
./nfc-list
cd ../examples
# hold a card over the RFID board
./nfc-poll

My output:

# ./nfc-list
Connected to NFC device: PN532 (/dev/ttyUSB0) - PN532 v1.6 (0x07)

# ./nfc-poll
NFC device will poll during 30000 ms (20 pollings of 300 ms for 5 modulations)
ISO/IEC 14443A (106 kbps) target:
    ATQA (SENS_RES): 00  04
       UID (NFCID1): 1b  21  4b  e0
      SAK (SEL_RES): 08

Now you know that your hardware is supported and works with CPP libraries. But what about Java?

I found NFC Tools but the online demo did not work with my reader. Another solution was Open-NFC.

Both solutions were feature rich but horrible because the first one did not compile and maven could not resolve all dependencies. The other solution was too complex for my use case. Why the hell are most libraries so complex. Nobody can handle big libraries.

My use-case was simple: I need a small Java library that can be bundled with my application and it should work on Linux, Windows and optionally on MacOS. It should connect to my Reader via RS232. I stopped evaluating libraries and decided to create my own "simple" library for my use-case.

The topic (NFC, RFID, smart cards) is really complex but I had a PDF that described how read/write basically should work. And I had a reference implementation in cpp. After some problems and night hacking, the problem was solved and I had my library that simply worked (only 2 source files and ~ 1000 LoC).

My first application only reads content from cards that are over the reader. Here is the output:

SAM = true
LOOP PAUSE
UUID length: 4
UUID: 1b 21 4b e0
Authentication receive: 00 FF 03 FD D5 41 00 EA
Authentication successful
Read block successfully:
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Read block successfully:
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Read block successfully:
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Read block successfully:
00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF

And it supports writing to the card, but don't overwrite the 4th block because it contains security settings. If you overwrite the 4th block with wrong values, the whole sector is unusable.

What'll come next? A JavaFX UI for in/out tracking.
The library itself is free but the source is not yet available because it needs some refactoring and beautifying.

Have fun ;-)

Oracle Forms' best friends...

...should be JVx and VisionX.

Our integration of JVx applications is now available.
We won't replace Forms with Java and don't say that Java is better than Forms. Of course, Forms is not dead and it will probably never die. But, Forms uses Java as client technology and why shouldn't we bring more Java to Forms?

If you search for Java and Forms all you will find are relatively simple components or PJCs, e.g. a JTable integration in your forms module. There are a lot of "ready-to-use" examples, but if you are not a Java pro, it will be hard to understand what happens.

I know that Forms needs a face lifting, but it is not a good idea to start from scratch. You should start pimpin' with some cool icons, colors and a nice background image. But if you need better usability, don't try to reinvent the wheel. You need more than modern controls like a JTable with sort-on-header. Do you know how you fill your table with data or how you transfer data from a remote database to your application within a 3-tier architecture?

What you need is a framework that is as powerful as forms, offers modern controls and solves communication problems. And it must be simple - should just work, because Forms simply works.
Oh... I forgot that the framework must work in Oracle Forms and without Forms. It must be a one-4-all solution.

If you think that this is impossible then you are wrong, because it works!

We married best of both worlds.

  • Use a modern table in your forms application and don't think about how you connect the table to your database. You get table headers and sort-on-header for free :)
  • Use layout managers for dynamic GUIs instead of fixed size GUIs.
  • Call a stored procedure on button click within your Java bean? No problem.
  • Use modern Look and Feels and pimp your forms GUI.
  • You need REST services? They are already implemented.

And you don't need different frameworks or tons of libraries. You need exactly one framework - JVx. It solves all your problems and with our Forms integration, it is possible to use your Java application within your Forms application without code changes.

We have some screenshots for you :)

Forms application with Java screen   Java screen without Forms

On the left side, you see the Forms application with exactly the same screens as in our Java application on the right side. We added a close button to the forms application, because it is Forms and you decide when you need Java and when standard Forms controls are better.

Oh... when you think you must migrate your Forms application to another technology - why do you think that? Modernize your existing Forms applications and if you decide to replace Forms, your Java screens are ready.

JVx beta releases?

Some of you asked me why no new beta releases are available.

The answer is that we don't build beta versions since we have our nightly builds. It is better to "release" daily instead of monthly. You get access to the latest features with the delay of one day.

You can download the nightly builds from here.

JVx nightly builds

We have posted that JVx quality reports are available.

Today, we also offer nightly JVx builds. The builds contain (nightly) in the Implementation-Title and Implementation-Version.

Don't use nightly build versions in production environments.

To use our nightly builds, go to

https://dev.sibvisions.com/jvx.nightly/

and click the Download link in the top menu.

Oracle Forms together with JVx/Swing (modernization)

The good old Oracle Forms UI does not look really cool. Of course, you can use nice icons and choose the right colors, but the controls are not fancy compared to swing controls.

If you try to to migrate from Oracle Forms to Java, wouldn't it be great to migrate one screen after the other. Or better, create new screens with Java and integrate them in your existing Oracle Forms application. Use both technologies as long as is necessary.

Don't think that you have to migrate the whole Oracle Forms application, migrate step by step. It is absolutely possible to use your new screens in your Oracle Forms aplication or as separate application without Forms. Save time, money and don't replace your existing Oracle Forms developers.

You would like to see how this can look like?


The first screenshot shows a standard Java swing application, with a simple master/detail and some editors:

JVx Swing UI

JVx Swing UI



The next screenshot shows the same screen (without source code changes) used in an Oracle Forms application:

Forms with Java screen

Forms with Java screen



You are right, it is great to embedd the same Java screen, but the Look and Feel is not very cool. Do you know that Java has some nice LaF's? Here is the same screen with Nimbus Look and Feel:

Oracle Forms Nimbus LaF

Oracle Forms Nimbus LaF

JVx EE

Our new project is created and we are preparing the source upload.

JVx EE

What is JVx EE?

It's the integration of JPA 2.0 in JVx. Create professional backend software with JVx and use your domain model which is already available in your Java EE based web application. With JVx EE you can use the configured EntityManager and JPA implementation of your web application. Reuse your existing DAOs or EAOs without changes in your application.

With JVx EE it is possible to create a standard JVx application that is connected to your domain model, e.g.:

JPAStorage jpaAddress = new JPAStorage(Address.class);
jpaAddress.setEntityManager(getEntityManager());
jpaAddress.open();

or with a custom EAO

CustomerEAO eaoCustomer = new CustomerEAO();
eaoCustomer.setEntityManager(getEntityManager());

JPAStorage jpaCustomer = new JPAStorage(Customer.class);
jpaCustomer.setEntityManager(getEntityManager());
jpaCustomer.getJPAAccess().setExternalEAO(eaoCustomer);
jpaCustomer.open();

Do you need a professional backend application for your existing web frontend? Use JVx and your problems are solved. You get all advantages of JavaEE in your JVx application.

JVx EE is licensed under Apache License 2.0.

Do you have any questions? Let me know.

JVx nightly build reports

We used Hudson for nightly builds since the first day of JVx. The hudson server was an internal server, so the reports were "private". We have never liked it!

Since 1 May are the reports now publicly available. Check it out:

https://dev.sibvisions.com/jvx.nightly/

You see the JUnit test reports, Checkstyle reports, Code Coverage reports and FindBugs reports.
And we now use Jenkins instead of Hudson ;-)