We’ve talked about time tracking issues in software development outsourcing in one of our previous articles. As a Project Manager, you need to monitor time spent by your team on the project tasks. As a Customer, you need to know what you actually pay for. This is where time tracking tools can help.Read More
In the previous article I mentioned that we’ve decided to use Jetty+Guice+Servlet combination in our Java Web application. What was it motivated for? Why have we refused to use Jersey? Why have we decided to implement a separate Resource class for every Web action and even for every HTTP method?
When everyone of us selects a tool to work with, we all set some requirements to it, and it should meet all requirements to get a green light. Everyone knows them – these are such obvious things as code readability, ease of debugging/testing, following traditional coding practices (OOD, patterns) etc. But today I’ll tell you what requirements I set specifically for a good server-side Web framework. I’ll be happy to work with any technology stack meeting these key requirements, and Jetty+Guice+Servlet is just one of the options.
Briefly, the requirements are:
- Common response format
- Automatic exception handling
- Transactionality of a request
And let me explain you what do I mean by this.
Our team was looking for a very simple Java Web framework for one of our projects, and we found the next combination of tools very fascinating:
- Eclipse Jetty Web server for HTTP request interception
- Google Guice for dependency injection
- Java Servlet for request handling
They work together pretty well, and there is a plenty of articles on the Internet covering this topic, so it is easy to get things started. But none of these articles explains how to scope your code in a single HTTP request. By design, servlet is always a singleton. Guice refuses to register servlets as request-scoped objects, so, the whole point of request-scoped object instantiation is being lost. Due to this issue, we’ve almost decided to abandon an idea of using low-level servlets and switch to Jersey framework, which wasn’t very attractive for us as well, for different reasons. But a deeper look to Guice API has saved my day.