Categories
Computing

JMS 2.0 Standalone Applications

For a project of mine, I was looking to connect a standalone Java application via JMS with a GlassFish 4 backend service. To put it in other words, I wanted to run GlassFish 4 and get access to the JMS queues and topics from a standalone container.

Having done this before with GlassFish 3.1. and JMS 1.8, I figured this be an easy migration task.

Wrong. As it turns out, it is not quite as simple. However, here is the solution to it.

I assume you are building your standalone application with Maven or, preferably, Gradle. The only artifact that you need to add to your build file is

compile 'org.glassfish.main.appclient:gf-client:4.0'

That alone should give you access to your GlassFish’s JMS queues. It doesn’t though. Instead, it will give you

Lookup failed for 'jms/__defaultConnectionFactory'

if you try to connect to your queues. As an example, use the following code:

QueueConnectionFactory connectionFactory = ServiceLocator.getInstance().
                getQueueConnectionFactory(Constants.JMS_CONNECTION_FACTORY);
Queue queue = ServiceLocator.getInstance().getQueue(Constants.JMS_QUEUE_OUTBOUND);

Connection connection = connectionFactory.createConnection();
connection.setExceptionListener(new JMSExceptionListener());
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

MessageConsumer consumer = session.createConsumer(queue);
consumer.setMessageListener(this);
connection.start();

After trying around for a while, I found that (at least in the current version that I am using) you will also require two additional jars:

  • imqbroker.jar
  • imqjmsra.jar

See also this thread on stackoverflow. If you have both jars in a subdirectory called “jms”, you can just add the following dependency to your gradle build script:

compile fileTree(dir: '../lib/jms', includes: ['*.jar'])

Note: The GlassFish Maven artifacts have huge dependencies, in particular gf-client:4.0 requires about 60 MB of libraries.

Categories
Computing

Clojure: Importing a Leiningen Project into Eclipse

To import a Leiningen project into Eclipse, so that you can use CounterClockwise with all its nice features, such as syntax highlighting, there is a handy plugin called lein-eclipse.

To get started, all you have to do is to add this plugin as a dev-dependency in your project’s project.clj.

(defproject my-project "1.0.0-SNAPSHOT"
  :description "My Clojure Leiningen Project"
  :dependencies [
        [org.clojure/clojure "1.2.0"]
        [org.clojure/clojure-contrib "1.2.0"]
	[ring/ring-jetty-adapter "0.2.5"]
  ]
  :dev-dependencies [
        [lein-eclipse "1.0.0"]
  ]
)

Then, you need to download the project dependencies via

prompt> lein deps

This will automatically install lein-eclipse and add a new task called eclipse to leiningen. Invoking

prompt> lein eclipse

runs this task and creates the Eclipse projects files .project and .classpath. Now you can simply import the project into Eclipse via “File->Import->Existing Project into Workspace”.

Categories
Computing

Android: NullPointerException when scrolling through a MapView w/ ItemizedOverlay

When I implemented a MapView with an ItemizedOverlay (the implementation steps are described in the Android developer documentation), I encountered a flaw in the API, or at least in the corresponding documentation. If you add an ItemizedOverlay to your MapView, but do not add any OverlayItems (which may be the default for your application, with OverlayItems being added during runtime), scrolling through the MapView causes the following NullPointerException:

ERROR/AndroidRuntime(232): java.lang.NullPointerException
  at com.google.android.maps.ItemizedOverlay.getItemsAtLocation(ItemizedOverlay.java:617)
  at com.google.android.maps.ItemizedOverlay.getItemAtLocation(ItemizedOverlay.java:586)
  at com.google.android.maps.ItemizedOverlay.handleMotionEvent(ItemizedOverlay.java:498)
  at com.google.android.maps.ItemizedOverlay.onTouchEvent(ItemizedOverlay.java:572)
  at com.google.android.maps.OverlayBundle.onTouchEvent(OverlayBundle.java:63)
  at com.google.android.maps.MapView.onTouchEvent(MapView.java:625)
  at android.view.View.dispatchTouchEvent(View.java:3709)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:852)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:822)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
  at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
  at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:123)
  at android.app.ActivityThread.main(ActivityThread.java:4363)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:521)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  at dalvik.system.NativeStart.main(Native Method)

After long hours of debugging, I was able to find help in the Android Bug Tracking system. An easy workaround for this problem (which should really be addressed in the API and/or the corresponding documentation) is to add a call to the “populate()” function in the constructor of the class that extends ItemizedOverlay. Then, your subclass constructor should look like this:

super(boundCenterBottom(defaultMarker));
populate();

This solves the problem and scrolling, even without any OverlayItems, works like a charm.

Categories
Computing

Reverse Engineering a PostgreSQL Database

When working with relational databases it might come in handy to visualize an existing schema. Microsoft Visio supports such a reverse engineering of most databases in a remarkably easy way. This little tutorial assumes that the database to be reverse engineered is a PostgreSQL installation.

Therefore, the first thing you need to do is to install the PostgreSQL ODBC driver.

Second, you can start Visio and create a new “Database Model Diagram”. Select the “Database” tap, and your window should look like this:

Visio Reverse Engineering

Now, select ‘Reverse Engineer’ and create a new data source. Choose “User Data Source” and “PostgreSQL Unicode”, as seen in the following screenshots. Enter your database connection credentials and test it.

Creating a PostgreSQL User DSN
Creating a PostgreSQL User DSN

If the User Data Source was successfully added, you should be able to select the “Generic ODBC Driver” and the specified PostgreSQL data source.

Visio Generic ODBC Driver

After filling in the correct username and password, you can for instance specify which object types you’d like to reverse engineer.

