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 URI
baseUrl
Defines the HTTP URL for the WAR that hosts the JAX-RS resources.static String
CATEGORIES_PATH
static String
CATEGORY_PATH
private javax.ws.rs.client.Client
client
private static org.slf4j.Logger
logger
private javax.ws.rs.core.MediaType
mediaType
Defines the protocol between the client and server.private static String
PRODUCT_PATH
private static String
PRODUCTS_PATH
-
Constructor Summary
Constructors Constructor Description InventoryJaxRSClientImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Product
createProduct(Product product, String categoryName)
This method uses HTML FORM mechanism to POST a new product in the inventory.boolean
deleteCategory(int id)
boolean
deleteProduct(int id)
Categories
findCategoryByName(String name, int offset, int limit)
Products
findProductsByName(String name, int offset, int limit)
private javax.ws.rs.core.UriBuilder
getBaseUri(String... resourcePath)
Helper class to build the base URI for a client call.Category
getCategory(int id)
Product
getProduct(int id)
private boolean
isSuccessful(javax.ws.rs.core.Response response)
void
setBaseUrl(URI baseUrl)
void
setClient(javax.ws.rs.client.Client client)
void
setMediaType(String mediaType)
Product
updateProduct(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:
findCategoryByName
in interfaceInventoryClient
-
getCategory
public Category getCategory(int id) throws javax.ws.rs.client.ResponseProcessingException
- Specified by:
getCategory
in interfaceInventoryClient
- Throws:
javax.ws.rs.client.ResponseProcessingException
-
deleteCategory
public boolean deleteCategory(int id)
- Specified by:
deleteCategory
in 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:
createProduct
in interfaceInventoryClient
-
findProductsByName
public Products findProductsByName(String name, int offset, int limit)
- Specified by:
findProductsByName
in interfaceInventoryClient
-
getProduct
public Product getProduct(int id)
- Specified by:
getProduct
in interfaceInventoryClient
-
updateProduct
public Product updateProduct(Product product)
- Specified by:
updateProduct
in interfaceInventoryClient
-
deleteProduct
public boolean deleteProduct(int id)
- Specified by:
deleteProduct
in interfaceInventoryClient
-
-