Tuesday, January 18, 2011

Making DevNexus.com more Restful

A few people had ask me, whether I can make the data of DevNexus.com consumable for other clients (e.g. Android or iPhone). Sure, no sweat - As I expose the URL in a somewhat RESTful fashion already, I thought exposing a variety of different data representations is not hard but it turned out to be a bit more tricky than I thought but I will blog about that in the next 1-2 days or so.

Under the covers I am using Spring MVC 3.0 that provides the Rest infrastructure, Jackson for the Json marshalling and Jaxb for marshalling the XML data. 

First of all, here is what I have accomplished: The page that returns a list of presentations and the page that returns a list of speakers, will both return the data in either XML or JSON as well. Bear in mind this is still a fairly rough cut and the data representation may still change quite a bit.

Anyway, these are the exposed endpoints so far:

http://www.devnexus.com/s/presentations
Returns any of the other following 3 data representations depending of the Accept Http header. (However, a defined file extension always wins over the Accept header.)
  • http://www.devnexus.com/s/presentations.html
  • http://www.devnexus.com/s/presentations.xml
  • http://www.devnexus.com/s/presentations.json
http://www.devnexus.com/s/speakers
Returns any of the other following 3 data representations depending of the Accept Http header. (However, a defined file extension always wins over the Accept header.)
  • http://www.devnexus.com/s/speakers.html
  • http://www.devnexus.com/s/speakers.xml
  • http://www.devnexus.com/s/speakers.json 
As Accept headers the following values are acceptable and handled right now:
  • application/xml
  • application/json
  • text/html
For testing the Firefox plugin "Rest Client" works really well:  https://addons.mozilla.org/en-US/firefox/addon/restclient/

As mentioned above, I will blog about the technical details and encountered issues in the next couple of days. Also, if you try to consume the data and run into issues and or have suggestions - ping me and add a comment!

Tuesday, January 4, 2011

Spring Mobile, jQuery Mobile and SiteMesh

I just realized that I haven't published a blog entry in a while. Time just flies by. Anyway, I am in the midst with several other volunteers to prepare for the Atlanta-based DevNexus developer conference which will take place March 21-22.

For this year's conference I reworked the conference website application using Spring (MVC) 3.0, JPA 2.0 etc. In addition to standard clients, I started looking into supporting mobile clients as well.

My requirement was to provide a decent looking mobile interface in a reasonable amount of time (heck, it is all done during my spare-time afterall). Plus, I wanted to support multiple mobile devices at once. Out of that reason I ruled out a native client implementation (at least for now).

Another option, would have been to look at other development frameworks such as PhoneGap and Appcelerator, something I may still have to do down the road.

As I have been using jQuery quite a bit, I started exploring it using either jQTouch or jQuery Mobile. I opted into looking at jQuery Mobile as it is the official jQuery sanctioned project.

As it turns out, you can easily create create some nice looking UIs using jQuery Mobile. As an example, just point, your mobile browser, e.g. Android to http://www.devnexus.com/. This is pretty impressive considering that I have been using an Alpha 2 version with just standard theming and functionality.

I still have to work on the detail pages, but the main landing page looks fairly nice out of the box using minimal amounts of code.

On the server-side, I am using Spring Mobile, which currently is available as a M2 release. What Spring Mobile allows you to do is to detect from within your Spring MVC controllers, whether the incoming request originates from a mobile device or not.

If you need to detect specific device capabilities, you can even use a WurflDeviceResolver, but for my use case I simply need to know whether a mobile device request is coming in or not. If so, forward to a mobile version of the respective controller's jsp page.

One, question I had to solve was how to make everything work with SiteMesh, which I use for templating purposes. As I use the same Urls for mobile and standard clients (No site-switching), I ended up needing to create a custom SiteMesh DecoratorMapper extending AbstractDecoratorMapper.



public class SpringMobileParameterDecoratorMapper extends AbstractDecoratorMapper {
    private String decoratorName = null;

    public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException {
        super.init(config, properties, parent);
        decoratorName = properties.getProperty("decorator.name", "mobile");
    }

    public Decorator getDecorator(final HttpServletRequest request, final Page page) {

        final Device device = DeviceResolverHandlerInterceptor.getCurrentDevice(request);

        if (device != null && device.isMobile()) {
         return getNamedDecorator(request, decoratorName);
        } else {
         return super.getDecorator(request, page);
        }

    }
} 

It may not be the bestapproach to have a hard dependency onto Spring Mobile in my SiteMesh DecoratorMapper...but it works nicely so far.

