Java

I wrote a web tool in Java EE, performing the following subtasks:

  • Reverse engineer the project file (zip-File with an XML describing the project and folders containing the device drivers)
  • Reverse engineer the XML file representing the entire project (i.e. house)
  • Reverse engineer the XML structure representing programs the installers wrote for old and new proxy versions
  • Create models for old and new proxies
  • Create a mapping between these models
  • Provide an online tool where installers can upload a project which is then migrated to the new versions:
    • replace the old drivers with new ones
    • configure them accordingly
    • automatically re-implement programs using the new interfaces
    • clean up invalid parts of the project file
    • be as fault-tolerant as possible: migrate as many drivers/devices as possible; inform the installer about parts that failed to migrate
  • Iterative process: based on failed migrations, learn more about the internal workings of the project file and improve the migration tool accordingly

Technology:

When writing to the file, I was using Writer. The solution is switching to OutputStream.

From JDOM reference, org.jdom2.output.XMLOutputter, output(Document doc, java.io.Writer out):
Warning: using your own Writer may cause the outputter's preferred character encoding to be ignored. If you use encodings other than UTF-8, we recommend using the method that takes an OutputStream instead.

Technology:

I implemented a custom WebSocketAppender for log4j. Log messages were escaped using String.escapeHtml4, newlines were replaced with <br>.
Depending on the log level, messages where printed in bold (WARNING) or in red (ERROR or FATAL).
Events that were considered a problem that needs the user's attention were explicitly stored in a collection, and written to the websocket at the end when the program was done.

ProgrammingLanguage:

Technology:

Use automated UI Test, which is possible with the Selenium library and a browser driver. The browser driver allows us to run actions in a browser while writing code. The Selenium library is an interface to connect many browsers with the same code base. So now we are able to code a simple test, where a robot is automatically clicking through the website and trying out the login functionality. This technique may also apply to test other important and high priority UI features.

OperatingSystem:

Using Html/Javascript you can only select files using the file upload html component (I think Flash / Silverlight wrap this to make things easier but its still sandboxed)
You can however use Java Applets (orwhatever they are called these days), Native ActiveX controls or .Net Controls to provide additional functionality (this hase security implications and required VM/Runtimes Frameworks etc)
Adobe Air or other client side technology might work, but looks like you want to do this in JavaScript. In this case, uploading the file to the server and manipulating from there is the best bet.

Taggings:

Make use of a time-based scheduler Cron, which is available on Debian (as well as on other Unix-like operating systems). Quartz offers a seamless integration with Java applications. Scheduling a particular script (e.g. restarting server) can be easily done using Cron expressions in form of a string consisting of five or six fields (separated by white space), which are respectively responsible for: minutes, hours, day of month, month, day of week, year.

1) Implement a procedure to restart server (e.g. integrated in Java application or through system script).
2) Make use of Quartz to provide Cron functionality to Java application, in particular to make use of Cron expressions.
3) Provide an option for (privileged/administrator) users to manage Cron expression string for restarting server in web interface.
4) Explain in a short summary the principle of functioning of Cron expressions, providing examples of the most common usages.

integrate a Google Map into a Website using JSF

If you are implementing a Website using JSF and Java, and you want to add a Google Maps, there can be different solutions.

You can use one of the PrimeFaces components. There is a nice little component called GMap: http://www.primefaces.org/showcase/ui/gmapHome.jsf
However it is doesn’t offer every function we are used to have with a Google Map.

A better possibility is to use gmap4jsf. To add a Google Mao into your JSF Page you need to add the gmaps4jsf tab library.
Here is a simple Example of who you can use it:

<%@ taglib uri="http://code.google.com/p/gmaps4jsf/" prefix="m" %>

The Example in the attachment uses the latitude and longitude to present a marker on a specific point on the Google Map. The picture in the attachment presents the resulting outcome.

Further examples can be found using the following link:
http://www.mashups4jsf.com/gmaps4jsf-examples/home.jsf

The gmpas4jsf provides JSF tags that make it easy to create a map using latitude and longitude or an address. You can add a marker to the map or an information text. Also some nice additional function like a zoom in and out or switching between map types can be used.
You can read an overview about the functionalities of gmaps4jsf using the following link: http://code.google.com/p/gmaps4jsf/

To calculate your coordinates you can use the Java API for Google geocoder v3
An overview about the functionality and also information about the Maven Repository can be found under the following link: http://code.google.com/p/geocoder-java/
The geocoder is an easy possibility if you want to search for a specifiy city or route that you want to presents in your Google Map.

Taggings:

Kill running process in a Unix-based console with the example of the Java Web Server Grizzly

1. Step: We need to find the proper running process in the background, for that we will use the command...


ps aux

... which lists all running processes which mostly is too long of a list:


jurgen 39191 0.0 0.8 904472 69368 ?? S 2:19PM 0:11.78 /Applications/Google Chrome
jurgen 39043 0.0 0.2 2524472 13976 ?? Ss 9:51AM 0:02.62 com.apple.security.pboxd
jurgen 38473 0.0 0.0 2467260 432 ?? Ss Tue03PM 0:00.20 com.apple.XType.FontHelper
...

So we filter out only the process that we are looking for, by using the command 'grep' and using the console pipe '|' to concatenate the commands


ps aux | grep java

Result:

jurgen 39543 0.1 1.9 4845420 163316 s008 S+ 5:49PM 0:07.18 /Library/Java/JavaVirtu... exec:java
jurgen 39573 0.0 0.0 2432768 460 s007 S+ 6:08PM 0:00.00 grep java

Now this returns us the proper process but also the 'grep' process itself which we were just running in our pipe, to filter this, we concatenate yet another 'grep -v grep':


ps aux | grep java | grep -v grep

... and we only get the process we need

jurgen 39543 0.1 1.9 4845420 163316 s008 S+ 5:49PM 0:07.18 /Library/Java/JavaVirtu... exec:java

Now that we have identified our process with its process number 39543 (second column in our process), we can terminate it with the 'kill -9'* command, as follows:


kill -9 39543

* If your wondering: The -9 parameter tells the kill-Command to send a SIGKILL signal to our process

In conclusion the following - more generic code - needs to be executed:

ps aux | grep [server_process_name] | grep -v grep
kill -9 [identified_process_id]

Taggings:

Stop Java process

Steps:

1. After login to the server where the process was running, we look for the Java process to be stopped (since the application is in Java, this should be visible in the process list). The "ps aux" command searches through all running processes and the "grep" command filters based on a key word:

ps aux |grep java

2. In order to be sure that our process is still active, we can look also for the specific name of the application:

ps aux |grep java|grep [application_name]

3.a. In case there are no other Java processes on the server (as it can be verified from the results of the first command), the easiest would be to kill all the Java processes:

killall -9 java

3.b. In case there are several Java processes running on the server, then from the results of the first command we can identify the process ID of our Java application. This process ID can then used for stopping the process:

kill -9 [process_ID]

Taggings:

Running Protégé 4.1 with JVM6

Solution

Problem description:
The problem occurs as Protégé 4.1 was build and working with Java version.
If you use version >6, like on up-to-date systems than you have to modify some things.

Precondition:
• Having also JVM (version 6) installed on your computer.

Steps:
1. Choose when downloading Protégé 4.1, download without JVM
2. When running the installer you have to choose a JVM at some point
3. Instead of choosing the up-to-date Java 1.7 choose instead Java 1.6 runtime
4. Run the application, be happy ;)

Pages

Subscribe to Java