Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ app:

If you run into issues, you can disable the new implementation and revert to the previous behavior by setting the `multiThreadedConsumer` property to `false`.

#### Bug fixes
- [ISSUE-159](https://github.com/SourceLabOrg/kafka-webview/issues/159) Fix for file uploads in Windows environment. Thanks for the contribution @[quentingodeau](https://github.com/quentingodeau)!


#### Internal Dependency Updates
- Upgrade from Spring Boot 2.0.8 to 2.0.9

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public Class<? extends T> getPluginClass(final String jarName, final String clas
final Path absolutePath = getPathForJar(jarName);
final URL jarUrl = absolutePath.toUri().toURL();
final ClassLoader pluginClassLoader = new PluginClassLoader(jarUrl, getClass().getClassLoader());
//final ClassLoader pluginClassLoader = new PluginClassLoader(jarUrl);
return getPluginClass(pluginClassLoader, classpath);
} catch (MalformedURLException exception) {
throw new LoaderException("Unable to load jar " + jarName, exception);
Expand Down Expand Up @@ -146,9 +145,10 @@ public T getPlugin(final String jarName, final String classpath) throws LoaderEx
* Check if instance of the class given at the classpath can be load from the given Jar.
* @param jarName Jar to load the class from
* @param classpath Classpath to class.
* @return boolean true on success.
* @throws LoaderException LoaderException When we run into issues.
*/
public void checkPlugin(final String jarName, final String classpath) throws LoaderException {
public boolean checkPlugin(final String jarName, final String classpath) throws LoaderException {
try {
final Path absolutePath = getPathForJar(jarName);
final URL jarUrl = absolutePath.toUri().toURL();
Expand All @@ -159,10 +159,10 @@ public void checkPlugin(final String jarName, final String classpath) throws Loa
try (URLClassLoader pluginClassLoader = new PluginClassLoader(jarUrl, getClass().getClassLoader())) {
Class<? extends T> pluginClass = getPluginClass(pluginClassLoader, classpath);
pluginClass.getDeclaredConstructor().newInstance();

return true;
}
} catch (MalformedURLException exception) {
throw new LoaderException("Unable to load jar " + jarName, exception);
} catch (IOException exception) {
} catch (final IOException exception) {
throw new LoaderException("Unable to load jar " + jarName, exception);
} catch (final NoClassDefFoundError e) {
// Typically this happens if the uploaded JAR references some dependency that was
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,38 @@ public void testWithRecordFilter() throws LoaderException {
recordFilter.includeRecord("topic", 1, 1L, "Key", "Value");
}

/**
* Test checking a RecordFilter.
*/
@Test
public void testCheckPlugin_WithRecordFilter() throws LoaderException {
final String jarFilename = "testPlugins.jar";
final String classPath = "examples.filter.LowOffsetFilter";

// Find jar on filesystem.
final URL jar = getClass().getClassLoader().getResource("testDeserializer/" + jarFilename);
final String jarPath = new File(jar.getFile()).getParent();

// Create factory
final PluginFactory<RecordFilter> factory = new PluginFactory<>(jarPath, RecordFilter.class);
final Path pathForJar = factory.getPathForJar(jarFilename);

// Validate path is correct
assertEquals("Has expected Path", jar.getPath(), pathForJar.toString());

// Get class instance
final Class<? extends RecordFilter> pluginFilterClass = factory.getPluginClass(jarFilename, classPath);

// Validate
assertNotNull(pluginFilterClass);
assertEquals("Has expected name", classPath, pluginFilterClass.getName());
assertTrue("Validate came from correct class loader", pluginFilterClass.getClassLoader() instanceof PluginClassLoader);

// Check filter instance
final boolean result = factory.checkPlugin(jarFilename, classPath);
assertTrue(result);
}

/**
* Test creating a Deserializer.
*/
Expand Down Expand Up @@ -104,7 +136,7 @@ public void testWithDeserializer() throws LoaderException {
assertEquals("Has expected name", classPath, pluginFilterClass.getName());
assertTrue("Validate came from correct class loader", pluginFilterClass.getClassLoader() instanceof PluginClassLoader);

// Crete filter instance
// Crete Deserializer instance
final Deserializer deserializer = factory.getPlugin(jarFilename, classPath);
assertNotNull(deserializer);
assertEquals("Has correct name", classPath, deserializer.getClass().getName());
Expand All @@ -114,6 +146,38 @@ public void testWithDeserializer() throws LoaderException {
final String result = (String) deserializer.deserialize("MyTopic", value.getBytes(StandardCharsets.UTF_8));
}

/**
* Test checking a Deserializer.
*/
@Test
public void testCheckPlugin_WithDeserializer() throws LoaderException {
final String jarFilename = "testPlugins.jar";
final String classPath = "examples.deserializer.ExampleDeserializer";

// Find jar on filesystem.
final URL jar = getClass().getClassLoader().getResource("testDeserializer/" + jarFilename);
final String jarPath = new File(jar.getFile()).getParent();

// Create factory
final PluginFactory<Deserializer> factory = new PluginFactory<>(jarPath, Deserializer.class);
final Path pathForJar = factory.getPathForJar(jarFilename);

// Validate path is correct
assertEquals("Has expected Path", jar.getPath(), pathForJar.toString());

// Get class instance
final Class<? extends Deserializer> pluginFilterClass = factory.getPluginClass(jarFilename, classPath);

// Validate
assertNotNull(pluginFilterClass);
assertEquals("Has expected name", classPath, pluginFilterClass.getName());
assertTrue("Validate came from correct class loader", pluginFilterClass.getClassLoader() instanceof PluginClassLoader);

// Check Deserializer instance
final boolean result = factory.checkPlugin(jarFilename, classPath);
assertTrue(result);
}

/**
* Tests loading a deserializer not from an external jar.
*/
Expand Down