Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KNOX-3064: Set the private gatewayservices field to fix nullpointer e… #935

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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