Wednesday, August 18, 2010

Google, Oracle and JUGs

One might think that developing software (web-applications in my case) is a pretty involved endeavor. It is a constant learning experience: from understanding the business domain of your customers for each and every project, to figuring out which frameworks to choose (How many web-frameworks to we have?), all the way to understanding the broader IT landscape.

Thus, in a nutshell life as a developer is busy...and then Oracle sues Google, adding just a tad more complexity to the mix (Things were also much easier back when it was all about Microsoft versus he rest of the world :-). Additionally, as the leader of the Atlanta Java Users Group, I wonder what kind of implication this development will have for our community of Java developers.

Following the various information sources, there is certainly no black-and-white battle going one, albeit Google seems to be certainly in a more favorable position among developers. A good source for gauging the mood within the Java community is to follow the mailing list of the global JUG community. Sentiments there have been ranging from surprise to shock.

Bruno Souza, THE Java advocate in Brazil (he also spoke at AJUG in Atlanta in May 2007) made probably the most balanced statements regarding the just started litigation process between Oracle and Google. Thus, from a technical/legal perspective you may very well argue in either direction, in favor of Google or in favor of Oracle.

However, I am concerned about the impact this may have in regards to our community and the leading edge open-source developers, that may again increasingly look elsewhere (Remember the wave of developers that left for Ruby on Rails a few years back?). 

I will cautiously follow the developments over the next couple of months and I hope that the negative impact to our community can be minimized. I mean, there is certainly the hope that Oracle and Google come to a quick agreement and maybe make Android an official part of the Java platform (too overly optimistic?)

Here are some pointers for further information:

InfoQ had a short article summarizing the latest developments: http://www.infoq.com/news/2010/08/oracle_sues_google

Javalobby has an insightful article regarding Oracle's open-source activities, e.g. essentially shutting down OpenSolaris: http://java.dzone.com/articles/oracle-and-open-source-list

JavaWorld takes it even a step further and ask whether SpringSource should be worried as well: http://www.javaworld.com/community/?q=node/4919

Many high-ranking Java advocates left Oracle in recent months, and Java inventor James Gosling is becoming increasingly outspoken. His blog provides some interesting insights:

http://nighthacks.com/roller/jag/entry/the_shit_finally_hits_the
http://nighthacks.com/roller/jag/entry/quite_the_firestorm
http://nighthacks.com/roller/jag/entry/cynical_chuckles

