Skip to content

Commit

Permalink
KNOX-3064: Set the private gatewayservices field to fix nullpointer e…
Browse files Browse the repository at this point in the history
…xceptions (#935)
  • Loading branch information
hanicz authored Sep 10, 2024
1 parent 2a8a8a8 commit b3b0e4a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -55,6 +56,7 @@
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;
Expand Down Expand Up @@ -189,7 +191,7 @@ private static void startGatewayServer() throws Exception {
* 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");
Expand Down Expand Up @@ -317,6 +319,8 @@ private static void setupGatewayConfig(final String backend)

EasyMock.replay(gatewayConfig);

setGatewayServices(services);

try {
services.init(gatewayConfig, options);
} catch (ServiceLifecycleException e) {
Expand All @@ -331,6 +335,17 @@ private static void setupGatewayConfig(final String backend)

}

/**
* 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() + "-");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
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;
Expand All @@ -41,6 +42,7 @@
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;
Expand Down Expand Up @@ -216,7 +218,7 @@ private static void startGatewayServer() throws Exception {
* @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");
Expand Down Expand Up @@ -347,6 +349,8 @@ public static void setupGatewayConfig(final String backend) throws IOException {

EasyMock.replay(gatewayConfig);

setGatewayServices(services);

try {
services.init(gatewayConfig, options);
} catch (ServiceLifecycleException e) {
Expand All @@ -360,6 +364,17 @@ public static void setupGatewayConfig(final String backend) throws IOException {
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() + "-");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -57,6 +58,7 @@
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;
Expand Down Expand Up @@ -249,7 +251,7 @@ private static void startGatewayServer() throws Exception {
* @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");
Expand Down Expand Up @@ -380,6 +382,8 @@ private static void setupGatewayConfig(final String backend)

EasyMock.replay(gatewayConfig);

setGatewayServices(services);

try {
services.init(gatewayConfig, options);
} catch (ServiceLifecycleException e) {
Expand All @@ -393,6 +397,17 @@ private static void setupGatewayConfig(final String backend)
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() + "-");
Expand Down

0 comments on commit b3b0e4a

Please sign in to comment.