Sunday 25 November 2012

Using a Null Modem Emulator for Testing


A recent application needed to send messages to an Epson DM-D110 display.  The device is connected via a serial cable.  My problem was I didn't have the device, or indeed even a serial port on my computer.  How to test sending data to a serial port?

Turned out there's a very simple solution, use a null-modem emulator.  This will, in effect, create 2 virtual serial ports and connect them.  Your application can then write to one port and you can use something like PuTTY to read the output from the other:

                         null modem emulator
      application ---> COM4 <----> COM5 --->PuTTY

I can now run my application and see the output (in PuTTY console) that would have been sent to the display.

Saturday 13 October 2012

Online Education

Education establishments (including some pretty prestigious universities) seem to be falling over themselves to offer free online eduction, for example:
edX (MIT, Harvard and Berkeley)
Coursera (33 Partnered Universities)
Udacity
there are even sites that attempt to collate online education courses, for example:
Class Central
This is an exciting development, particularly for the IT industry.  IT evolves at a fantastic rate, you cannot take a university course in your late teens and expect it to carry you through your career.  You will need to learn new skills, concepts and paradigms throughout your career.  You may also need to become re-acquainted with previously learnt, but subsequently forgotten knowledge.  Unfortunately not many will have the oppourtunity to go back to university full time mid-career, so a piecemeal approach is required.  The phrase "Continuing Professional Development" has been coined, but everyone should be doing it regardless of whether it's formalised or not, if you don't you may find yourself trapped in a legacy role.  Perhaps these online courses offer a solution.  They cost nothing (as opposed to extortionate professional training) other than your own time.

Another approach is a paid-for part-time university MSc course, these are becoming more flexible with universities offering block mode tuition (course modules are taught intensively over a week) and online options, rather than the more traditional, but less flexible 2 or 3 days a week on-site.  The major advantage of this is (hopefully!) a recognisable award at the end of the course.

In summary, things seem to be converging towards a more flexible, fair and accesible approach to further education which can only be good thing.

Sunday 5 August 2012

Spring Core Certification Exam



To become certified you must take the official Spring course and pass the exam.  The Live Online delivery method works well (they use WebEx) and is a little cheaper, especially if booked in advance.


I used the following resources to prepare for the exam:

* Re-read the training manual
* http://www.springsource.com/files/core-spring-3.0-certification-study-guide_0.pdf
http://springcert.sourceforge.net/
* http://knowledgeblackbelt.com/#!Exam/12904481
http://www.springcertification.co.uk/core-spring-certification-mock-test.php
http://www.javaranch.com/jeanne/Spring_3_Certification_Study_Notes.pdf
http://www.skill-guru.com/test/81/core-spring-certification-mock

Follow-up:  I passed first time.   I've starred the most useful resources above.  Official advice is to re-do the lab work, but this isn't an efficient use of your time IMHO. The exam is not as tough as the Java Programmer, but you do need good Spring knowledge.  I've been working with Spring for a number of years, but I doubt I would have passed without some revision.  Know the Container, AOP and Transactions inside and out and you're well on your way.  Good luck!

Friday 27 July 2012

OMNIKEY 3821 driver popups when inserting card

This PINpad installs easily and generally plays nice, but on Windows 7 you get an annoying and unsuccessful attempt to install a driver (with associated popups) every time you insert a card.

