Added support to request contexts uuids in instances header #20012

This commit is contained in:
Luca Frosini 2020-11-09 15:47:59 +01:00
parent 3aff1841fb
commit d822121adf
2 changed files with 45 additions and 10 deletions

View File

@ -24,14 +24,33 @@ public class ResourceRegistryClientFactory {
protected static boolean HIERARCHICAL_MODE; protected static boolean HIERARCHICAL_MODE;
public static boolean isHierarchicalMode() { protected static boolean isHierarchicalMode() {
return ResourceRegistryClientFactory.HIERARCHICAL_MODE; return ResourceRegistryClientFactory.HIERARCHICAL_MODE;
} }
/**
* The affected methods are {@link ResourceRegistryClient} instances safe methods i.e. read* and exists*
* @param hierarchicalMode
*/
public static void setHierarchicalMode(boolean hierarchicalMode) { public static void setHierarchicalMode(boolean hierarchicalMode) {
ResourceRegistryClientFactory.HIERARCHICAL_MODE = hierarchicalMode; ResourceRegistryClientFactory.HIERARCHICAL_MODE = hierarchicalMode;
} }
protected static boolean INCLUDE_CONTEXTS_IN_INSTANCES_HEADER;
protected static boolean includeContextsInInstanceHeader() {
return ResourceRegistryClientFactory.INCLUDE_CONTEXTS_IN_INSTANCES_HEADER;
}
/**
* The affected methods are {@link ResourceRegistryClient} instances safe methods i.e. read* and exists*
* @param hierarchicalMode
*/
public static void includeContextsInInstanceHeader(boolean includeContextsInInstancesHeader) {
ResourceRegistryClientFactory.INCLUDE_CONTEXTS_IN_INSTANCES_HEADER = includeContextsInInstancesHeader;
}
protected static List<String> addresses; protected static List<String> addresses;
static { static {

View File

@ -44,20 +44,36 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
protected final String address; protected final String address;
private void checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{ private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest) throws UnsupportedEncodingException{
checkHierarchicalMode(gxHTTPStringRequest, null); return includeAdditionalQueryParameters(gxHTTPStringRequest, null);
} }
private void checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{ private GXHTTPStringRequest includeAdditionalQueryParameters(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
gxHTTPStringRequest = checkHierarchicalMode(gxHTTPStringRequest, queryParams);
return checkIncludeContextsInInstanceHeader(gxHTTPStringRequest, queryParams);
}
private GXHTTPStringRequest checkHierarchicalMode(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
if(ResourceRegistryClientFactory.isHierarchicalMode()) { if(ResourceRegistryClientFactory.isHierarchicalMode()) {
if(queryParams==null) { if(queryParams==null) {
queryParams = new HashMap<>(); queryParams = new HashMap<>();
} }
queryParams.put(AccessPath.HIERARCHICAL_MODE_PARAM, Boolean.toString(true)); queryParams.put(AccessPath.HIERARCHICAL_MODE_PARAM, Boolean.toString(true));
} }
gxHTTPStringRequest.queryParams(queryParams); return gxHTTPStringRequest.queryParams(queryParams);
} }
private GXHTTPStringRequest checkIncludeContextsInInstanceHeader(GXHTTPStringRequest gxHTTPStringRequest, Map<String,String> queryParams) throws UnsupportedEncodingException{
if(ResourceRegistryClientFactory.includeContextsInInstanceHeader()) {
if(queryParams==null) {
queryParams = new HashMap<>();
}
queryParams.put(AccessPath.INCLUDE_CONTEXTS_IN_HEADER_PARAM, Boolean.toString(true));
}
return gxHTTPStringRequest.queryParams(queryParams);
}
protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() { protected ContextCacheRenewal contextCacheRenewal = new ContextCacheRenewal() {
@Override @Override
@ -218,7 +234,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString()); gxHTTPStringRequest.path(uuid.toString());
checkHierarchicalMode(gxHTTPStringRequest); includeAdditionalQueryParameters(gxHTTPStringRequest);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.head(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.head();
HTTPUtility.getResponse(String.class, httpURLConnection); HTTPUtility.getResponse(String.class, httpURLConnection);
@ -260,7 +276,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
gxHTTPStringRequest.path(type); gxHTTPStringRequest.path(type);
gxHTTPStringRequest.path(uuid.toString()); gxHTTPStringRequest.path(uuid.toString());
checkHierarchicalMode(gxHTTPStringRequest); includeAdditionalQueryParameters(gxHTTPStringRequest);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
String ret = HTTPUtility.getResponse(String.class, httpURLConnection); String ret = HTTPUtility.getResponse(String.class, httpURLConnection);
@ -302,7 +318,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
Map<String,String> parameters = new HashMap<>(); Map<String,String> parameters = new HashMap<>();
parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString()); parameters.put(AccessPath.POLYMORPHIC_PARAM, polymorphic.toString());
checkHierarchicalMode(gxHTTPStringRequest, parameters); includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
@ -349,7 +365,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
parameters.put(AccessPath.FETCH_PLAN_PARAM, fetchPlan); parameters.put(AccessPath.FETCH_PLAN_PARAM, fetchPlan);
} }
checkHierarchicalMode(gxHTTPStringRequest, parameters); includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();
@ -399,7 +415,7 @@ public class ResourceRegistryClientImpl implements ResourceRegistryClient {
parameters.put(AccessPath.REFERENCE_PARAM, referenceEntity.toString()); parameters.put(AccessPath.REFERENCE_PARAM, referenceEntity.toString());
} }
checkHierarchicalMode(gxHTTPStringRequest, parameters); includeAdditionalQueryParameters(gxHTTPStringRequest, parameters);
HttpURLConnection httpURLConnection = gxHTTPStringRequest.get(); HttpURLConnection httpURLConnection = gxHTTPStringRequest.get();