(Interestingly, looks like too many people were trying to read read James Gosling's blog on 2010-08-16 because his blog was not accessible for a good portion of the day)

The following link points to an official statement by Oracle regarding its patent policy in 1994. Things seemed to have changed since then, unfortunately:

http://www.bustpatents.com/articles/oracle.htm

Wednesday, August 11, 2010

Function based indexes in Oracle

If you ever have to query tables in Oracle containing million of records using "is null" in the where clause, then you will notice that your normal indexes won't kick in. They work as prescribed for "is not null", though.

Using a function-based index you can work around that issue. Take a look at the following article which might be quite helpful if you run into the issue: http://www.dba-oracle.com/oracle_tips_null_idx.htm

Thursday, May 6, 2010

Using Hibernate's SchemaExport Feature from within a Spring/JPA Context

My Spring-based application uses the Java Persistence Api (JPA) with Hibernate as persistence provider. As business requirement, I have the need to generate the SQL schema from my JPA annotated classes at application startup (As a disclaimer: I used the Maven Hibernate3 plugin in the past and there is also an Ant task provided by Hibernate, however in my case I needed a programmatic approach to have some more flexibility). Anyway, A logic choice for this would be Hibernate's SchemaExport class.

The problem is that Hibernate's SchemaExport class requires a org.hibernate.cfg.Configuration class to be passed in. Configuring this within Spring based applications is sparsely documented (Furthermore, the Configuration class is not easy to get hold off) but nevertheless there are some good pointers on how to get the Configuration object, when using straight Hibernate e.g:
Unfortunately, I am a bit on the cutting edge and I configured my persistence using
  • org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean and
  • org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter
How do you make that work? The best, albeit limited, information I found (as usual) on Stackoverflow:
That discussion pointed to the following blog post:
That was pretty much it. The blog post gave me some ideas about where to look next for answers (the Hibernate and Spring source code ;-), but the example just felt a bit heavy for my use-case. Everything was already configurred using Spring/JPA in my environment. Why shouldn't I be able to reuse my existing infrastructure to use the SchemaExport class?

The solution

After some more searching, I think I found a workable example:

In my class I inject the LocalContainerEntityManagerFactoryBean:

@Autowired LocalContainerEntityManagerFactoryBean fb;

Then I use the following code to setup SchemaExport:

org.hibernate.ejb.Ejb3Configuration cfg = new org.hibernate.ejb.Ejb3Configuration();
org.hibernate.ejb.Ejb3Configuration configured =     
                 cfg.configure(fb.getPersistenceUnitInfo(), fb.getJpaPropertyMap()); org.hibernate.tool.hbm2ddl.SchemaExport schemaExport = 
new org.hibernate.tool.hbm2ddl.SchemaExport(configured.getHibernateConfiguration());

And then do whatever you need to, such as printing the SQL Schema DDL to the console:       

schemaExport.create(true, false);

Not that bad after all. If you have similar needs, hopefully the Google gods are with you and this blog posting showed up in your search results. See you next time. 

Thursday, April 29, 2010

Martin Fowler in Atlanta - DSLs, Agile, CI

I went to Martin Fowler's talk last night night at the Crowne Plaza Hotel next to Perimeter Mall. Martin Fowler is the Chief Scientist at ThoughtWorks and it has been a great experience to finally hear him speak personally. He have three mini presentations:

His first talk was about domain specific languages (DSL) covering all the different variation of DSLs - external DSLs (XML, custom language) and internal DSLs (e.g Ruby). Martin Fowler also had a slide about Language Workbenches - I saw an article on his website covering that subject, which I need to look at in the next few days.

An interesting point I thought he raised was, to focus on making codified business concerns "readable" through DSLs rather than making the DSL available to business people to write rules, business logic etc. as this would be so much harder to achieve.

In his second presentation segment, Martin Fowler answered questions, that were submitted by the audience prior to his presentation, which covered various aspect of agile software development. He mentioned that the British newspaper The Guardian, is releasing software changes into production every 2 weeks.

The way to achieve this is through total test automation. He mentions that at Thoughtworks manual QA is reduced to exploratory testing and that any test plans etc. are part of the automated build process (More details about this at the end of this blog post)

A popular question these days also seems to be whether Java has peaked and whether also languages shall be considered. Martin Fowler, stated that "Java stalled" but it is not going away. However, he  also pointed to the fact, that you should consider more productive languages (especially for new projects). He mentioned an internal and informal Thoughtworks survey in which developers on average attested a 0.5-2.5x increase in productivety when using alternative languages (Ruby, Groovy, Scala, Clojure etc.). Martin Fowler himself expressed his preference for Ruby.  

His last talk was about continuous integration and continuous delivery. He talked a bit about different approaches regarding managing your source code in your respective source repository (e.g. Subversion). Specifically he talked about having feature branches versus just a single trunk (for the most part). It was interesting to hear him talk about that as at work we recently had that same discussion and we finally settled on having just a single trunk for all our regular development efforts. He said feature branches are just too painful when doing merges.

Moving on, he suggested to commit your code at least once a day, preferably even more often.

He then talked about continuous delivery, meaning to continuously push code into production in a controlled fashion. He mentioned a Suisse Insurances company that would deploy code into production once a day. As far as I remember he said that at Thoughtworks they typically deploy into production every two weeks to once a month.

In order to achieve that you must have really good automated testing at which point Martin Fowler talked about having a "build pipeline" which consists of the following phases:
  1. Commit Stage - Build project run tests (unit-tests), execution shouldn't take longer than 10 minutes. Deploy artifacts to artifacts repository
  2. Acceptance Stage - Deploy the application, run smoke tests, run acceptance tests. This stage may take much longer (e.g. 1-2 hours)
  3. Performance Stage - Run Performance Tests - This may take a very long time
  4. Deployment Stage - Deploy the application into production - It is important to be able to deploy by just  pressing one button. However, have a rollback option
Then he talked a little bit about Cruise, Thoughtwork's product to help implement that kind of continuous delivery. There is also a book coming out from Addison Wesley called Continuous Delivery.

That basically conclded his talk - there was one further question from the audience that caught my attention. Chris Curtin (CTO of Silverpop) asked him about the Devops movement. Personally I was unaware of that term. In my understanding, this fairly new concept brings developers and operation teams closer together.

Martin Fowler found that concept to be a very positive thing saying that if a production issue was caused by a developer, he should carry the pager for that and fix it. I have to learn more about the Devops movement - here is an interesting blog entry that seems to summarize it quite well: http://www.jedi.be/blog/2010/02/12/what-is-this-devops-thing-anyway/.

A great evening - learned a lot.


Tuesday, March 23, 2010

Java Posse Roundup 2010 - Summary

I am sitting in the plane right now returning back to Atlanta from Denver, Colorado. It has been an incredible week. As you may have seen my Twitter tweets, I spent last week at the Java Posse Roundup in Crested Butte, Colorado. It was simply amazing. Some of the brightest minds in our industry were there and the conference setting was very cozy with around 40 attendees. It was a very diverse crowd with attendees from all parts of the US (incl. 4 people from Atlanta and 1 from Nashville) as well as quite a few folks from Europe (UK, Denmark, Norway) as well as Israel.


James Ward was there (Flex Evangelist for Adobe), Bruce Eckel (Author of "Thinking in Java"), ???? Joe Darcy (Lead at Oracle for Project “Coin” [JDK7]), Bill Pugh (Findbugs) and many more.

Here are the sessions I attended at the Roundup:

Tuesday

  • NoSQL Databases
  • Apple and HTML 5 versus Flash (What Does the Future hold) and UI Framework experiences GWT vs Flex vs ? 
Wednesday
  • Measurable ≠ Meaningful (Business)
  • Architecture standardisation
  • JavaFX - What else do we want?
Thursday
  • Alternative Views of SW Development (Convention over configuration, static vs. dynamic, Rockstar dependencies)
  • When companies transition from awesome to sucky corporate environments
  • Project Coin, JDK7, Language Evolution
Friday
  • Source Control Systems (Server based (SVN) vs. Distributed VCS (Git, Mercurial)
  • When the wheels come off agile
  • Share your IDE/Editor tips and tricks
On Tuesday and Wednesday, there were Lightning Talks. Every attendee could sign up for 5 minute mini-presentations on any topic (technical, personal, informational you name it). This was really cool. Did you ever attend an IT conference where you could see fire eating? Bill Pugh did it!!!

On Thursday, I did a lightning talk on YSlow and JAWR which I think went pretty well (considering that I only prepared for it 1 hour in the afternoon that same day).
Thursday night, the 300th episode of the JavaPosse was recorded. It has been a lot of fun. The podcast episode was released on Friday!


This was my first JavaPosse Roundup conference. I am sure that I will return next year. It was an incredible learning experience and a ton of fun! A massive THANK YOU to Dick Wall, Tor Norbye, Carl Quinn, Joe Nuxoll and Bruce Eckel for organizing this amazing experience!

Tuesday, March 9, 2010

DevNexus Day One

Alright, this is just a super quick update on day one of our DevNexus conference. Day 1 went very smoothly with no major hick-ups. We have around 340 attendees (Incl. sponsors, speakers etc.), which constitutes a 40% growth compared to last year!!! Thanks to all that attended!

I attended the following sessions:
  1. "Better Software with Java and Flex" (James Ward)
  2. "Next Generation Development Infrastructure: Maven, M2Eclipse, Nexus & Hudson" (Jason van Zyl)
  3. "Google App Engine: Cloud vs Cluster" (Toby Reyelts)
  4. "The 90-Day Startup with Google AppEngine: A Case Study" (David Chandler)
  5. "Effective Java" (Venkat Subramaniam)
  6. "Smithing in the 21st Century" (Neal Ford)
The day finished off with a cocktail hour and I met some nice folks from The Home Depot and I spent the rest of the eventing chatting with the hard core of the crowd which involved mostly speakers such as Toby Reyelts, Charlie Collins, Barry Hawkins, James Ward, Pratik Patel and Greg Luck. After dropping Greg off at his hotel, I finally made it home right around midnight.

This has been a very good day. Time to get some sleep. See you all tomorrow at day 2!

Monday, March 1, 2010

DevNexus has its own Android App

Pretty cool - Charlie Collins created the first Android phone app for the DevNexus conference. Check it out at: http://code.google.com/p/and-conference/. Thanks Charlie!

Also, in case you haven't registered for DevNexus, yet. Please sign-up because registration is closing March 3rd.

Tuesday, February 2, 2010

Atlanta DevNexus 2010 Conference - Status

We at AJUG are humming along preparing for DevNexus (March 8-9, 2010). Today we got confirmation that Jason van Zyl from Sonatype is speaking at our event. He is the founder of Apache Maven and Sonatype. I added his bio and abstract to the website tonight. Thus, check out our presentation line-up for details.

Also, we got our very own Twitter account (Many thanks to Barry Hawkins for organizing this!!). Over the next few day I will add it to the DevNexus website and we will post noteworthy updates through that channel.

Thus, start following us at: http://twitter.com/devnexus/