This is caused by the Microsoft Smartcard PnP service, which can be disabled by adding the following registry key (Although this is a simple fix, note Microsoft's advice:  This is the least-recommended option. You should use this option only if the cards are legacy cards and there are no plans to implement smart card minidrivers in future.)


HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\ScPnP
EnableScPnP   REG_DWORD   00000000

You'll probably need to reboot as well.

Further reading:
http://www.hidglobal.com/main/technical-support/ 
http://support.microsoft.com/kb/976832
http://lazybit.com/index.php/2010/10/20/smart-card-driver-for-windows-7-popup

Wednesday 18 July 2012

Spring Integration Exception Handling

Sooner or later you're going to have to deal with exceptions, it's essential that you understand exactly how they work, yet the Spring Integration documentation is fairly lightweight in this area.  Start by reading this as many times as it takes to sink in:  Error Handling

Understand the key differences between direct and asynchronous communication:
  1. With direct channels there is no hand-off between threads, the functionality is all handled in the same thread and exceptions (wrapped in a MessageHandlingException) are propagated and caught as usual
  2. Asynchronous commmunication - for example a queue channel - involves multiple threads, this creates complexity like how to pass back exceptions and transaction management (the standard transaction context is thread bound).  To handle the asynchronous exception problem SI wraps the exception in an ErrorMessage and places it on an error channel (again read the Error Handling link to understand which error channel it will choose).  You can call getPayload() and generally cast the result to a MessagingException.

Thursday 10 May 2012

Windows 7 Corrupted Smart Card Base Components

Windows isn't a natural platform for me and occasionally I end up doing pretty dumb things in frustration.  Like installing Microsoft NT Win32 Smart Card Base Components on a Windows 7 machine.  This corrupted the smartcard setup.

I knew this because my smartcard app ran ok on a Windows 7 guest virtual machine, but not the Windows 7 host (on which I'd done the above).

This blog entry fixed the problem: Install the smart card service on Windows 7 and Vista

A big thank you to Lazybit :)

Tuesday 1 May 2012

seeking 2560x1440

Despite conflicting advice from Dell support, a Dell XPS 14z laptop does work with the Dell UltraSharp U2711 out-of-the-box @ 2560x1440.  Tested with an Accell B119B-007J Mini DisplayPort to DisplayPort cable.  Very nice indeed.

Thursday 26 April 2012

soapUI: Service Mocking and Database Connections

Start script: Stop script: and remember to copy mysql-connector-java-5.1.19-bin.jar to soapui/bin/ext directory

Wednesday 25 April 2012

JavaScript links

jsBin - test JavaScript snippets (simple and clean)
jsFiddle - test JavaScript snippets (support for common frameworks)
jsPerf - JavaScript performance
Eloquent JavaScript - book for learning JavaScript
JavaScript Date, UTC and local times

Sunday 15 April 2012

CognitiveTPG A798 Logo Loading

I needed to load some logos for a demo.  Other POS printers I have used have had helpful utilities for uploading logo images to the printer.  Not it seems the A798....  I only cracked it after reading and re-reading the Programmer's Guide and an extraordinary piece of luck...

From the CognitiveTPG Downloads Page you can obtain a Printer Configuration Utility for POS printers.  Download and install this (as well as the appropriate driver).  Unfortunately there doesn't appear to be any manual for this utility (I asked their tech support but was referred to the Programmer's Guide.  UPDATE 16/04/2012: tech support have now sent me a PPT hmUtility guide and some additional instructions on logo upload - very similar to what is described below), so there's a lot of scratching around in the dark....

Run hmUtility.  I have a USB connected printer.  The utility Port Selection reads "USB, PRINTER CLASS, ON".  If it says "USB, PRINTER CLASS, OFF" double click on it.

Prepare a BMP logo file.  Note this must be a 2 colour monochrome BMP.  You could use GIMP (Image->Mode->Indexed->Use black and white palette) to do this.  If you  use a RGB or Grayscale BMP it won't work.

If you want to upload more than 1 logo, select the current logo number.  Go to "Configure" and type "1D 23 XX" (XX is the desired logo number) into the Command Selection Cmd box and then press "send".

Then go to "DLoad BMP" and double click on the .bmp you wish to upload.  After a short while you should see soemthing like "Port1 download is complete".

Test print the logo by going back to "Configure" and typing "1C 70 XX 00" (XX is the logo number) into the Command Selection Cmd box and then press "send".

I think loading by script is also possible - take a look at SampleConfigurationScript.txt ([BMP] command) in the hmUtility installation directory.

Saturday 7 April 2012

