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
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.
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:
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:
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:@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;}
Note there are several different ways to solve this problem, so it's worth investing some time to digest the Jackson documentation.{"type": "One"
, "att1": "hello from SubOne!"}
or
{"type": "Two"
, "att2": "hello from SubTwo!"
}
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:
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 aTalk about saving your day!int unsigned
data type and the foreign key column uses anint
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 theint unsigned
data type.
Subscribe to:
Posts (Atom)