Monday, October 13, 2014

jHipster, the super baby in SpringRoo's pouch !

In this development productivity blog, I share my excitements about being productive using approaches such as code generators and seeing dream of having that iWAOW application really taking shape over the lazy weekend !


But I was kind of disappointed that my favorite code generator tool, to be specific "app generator" tool, Spring Roo went into maintenance only mode ! I was hoping Spring Roo would get new releases which included modules like Spring Boot, Spring Data Rest on backend and most importantly, greatest and coolest new technologies on front end. For example, Angular JS, Ext-JS/Sencha, Backbone JS. But looks like Spring guys decided to keep Spring Roo where it was. There are some valid reasons SpringRoo was demoted. For example, First of all, the revolution on front end technologies is so huge, that it is not primary business of Spring guys. Also, Roo is based on OSGi which is not much preferred technology by developers, with the debut of Spring Boot, Spring Roo is too old to refactor I guess.

Spring Boot ! (projects.spring.io/spring-boot)


I was excited to listen to launch of Spring Boot live at Santa Clara SpringOne convention, but after trying that, I realized, it is quick way to boot the spring application, but it did not have the command I was looking for, something like

> boot create entity <entityName> ( quick googlers don't copy paste this command please ! :)

This is the cool command I was looking for, but realized that boot had totally different purpose, like gathering dependencies in flash of a second by just looking at the code and following convention-over-configuration approach. That is cool too !

Playing With Play! (playframework.com)

During all this disappointment that Roo is being (only) maintained by some small company in Spain, I was looking who is that can replace Roo. I also checked Play Framework, tried some sample programs but turned out that was from totally different world where even java programmers deny there is standard like Servlets ! But that's fine, I realized great companies like LinkedIn has contributed and used Play a lot and it gives fantastic results. But it is another framework like Spring and I was looking for something on top of base framework which helps in creating at least CRUD application.

jHipster ! (jhipster.github.io ) 

During this search I did have an idea there is one weird named Hipster trying to leap like Roo with all greatest technology stack and here it is, I waited until it's born as stable release and I do see exactly what I looking for,

yo jhipster:entity <anEntity> (Create entity anEntity )
yo jhipster:service aService ( Create service aService) 

Yo !!! Yes, I did say it for the magic it would do and create CRUD angular page including Spring server side, but YO here also mean Yeoman ! The super-cool CRUD generator for 100+ web frameworks is base of jHipster ! In fact, jHipster is one of those hundreds of plugins, called "generators" written to generate server side code using Spring's latest offsprings like Spring-Boot, Spring Data, Spring Data Rest etc..

You can just land on this page and get tired of reading how many plugins have been already written, here you go http://yeoman.io/generators/


Now back to jHipster, I am thrilled about jHipster because, using all these already cool frameworks, it generates full stack web application using Angular and Spring ! Look at the great questions it asks when creating jHipster application !
  1. What is the base name of your application? 
  2. Would you like to use Maven or Gradle? - So, decide your server side build manager !
  3. What is your default Java package name?
  4. Do you want to use Java 8? - Cool ! 
  5. Which *type* of authentication would you like to use? - Superb ! You can also choose OAuth 
  6. Which *type* of database would you like to use? SQL / NoSQL ?
  7. Do you want to use Hibernate 2nd level cache? - Hardcore server side engineers know how it helps !
  8. Do you want to use clustered HTTP sessions? So by default, very minimal in session, almost stateless which is need for scalability.
  9. Do you want to use WebSockets? Applause ! 
  10. Which *production* database would you like to use? Means, you can have different databases already configured in production and development.
  11. Which *development* database would you like to use? 
  12. Would you like to use Grunt or Gulp.js for building the frontend? Cool - Options here too ! 
  13. Would you like to use the Compass CSS Authoring Framework? Incredible ! Compass is most advanced tool to generate CSS.
Imagine the comfort you get by having all these dependencies in your app right there when you start the development !

Hmm.. There are so many technologies embedded as a inherient part of jHipster.

HTML5BoilerPlate - So you dont have to worry adding things like Modernizer on your own. This boiler plate takes care of old browsers too, so many old-school browsers got taken care of.

Twitter Bootstrap : Need to talk anything about this most popular project on Github ?

Bower : Dependency management on client side ! Very popular now a days ! 

Karma, PhantomJS : When it is angular, no need to really mention this as it comes part of Angular. But just not to forget !

Following on server side !

Boot should be mentioned again and again because Boot was mentioned again and again in this year's SpringOne (which I did not attend btw :) , for architecture style of Micro-service. Spring guys have Boot everywhere now a days ! 

And when it is Spring world, I dont have to mention Spring Security, Spring MVC etc Right ? 

I am also so much impressed with what jHipster has for production readiness ! Monitoring with Metrix (which I dont know !) , caching with something called HazerCast (sorry, Dont know this too ) .

Conclusion : 
So in short, jHipster is like a Monster Platter you order in restaurant and avoid hassles of thinking of each item separately and getting that great feeling "I have everything" ! 



Monday, March 17, 2014

Has REST architecture finally put JSP to rest ?

I remember my development manager's sarcastic laugh with his bouncing shoulders when I had tried to access JSP tags from Javascript ! :( That was my first web application project as an intern and I was learning all Servlets, JSP etc. after my short journey in plain java.  I had gotten totally confused with crazy mix of HTML + CSS + Javascript + Java + Scriptlets + JSTL + Struts + whatever is missing in this list.. ! It took me some time to understand what exactly is going on with all these buzzwords of that time..

May be writing JSP is better than writing servlets with "out.println", may be writing JSTL/Struts is better than writing scriptlets, but whenever I looked at any JSP I always thought it was perfect example of "kitchen sink" ! Both kitchen sink and JSP kept on reminding me of each other for years ! And I still feel about JSP the same way !

In all this chaos, Sir Roy Fielding (@fielding) was contemplating to transform this restless world of web development into RESTful world with REST architectural style ! Thanks to him, we are seeing this beautiful architectural style which separates client code and server code so elegantly. It's like marriage made in heaven by giving freedom to each other !


For Those Who Don't Know REST :


For readers, who don't know REST, it's Representational State Transfer ! Still don't get it ? It is based on the concept that all web is made up of "Resources" and when we use web-site as user, we keep on changing the state of the application. So, in short, it's "representing the state of the application" which is "transferred" to the user. Also, we perform 4 basic operations on resources. These 4 operations are popularly called as CRUD, Create, Read, Update and Delete. These 4 operations are (usually) accomplished using POST, GET, PUT and DELETE methods of the HTTP protocol.

Why REST ? :



Current device-diversity and the numerous development platforms have made sure you don't have any other way (mostly) than to go the REST way. And new HTML5 capabilities, increase in javascript efficiency and iOS/Android native platforms have made it easier to go REST way. REST has made the server a real server as its name suggests and has been given the responsibility of doing back end stuff only. So now server just provides data and thats what it should do ! It has nothing to do with HTML, CSS and client side Javascript. So there is no JSP where web designers and server engineers both try to cram in their art ! Though CSS makes web designer's silo to play, not everything can be isolated so much in this JSP model.

It's not just advantages of client/server code isolation and cleaner code, there are so many other advantages in this modern world of application development using RESTful style.. Of course, reader should keep in mind that the REST is a "style" not a "specification", so nothing is wrong or right in REST! (and actually I don't like to say this, sounds so clumsy but.. )

