From 7dbe38ba0522b346a0fcd9851e797f0fd71ecd5e Mon Sep 17 00:00:00 2001 From: Michael Dürre Date: Thu, 16 Jul 2020 05:55:07 +0200 Subject: switch to rfc8040 restconf MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit change rest interface and some small code cleanups Issue-ID: CCSDK-2572 Signed-off-by: Michael Dürre Change-Id: I3475bd2574b32950c4bf84fbd1c2a9dac9af208a --- .../opensymphony/xwork2/util/ClassLoaderUtil.java | 125 +++++++++++---------- .../wt/odlux/model/bundles/ClassLoaderUtilExt.java | 8 +- .../sdnr/wt/odlux/model/bundles/OdluxBundle.java | 25 ++--- .../wt/odlux/model/bundles/OdluxBundleLoader.java | 2 +- .../model/bundles/OdluxBundleResourceAccess.java | 2 + 5 files changed, 81 insertions(+), 81 deletions(-) (limited to 'sdnr/wt/odlux/core/model/src/main') diff --git a/sdnr/wt/odlux/core/model/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java b/sdnr/wt/odlux/core/model/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java index 133b08494..636c9db29 100644 --- a/sdnr/wt/odlux/core/model/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java +++ b/sdnr/wt/odlux/core/model/src/main/java/com/opensymphony/xwork2/util/ClassLoaderUtil.java @@ -22,11 +22,11 @@ import java.util.*; /** - * This class is extremely useful for loading resources and classes in a fault tolerant manner - * that works across different applications servers. + * This class is extremely useful for loading resources and classes in a fault tolerant manner that works across + * different applications servers. * - * It has come out of many months of frustrating use of multiple application servers at Atlassian, - * please don't change things unless you're sure they're not going to break in one server or another! + * It has come out of many months of frustrating use of multiple application servers at Atlassian, please don't change + * things unless you're sure they're not going to break in one server or another! * * It was brought in from oscore trunk revision 147. * @@ -37,58 +37,59 @@ public class ClassLoaderUtil { //~ Methods //////////////////////////////////////////////////////////////// /** - * Load all resources with a given name, potentially aggregating all results - * from the searched classloaders. If no results are found, the resource name - * is prepended by '/' and tried again. + * Load all resources with a given name, potentially aggregating all results from the searched classloaders. If no + * results are found, the resource name is prepended by '/' and tried again. * * This method will try to load the resources using the following methods (in order): * * * @param resourceName The name of the resources to load * @param callingClass The Class object of the calling object */ - public static Iterator getResources(String resourceName, Class callingClass, boolean aggregate) throws IOException { + public static Iterator getResources(String resourceName, Class callingClass, boolean aggregate) + throws IOException { - AggregateIterator iterator = new AggregateIterator<>(); + AggregateIterator iterator = new AggregateIterator<>(); - iterator.addEnumeration(Thread.currentThread().getContextClassLoader().getResources(resourceName)); + iterator.addEnumeration(Thread.currentThread().getContextClassLoader().getResources(resourceName)); - if (!iterator.hasNext() || aggregate) { - iterator.addEnumeration(ClassLoaderUtil.class.getClassLoader().getResources(resourceName)); - } + if (!iterator.hasNext() || aggregate) { + iterator.addEnumeration(ClassLoaderUtil.class.getClassLoader().getResources(resourceName)); + } - if (!iterator.hasNext() || aggregate) { - ClassLoader cl = callingClass.getClassLoader(); + if (!iterator.hasNext() || aggregate) { + ClassLoader cl = callingClass.getClassLoader(); - if (cl != null) { - iterator.addEnumeration(cl.getResources(resourceName)); - } - } + if (cl != null) { + iterator.addEnumeration(cl.getResources(resourceName)); + } + } - if (!iterator.hasNext() && resourceName != null && (resourceName.length() == 0 || resourceName.charAt(0) != '/')) { - return getResources('/' + resourceName, callingClass, aggregate); - } + if (!iterator.hasNext() && resourceName != null + && (resourceName.length() == 0 || resourceName.charAt(0) != '/')) { + return getResources('/' + resourceName, callingClass, aggregate); + } - return iterator; - } + return iterator; + } /** - * Load a given resource. - * - * This method will try to load the resource using the following methods (in order): - *
    - *
  • From Thread.currentThread().getContextClassLoader() - *
  • From ClassLoaderUtil.class.getClassLoader() - *
  • callingClass.getClassLoader() - *
- * - * @param resourceName The name IllegalStateException("Unable to call ")of the resource to load - * @param callingClass The Class object of the calling object - */ + * Load a given resource. + * + * This method will try to load the resource using the following methods (in order): + *
    + *
  • From Thread.currentThread().getContextClassLoader() + *
  • From ClassLoaderUtil.class.getClassLoader() + *
  • callingClass.getClassLoader() + *