Jackson JSON: Deserializing polymorphic types

Let's start with some terminology.  When dealing with Jackson, serializing is the act of converting your Java object to JSON and deserializing is the opposite, i.e. converting JSON to your Java object.

Polymorphic types present a challenge when deserializing.  How does the mapper know which Java subtype object to create?  The soultion is to include some extra metadata to the JSON which specifies the subtype.

Jackson supports a number of ways of doing this - see JacksonPolymorphicDerialization.  I found this page a little tricky to understand, particularly the subject of using a logical name to determine type.

I specifically did not want to use JsonTypeInfo.Id.CLASS or even JsonTypeInfo.Id.MINIMAL_CLASS.  These seem like bad practice as you end up exposing implementation details in the JSON.  Do you really want to be exposing the fully qualified name to your application class?  Also, in terms of efficiency, it's an awful lot of wasted characters.

So I went for the JsonTypeInfo.Id.NAME solution, here's a dumbed-down example:
@JsonTypeInfo(use=Id.NAME, include=As.PROPERTY, property="type")
@JsonSubTypes({
    @JsonSubTypes.Type(value=SubOne.class, name="One"),
    @JsonSubTypes.Type(value=SubTwo.class, name="Two")
})  
public class Base {
}

public class SubOne extends Base {
    private String att1; 
}

public class SubTwo extends Base {
    private String att2;
}
The property="type" refers to a field in the JSON only, it is not deserialized into the Java object.  Here is some example JSON that you could now feed into your deserializer:
{"type": "One", "att1": "hello from SubOne!"} 
or
{"type": "Two", "att2": "hello from SubTwo!"}
Note there are several different ways to solve this problem, so it's worth investing some time to digest the Jackson documentation.

Tuesday 3 April 2012

MySQL: ERROR 1005 ADD CONSTRAINT FOREIGN KEY

I couldn't figure this error out until I read Michael McLaughlin's Technical Blog:

decoding-1005-on-mysql

As suggested this was my problem:
The most common variation that I’ve run into is where the primary key column uses a int unsigned data type and the foreign key column uses an int data type. It’s quite nice that the InnoDB Engine stops this cold. Naturally, you fix it by changing the foreign key data type to match the int unsigned data type.
 Talk about saving your day!

Tuesday 27 March 2012

Transaction marked as rollbackOnly

This exception is exceptionally frustrating: 

org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:476)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at $Proxy75.call(Unknown Source)
    at org.springframework.integration.endpoint.AbstractPollingEndpoint$Poller$1.run(AbstractPollingEndpoint.java:207)
    at org.springframework.integration.util.ErrorHandlingTaskExecutor$1.run(ErrorHandlingTaskExecutor.java:52)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.persistence.RollbackException: Transaction marked as rollbackOnly
    at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:73)
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:467)
    ... 12 more


 ....of course you want to know what set the rollbackOnly flag and why.  Here's one way of finding out:
  1. Attach to application with debugger (e.g. Debug Tomcat)
  2. Assuming Hibernate is the underlying implementation, break on the setRollbackOnly() method in org.hibernate.ejb.TransactionImpl (Eclipse tip: use Ctrl+Shift+T to search for a class)
  3. when the debugger breaks on this method you can bubble up the call stack in the debugger and usually find out what caused this transaction to be marked as rollbackOnly.
Thanks to Useful Code Snippets blog:  But why was my transaction marked as rollbackOnly?

Wednesday 21 March 2012

O2 Mobile Broadband (UK)

A SIM with no instructions and it's a little tricky to figure out how to connect to O2 Pay & Go mobile broadband.  These settings worked for me:

APNm-bb.o2.co.uk
Usernameo2bb
Passwordpassword
Number*99#
AuthenticationPAP

Then go to https://mobilebroadbandaccess.o2.co.uk to check your balance, top-up, etc.  I assumed I had to create a "My O2" mobile account, but that doesn't appear to work with mobile broadband.

Friday 17 February 2012