Here are some of those
  1. RIP that troublesome session object on server side ! : REST is stateless. Good REST design sends user-id and  password in every request ! Or at least uses cookies in web-friendly client. So there is no need of long living session object on server side. User is authenticated every time and user data is live only for that request. In today's high performance hardware, authenticating user every time is not at all big burden compared to the advantages it brings.
  2. Cloud computing friendly : Advantages of above fact ? It helps us to RIP those session replication needed for failover as well ! Less memory requirements on server side because no more session objects of million of users. Plus, adding virtual machines in cloud is now does not have the complexity of adding those machines as session buddies in those jboss-like application servers ! So simple round-robin load balancing could be good enough.
  3. Readable and cacheable URLs : Unlike usual web application URL, where parameters are in the URL itself, REST application web URL is clean because all parameters take form of request body rather than the URL and submitted in the form of Json/XML object. Typical URL can be like http://www.example.com/appName/resource/<resource-id>. Being clean URLs, resources can be cached in better way than parameter based URLs.
  4. Versioning freedom (at least in pure REST) : Original definition of REST likes client application start from root URL and subsequently get URLs of further resources. It avoids client to have pre-defined sets of URLs to avoid continuous changes in client code if server URI changes. This is also called HATEOAS (what a scary looking word by the way). It means Hypermedia As The Engine Of Application State. Server provides hypermedia as the state of the application. So even if there is any change in URLs, client does not need to know since client only follows the path provided through server provided objects. 

Practical REST : 


Though ideal/pure REST promotes HATEOAS as mentioned above, practical problem is, that the communication becomes too chatty.  It may end up making hundreds of calls to just show personalized front-page for the user. So many practical people go for fixed API. They handle versioning in different ways. For example www.example.com/v2 or v2.example.com etc.

For this approach, client code needs to change every time there is change in URL. But some avoid this problem by just adding new version related attributes in the payload itself. Next version clients can use those extra/new information, old version client will get the same payload but would not even know what the extra attributes are and will just keep ignoring it.

