понеділок, 16 квітня 2012 р.

Jersey as yout REST impl in standalone app

Just today morning I wrote a simple standalone application which works with REST as a server (and client). Well, server-client application via REST. In general, the idea is pretty simple, but I was disappointed when got next exception: A message body reader for Java class java.lang.String, and Java type class java.lang.String, and MIME media type text/plain was not found. wtf? I googled this problem and found there are problems with packing META-INF/services/*. Not sure, but it seems happens when you use Maven to assemble your Jersey application. Fortunately, the solution is very simple and fast. You have to add next plugin to your pom.xml ServicesResourceTransformer For now, all works:)

середа, 14 березня 2012 р.

Execute commands in parallel via SSH

When you need to manage one web-server (or AS) there isn't problems. because you make all operations just one time. But what about next situation: you have several servers and need to do the same operations several times? Of course, you can repeat your set of commands several times. However there is much better solution - Capistrano. In fact, it was developed in Ruby and for Ruby projects need. Don't worry, you can use it not for only Ruby applications:)
Capistrano uses special DSL for specifying commands.
Yeap, it's perfect solution for executing commands in parallel

вівторок, 6 березня 2012 р.

how to add logger to class in one click

Hi! Just a simple genius way to add logger to each java class in one click (for Eclipse)
There is Eclipse template, to add this one go to Windows — Preferences — Java — Editor — Templates — New
And text of template:
${:import(org.slf4j.Logger, org.slf4j.LoggerFactory)}
private static final Logger log = LoggerFactory.getLogger(${primary_type_name}.class);

середа, 15 лютого 2012 р.

патерни українською

книга з патернів проектування від львівського розробника
http://designpatterns.andriybuday.com/
усі патерни описано дотепно та весело, читати можна (і навітьрекомендується) не зважаючи на приклади мовою С# (і відповідне неканонічне форматування коду)

вівторок, 14 лютого 2012 р.

calc median in mysql

Aloha! As you know, MySQL is a very poor rdbms, but cheap. There aren't a lot of build in functions, special for statistic processing...
But imagine, you need to calculate median. It seems very easy, isn't it? Well, I have bad news for you - Mysql doesn't have this aggregation function.
I've googled it and found several solutions, but all of them have a problems with performance and ugly plan... So, I created own stored procedure (inspired by comment to http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html)

CREATE PROCEDURE calcMedian(IN tbl CHAR(64), IN col CHAR(64))
BEGIN
DECLARE counter INT;
SET @counter:= 0;
SET @s1 = CONCAT('select floor(count(',col,')/2) into @counter from ',tbl);
prepare rowsCounterStmt from @s1;
execute rowsCounterStmt;
SET @s2 = CONCAT('select ',col,' from ',tbl,' order by ',col,' asc limit ',@counter,', 1' );
PREPARE stmt FROM @s2;
EXECUTE stmt;
END


Another way: you can use User defined function as explained here http://mysql-udf.sourceforge.net/. In fact, it's much more powerful solution, but it's not suitable for all of us

пʼятниця, 10 лютого 2012 р.

funny trap : JUnit vs TestNG

I've found a funny trap just several minutes ago:) If you have strong background in JUnit and then you start coding in TestNG, you can fall in trouble with asserts.
In JUnit we have: assert(expected, actual)
In TestNG: assert(actual, expected)
So, be careful!

понеділок, 16 січня 2012 р.

use runtime data in soapUI


If you are using SoapUI for web-service testing, you can want to set up some data in the request in runtime (for example, for testing purposes).
The easiet way to set up date time in runtime is:
Time_is_${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm").format(java.util.Calendar.getInstance().getTime())}

Also, you can get values from system setings or from special property file:
${System.getProperty("some.property")}