@@ -35,6 +35,13 @@ public class KafkaSinkTask extends SinkTask {
35
35
private Converter keyConverter ;
36
36
private Converter valueConverter ;
37
37
38
+ private Converter instantiateConverter (Map <String , String > configuration , ConnectorConfigurationEntry configKeyName ) throws ClassNotFoundException , NoSuchMethodException , InvocationTargetException , InstantiationException , IllegalAccessException {
39
+ final var clazz = getClass ().getClassLoader ().loadClass (
40
+ configuration .get (configKeyName .getConfigKeyName ())
41
+ );
42
+ return (Converter ) clazz .getDeclaredConstructor ().newInstance ();
43
+ }
44
+
38
45
/**
39
46
* Returns the Kafka topic set
40
47
*
@@ -91,24 +98,18 @@ public void start(Map<String, String> configuration) {
91
98
}
92
99
93
100
try {
94
- final var clazz = getClass ().getClassLoader ().loadClass (
95
- configuration .get (ConnectorConfigurationEntry .KEY_CONVERTER_CLASS .getConfigKeyName ())
96
- );
97
- keyConverter = (Converter ) clazz .getDeclaredConstructor ().newInstance ();
101
+ keyConverter = instantiateConverter (configuration , ConnectorConfigurationEntry .KEY_CONVERTER_CLASS );
98
102
keyConverter .configure (ConnectorConfiguration .getKeyConverterProperties (configuration ), true );
99
- LOGGER .debug ("Instantiated Key Converter class: {}" , clazz );
103
+ LOGGER .debug ("Instantiated Key Converter class: {}" , keyConverter . getClass (). getCanonicalName () );
100
104
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException
101
105
| InstantiationException | InvocationTargetException e ) {
102
106
throw new IllegalArgumentException (e );
103
107
}
104
108
105
109
try {
106
- final var clazz = getClass ().getClassLoader ().loadClass (
107
- configuration .get (ConnectorConfigurationEntry .VALUE_CONVERTER_CLASS .getConfigKeyName ())
108
- );
109
- valueConverter = (Converter ) clazz .getDeclaredConstructor ().newInstance ();
110
+ valueConverter = instantiateConverter (configuration , ConnectorConfigurationEntry .VALUE_CONVERTER_CLASS );
110
111
valueConverter .configure (ConnectorConfiguration .getValueConverterProperties (configuration ), false );
111
- LOGGER .debug ("Instantiated Value Converter class: {}" , clazz );
112
+ LOGGER .debug ("Instantiated Value Converter class: {}" , valueConverter . getClass (). getCanonicalName () );
112
113
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException
113
114
| InstantiationException | InvocationTargetException e ) {
114
115
throw new IllegalArgumentException (e );
0 commit comments