Class InventoryJaxRSClientImpl
- java.lang.Object
-
- ejava.examples.ejbwar.inventory.client.InventoryJaxRSClientImpl
-
- All Implemented Interfaces:
InventoryClient
public class InventoryJaxRSClientImpl extends Object implements InventoryClient
This class implements a JAX-RS Client interface to the inventory web application. All commands are through HTTP POST, GET, PUT, and DELETE methods to specific resource URIs for products and categories. However, this uses an API interface that hides some of the HTTP and marshaling details.
-
-
Field Summary
Fields Modifier and Type Field Description private URIbaseUrlDefines the HTTP URL for the WAR that hosts the JAX-RS resources.static StringCATEGORIES_PATHstatic StringCATEGORY_PATHprivate javax.ws.rs.client.Clientclientprivate static org.slf4j.Loggerloggerprivate javax.ws.rs.core.MediaTypemediaTypeDefines the protocol between the client and server.private static StringPRODUCT_PATHprivate static StringPRODUCTS_PATH
-
Constructor Summary
Constructors Constructor Description InventoryJaxRSClientImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ProductcreateProduct(Product product, String categoryName)This method uses HTML FORM mechanism to POST a new product in the inventory.booleandeleteCategory(int id)booleandeleteProduct(int id)CategoriesfindCategoryByName(String name, int offset, int limit)ProductsfindProductsByName(String name, int offset, int limit)private javax.ws.rs.core.UriBuildergetBaseUri(String... resourcePath)Helper class to build the base URI for a client call.CategorygetCategory(int id)ProductgetProduct(int id)private booleanisSuccessful(javax.ws.rs.core.Response response)voidsetBaseUrl(URI baseUrl)voidsetClient(javax.ws.rs.client.Client client)voidsetMediaType(String mediaType)ProductupdateProduct(Product product)
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
CATEGORIES_PATH
public static final String CATEGORIES_PATH
- See Also:
- Constant Field Values
-
CATEGORY_PATH
public static final String CATEGORY_PATH
- See Also:
- Constant Field Values
-
PRODUCTS_PATH
private static final String PRODUCTS_PATH
- See Also:
- Constant Field Values
-
PRODUCT_PATH
private static final String PRODUCT_PATH
- See Also:
- Constant Field Values
-
client
private javax.ws.rs.client.Client client
-
baseUrl
private URI baseUrl
Defines the HTTP URL for the WAR that hosts the JAX-RS resources.
-
mediaType
private javax.ws.rs.core.MediaType mediaType
Defines the protocol between the client and server.
-
-
Method Detail
-
setClient
public void setClient(javax.ws.rs.client.Client client)
-
setBaseUrl
public void setBaseUrl(URI baseUrl)
-
setMediaType
public void setMediaType(String mediaType)
-
isSuccessful
private boolean isSuccessful(javax.ws.rs.core.Response response)
-
getBaseUri
private javax.ws.rs.core.UriBuilder getBaseUri(String... resourcePath)
Helper class to build the base URI for a client call.- Parameters:
resourcePath-- Returns:
- uri builder ready to accept path parameter values
-
findCategoryByName
public Categories findCategoryByName(String name, int offset, int limit)
- Specified by:
findCategoryByNamein interfaceInventoryClient
-
getCategory
public Category getCategory(int id) throws javax.ws.rs.client.ResponseProcessingException
- Specified by:
getCategoryin interfaceInventoryClient- Throws:
javax.ws.rs.client.ResponseProcessingException
-
deleteCategory
public boolean deleteCategory(int id)
- Specified by:
deleteCategoryin interfaceInventoryClient
-
createProduct
public Product createProduct(Product product, String categoryName)
This method uses HTML FORM mechanism to POST a new product in the inventory.- Specified by:
createProductin interfaceInventoryClient
-
findProductsByName
public Products findProductsByName(String name, int offset, int limit)
- Specified by:
findProductsByNamein interfaceInventoryClient
-
getProduct
public Product getProduct(int id)
- Specified by:
getProductin interfaceInventoryClient
-
updateProduct
public Product updateProduct(Product product)
- Specified by:
updateProductin interfaceInventoryClient
-
deleteProduct
public boolean deleteProduct(int id)
- Specified by:
deleteProductin interfaceInventoryClient
-
-