Gotta love open source and github

The Problem

I have been working on this project to make our app run in any Java Container. Currently we run in JBoss, but ideally I would like the app to work in JBoss or Tomcat, or TomEE or Wildfly. One of the challenges in making this change is to remove JBoss specific dependencies from our app and pull those libs into the webapp as part of our project. We did the first piece of this a couple of years ago when we stopped using JBoss’ version of Hibernate and pulled a newer version into our app. We have since upgraded JBoss versions so this is somewhat moot since the bundled version and our version are the same, but it is one less thing that I will have to deal with as part of this project.

The first part that I have decided to tackle is not using JBoss’ built in transaction manager and instead bundling one. Looking around it seems like my choices are Atomikos, Bitronix, or JBossTM in standalone mode. Our situation is somewhat more complicated based on the fact that we are not running an XA jdbc driver. Originally the company was using one, but at some point ripped it out because Microsoft SQLServer wouldn’t work correctly or scale with it in there. We are aware of the limitations of not running in XA mode.

Bitronix

That alone rules out Bitronix as they pretty much require XA to do their thing. I had also sort of ruled them out given that the commercial company behind them ceased operating some time ago, and ideally we want to be in a position to pay a company for support. I will say one nice thing about Bitronix is it does have good Spring Boot support.

Atomikos

Atomikos does have a paid supported version if we found we needed it down the line and they have support for a Non XA datasource. Another thing Atomikos has going for it, is that we are already using it for our persistence unit tests, though not with the NonXADataSourceBean but rather with Apache Commons DBCP. I switched over to the NonXADataSourceBean version and most of the unit tests seemed to work which was promising.

JBossTM aka Narayana

At the end of the day though my thinking was the lowest risk solution would be to use JBossTM in standalone mode. Given that we are already using JBoss’ built in version of it this seems to be the least amount of change we can do. The first challenge is actually finding anything out about the project. Just searching JbossTM or JBoss Transactions doesn’t find much for you. I eventually discovered it is called Narayana. Ignore the horribly designed website, I just found that tonight, I originally found it on the JBoss home pages and on github. JBoss has a quickstarts example github repository showing you how to use their stuff as well. The Spring example was sort of what I wanted, but not exactly so I figured why not just do a quick Spring Boot app as a proof of concept. So I forked the repository and added a Spring Boot app. I hit a problem though, I created a unit test to try out reverts my insert wasn’t reverting on a Runtime exception. Just to make sure I wasn’t completely crazy I created a quick Spring Boot app doing the same thing using Atomikos. That test app worked perfectly.

At this point I feared I would be forced into switching to Atomikos as that was all that I could prove was working with a trivial test. I went over to the JBoss forums as a last ditch effort and posted a question about it. Back in the day when I would post things to forums I would often get very little response or things would be vague cause it is hard sometimes on the other side of a forum to be clear what a person is asking about. In this case I could just include the links to the two github repositories as examples of what I was trying to do. I posted it and didn’t hear anything back on the day. The next morning I woke up and saw that at 3am a Redhat Engineer in China had forked my project and provided a fix. Immediately I could see what I was missing and he made my test pass right away. Back in the day I probably would have given up and just gone Atomikos, but with github it is so easy to share sample code of what you are trying to do and Spring boot makes it so fast to stand up a sample app there is really no reason not to do so anymore.

 One more note while I was working on this experiment in testing how to configure different JTA managers the Narayana guys submitted code to Spring Boot 1.4 Milestone 2 to include a Narayana Quickstarter so now it will be possible to easily wire that into a Spring Boot app. I know I talk about the greatness of Spring Boot all the time, but once again it saved me a ton of time by allowing me to prototype out a few options before I go too far down the road of solving the problem, and with github allowing me to collaborate with people around the world, we truly live in some amazing times.

Spring Boot and Security using Spring Data JPA for authentication

