1 # Common REST Client Library
3 This library provides a single client implementation to be used by micro services for communicating via its REST API.
8 In order to make the _REST Client_ library available to your microservice, include the following dependency in your service's pom.xml:
10 <!-- Common REST Client Library -->
12 <groupId>org.openecomp.aai</groupId>
13 <artifactId>rest-client</artifactId>
14 <version>1.0.0-SNAPSHOT</version>
19 ### Creating and Configuring a Client Instance
20 In order to start talking to a service, you need to create a client instance and configure it. The _RestClient_ uses a fluent interface which allows it to be both instantiated and configured as in the following example:
22 // Create an instance of the Rest Client and configure it.
23 RestClient myClient = new RestClient()
24 .validateServerHostname(false)
25 .validateServerCertChain(true)
26 .clientCertFile("certificate_filename")
27 .trustStroe("trust_store_filename")
28 .connectTimeoutMs(1000)
31 Note, that all of the above configuration parameters are optional and will be set to default values if they are not specified.
34 Once your service has a client instance, it can query the _Active & Available Inventory_ by specifying an HTTP endpoint, headers, and the expected response format:
36 MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
37 headers.put("Accept", Arrays.asList(new String[]{"application/json"}));
38 headers.put("X-FromAppId", Arrays.asList(new String[]{"APP-ID"}));
39 headers.put("X-TransactionId", Arrays.asList(new String[]{UUID.randomUUID().toString()}));
41 OperationResult result = myClient.queryActiveInventory("http://some/endpoint", headers, RestClient.RESPONSE_MIME_TYPE.JSON);
43 // You can also specify number of re-tries:
45 OperationResult result = myClient.queryActiveInventory("http://some/endpoint", headers, RestClient.RESPONSE_MIME_TYPE.JSON, retries);
48 The result of the query is returned as an _OperationResult_ object, which can be unpacked in the following manner:
50 The standard HTTP result code received back from the _A&AI_ is accessible as follows:
52 int resultCode = getResultCode()
54 The actual result payload is accessible in the following manner:
56 String resultPayload = result.getResult()
58 Finally, in the event of a failure, a failure cause message will be populated and can be accessed as follows:
60 String failureCause = result.getFailureCause()