Kick Remote Desktop (RDP) user

You try to RDP onto a machine but get this error:


The simplest way to remove an idle connection (Windows 2003):

1) log into a machine on the same network
2) select the Terminal Services Manager (or Start->Run tsadmin.exe)


3) right click on network in left pane, select "Connect to Computer".  Enter required IP or hostname
4) right click on user in right pane, select "Log Off"

Thursday 16 February 2012

Debug Tomcat Windows Service from Eclipse

1) Launch "Configure Tomcat" GUI
2) On Java tab under Java Options add the following 2 lines:
-Xdebug
-Xrunjdwp:transport=dt_socket,address=127.0.0.1:1044,server=y,suspend=n
alternatively, and preferred since Java 5.0, add the following line:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044


3) Restart Tomcat
4) In Eclipse go to Run->Debug Configurations.  Create a new Remote Java Configuration with the following settings:
Connection Type: Standard (Socket Attach)
Host: localhost
Port: 1044

Change server/port as appropriate.

To detach press this button:

Further Info:

> java -agentlib:jdwp=help

            Java Debugger JDWP Agent Library
            --------------------------------

(see http://java.sun.com/products/jpda for more information)

jdwp usage: java -agentlib:jdwp=[help]|[<option>=<value>, ...]

Option Name and Value            Description                       Default
---------------------            -----------                       -------
suspend=y|n                      wait on startup?                  y
transport=<name>                 transport spec                    none
address=<listen/attach address>  transport spec                    ""
server=y|n                       listen for debugger?              n
launch=<command line>            run debugger on event             none
onthrow=<exception name>         debug on throw                    none
onuncaught=y|n                   debug on any uncaught?            n
timeout=<timeout value>          for listen/attach in milliseconds n
mutf8=y|n                        output modified utf-8             n
quiet=y|n                        control over terminal messages    n
suspend=y tells the jvm to wait until debugger attached

Java Virtual Machine Tool Interface
More Info on JVM TI and writing agents
Java Platform Debugger Architecture (JPDA)
Java Debug Wire Protocol (JDWP)

Friday 3 February 2012

Subject Alternative Name

I'm using Spring Integration to talk to a HTTP/REST service.  To secure the link I set up mutual SSL authentication.  I now get the following error:

java.security.cert.CertificateException: No subject alternative names present

I'm talking to an IP address rather than a domain name, the RFC2818 specs say:
In some cases, the URI is specified as an IP address rather than a
hostname. In this case, the iPAddress subjectAltName must be present
in the certificate and must exactly match the IP in the URI. 
This blog entry is also helpful to understanding the problem:


Under the covers Spring Integration is using a HostNameChecker which is throwing the exception.  The next line of the exception stack confirms:

 at sun.security.util.HostnameChecker.matchIP(Unknown Source)

I will need to set the IP address as subject alternative name with type IPAddress (key=7).  In Java 6 or lower, keytool does not support X.509v3 certificate extensions:


OpenSSL is an alternative way of generating certificates with extensions.  However, I chose to download Java 7 and the new version of keytool:

# create keystore and generate client key pair
keytool -genkey -alias client -keyalg RSA -validity 3650 -ext san=IP:<ip address> -keystore .\client.keystore -storepass <password> -keypass <password>

Export and import into client's truststore as before and the no subject alternative names problem is fixed :)

Tuesday 24 January 2012

amaysim Mobile Broadband (Australia)

Another virtual operator on the Optus network.  Good value smaller prepaid data packs.  amaysim mobile broadband.  Untested modem settings:

APNinternet
Username[blank]
Password[blank]
Number*99#
AuthenticationNONE

Friday 20 January 2012

Editing Windows Services

In regedit go to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Service.

Wednesday 11 January 2012

Optus Mobile Broadband (Australia)

The following modem settings for worked for a Prepaid SIM:

APNpreconnect
Username[blank]
Password[blank]
Number*99#
AuthenticationCHAP

See Technical Settings & APNs