Recently one of my friends was working on a Spring Boot project and he was having trouble finding an example of how to configure user login for his site with Spring Boot using JPA. I had mentioned that there is some mention of configuring security in Greg Turnquist’s book Learning Spring Boot. He had just purchased Spring Boot in Action and I don’t think he was rushing to grab another book, but he hadn’t been able to find a good online tutorial.

Today I was browsing Twitter and I came across exactly what my friend was looking for. Priyadarshini B wrote a great online tutorial on doing just that on her blog. The post was so great I wanted to share it. So head over there and check it out, you won’t be disappointed as it will walk you through the whole process.

JavaMug Spring Boot Discussion

I attended JavaMug last Wednesday as the speaker was Craig Walls author of Spring Boot in Action. When I heard about the book I had planned on purchasing it, but was disappointed there was no kindle version on Amazon. It does state if you purchase the print edition they will give you the kindle one for free, but I am trying to move away from paper books in general.

Overall the talk was pretty good. It is nice that there is a Pivotal employee local to the area so we can get a talk like this done. For most of the talk Craig just sort of demonstrated examples of what you can do with Spring Boot since there were people of varying degrees of experience with it. It was held at Improving in Addison which I had never been to, but they had some nice beer on tap (Kentucky Bourbon Barrel Ale). In a talk like this where you are just trying to introduce the concept to people it is hard to get as deep of a dive as I would like. But I did enjoy the part of the demo playing around with the metrics. That is something I haven’t really played around with, but of course got me immediately thinking about how much I would like to use that at work. I think maybe this year I will attempt to convert our legacy app to Spring Boot. It will be painful, but it just seems like more and more the benefits are so good that is what we should be doing. Hopefully I can find the time at work.

Then at the end of the talk they did a raffle and lo and behold I won the digital copy of Spring Boot in Action. I was pretty stoked about that given that I wanted that originally to begin with. When they get it to me and I get a chance to read it I will post a review up here.

Themes for 2016

As my holiday vacation winds down I decided it is time to figure out what my themes are going to be for 2016. Last year I did a fairly good job at hitting the themes I laid out for the year, so I Am curious to see how it will turn out this year.

  • The first theme is going to be the same. Regular updates to the blog ideally once a week, though as I saw last year I Didn’t quite make the weekly thing but I did average it given 52 posts. Hopefully I can keep the content somewhat regular this year.
  • I want to continue with reading like last year, but that number will for sure drop as we are expecting a baby in February and I know depending on my sleep situation reading may go right out the window.
  • At work I would like to migrate to Spring Security 4. This is going to be a bit of an annoying upgrade for us based on some of the changes, but I think this year is the year to bite the bullet and figure it out before we are dealing with Spring 5 in 2017.
  • At home I would like to play around with Swift and write my first iOS app. I have been programming Java for 17 years now and I feel like mixing it up a little bit to keep things interesting. I was actually going to work on that over my vacation, but I ended up getting Fallout 4 on the Steam winter sale and messing around with that instead.
  • I would like to restructure our webapp at work from an EAR Structure to a WAR structure. If that is successful I would then like to move away from JBoss to Tomcat. And if I got really crazy I would like to end up converting our Spring App to a Spring Boot App which would be a massive restructuring our our application. I think if I could accomplish all of that we would be in a great place going forward, but this is pretty ambitious as a side project and not sure I will be able to find the hours to get us all the way there.
  • I think it would be cool to contribute some sort of patch or something into the openjdk or Spring just to say I have contributed there. It just depends if I find enough time to find a small issue and work it out and do so.

At the end of the day whether or not I do any of these things doesn’t matter too much to me. It is sort of just setting some sort of milestones to track how my year is going. The main purpose of this blog is just keeping myself accountable so that I am always sort of improving a little bit each day, so if I find that I have nothing to write about then I can see I am not pushing myself hard enough to learn something new. Here is to another great year.

Recap for 2015

