The simple web application, which works from json/xml through HTTP on the one hand, is drawn from the questioning and then crawls into the database.There are three canonal layers: web service, business logistics and data storage. This scheme is actually widely considered by all parties on the Internet. Let's see again.Web ServicesIt's an outward API, everything else is the details of implementation. To receive HTTP requests, it's gonna take a web server, the most popular Java environment. http://www.eclipse.org/jetty/ ♪ http://tomcat.apache.org/ ♪ https://grizzly.java.net/ ♪ I'd start on Jetty, it's easy to start with a minimum configuration, and it's easy to fit into your app if necessary. Further, the concept of web service should be defined: https://ru.wikipedia.org/wiki/%D0%A3%D0%B4%D0%B0%D0%BB%D1%91%D0%BD%D0%BD%D1%8B%D0%B9_%D0%B2%D1%8B%D0%B7%D0%BE%D0%B2_%D0%BF%D1%80%D0%BE%D1%86%D0%B5%D0%B4%D1%83%D1%80 (sighs) https://ru.wikipedia.org/wiki/SOAP ♪ https://ru.wikipedia.org/wiki/XML-RPC ♪ https://ru.wikipedia.org/wiki/JSON-RPC ♪ http://hessian.caucho.com/ ♪ https://thrift.apache.org/ ) or https://ru.wikipedia.org/wiki/REST : RPC is easier to understand because it looks like a common locality challenge, but they hide all magic under the hood and usually use their data transmission formats (based on xml/json or binary). API based on RPC is easy to prototype: usually you describe the normal interface, run its server part, do everything else for you, and even generating boxes for the client code in a certain set of programming languages.REST is built around the idea of transferring facilities between the client and the server, i.e. operating objects, not actions. This API is good on CRUD, but requires careful reflection for the more complex cases. It's low-level enough that you define the data formats yourself, the processing of errors, which adds complexity. But all this, with the right approach, makes it easier to scale web services in the future.Based on your demands (CRUD-Operation and one-time support to JSON and XML), you're probably more likely to have REST. For Java there is a specification http://docs.oracle.com/javaee/6/tutorial/doc/giepu.html describing the standard way of establishing REST services and a number of its applications: https://jersey.java.net/ ♪ http://cxf.apache.org/docs/jax-rs.html ♪ http://resteasy.jboss.org/ ♪ The general idea is that you write classrooms that accept and return your facilities, you send annotations and web services ready:@Path("/api")
@Produces({"application/json", "application/xml"})
@Consumes({"application/json", "application/xml"})
public class MyApi {
@GET
@Path("/foo/{id}")
public Foo getFooById(@PathParam("id") Long id) { ... }
@POST
@Path("/foo")
public Foo createFooById(Foo foo) { ... }
}
And we can go through. POST and GET to create and receive copies of the class Foo♪ Marshaling in json/xml and back will make Jackson's library transparent.Business logisticsIt's easy, it's your classes that do something useful over downstream objects: validate or supplement data, make mistakes, create notices, interact with the file system. Shortly, they do direct work.Perhaps, for the convenience of control, you'd like to place the classes in any DI container: https://spring.io/ ♪ https://ru.wikipedia.org/wiki/Enterprise_JavaBeans (only, in the case of the Enterprise) or connecting something more easily https://github.com/google/guice/wiki/GettingStarted ♪Data storageYou'll find a lot of information, too. Size separate classes (usually referred to as DAO - Data Access Objects) that will be rigged and delivered from the OBD. This is JDBC, JPA, ORM-a. It's important to imagine that the same Hibernate is heavy and complex, and if it comes to a dozen classes/tables, it'll be easier to settle with JDBC http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/jdbc/core/JdbcTemplate.html or a pretty library http://jdbi.org/ ) You can see. http://projects.spring.io/spring-data/ - this is a global abstraction of any vaults (in case tomorrow you'll decide to store data on another server available through REST).Another point is that it should not be tempted to give copies of the classes that ORM will remove from the OBD immediately to REST. At the web service level, move them to DTOs. It'll spare you any further pain. If you move your hands, you can try something. http://dozer.sourceforge.net/ (but it will have to be configured in turn by XML). Blue isolentLet's see what the technology is like:Web-server: Jetty/Tomcat/GrizzlyRest-endpoint: Jackson and Jersey/CXF/ResteasyDI: Spring/GuicePersistence: JDBC/JPA/ORM + Optical Spring JDBC/Spring Data/JDBIAll of this, of course, needs to be logged. SLF4J + Logback is now popular. It tastes like picking up a meter, like, https://dropwizard.github.io/metrics/3.1.0/ ♪ From the components described, both a classic web-based application in a war file that can be launched into a silverware (Jetty, Tomcat) or a serial application and standalone application, with a built-in web server that can be downloaded and released from a command line. If you want to go on the second way (now the writing of independent microservices) http://projects.spring.io/spring-boot/ (sighs) http://start.spring.io/ ) or http://www.dropwizard.io/ ♪ These tools generate all the necessary connections so you can focus on business logic writing.