Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

G11n java client - New caching workflow #425

Merged
merged 53 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
f4c1214
Loading configuration from the JSON configuration file
jessiejuachon Mar 11, 2020
1a4d95e
Removing code that is not yet ready to be used from the sample applic…
jessiejuachon Mar 11, 2020
5e72b73
fixing failing code scan
jessiejuachon Mar 11, 2020
73d85ca
Adding a cache properties map to hold cache details such as etag and …
jessiejuachon Mar 12, 2020
2a38107
Removing white space
jessiejuachon Mar 12, 2020
c7f5d4f
Fixing failing unit test
jessiejuachon Mar 12, 2020
056891a
Parse headers, response code, response message from an HTTP response …
jessiejuachon Mar 12, 2020
a2ba98b
Storing response headers in Map of cache properties
jessiejuachon Mar 17, 2020
17978bd
Fixing failing unit test due to NullPointerException when doing Map.p…
jessiejuachon Mar 17, 2020
6c69170
Changes after code review.
jessiejuachon Mar 17, 2020
41a8aa1
Removing exception handling for now
jessiejuachon Mar 18, 2020
dd2455d
Deprecating VIPCfg.initialize; cleaning up code
jessiejuachon Mar 19, 2020
e26d372
Storing the http response code in the cache
jessiejuachon Mar 20, 2020
01ab69e
Using cached etag as if-none-match request header value in the reques…
jessiejuachon Mar 25, 2020
750c9d2
Handling 404 response from Singleton service
jessiejuachon Mar 26, 2020
529e5cc
Using HTTP repsonse's Cache-Control max-age and timestamp to dertermi…
jessiejuachon Mar 26, 2020
b40fcf9
Moving constants to URLUtils
jessiejuachon Mar 26, 2020
fa123f9
Fixing failing test
jessiejuachon Mar 27, 2020
30b2054
Fixing failing code scan
jessiejuachon Mar 27, 2020
0c69787
Merge branch 'g11n-java-client' into g11n-java-client
Xiaochao8 Mar 27, 2020
ffc0a74
Cleaning up import in ComponentService,java
jessiejuachon Mar 30, 2020
d8450e4
Cleaning up code - caching/expiry
jessiejuachon Mar 30, 2020
d7f7641
Merge branch 'g11n-java-client' of https://github.com/jessiejuachon/s…
jessiejuachon Mar 30, 2020
0dcd827
Adding tests for new caching workflow; enabling old caching workflow …
jessiejuachon Mar 31, 2020
d06adb3
Fixing a failing test
jessiejuachon Mar 31, 2020
48c8558
Adding mock server response
jessiejuachon Mar 31, 2020
4e45bed
Removing unused file sampleconfig.json
jessiejuachon Mar 31, 2020
6a40dc8
Changes from code review
jessiejuachon Mar 31, 2020
4c3c12d
Value of VIPCfg.cacheExpiredTime is -1 when value is not set in confi…
jessiejuachon Mar 31, 2020
7e0d939
Changing a LinkedHashMap to a HashMap because insertion order does no…
jessiejuachon Apr 2, 2020
baef0d0
Adding CacheItem object to contain map of data and a another map for …
jessiejuachon Apr 3, 2020
02a96e9
Fixing failing unit test
jessiejuachon Apr 3, 2020
78d88f7
Fixing code scan issues
jessiejuachon Apr 3, 2020
655c223
Code cleanup
jessiejuachon Apr 3, 2020
8746915
Lazily instantiating cacheProps; code clean up and comments
jessiejuachon Apr 5, 2020
897a03c
Changes after code review
jessiejuachon Apr 7, 2020
3a4e183
Adding header to CacheItem.java
jessiejuachon Apr 7, 2020
b08feb4
Fixing code san issue. Synchronize on a final field
jessiejuachon Apr 7, 2020
8f57e24
Fixing code scan bug
jessiejuachon Apr 7, 2020
72c8799
Changes after code review
jessiejuachon Apr 7, 2020
92edfc8
Updating CasheService.isContainComponent to return false if cache key…
jessiejuachon Apr 7, 2020
2042554
HttpRequester if-none-match header and other customized headers are a…
jessiejuachon Apr 8, 2020
ae707ff
Code clean up; keep old caching expiration logic
jessiejuachon Apr 8, 2020
82818d5
Fixing code scan bug
jessiejuachon Apr 8, 2020
31d4ff6
Merge branch 'g11n-java-client' into g11n-java-client
jessiejuachon Apr 8, 2020
c9f83d7
code clean up
jessiejuachon Apr 9, 2020
78dcc1c
Removing response code and response msg from cache; Passing cacheItem…
jessiejuachon Apr 9, 2020
9281c64
Changes after code review
jessiejuachon Apr 10, 2020
2657762
Adding header to CacheItem.java file
jessiejuachon Apr 10, 2020
9e80f09
Fixing failing unit test
jessiejuachon Apr 10, 2020
68467f3
Changes after code review
jessiejuachon Apr 10, 2020
d67c72e
Fixing code scan bugs
jessiejuachon Apr 10, 2020
8591973
Not storing anything in cache if response is neither 200 nor 304
jessiejuachon Apr 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sample-client-app/src/main/resources/sampleconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
jessiejuachon marked this conversation as resolved.
Show resolved Hide resolved
"product": "JavaSample",
"version": "1.0.0",
jessiejuachon marked this conversation as resolved.
Show resolved Hide resolved
"online_service_url": "https://mydomain.com:port/singleton/myproduct/1.0",
"components": [
{
"name": "first_component"
}
]
}
52 changes: 45 additions & 7 deletions src/main/java/com/vmware/vipclient/i18n/VIPCfg.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
*/
package com.vmware.vipclient.i18n;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -55,6 +62,7 @@ public class VIPCfg {
private String version;
private String vipServer;
private String i18nScope = "numbers,dates,currencies,plurals,measurements";
private String offline_resources_base_url;

// define key for cache management
public static final String CACHE_L3 = "CACHE_L3";
Expand Down Expand Up @@ -117,17 +125,46 @@ public void initialize(String vipServer, String productName, String version) {
this.version = version;
this.vipServer = vipServer;
}


/**
* Load client configuration from a JSON file in the resource folder
*
* @param configFile This is the name of the JSON configuration file
* @throws ParseException
* @throws IOException
*/
public void loadConfig(String configFile) throws VIPClientInitException {
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is = classloader.getResourceAsStream(configFile + ".json");
jessiejuachon marked this conversation as resolved.
Show resolved Hide resolved

Reader reader = new InputStreamReader(is);
JSONParser parser = new JSONParser();
JSONObject jsonObject = null;
try {
jsonObject = (JSONObject) parser.parse(reader);
this.vipServer = (String) jsonObject.get("online_service_url");
jessiejuachon marked this conversation as resolved.
Show resolved Hide resolved
jessiejuachon marked this conversation as resolved.
Show resolved Hide resolved
this.offline_resources_base_url = (String) jsonObject.get("offline_resources_base_url");

// will be removed once product name becomes part of online_service_url
this.productName = (String) jsonObject.get("product");
// will be removed once version becomes part of online_service_url
this.version = (String) jsonObject.get("version");
} catch (NullPointerException | IOException | ParseException e) {
e.printStackTrace();
throw new VIPClientInitException("Failed to load configuration");
}
}

/**
* initialize the instance by a properties file
*
* @param cfg
*/
public void initialize(String cfg) throws VIPClientInitException {
ResourceBundle prop = ResourceBundle.getBundle(cfg);
if (prop == null) {
throw new VIPClientInitException("Can't not initialize VIPCfg, resource bundle is null.");
}
ResourceBundle prop = ResourceBundle.getBundle(cfg);
if (prop == null) {
throw new VIPClientInitException("Can't not initialize VIPCfg, resource bundle is null.");
}

if (prop.containsKey("productName"))
this.productName = prop.getString("productName");
Expand Down Expand Up @@ -158,7 +195,8 @@ public void initialize(String cfg) throws VIPClientInitException {
if (prop.containsKey("cacheExpiredTime"))
this.cacheExpiredTime = Long.parseLong(prop
.getString("cacheExpiredTime"));
}

}

/**
* initialize VIPService instances to provide HTTP requester
Expand All @@ -169,7 +207,7 @@ public void initializeVIPService() {
this.vipService.initializeVIPService(this.productName, this.version,
this.vipServer);
} catch (MalformedURLException e) {
logger.error("'vipServer' in configuration isn't a valid URL!");
logger.error("'vipServer' " + this.vipServer + " in configuration isn't a valid URL!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,9 @@ private boolean isNegative(double number) {
// -0.0. This is a double which has a zero mantissa (and exponent), but a negative
// sign bit. It is semantically distinct from a zero with a positive sign bit, and
// this distinction is important to certain kinds of computations. However, it's a
// little tricky to detect, since (-0.0 == 0.0) and !(-0.0 < 0.0). How then, you
// may ask, does it behave distinctly from +0.0? Well, 1/(-0.0) ==
// -Infinity. Proper detection of -0.0 is needed to deal with the issues raised by
// bugs 4106658, 4106667, and 4147706. Liu 7/6/98.
return (number < 0.0) || (number == 0.0 && 1 / number < 0.0);
// little tricky to detect, since (-0.0 == 0.0) and !(-0.0 < 0.0). Use the Double.equals test
// where if d1 represents +0.0 while d2 represents -0.0, or vice versa,
// it will return false, even though +0.0==-0.0 has the value true.
return (number < 0.0) || (number == 0.0 && Double.valueOf(number).equals(-0.0));
}
}