You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/12/24 09:35:23 UTC

[camel] 02/02: CAMEL-17329: Drop Java 8 - camel-printer uses sun.awt code changed to reflection

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git

commit c6374172b32f65ffd1170f68936bec7b77ae9156
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Dec 24 10:34:02 2021 +0100

    CAMEL-17329: Drop Java 8 - camel-printer uses sun.awt code changed to reflection
---
 .../camel/component/printer/PrinterPrintTest.java      | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/components/camel-printer/src/test/java/org/apache/camel/component/printer/PrinterPrintTest.java b/components/camel-printer/src/test/java/org/apache/camel/component/printer/PrinterPrintTest.java
index 56255fb..b4b28e1 100644
--- a/components/camel-printer/src/test/java/org/apache/camel/component/printer/PrinterPrintTest.java
+++ b/components/camel-printer/src/test/java/org/apache/camel/component/printer/PrinterPrintTest.java
@@ -69,7 +69,7 @@ public class PrinterPrintTest extends CamelTestSupport {
     }
 
     @AfterEach
-    public void tearDown() {
+    public void tearDown() throws Exception {
         restoreJavaPrint();
     }
 
@@ -407,9 +407,13 @@ public class PrinterPrintTest extends CamelTestSupport {
 
     protected void setupJavaPrint() throws Exception {
         // save the current print services
-        printServiceLookup = sun.awt.AppContext.getAppContext().get(printServiceLookupServicesClass);
+        Class<?> clazz = context.getClassResolver().resolveClass("sun.awt.AppContext");
+        Object ac = clazz.getMethod("getAppContext").invoke(null);
+        printServiceLookup = clazz.getMethod("get", Object.class).invoke(ac, printServiceLookupServicesClass);
+
         // setup a new empty list of printer services
-        sun.awt.AppContext.getAppContext().put(printServiceLookupServicesClass, null);
+        clazz.getMethod("put", Object.class, Object.class).invoke(ac, printServiceLookupServicesClass, null);
+
         Method method = PrintServiceLookup.class.getDeclaredMethod("initListOfLookupServices");
         method.setAccessible(true);
         method.invoke(null);
@@ -432,9 +436,13 @@ public class PrinterPrintTest extends CamelTestSupport {
         PrintServiceLookup.registerServiceProvider(psLookup);
     }
 
-    protected void restoreJavaPrint() {
+    protected void restoreJavaPrint() throws Exception {
         // restore print services
-        sun.awt.AppContext.getAppContext().put(printServiceLookupServicesClass, printServiceLookup);
+        if (printServiceLookup != null) {
+            Class<?> clazz = context.getClassResolver().resolveClass("sun.awt.AppContext");
+            Object ac = clazz.getMethod("getAppContext").invoke(null);
+            clazz.getMethod("put", Object.class, Object.class).invoke(ac, printServiceLookupServicesClass, printServiceLookup);
+        }
     }
 
 }