You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by pz...@apache.org on 2024/09/10 18:36:00 UTC
(knox) branch master updated: KNOX-3064: Set the private gatewayservices field to fix nullpointer exceptions (#935)
This is an automated email from the ASF dual-hosted git repository.
pzampino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push:
new b3b0e4adc KNOX-3064: Set the private gatewayservices field to fix nullpointer exceptions (#935)
b3b0e4adc is described below
commit b3b0e4adc20215d0fc2ad1e79c74137debb97a99
Author: hanicz <ha...@users.noreply.github.com>
AuthorDate: Tue Sep 10 20:35:55 2024 +0200
KNOX-3064: Set the private gatewayservices field to fix nullpointer exceptions (#935)
---
.../org/apache/knox/gateway/websockets/BadUrlTest.java | 17 ++++++++++++++++-
.../knox/gateway/websockets/WebsocketEchoTestBase.java | 17 ++++++++++++++++-
.../websockets/WebsocketMultipleConnectionTest.java | 17 ++++++++++++++++-
3 files changed, 48 insertions(+), 3 deletions(-)
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java
index 4b405989b..360f2da81 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java
@@ -27,6 +27,7 @@ import static org.apache.knox.gateway.config.GatewayConfig.DEFAULT_IDENTITY_KEY_
import com.mycila.xmltool.XMLDoc;
import com.mycila.xmltool.XMLTag;
import org.apache.commons.io.FileUtils;
+import org.apache.knox.gateway.GatewayServer;
import org.apache.knox.gateway.config.GatewayConfig;
import org.apache.knox.gateway.config.impl.GatewayConfigImpl;
import org.apache.knox.gateway.deploy.DeploymentFactory;
@@ -55,6 +56,7 @@ import javax.websocket.WebSocketContainer;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import java.lang.reflect.Field;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
@@ -189,7 +191,7 @@ public class BadUrlTest {
* Initialize the configs and components required for this test.
*/
private static void setupGatewayConfig(final String backend)
- throws IOException {
+ throws Exception {
services = new DefaultGatewayServices();
URL serviceUrl = ClassLoader.getSystemResource("websocket-services");
@@ -317,6 +319,8 @@ public class BadUrlTest {
EasyMock.replay(gatewayConfig);
+ setGatewayServices(services);
+
try {
services.init(gatewayConfig, options);
} catch (ServiceLifecycleException e) {
@@ -331,6 +335,17 @@ public class BadUrlTest {
}
+ /**
+ * Set the static GatewayServices field to the specified value.
+ *
+ * @param gws A GatewayServices object, or null.
+ */
+ private static void setGatewayServices(final GatewayServices gws) throws Exception {
+ Field gwsField = GatewayServer.class.getDeclaredField("services");
+ gwsField.setAccessible(true);
+ gwsField.set(null, gws);
+ }
+
private static File createDir() throws IOException {
return TestUtils
.createTempDir(WebsocketEchoTest.class.getSimpleName() + "-");
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTestBase.java b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTestBase.java
index 5db254fd8..f3d9b6b5b 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTestBase.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTestBase.java
@@ -20,6 +20,7 @@ package org.apache.knox.gateway.websockets;
import com.mycila.xmltool.XMLDoc;
import com.mycila.xmltool.XMLTag;
import org.apache.commons.io.FileUtils;
+import org.apache.knox.gateway.GatewayServer;
import org.apache.knox.gateway.config.GatewayConfig;
import org.apache.knox.gateway.config.impl.GatewayConfigImpl;
import org.apache.knox.gateway.deploy.DeploymentFactory;
@@ -41,6 +42,7 @@ import org.eclipse.jetty.websocket.server.WebSocketHandler;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import java.lang.reflect.Field;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
@@ -216,7 +218,7 @@ public class WebsocketEchoTestBase {
* @param backend topology to use
* @throws IOException exception on setting up the gateway
*/
- public static void setupGatewayConfig(final String backend) throws IOException {
+ public static void setupGatewayConfig(final String backend) throws Exception {
services = new DefaultGatewayServices();
URL serviceUrl = ClassLoader.getSystemResource("websocket-services");
@@ -347,6 +349,8 @@ public class WebsocketEchoTestBase {
EasyMock.replay(gatewayConfig);
+ setGatewayServices(services);
+
try {
services.init(gatewayConfig, options);
} catch (ServiceLifecycleException e) {
@@ -360,6 +364,17 @@ public class WebsocketEchoTestBase {
monitor.reloadTopologies();
}
+ /**
+ * Set the static GatewayServices field to the specified value.
+ *
+ * @param gws A GatewayServices object, or null.
+ */
+ private static void setGatewayServices(final GatewayServices gws) throws Exception {
+ Field gwsField = GatewayServer.class.getDeclaredField("services");
+ gwsField.setAccessible(true);
+ gwsField.set(null, gws);
+ }
+
private static File createDir() throws IOException {
return TestUtils
.createTempDir(WebsocketEchoTest.class.getSimpleName() + "-");
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java
index e40ec1711..edcfeff63 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java
@@ -27,6 +27,7 @@ import static org.apache.knox.gateway.config.GatewayConfig.DEFAULT_IDENTITY_KEY_
import com.mycila.xmltool.XMLDoc;
import com.mycila.xmltool.XMLTag;
import org.apache.commons.io.FileUtils;
+import org.apache.knox.gateway.GatewayServer;
import org.apache.knox.gateway.config.GatewayConfig;
import org.apache.knox.gateway.config.impl.GatewayConfigImpl;
import org.apache.knox.gateway.deploy.DeploymentFactory;
@@ -57,6 +58,7 @@ import javax.websocket.WebSocketContainer;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import java.lang.reflect.Field;
import java.net.URI;
import java.net.URL;
import java.nio.file.Files;
@@ -249,7 +251,7 @@ public class WebsocketMultipleConnectionTest {
* @param backend name of topology
*/
private static void setupGatewayConfig(final String backend)
- throws IOException {
+ throws Exception {
services = new DefaultGatewayServices();
URL serviceUrl = ClassLoader.getSystemResource("websocket-services");
@@ -380,6 +382,8 @@ public class WebsocketMultipleConnectionTest {
EasyMock.replay(gatewayConfig);
+ setGatewayServices(services);
+
try {
services.init(gatewayConfig, options);
} catch (ServiceLifecycleException e) {
@@ -393,6 +397,17 @@ public class WebsocketMultipleConnectionTest {
monitor.reloadTopologies();
}
+ /**
+ * Set the static GatewayServices field to the specified value.
+ *
+ * @param gws A GatewayServices object, or null.
+ */
+ private static void setGatewayServices(final GatewayServices gws) throws Exception {
+ Field gwsField = GatewayServer.class.getDeclaredField("services");
+ gwsField.setAccessible(true);
+ gwsField.set(null, gws);
+ }
+
private static File createDir() throws IOException {
return TestUtils
.createTempDir(WebsocketEchoTest.class.getSimpleName() + "-");