Visio ODBC Setup

The result of this process is a nicely layouted diagram of the corresponding database.

Example Reverse Engineered Diagram
Categories
Computing

Java Servlet & JSP Form-based File Upload

Surprisingly, Java Servlets and JSP do not have build-in support for handling form-based file uploads. However, there are several open source libraries available for this purpose, among which the Apache Commons FileUpload is one of the most stable. This post will demonstrate how to use this library to handle form-based file uploads using JSP technology.

Two files will be required for this to work: the Apache Commons FileUpload library, as well as the Apache Commons IO library.

In order to install them correctly, one needs to extract the downloaded archives and copy the commons-fileupload-<version>.jar and commons-io-<version>.jar to the WEB-INF/lib directory of the web app that is to be developed. If these libraries rather be available to all web applications on the server, the jar files should be copied to $CATALINA_HOME/shared/lib/, where $CATALINE_HOME is the root directory of the Tomcat installation.

The following assumes that two files have been set up: first, a simple HTML file with a form that allows the user to select the file to be uploaded. Note that enctype=”multipart/form-data” is essential here.

<form method="POST" action="action.jsp" enctype="multipart/form-data">
  <input type="file" name="file"/>
  <input type="submit"/>
</form>

Second, a file action.jsp that receives the HTML file’s HTTP request and processes it. To do so, it will need to import several packages:

< %@page import="org.apache.commons.fileupload.servlet.*"%>
< %@page import="org.apache.commons.fileupload.disk.*"%>
< %@page import="org.apache.commons.fileupload.*"%>
< %@page import="java.io.InputStream"%>

The next thing to do is to check if the HTTP request is correctly encoded in the multipart format.

if (ServletFileUpload.isMultipartContent(request)){
  // Process the request
}

The actual parsing of the request is done via the ServletFileUpload class and the DiskFileItemFactory class. Here, the uploaded file is stored as a byte array in the session.

ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());

try {
  @SuppressWarnings("unchecked")
  List< fileitem> fileItemsList = servletFileUpload.parseRequest(request);
  for (FileItem fileItem : fileItemsList) {
    if (fileItem.isFormField()) {
      /* The fileItem is not a file, but rather a name-value pair. */
      String name = fileItem.getFieldName();
      String value = fileItem.getString();
      // business logic here
    } else {
      /* The fileItem is an uploaded file. */
      byte[] fileData = fileItem.get();
      session.setAttribute("file", fileData);
    }
  }
} catch (Exception ex) {
  /* Possible exceptions include the file exceeding the upload size limit. */
}

This is only a very basic example, of course, and may not perform well with large files for example. Moreover, you might want to change the default settings for parsing the HTTP request, using the methods setSizeThreshold() and setRespository() of the DiskFileItemFactory class and the setSizeMax() method of the ServletFileUpload class.

Categories
Computing

ISTQB Certified Tester – Foundation Level

Today, I took the ISTQB certification exam for the foundation level and some things struck me that might be of some interest for future examinees. As one has to sign a formal obligation saying that you’re not allowed to give information about exam questions, I cannot be very specific. However, here are some hints:

  • The standard textbook for the exam, “Software Testing Foundations – A Study Guide for the Certified Tester Exam” written by Spillner and Linz, is suitable for giving a survey and it prepares you very well for the chapters “Tool support for testing”, “Fundamentals of testing” and some other. Learn them by heart!
  • Still, even if you know the whole book literally by heart, there is only a not-so-good chance to pass! In order to be really good prepared, you should also learn the Syllabus, which can be downloaded from the ISTQB website. You should learn the Syllabus really good, otherwise a lot of questions are unanswerable, because they do not depend on understanding but the wording of the Syllabus.
  • Some questions are really incomprehensible, even if you are well prepared. At least one question in my exam didn’t make any sense, so you better anticipate that some questions are like gambling.
  • The word is that some people offer sample papers / sample exams / sample solutions on the web. If you like, use them to a impression of how questions are asked, but better be careful with the solutions–they often are wrong! So, don’t rely on things on the web, but on the Syllabus.

The examination results are send via email one week after the exam, at the latest. Of course, I’m gonna post my results as soon as I get them.

Update:
Just got my results: PASSED with 85%! 😉

Categories
Computing

3DScanner completed

Gauss 3D-ModelToday, after 4 months’ work, we completed our team project software 3DScanner. The project’s goal was to capture real-world objects of any size and recreate them as 3D models in a virtual environment.

3DScanner has a lot of advantages compared to other (even commercial) products. Firstly, only one camera is needed. Any off-the-shelf digital camera can be used. It does not have to be stabilized in any way (i.e. no tripod necessary), neither does it have to be calibrated. Camera calibration takes place automatically after downloading the images to a computer.

The process is fully automatic, only silhouette images have to be created manually. We propose using GIMP to cut out the objects and and fill the background with black. Then, 3DScanner is able to create a mesh in the obj file format.

For further information, please visit the project website.

Categories
Computing

OpenGL with GLUT

For I have only found few explanations about how to use the GLUT library for OpenGL programming with Visual Studio 2008, I’ll give it a try myself:

  1. Download the GLUT library from
  2. Unzip it
  3. glut.h – needs to be copied to the include/gl directory within the Microsoft SDK installation dir.
  4. glut32.lib – at the same place, but in the lib subdir
  5. glut32.dll – put this in the System32 dir.

Now, in Visual Studio create a new project as console application. Then, open the project properties, go to the Linker tab. Under Object/Library modules add

opengl32.lib glut32.lib glu32.lib

Finally, include <glglut.h></gl> in your source and you’re ready to go!