At the start of the year I posted my Themes for 2015. I decided now is a good time to look at what I was thinking at the start of the year and see how my year turned out. I think it is sort of pointless to set out some ideas of things you want to accomplish if you never stop and assess what you actually did, so this is sort of an accountability post to myself to see how things played out for the year.

  • On the first idea of working on weekly updates. I didn’t accomplish that. On the other hand if we look at it from a post count standpoint I did average that, so I would call that a pretty successful year for my blog even if there were points that I went a whole month without putting some thoughts down.
  • The next theme was to do more reading. Overall I was pretty successful with this. I didn’t always meet the 10% of my kindle book a day, but I did actually read more books than the previous year. I would call that a success, I hope to keep the momentum going, but with another baby on the way this year, I will probably read fewer books this year. I find that when I am overtired I can’t read as it just puts me to sleep so depending on how soon my little one is sleeping will depend upon how much reading I end up doing.
  • The next thing on my list was spending more time doing stuff in Spring Boot. I did a little bit of work on the side playing with the framework. I am convinced that this is the only way to do development with Spring going forward, but migrating a very large legacy app in that direction is easier said that done. On the positive side though our organization did roll out a new microservice in spring boot this year, so we are beginning to bring it into production. The real key will be migrating the bulk of our code to the framework.
  • The next idea I had was to try to learn Angular and get more serious with that. I can say that did not come to pass. I did take Code School’s shaping up with Angular.js course, and I just recently noticed they have added the next level to the free plan. I may end up messing with that over the coming year, but I am not sure. I am sort of watching to see if I think people start moving over to Angular 2 or if the change in compatibility is going to hurt the popularity of the framework. Also I am hearing more buzz about react.js so that is always an option to look at as well. Either way 2015 was not a year of doing front end stuff for me.
  • For my architectural updates 2015 was a huge success. It started off slow with having issues aspectj-maven-plugin. I was forced to fork the project temporarily on github as the maintainer showed now interest in rolling a patch that someone contributed to solve the problem. Then codehaus shut down. After they moved the project into github one of the other maintainers rolled the fix in when I pointed out it was in the old Jira. So I was happy to be able to abandon my fork of the project and get back on the mainline branch. Then I ended up ripping the whole Hibernate Metamodel Generator out of the project anyway which probably wouldn’t have necessitated needing the aspectj plugin update, but that happened later in the year after we needed that upgrade. After getting the aspectj plugin situation resolved I was able to get us upgraded to Spring 4.1. Even better than that we closed the year running the 4.2 branch. So that was beyond what I was hoping to get done. JBoss finally released EAP 6.4 in April which is what I had been waiting on in order for us to upgrade to Java 8. We were able to get the container upgrade into production this fall. Then a few weeks later we switched our VM to Java 8 with that JBoss and ran successfully with that. Finally near the end of my work year in December I was able to switch our compiles to Java 8. So we are now at a point where we can use all the new lambdas and streams and I look forward to playing around with it in January.

All in all I was very happy with my year. I will spend some time in the near future to figure out my plan for 2016, I have some big ideas at work I want to deal with and I even have a few ideas for home projects to mess around with too. So here is to a great year that just ended and an even better one going forward.

Update

I was thinking I should probably have noted anything big that actually happened that I didn’t predict.

  • I got to learn a bunch more Cassandra since I reworked our whole Cassandra Data layer as part of a big project to hide some of the complexity of what we are doing from the rest of the developers.
  • I took a team lead position so I now lead a group of 3 developers. I didn’t expect that at the start of last year, but it has actually been a great thing.
  • I started mentoring 2 other developers under a mentorship program at work. This started towards the end of the year, but I think it is going to be a great program. I think it will be a valuable part of onboarding new hires in the future when we hire people right out of university.

Spring Boot Actuator Guide

