Infinispan/JDG Quickstarts Pt5 – Java HotRod

All

Intro

Another Hot Rod tutorial, this time with java, similar concept but using a Hot Rod java client. Just a reminder, basically TCP client that access the cache on JDG.

Core part

There is the `​FootballManager` and the Team, which are pretty much the classes that play a role here (except for the user). So then a FootballManager has team(s) and so forth. The team just encapsulates the list of players and the name. The core part (talking with the cache itself) is on the FootballManager class.

ConfigurationBuilder builder = new ConfigurationBuilder();
builder.addServer()
.host(jdgProperty(JDG_HOST))
.port(Integer.parseInt(jdgProperty(HOTROD_PORT)));
cacheManager = new RemoteCacheManager(builder.build());
cache = cacheManager.getCache(“teams”);

The main part is then the builder adding the server with jdgProperty (from a file) and the port. Then it adds the players. The file has basically the host and the port:

jdg.host=localhost
jdg.hotrod.port=11222

To read the commands,  it is used java.io.Console in comparison with the javascript version (that uses Vorpalo=||==>).

Interesting Topics

– Originally the players added were Messi, Pedro, and Puyol. I changed for Pele, Tostao, and Rivelino (Tri-world champions on the1970th World Cup in Mexico)

– Comparing with the JS version: This version is done in Java,that’s the only difference. Although js has a simpler connection with JDG.

– Interestingly, java.io.Console reading is faster than bufferedReader

REFs

inline

 

Mocking request http

All

Intro

Recently I needed to simulate some requests http so then I used EasyMock. Quite useful indeed and very simple:

Code

HelloServletMock mock = new HelloServletMock();

HttpServletRequest request = createMock(HttpServletRequest.class);
HttpServletResponse response = createMock(HttpServletResponse.class);

expect(request.getParameter(“yourName“)).andReturn(“Jose Carlos“).times(1, 2);
replay(request);

On this case the request will return “Jose Carlos” when I get the paramter “yourName”, example:

String yourName = request.getParameter(“yourName”);

Icedtea-web ~ jnlp launcher

All

Intro

As replacement for Java Web Start, IcedTea-web, provides a Java Web browser plugin. What I like about this project is that it is so clean, easy to access, easy to execute some Java Network Launch Protocol files.

Icedtea-web

Control Panel

ice_tea

Iced Tea Web – Control Panel

JVM Settings

Using this setting will help to set the JVM properties.

Policy Settings

This basically is a link to the java.policy:

[$JAVA_HOME/jdk1.8.0_191]$ cd jre/lib/security/
[fdemeloj@fdemeloj security]$ ls
blacklist blacklisted.certs cacerts java.policy java.security javaws.policy policy trusted.libraries

         Extended applet security

So here one can add the exceptions, in a similar way to JWS. So then you edit the rows in order to add the site exception.

IcedTea-Web Tests/Samples

On the link you can select the test to be done, the tests are .jnlp files that you execute directly clicking on it (of course, the default will be IcedTea-web) so we open. This one is pretty cool: circuit-construction-kit-dc_en.jnlp – Developed by PhET at the University of Colorado.

icedtea2

IcedTea test – circuit construction

The code is pretty straightforward, is jnlp file:

You will have a XML file with:

                    1. code base link (to fetch),

                    2.a jar file (to execute),

                    3. some properties – language for example

<?xml version=”1.0″ encoding=”utf-8″?>

<!– JNLP File for Circuit Construction Kit (DC Only) –>

<jnlp spec=”1.0+” codebase=”https://phet.colorado.edu/sims/circuit-construction-kit” href=”circuit-construction-kit-dc_en.jnlp”>

<property name=”javaws.phet.locale” value=”en” />
<property name=”javaws.user.language” value=”en” />

<jar href=”circuit-construction-kit_all.jar”/> ii

</resources>

<application-desc main-class=”edu.colorado.phet.circuitconstructionkit.CircuitConstructionKitDCApplication“>

</application-desc>

</jnlp>

  1. The main class to be executed is set with <application-desc main-class>
  2. Interestingly they have this application for several languages, including Korean and Portuguese! It is possible to change the language by changing the property <property name=”javaws.phet.locale” value=”LANGUAGE” /> AND the doc circuit-construction-kit-dc_es.jnlp. And yes, Ampolleta means light in Spanish.

The tags and meaning of them can be found in JNLP Syntax

REFs

inline