from my work as a developer
technical
copy pattern
Jun 8th
Recently I’ve joined a new ongoing project. In theory it should have been easily jump into it, but as usual each project is specific. The team developed a custom framework to generate JSF view base on an entity class. The framework after first look is quite simple, but as always the devils is in the details
So, I’ve spent a bit of time to catch up what is real going on. The next thing I had to implement was an option to export entire view to PDF – there was already an example how to do it and I followed it. Just copied the source and started adjusting it to my needs.
That’s the Copy Pattern. It’s used very often when you join a new project, when you learn a new language, when you do something first time. You need a pattern to base on, to follow.
So, it isn’t a bad idea to use the copy pattern, but you cannot stop on that. After first step, after you grasped the problem you must apply another patterns – real software development patterns. Leaving the code as is after using the copy pattern is bad – we’ve seen it a lot in many places. The copy pattern is just a beginning, is the easiest way to get into the project.
And the beauty of this is that you can change the name of the class, extract methods, extract new classes – just before messing with a code repository, before posting too match changes,that no one will know what is really happening;-)
Don’t be afraid to use the copy pattern, but also don’t stop on it!
And as usual at the end a talk from TED, this time about a car for blind people. And about new control interfaces we can face soon
Enjoy!
laugh, laugh, …
Feb 2nd
It was quite busy beginning of the year. I was working on the two projects – in both partially
Anyway I found out the way how to handle such situation. What works the best are the short Sprints (Scrum), about a week. So I’m working hard one week on the first project and at the end of the week I’m delivering some peace on a functionality. Next week I’m starting a new Sprint but for the second project.
In such a case, I can focus and get into the project for a long time. I don’t feel disrupted that I forgot to finish something.
On the beginning I was trying to switch the project each day, but it worthless and useless. Human’s brain needs up to 20 minutes to switch a context. For large tasks (like a project) even more, for me it was around half a day to get into – to check what I did previously, what are the new task and where the project is in matter of functionality.
Short Sprints demands a short estimation and short tasks. After second, third sprint I’ve got used to it
And it was even funny to work that way – short sprint are the best!
To be more specific what I did, I’m going to share my deep knowledge with you
The first project is related to Circular – I’m writing a Desktop Client which will be able to communicate throughout a REST API with the service. Is written in Java Swing and the latest Java 1.6 brings many new futures to cooperate with a Desktop System. The first is the java.awt.Dekstop class. It can be used to open file with a default editor, open links with the default browser and so on. Very useful class. The next is the javax.swing.SwingWorker class. It’s used to launch long running process which must communicate with a Swing UI, e.g. to display progress.
You’re wondering why I’m using the native Swing instead Eclipse RCP or NetBeans Platform. The answer is easy – size of the file. With the current solution, the executable file has around 3.6 MB with all the dependencies included in it – you can use Maven Shade Plugin to do it. I’m also using a modified Launch4j Maven Plugin to create Windows Executable file from my Mac OSX – the modified source code you can find here.
The second project I’m working on is the Attikis service. It’s used to monitor Alarm Systems throughout a phone line. The UI is built using JavaServer Faces 2.0. And the last time I spent the whole day to solve a problem with the SelectManyListBox tag that has a custom converter attached to it. In such a case, you must use a bean with well defined equals() and hashCode() methods or just a simple String as a SelectItem. In other case you will end up with strange error: Field not valid!
It’s a very weird behaviour, whilst you will attach a built in converter, you can use Integer or what else you want
Ok, that’s it for today and at last I’ve got something from TED that I want to share with you
camels and rollbacks
Dec 16th
I had been preparing a new Struts 2 release for last few weeks. It contains only a tiny change regarding security and I had been counting that it shouldn’t take more than a week to release it. How wrong I was
Everything had started smoothly, I’ve created a new Subversion branch, to not interfere with current on-going development of the new Struts 2.2.2. The branch was made from Subversion tag (yeah, branches, tags and trunks are all the same, just copies
). Next, I’ve applied a patch to solve the security hole and I was truly sure that’s it – I can start the release process. So I’ve gone ahead, mvn release:prepare command went smoothly, so the next step was mvn release:perform. And after almost waiting 1h I’ve got a strange looking massage: not all licenses were approved !?!
The first thought, I’m using the latest Maven 3.0.1 and that’s the problem, but it wasn’t. I started looking into RAT plugin source code to check what could be wrong. I’ve just discovered that the plugin is checking wrong Apache License header but also looking for the License’s URL so it should be ok. The origin of the problem was quite simple. The Maven Release plugin allows to make release only from a SNAPSHOT version, so I’ve changed the version only in the parent pom of the project. The rest was unmodified. After changing all the version signatures in all the poms the problem was gone
To launch another release process I’ve had to rollback all the changes made during previous launching release command. mvn release:rollback did the job but I’ve had to manually remove the tag from Subversion repository. And of course I’ve removed the wrong one
Thanks to Wes for a tip how to rollback such a huge mistake, the command looks like this:
svn copy https://svnrepo/project/tags/TAG_1@10 https://svnrepo/project/tags
TAG_1 is the removed tag, number 10 is the revision -1 when the tag was removed.
So I’ve started again, to make a release and again something went wrong. I noticed the release plugin is making a tag base on wrong path – it was using the original path of the tag from which the branch was made of instead the branch path. And again I’ve had to rollback all changes and remove the tag – this time the correct one
Resolution was easy – change scm tag in all the poms to point to the branch
And again, I’ve started the release process and this time everything went more than smoothly, all the artifacts were uploaded to Apache Nexus, so the last think before calling a vote was to close a staging repository. And again I was wrong, during that, Nexus reported that two jar files don’t have corresponding files with signature. I’ve checked locally and everything was ok. After short conversation with guys from support, I’ve got the solution – upgrade to latest Apache Parent
Yep, easy, but to do that I’ve had to once again rollback everything, prepare a new Struts Parent that will inherit from the latest Apache Parent, release it and call for a vote
Finally, after almost 2 months I was able to release Struts 2.2.1.1 – the vote is under way, so if you are Struts PMC, please test the release and vote!
Just to relax a bit, take a time and watch that very inspiring talk about camels:
migration and bosses
Dec 1st
The whole last week I was migrating my current project from the JBoss AS 6 M2 to the JBoss AS 6 CR1. First of all I had been thinking it should be easy, just switch few things, use other Java packages and so on. Niether I had been expecting some problems nor it will take a week. So I’ve just started my migration “project” – yep, you should always treat it that way, it isn’t just renaming packages or tweaking some configuration files. It’s a huge project that either can take a hour or a week. So be prepared!
To move to the JBoss CR1 I had to also switch to latest versions of our internal libraries, commonly called SML Commons. The main problem was with the CDI Extension package, which base on WELD. During switching the version I discovered some problems during an application deployment. First of all Bean Manager was missing in JNDI context. Googling and looking through existing solution didn’t help. I had to prepare a demo application and try to register an issue with JBoss’ JIRA. The problem was, that my demo application was working just fine with the JBoss CR1. Just Adam was able to break it – the trick was to include in EAR package another module as a Java JAR archive with CDI enabled beans. Then the application blown up!
After few hours we got answer to the problem – add additional beans.xml file to WAR archive!
So I thought the rest should be easy, but wasn’t
The next problem was with the application’s tests. All the tests that were base on Arquillian started yielding – wrong dependency in Maven pom, I had to remove few of them, cut out some unused profile and everything went smoothly.
So, the next problem was with Selenium and it looked strange as the whole JVM blown up with irritating ”red zone” message. And till now I don’t know what it was, maybe just wrong configuration or missing dependency. And during solving that problem I discovered a really interesting CDI behaviour. When you defining a bean with @Produces annotation you have access to the InjectionPoint object. It provides many different information about where your bean will be injected.
But there is a slight diference how InjectionPoint.getBean() is working. If your @Produces annotated bean will be used / injected in already CDI managed bean, getBean() will return that bean. But in other way it will return null
Finally, I gave up
After passing all that problems, another one hit me directly in the face and I haven’t had enough energy to solved it. I shelved all my changes with IntelliJ IDEA and returned to normal coding work, ufff….
And just to change my attitude, today’s morning I got monthly newsletter from TED and I want to share with you that brilliant talk about why bosses and meetings are boilerplate at work, enjoy!
making a cloud
Nov 8th
Recently I’ve been changing a cluster configuration. Maybe it isn’t a real cluster, it looks more like a cloud or load balancer. The ingredients are as follow:
The problem I had was that I just want to enable clustering for given VirtualHost section and not for the whole Web server. Current configuration was quite simple, as you can find out on mod_cluster’s web page. On the JBoss AS side you must uncomment one line or so and provide list with mod_cluster enabled web servers.. But as I said, such configuration enable clustering for the entire web server. I didn’t want that, as I want to create another Virtual Host to serve static content.
So, the first step was to read the documentation, but it didn’t answer my questions. I was trying many different configurations and what I achieved was a separation of Virtual Hosts – I could define the different clusters for different Virtual Hosts, but still wasn’t able to serve static content
The answer was simple, just disable creation of balancer for all Virtual hosts with this directive:
CreateBalancers 1
The second thing was to enable use of aliases (and disabling advertising as it isn’t supported by Amazon EC2)
UseAlias 1 ServerAdvertise Off
Also on JBoss AS I had to define the Alias:
<Host name="localhost"> <Alias>my.domain.com</Alias> ...
The rest was easy, just I have had to enable use of Virtual Hosts on given IP address, specify the web server name and define the Virtual Hosts. After restart everything seemed to work perfectly. I had static pages under one domain name and an application under second. The only problem was that I wasn’t able to login to the application. Why? Simply, my session wasn’t a Sticky Session. And not because JBoss server didn’t support it. Much simpler. My session ID wasn’t passed to the JBoss server and back to the Apache HTTPD
To solve that I just had to add ProxyPass and ProxyPassReverse directive:
ProxyPass / balancer://mycluster/ stickysession=JSESSIONID|jsessionid nofailover=On ProxyPassReverse / balancer://mycluster/ stickysession=JSESSIONID|jsessionid
And that was the end, everything was working smoothly. But the customer decide not to use the same server for load balancing and serving static pages. So all my work was useless, except experience I’ve got
Anyway it’s a very elastic configuration, as you can add another JBoss servers and attach them to the cloud in a minute.
The whole configuration just for future reference:
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_ajp_module /usr/lib/apache2/modules/mod_proxy_ajp.so
LoadModule slotmem_module /usr/lib/apache2/modules/mod_slotmem.so
LoadModule manager_module /usr/lib/apache2/modules/mod_manager.so
LoadModule proxy_cluster_module /usr/lib/apache2/modules/mod_proxy_cluster.so
LoadModule advertise_module /usr/lib/apache2/modules/mod_advertise.so
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
ServerName www.domain.com
NameVirtualHost 10.10.10.10:80
DocumentRoot /var/www
CreateBalancers 1
ServerAdvertise Off
UseAlias 1
<VirtualHost 10.10.10.10:80>
DocumentRoot /var/www
ServerName www.domain.com
ServerAlias domain.com
</VirtualHost>
<VirtualHost 10.10.10.10:80>
ServerName my.domain.com
ProxyPass / balancer://mycluster/ stickysession=JSESSIONID|jsessionid nofailover=On
ProxyPassReverse / balancer://mycluster/ stickysession=JSESSIONID|jsessionid
<Location /status>
SetHandler mod_cluster-manager
Order deny,allow
Deny from all
Allow from 127.0.0.1
#Allow from all
</Location>
KeepAliveTimeout 60
MaxKeepAliveRequests 0
</VirtualHost>
playing scrum
Jul 21st
At last, out team grow up and started using Scrum. It was a spontaneity idea, we had been left to our self for two weeks and during that time we had to delivery specific functionality. As usual, the specification wasn’t prefect and we haven’t had anybody to ask.
So we decided to use Scrum, even if fail it can be a funny experience
The first step was to organize our Task Board, with ToDo, In Progress and Done columns. Below we put our Backlog. We haven’t had a real Planning Meeting and it was a mistake (but that brought to our minds after the First Iteration). We just wrote down all the tasks that were assigned to us, put on ToDo column yellow posits and started the First Iteration.