One of the most interesting Spring Boot features to me is the Spring Boot Actuator. I just love the concept of having all these restful endpoints to get useful operational data right out of the box. One issue I have had is that I don’t actually know all the endpoints just a few that I have used here and there. Today I saw a link to the Complete Guide for Spring Boot Actuator which is a pretty amazing post that covers everything and anything that you would want to know. The purpose of this post is just so I can go back and find this data later. If you are playing around with Actuators go and check out this post.

Spring Boot for prototyping

I am on a new project at work that looks to be very interesting. I am redesigning our Cassandra layer. Currently we have a beautifully done layer that was designed and implemented by our former architect. It ends up making Cassandra look just like a JPA entity and we have Cassandra Repositories that look just like Spring Data JPA Repositories. After this was in place we discovered the Spring Data Cassandra project. We went to the talk on Spring Data Cassandra and it turns out they had implemented pretty much the system that our architect implemented.

Now my goal for this project is to create a higher level Cassandra abstraction for our system. Often in Cassandra we create multiple tables to represent the same data. The reason is depending on how you structure the data in CQL determines what queries you can run. We have the need to query some tables in many different ways so we need multiple tables to be able to answer the questions that we could in the SQL world. In our architecture we don’t want the developer to worry about which table they need to query for a given question, we would like to present this more like a standard JPA entity where the developer doesn’t need to worry about it and we abstract away which particular table is being queried or which tables are being saved to.

One of the initial thoughts of this project was to use Spring Data Cassandra. The advantage of that is we would have a third party library we could use so we wouldn’t have to maintain the low level Cassandra code. At one point I was considering ripping out our custom Cassandra Data layer and just using the Spring Data one (prior to this project) as ours is so close to what they are doing anyway why should we maintain that code when there is a perfectly good library we could use and we are already using Spring Data JPA. Right now I am not sure if I want to do that anymore though. If I go with Spring Data Cassandra each of the underlying tables would need to be modeled as a separate entity like our current framework. In that case then I would need a second layer on top if I am trying to present 1 domain object backing multiple tables so this seems like it isn’t ideal for what we are thinking. Another thing I am not 100% on with Spring Data Cassandra is that it isn’t backed by Pivotal. It is a community plugin. That isn’t necessarily a problem but I do have concerns about how up to date it will be. One way to look at this is maybe I should be involved in the plugin since clearly I could be working on that as well, but I get a little concerned about if it will be around otherwise. I noticed that the Spring Data Cassandra project is built off of the Datastax 2.0 driver. So if we are running off of Cassandra 2.1 (which we probably will be by the time this project goes live) we aren’t necessarily taking advantage of the new features. Again I could submit a pull request to update it, but given that I am not sure this is the right approach anyway at this point I haven’t decided to go this route (though that may change). Another thing I noticed is Spring’s initializr doesn’t list Cassandra as an option out of the box. Though I suspect if you checked JPA and then added the Spring Data Cassandra to your maven pom or Gradle file it would probably work.

So how does this tie into Spring Boot? Well I am not a big design everything up front kind of person. I tend to like to play around in code to come up with my design ideas. So I decided I want to prototype against what we are doing so I can see how this design would play out in code. I downloaded a new Spring project from the initializr with AOP, JAX-RS, Actuator, and Shell support. I then pulled our code for our Cassandra layer into there and added the Cassandra driver to the maven pom. I updated the application.properties file with my Cassandra database properties and low and behold I was up and running with a framework to test all of my changes in. Even though I have played around with boot, seeing myself able to build a sandbox to play around with this design in so quickly was very impressive to me. So now I can evolve this design without messing up our current code base and when I get to something I am happy with I can just bring those changes into back into our branch and we will be ready to go with our new design. So even though I am stuck with a monolith and I couldn’t easily bring boot into our main product the design of our project is such that it was very easy to pull that whole layer into this project and just be up and running with almost no configuration (aside from setting up the Cassandra connection properties).

