The road so far….

April 7, 2013

Spring Recepies : URI redirection

Filed under: java — Tags: , — Rahul Sharma @ 6:51 pm

We have a application which has gone through a short developments sprints. Things got added and then some got modified or removed etc. During this phase a number of service URLs got added/removed/modified. Now if such an application is getting crawled by Google, the you have a mess to clear about. Clearing such a mess is not easy, some URLs should give 301 to a relevant page which some should show 404 and 500 status errors. More over there can be other requirements from the application like domain/sub-domain redirections eg making http://www.myapp.com to myapp.com, ver1.myapp.com to ver2.myapp.com etc. (more…)

March 1, 2013

Tip ! : How to call static method from JSP

Filed under: java — Tags: , — Rahul Sharma @ 9:25 am

Every application has some user information which it displayed to the logged-in user. My application also has the same information, but at few places it needs to be converted to JSON format as well, besides being displayed. Now either I can pass this JSON information from my Controller or I can somehow reuse the existing information that is being  passed. I choose the second route, but then the next question comes to your mind is how to convert this  on server-side ? on client side etc. ? Since we already had a static method to do  such conversions so I needed to figure out a way how I can call the same static method which could do the conversion on JSP  ?

Answer : Spring EL, is the way to do this. Using this you can access any static method of a class or an Enum on the JSP.


<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>

<s:eval expression="T(com.rahul.devlearnings.MyClass).callStaticMethod()" var="data1" />

<s:eval expression="T(com.rahul.devlearnings.MyEnum).enum.call(data)" var="data2" />

February 1, 2013

Mongo, the silent killer!!

Filed under: java — Tags: , , — Rahul Sharma @ 6:22 pm

I was pretty much convinced that Mongo db is not the best choice for an application.  But a recent incident makes me believe that it is a silent killerof the application. As you work with it and  increase the amount of data/ concurrency  you realize  its one or more pain points.

Our application was working fine,  and one fine day one of the bugs got reported signup is not working as expected. It was creating user but could not login them. The app was not updated from quite some time, no changes to the schema how could this happen. So then we searched for logs, and it was sparkling clean !!! But still no user creation and other db operations, for some reason. After some debugging we realized that saves are getting called but data is not available in mongo after the operations and surprisingly it does not throw errors. WTF !!!
(more…)

December 6, 2010

Embedded DB + AbstractRoutingDataSource + Hibernate = Data Router Application

Filed under: java — Tags: , — Rahul Sharma @ 9:40 pm

Spring 3 contains a new feature of embedded databases. You could efficiently use this feature for an application at the start of a developement or for tests concerning db access or for smaller use cases of data storage. Basically using this feature you could start any of three viz. HSQL, Derby, H2. These all create  in memory database instances and you could create schema and import data in them. The EmbededDatabaseBuilder API offered by Spring can be used to create instances of  EmbededDatabase. The EmbededDatabase is of type Datasource and can  be plugged into the SessionFactory. This makes it easier to use these APIs for tests and smaller use cases where you will be required to create the database, perform actions, verify/show results and  just shutdown.

While this is an interesting API offered by Spring 3, I tried to use this API with one of the interesting ones introduced in Spring 2, the AbstractRoutingDatasource API. Using this API we could have two different data bases and then depending on some criteria shuffle our data in different( Homogeneous/Heterogeneous ) databases. This is an abstract class and you have to implement it for the business criteria for shuffling data . Also the offered API is of type Datasource and is pluggable in the SessionFactory. But by doing this we need standards that will remain same across different databases i.e. SQL,  as the goal is to have an  unaware access to all the databases. So using SpringJdbc looked quite promising and thus accomplished the task. (more…)

November 22, 2010

Mixed approach of loading java.util.Properties using Spring

Filed under: java — Tags: — Rahul Sharma @ 8:05 pm

Last week  I was attending a training where we were developing  a command line application. The application had  few static properties that were stored in a properties file and few of them where supposed to be generated when the application would start.  The application was using Spring, so loading the Properties file was a simple use case of using PropertiesPlaceholderConfigurer but the complication came from, how to load the properties  that were generated when the application started ? (more…)

Older Posts »