Introducing Spring Framework

Introducing Spring Framework Introducing Spring Framework

25.02.2015 Views

Chapter 12 ■ Exposing a REST API select d.documentId, d.name, d.location, d.description as doc_desc, d.typeId, d.created, d.modified, t.name as type_name, t.description as type_desc, t.extension from documents d join types t on d.typeId = t.typeId select d.documentId, d.name, d.location, d.description as doc_desc, d.typeId, d.created, d.modified, t.name as type_name, t.description as type_desc, t.extension from documents d join types t on d.typeId = t.typeId where d.documentId = ? insert into documents (documentId,name,location,description, typeId, created, modified) values (?,?,?,?,?,?,?) update documents set name = ?, location = ?, description = ?, typeId = ?,modified = ? where documentId = ? delete from documents where documentId = ? 176

Chapter 12 ■ Exposing a REST API The only modification you made in the Listing 12-5 was adding the sql bean as a HashMap. Remember that instead of using individual properties for each SQL statement, now you’re going to use a map. Now, you can test the web application. You need to run the following command: gradle :ch12:jettyEclipseRun After you execute the preceding command, you can start testing each RESTful call. ■ ■Note In Chapter 10 you used the gradle :ch10:jettyRun command. But here you are using a more robust plugin for gradle that supports the latest version of the Jetty container. This is the jettyEclipse plugin that uses the latest servlet specification, version 3.0. You can find more information about how to define it in the book’s source code companion. HTTP-GET First, let’s go with HTTP-GET for the /documents resource. Figure 12-1 shows the result of executing the http://localhost:8080/mydocuments/documents URL. You need to remember that this data is located in the META-INF/data/ folder and is loaded in memory (using the HSQL) when the server is starting up. Figure 12-1. Response of the HTTP GET Method from http://localhost:8080/mydocuments/documents 177

Chapter 12 ■ Exposing a REST API<br />

The only modification you made in the Listing 12-5 was adding the sql bean as a HashMap. Remember that<br />

instead of using individual properties for each SQL statement, now you’re going to use a map. Now, you can test the<br />

web application. You need to run the following command:<br />

gradle :ch12:jettyEclipseRun<br />

After you execute the preceding command, you can start testing each RESTful call.<br />

■ ■Note In Chapter 10 you used the gradle :ch10:jettyRun command. But here you are using a more robust plugin for<br />

gradle that supports the latest version of the Jetty container. This is the jettyEclipse plugin that uses the latest servlet<br />

specification, version 3.0. You can find more information about how to define it in the book’s source code companion.<br />

HTTP-GET<br />

First, let’s go with HTTP-GET for the /documents resource. Figure 12-1 shows the result of executing the<br />

http://localhost:8080/mydocuments/documents URL. You need to remember that this data is located in the<br />

META-INF/data/ folder and is loaded in memory (using the HSQL) when the server is starting up.<br />

Figure 12-1. Response of the HTTP GET Method from http://localhost:8080/mydocuments/documents<br />

177

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!