+ * + * @param resourceName The name IllegalStateException("Unable to call ")of the resource to load + * @param callingClass The Class object of the calling object + */ public static URL getResource(String resourceName, Class callingClass) { URL url = Thread.currentThread().getContextClassLoader().getResource(resourceName); @@ -112,13 +113,13 @@ public class ClassLoaderUtil { } /** - * This is a convenience method to load a resource as a stream. - * - * The algorithm used to find the resource is given in getResource() - * - * @param resourceName The name of the resource to load - * @param callingClass The Class object of the calling object - */ + * This is a convenience method to load a resource as a stream. + * + * The algorithm used to find the resource is given in getResource() + * + * @param resourceName The name of the resource to load + * @param callingClass The Class object of the calling object + */ public static InputStream getResourceAsStream(String resourceName, Class callingClass) { URL url = getResource(resourceName, callingClass); @@ -130,20 +131,20 @@ public class ClassLoaderUtil { } /** - * Load a class with a given name. - * - * It will try to load the class in the following order: - *
    - *
  • From Thread.currentThread().getContextClassLoader() - *
  • Using the basic Class.forName() - *
  • From ClassLoaderUtil.class.getClassLoader() - *
  • From the callingClass.getClassLoader() - *
- * - * @param className The name of the class to load - * @param callingClass The Class object of the calling object - * @throws ClassNotFoundException If the class cannot be found anywhere. - */ + * Load a class with a given name. + * + * It will try to load the class in the following order: + *
    + *
  • From Thread.currentThread().getContextClassLoader() + *
  • Using the basic Class.forName() + *
  • From ClassLoaderUtil.class.getClassLoader() + *
  • From the callingClass.getClassLoader() + *
+ * + * @param className The name of the class to load + * @param callingClass The Class object of the calling object + * @throws ClassNotFoundException If the class cannot be found anywhere. + */ public static Class loadClass(String className, Class callingClass) throws ClassNotFoundException { try { return Thread.currentThread().getContextClassLoader().loadClass(className); @@ -161,8 +162,8 @@ public class ClassLoaderUtil { } /** - * Aggregates Enumeration instances into one iterator and filters out duplicates. Always keeps one - * ahead of the enumerator to protect against returning duplicates. + * Aggregates Enumeration instances into one iterator and filters out duplicates. Always keeps one ahead of the + * enumerator to protect against returning duplicates. */ static class AggregateIterator implements Iterator { diff --git a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/ClassLoaderUtilExt.java b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/ClassLoaderUtilExt.java index f6d0b55bf..a4a0e76c3 100644 --- a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/ClassLoaderUtilExt.java +++ b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/ClassLoaderUtilExt.java @@ -37,7 +37,7 @@ public class ClassLoaderUtilExt { try { urls = getResources(resourceName, callingClass, true); } catch (IOException e) { - LOG.debug("No resource {}",resourceName); + LOG.debug("No resource {}", resourceName); } if (urls != null) { while (urls.hasNext()) { @@ -50,11 +50,9 @@ public class ClassLoaderUtilExt { if (url == null) { LOG.debug("res currently not found. try to find with bundle"); Bundle b = FrameworkUtil.getBundle(callingClass); - if(b!=null) - { + if (b != null) { url = b.getEntry(resourceName); - } - else { + } else { ClassLoader loader = Thread.currentThread().getContextClassLoader(); url = loader.getResource(resourceName); } diff --git a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundle.java b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundle.java index e1e300a0d..ab69d63c8 100644 --- a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundle.java +++ b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundle.java @@ -25,8 +25,8 @@ import java.io.InputStreamReader; import java.net.URL; /** - * At startup of each karaf bundle, each UI module creates an instance of this class via blueprint. - * Initialize method gets called at loading of bundle. + * At startup of each karaf bundle, each UI module creates an instance of this class via blueprint. Initialize method + * gets called at loading of bundle. */ public class OdluxBundle { @@ -103,12 +103,12 @@ public class OdluxBundle { public String getResourceFileContent(String filename) { return this.loadFileContent(this.getResource(filename)); } - + protected URL getResource(String filename) { return ClassLoaderUtilExt.getResource(filename, this.getClass()); } - protected String loadFileContent(final URL url ) { + protected String loadFileContent(final URL url) { if (url == null) return null; LOG.debug("try to load res " + url.toString()); @@ -124,15 +124,14 @@ public class OdluxBundle { } catch (IOException e) { LOG.warn("could not load resfile " + url.toString() + ": " + e.getMessage()); return null; - } - finally { - if(in!=null) { - try { - in.close(); - } catch (IOException e) { - - } - } + } finally { + if (in != null) { + try { + in.close(); + } catch (IOException e) { + + } + } } return sb.toString(); diff --git a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleLoader.java b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleLoader.java index 455c83296..870011e85 100644 --- a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleLoader.java +++ b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleLoader.java @@ -25,6 +25,6 @@ public interface OdluxBundleLoader { public int getNumberOfBundles(); - public String getResourceContent(String fn, OdluxBundleResourceAccess indexBundle); + public String getResourceContent(String fn, OdluxBundleResourceAccess indexBundle); } diff --git a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleResourceAccess.java b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleResourceAccess.java index f9a842556..1abed468b 100644 --- a/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleResourceAccess.java +++ b/sdnr/wt/odlux/core/model/src/main/java/org/onap/ccsdk/features/sdnr/wt/odlux/model/bundles/OdluxBundleResourceAccess.java @@ -22,7 +22,9 @@ import java.util.List; public interface OdluxBundleResourceAccess { boolean hasResource(String fn); + String getResourceFileContent(String fn, List bundleNames); + String getBundleName(); } -- cgit 1.2.3-korg