Enterprise Java Development@TOPIC@

Chapter 2. Resources, URI, and Methods

Exposing EJB methods to the Web

2.1. Resources
2.2. URIs
2.3. Methods
2.4. Response Codes
2.5. JAX-RS Resource Class
2.5.1. JAX-RS Resource POST Method
2.5.2. JAX-RS GET Resource Method
2.5.3. JAX-RS PUT Resource Method
2.5.4. JAX-RS DELETE Resource Method
2.6. HTTP Request/Response


@Path("/products")
public class ProductsResource {
    private static final Log log = LogFactory.getLog(ProductsResource.class);
    @Inject
    private InventoryMgmtEJB ejb;
    @Context
    private Request request;
    @Context 
    private UriInfo uriInfo;
    ...
GET /jaxrsInventoryWAR/rest/categories?name=snacks&offset=0&limit=0 HTTP/1.1
Accept: application/xml
Host: 127.0.0.1:7080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.3 (java 1.5)
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Tue, 06 Nov 2012 07:32:18 GMT

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:catageories xmlns:ns2="http://webejb.ejava.info/inventory" count="1" limit="0" offset="0" version="0">
    <categories id="4" name="snacks" version="1">
        <productCount>1</productCount>
    </categories>
</ns2:catageories>