in runner-starter/src/main/java/org/apache/apisix/plugin/runner/DynamicClassLoader.java [41:74]
public Class<?> findClass(String name) throws ClassNotFoundException {
if (this.name == null) {
return super.findClass(name);
}
// can we do replacements for windows only?
String packagePath = packageName.replaceAll("\\.", "/");
String classPath = "file:" + classDir + "/" + packagePath + "/" + this.name + ".class";
URL url;
URLConnection connection;
try {
url = new URL(classPath);
connection = url.openConnection();
} catch (IOException e) {
logger.error("failed to open class file: {}", classPath, e);
throw new RuntimeException(e);
}
try (InputStream input = connection.getInputStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream()) {
int data = input.read();
while (data != -1) {
buffer.write(data);
data = input.read();
}
input.close();
byte[] classData = buffer.toByteArray();
String fullyQualifiedName = packageName + "." + name;
return defineClass(fullyQualifiedName, classData, 0, classData.length);
} catch (IOException e) {
logger.error("failed to read class file: {}", classPath, e);
throw new RuntimeException(e);
}
}