Everywhere REST


  1. Now most of the leading code generators like Spring Roo, Play framework use RESTful URLs, even in traditional model of JSP (by keeping URLs RESTful ). 
  2. New world of Micro-Services is based on RESTful interaction between those services. New initiatives like Spring Boot helps create REST applications quickly using embedded servlet containers making micro-services easy to develop. 
  3. Spring now now also has Async support for REST using AsyncRestTemplate. 
  4. Almost all Javascript libraries support RESTful calls. Spring now has getting started guides for many Javascript frameworks for consuming RESTful services based on Spring as backend. For example, Spring REST with angular.js https://spring.io/guides/gs/consuming-rest-angularjs  

Conclusion : Pay Your Respects For JSP ! :)




Tuesday, January 14, 2014

Spring Data Should be Renamed to Spring Datta ?

In this Google era, everything should be searchable and Spring Data definitely needs its re-naming ceremony and some cool looking name ! In fact, many of Spring sub-projects needs it's own name like Apache has been doing.

So "Datta" or Dutta is short form of "Dattatreya" and originates from India and it means "God". Spring Data deserves that stature anyway, doesn’t it ?! :)  And if you you don't want to be religious, the same Datta has been transformed as powerful street fighter Dhalsim ! http://en.wikipedia.org/wiki/Dhalsim . I have found Spring Data so powerful, I can't stop writing about it in this usually-developer-productivity-related blog !


Spring Data
For them, who have not used or read about Spring Data. It is name of the umbrella project for everything related to Data. So, Spring Data JPA is working with data using JPA. And Spring Data MongoDB is same shell but works on MongoDB.

Flip-phone Vs Smart-Phone

After reading about Spring Data, I remembered start of my software development career with Java Prepared Statement ! It's like remembering your flip-phone after handling your new S4 or iPhone 5s.
I remember those arguments to pStmt (you remember this variable name ? ) and how I screwed with sequence of arguments ! :)

Then came Hibernate where I could make use of my Object oriented mind to map database tables to objects and I was partially relieved from switching my mind from OO to Relational !

New Logo ? Spring Datta ?
You might ask what Spring Data brings compared to Hibernate/JPA. It goes beyond or on top of JPA/Hibernate where you get far more than only mapping database entities to java objects. Those basics are done by JPA/Hibernate as usual.
Here are some Datta like features of Spring Data ! I am usually excited about any framework's feature which reduces the time of development drastically ! So I would mostly focus on "productivity" features of Spring Data.

Forget about SQL , remember the English !

This is the feature I was really impressed and it got me tempted to try to believe it ! :) Not that I don't believe the new spring.io documentation, in fact it's way too improved and I love those getting started guides ! Short and sweet, plus their sweet requirement in the list of "What you will need"- "You need to have 15 minutes" :)

So what I tried was this. As per documentation, just write the method names in right way, you will get implementation automatically ! So here is my simple method name and it worked so nice !

CustomerRepository customerRepository = context.getBean(CustomerRepository.class);
customerRepository.findByAccountsInternalType("PremiumChecking");

Here each Customer has one or more Accounts. Account has "InternalType" as one of attribute/column which may indicate say Checking, Savings , PremiumChecking etc. So this little piece of English "customerRepository.findByAccountsInternalType("PremiumChecking");  means find customers who have accounts with internal-type equal to PremiumChecking. Wow, this has saved me so much joins or criteria I would have to write if I was using just Hibernate or JPA. So you can go endless findByTable2Colum2Table3Column4 and so on..

And of course you can use all the grammar. For example words like "Between" , "Like" and what not ! See here  http://docs.spring.io/spring-data/jpa/docs/1.2.0.RELEASE/reference/html/#repository-query-keywords

I have used Spring Roo extensively and was amazed by it's auto-generated finder methods but it could never do cross entities join but Spring Data can do it !

Many modern databases are joining under Spring Data umbrella :

As I mentioned above, Spring data is umbrella project and all this "English Vocabulary" can be used on many databases like MongoDB, Neo4J , Hadoop , surely many other databases joining under the umbrella to handle the rain of data from all directions.
Spring data not only works with databases but the same interface can be used for distributed memory like Gemfire too.

Talk in DSL as well :

Spring data supports QueryDSL as well to ease writing complex finders in your code which is more readable. Here is the example by queryDSL itself.

List<Customer> result = query.from(customer)
    .where(customer.lastName.like("A%"), customer.active.eq(true))
    .orderBy(customer.lastName.asc(), customer.firstName.desc())
    .list(customer); 

Add REST on top : There is another project called "Spring Data REST" based on Spring data. I dont know much about it at this time, but I am sure it adds effortless REST support on all what Spring data can do and makes your "modern webapp" development super easy.

Conclusion : One can be super-productive using Spring data ! Go for it ! :)

My tweets on similar topics