So as usual I think Spring Boot is the bomb and everyone should be using it. I look forward to seeing where this design takes me. Once I have my high level sorted out I may try playing with dropping Spring Data Cassandra in the low level to see if we want to use that as our base, but my current guess is we won’t end up going that route.

JHipster webinar

I saw this come across the Spring blog this week. They are going to be doing a webinar for JHipster. As I mentioned in a previous post I am very interested in JHipster as it combines 2 things I am interested in learning Spring Boot and Angular. If you are interested in checking it out sign up here.

Also as a completely unrelated side note, why doesn’t projects.spring.io support HTTPS? This is 2015 and all sites should really support secure access.

JHipster

I was reading the Spring Blog the other day and I came across this story. I was intrigued because I found the name funny so I read the post and watched the embedded youtube video and was completely blown away. Take all the excitement I had for Spring Boot after SpringOne and multiply it by 10. Not only does this build on top of Spring Boot it integrates in all the trendy front end technologies that are in use today. All the pain of bootstrapping and setting up a full on website is taken away while they do all the work for you.

JHipster is built on Spring Boot, Spring Security, Node.js, Angular.js, and Yeoman. Basically it manages to boil down every trendy front end technology with every trendy back end technology and do all the integration for you so you can start ripping code. They support Maven and Gradle as well as Grunt or Gulp. I admit I had never really heard of Yeoman or looked into it, but it is amazing. You can really automate a ton of your repetitive tasks with it so you can focus on solving the real problems you are facing. This project seems like a startup companies dream since all that monotonous configuration can just be skipped and you can focus on getting your application up and running and just out there.

This also fits in with my themes for the year where I wanted to spend more time working with Spring Boot as well as learning Angular and now I can all in the context of trying to build a small project under JHipster. Anyway the technology looks amazing and I would encourage everyone to give it a look and see what you think. Oh and a pro-tip if you are a non-hipster like myself running windows, when you do yo jhipster to generate your app, do it from inside of your git-bash window as if you use a normal windows cmd prompt it seems to fail in the course of generating the app.

Themes for 2015

As my Christmas vacation draws to a close I am starting to think of themes for 2015. Why themes and not goals or resolutions? Well I think resolutions are sort of setting yourself up for failure and goals are very rigid so I am going with more general themes.

  • Obviously the first theme I am working towards will be updating this site at least once a week ideally with something technical that I have learned during the week or thoughts on a problem I am solving.
  • Next on the agenda I would like to try to read more. I haven’t been reading as many books as I like to during 2014. But at the end of the year I have been picking up the pace a bit so I hope to read at least 2 books a month. My system I have been using is to try to get through 10% of a book a day on my kindle.
  • I would like to spend more time doing stuff in Spring Boot this year. I have been reading Greg Turnquist’s Learning Spring Boot and it is a great book which I strongly recommend. He seems to lay out the information right when I want it in the book and has saved me tons of time that I would have spent digging in the docs for answers otherwise.
  • Anyone who knows me know that I am not a big front end person, but as a full stack developer I need to know all the layers of the stack, so I think 2015 is the year that I need to learn Angular JS. I learned Knockout JS in 2014 and appreciated how much more productive it was for things than just jQuery and it seems to me that the market is all going Angular and people say it is more productive than knockout so it is time to give it a try.
  • I am hoping to do some architectural updates at work. I am ready to get our stack upgraded (I want to be on Spring 4.1 and Java 8 at a minimum and ideally JPA 2.1 as well instead of 2.0). I always prefer to run the latest stuff so I will be working hard to make sure that I can do so. On that note I submitted a Jira for the issue holding me back on Spring 4.1 related to the aspectj-maven-plugin. With any luck I will be on Spring 4.1 at work within the next 2-3 weeks. Java 8 may take a bit longer as it is going to mean a container upgrade.

Anyway that is what I have come up with so far I am sure more things will apply as time goes on, but this is a good start to my year plan. Now to enjoy my final 2 days of vacation before I return to work.