Every day we had StandUp Meetings where each developer said what he did, what he is going to do and what blocks him. And we use a Talking Stick
That went smoothly more or less with additional discussion. Each day I was updating the Burndown Chart and we discovered that we can do tasks faster than we planned. And we have been basing on 4 hour work day – you know, average developer spend 50% of his time on coding
The First Iteration took around 7 days, after that we had a Demo. It was a simple task, our business analyst took all the posits and walk round each developer and asked to present given functionality. It was the best think, we discovered many small bugs or mistakes. That was the end of the Iteration One!
We also did the Retrospection and basically we agreed that we must improve our StandUp Meetings and be more accurate when describing the tasks.
Right now we started the Second Iteration and we’ll see…
avoid reflection
May 14th
The Java Reflection API is a very nice future of the Java language. With the API you can do the Magic with Java classes, create an object or call a method on fly base just only on a name. The real Magic!
So then, we all should use it all the time, to write a better code, yes? NO!
Avoid using it, try to write a code without the Reflection. The worst you can do is if you introduce some generic mechanism with it – a custom validation framework or a flow engine where class and method names are stored as a String (in a text file or a XML file).
You can ask: why?
The answer is simple: your IDE doesn’t support it! When you refactor your class or method, eg. just rename it, IDE will find all the references and change them appropriately for you. But IDE won’t know about your custom solution, is just a text, nothing more!
When you are using the Reflection, your IDE is blind!
Right now I’m working on our custom validation framework, to move definitions of validation from a XML file directly to a Java code. The case is, to not to change the validators, just used them as is. And not to use the Reflection as well
I’ve done some draft implementation base on anonymous classes and the word “final” (thanks Rafal for the tip!). And introduce the ValidationAware interface to be able at the same time use the old way and my new solution! Next week on Monday I will ask other team mates for opinion!
are you affraid
May 6th
The last two weeks I’ve been simplifying an application flow engine base on Apache Struts 1 – I know it’s a bit old technology but I don’t care, I have a job to do
Anyway I discovered lot of strange use cases where some custom mechanism was build instead to use what was already provided with the framework. It was like inventing a wheel once again! Frankly, I was truly surprised how someone could do this that way. And I start thinking what was the reason to do that…
The only thought came to the mind that someone was afraid to use what was already provided to him with Apache Struts 1 – he didn’t know the framework well, he was too lazy to check sources, and so on. I was real devastated! If someone doing application in such way, no framework will help him or do the job for him!
Recently I’ve been solving issues in Apache Struts 2 and one of them was to add wildcard support to a file upload mechanism. Provided patch had solved that problem with some home made RegExp engine. I just added a test case to proof it was working properly and committed all the changes to a source code repository. After that a more experienced Committer pointed me out that I should use existing PatterMatcher class instead, what I did and the code looks much better right now. You can see an example here Apache Struts 2 useful beans.
storm is comming
Apr 23rd
Yap, it’s true!
It will demolish all available PHP development environments! You are probably thinking – ”what’s he talking about?! PHP for Java developer??”. Yeah…. I wasn’t Java developer from beginning, I started my professional career as a PHP developer – the first earned money I got was for a web application I wrote in PHP! That was an amazing time, no unit tests, no bullshit about craft and so on. What was the most important – customer satisfaction!
Never mind, after 7 years I had to go back to PHP. It’s impressive, yeah? 7 years without problems and any issue. Marvelous!
Previously I used ordinary text editor to write the application, but nowadays I thought there should be something better – we have the craft, so with the craft you must have THE tools.
The first place I checked was The JetBrains side and they didn’t disappointed me – what I found was The JetBrains PHP Storm! Still in Beta but who cares
The first thing I noticed after installation was that I was able to open the application without any “Import”, “Converting” and so on. Just open it and develop (with pleasure)! What can I say, just astonishing!
Today I discovered another brilliant feature “Compare with deployed version”! What’s that? Is the same functionality when you are comparing your local changes with version in source code repository.
And the result is:
And the most important feature it has is that I can use exactly the same keyboard shortcuts I’ve been using for InetlliJ IDEA! With pleasure
do it on client side
Mar 18th
This post is regarding my previous one about hacking Axis 2. I was asked to try to use Handlers instead of my brilliant hack! Easy to say
I was googling trying to find any example how-to do it on client side. There is a plenty numbers of examples for server side. In theory it should be easy – implement Handler interface and add it to particular phase in execution queue – easy? Yes! In practice not really
I wasn’t able to find any example how I should instruct Axis 2 client to use my handler. I found that I must create axis2.xml configuration file and put on class path, then Axis will auto-magically read that file and my handler will work! In practice it didn’t work, to inform Axis 2 base client that it should use that specific configuration I had to change the way how I was creating stubs.
URL resource = getClass().getClassLoader().getResource("axis2.xml");
ConfigurationContext configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, resource.getPath());
MyClientStub myClient = new MyClientStub(configurationContext, "url://to.web.service");
I based my axis2.xml file on original one from main Axis 2 jar. I just removed classes that have been depending on JavaEE 5 (J2EE rulez!) to had everything up and running! I added my handler to OperationOutPhase phase – hopefully is the correct one
The funny thing was that each time I started my WebLogic server my start up environment just blown up! After stopping server I had to reinstall it to be able to rebuild a project
Anyway, my first approach got positive opinion and will be implemented! Uff… I could get rid of this whole Axis 2 custom configuration!


