16
16
17
17
package org .springframework .kafka .support .serializer ;
18
18
19
- import java .io .ByteArrayOutputStream ;
20
- import java .io .IOException ;
21
- import java .io .ObjectOutputStream ;
22
19
import java .util .Map ;
23
20
import java .util .function .Function ;
24
21
25
22
import org .apache .kafka .common .header .Headers ;
26
- import org .apache .kafka .common .header .internals .RecordHeader ;
27
23
import org .apache .kafka .common .serialization .Deserializer ;
28
24
29
25
import org .springframework .util .Assert ;
@@ -46,18 +42,25 @@ public class ErrorHandlingDeserializer<T> implements Deserializer<T> {
46
42
47
43
/**
48
44
* Header name for deserialization exceptions.
45
+ * @deprecated in favor of {@link SerializationUtils#DESERIALIZER_EXCEPTION_HEADER_PREFIX}.
49
46
*/
50
- public static final String KEY_DESERIALIZER_EXCEPTION_HEADER_PREFIX = "springDeserializerException" ;
47
+ @ Deprecated
48
+ public static final String KEY_DESERIALIZER_EXCEPTION_HEADER_PREFIX =
49
+ SerializationUtils .DESERIALIZER_EXCEPTION_HEADER_PREFIX ;
51
50
52
51
/**
53
52
* Header name for deserialization exceptions.
53
+ * @deprecated in favor of {@link SerializationUtils#KEY_DESERIALIZER_EXCEPTION_HEADER}.
54
54
*/
55
- public static final String KEY_DESERIALIZER_EXCEPTION_HEADER = KEY_DESERIALIZER_EXCEPTION_HEADER_PREFIX + "Key" ;
55
+ @ Deprecated
56
+ public static final String KEY_DESERIALIZER_EXCEPTION_HEADER = SerializationUtils .KEY_DESERIALIZER_EXCEPTION_HEADER ;
56
57
57
58
/**
58
59
* Header name for deserialization exceptions.
60
+ * @deprecated in favor of {@link SerializationUtils#VALUE_DESERIALIZER_EXCEPTION_HEADER}.
59
61
*/
60
- public static final String VALUE_DESERIALIZER_EXCEPTION_HEADER = KEY_DESERIALIZER_EXCEPTION_HEADER_PREFIX + "Value" ;
62
+ @ Deprecated
63
+ public static final String VALUE_DESERIALIZER_EXCEPTION_HEADER = SerializationUtils .VALUE_DESERIALIZER_EXCEPTION_HEADER ;
61
64
62
65
/**
63
66
* Supplier for a T when deserialization fails.
@@ -188,7 +191,7 @@ public T deserialize(String topic, Headers headers, byte[] data) {
188
191
return this .delegate .deserialize (topic , headers , data );
189
192
}
190
193
catch (Exception e ) {
191
- deserializationException (headers , data , e , this .isForKey );
194
+ SerializationUtils . deserializationException (headers , data , e , this .isForKey );
192
195
return recoverFromSupplier (topic , headers , data , e );
193
196
}
194
197
}
@@ -211,39 +214,4 @@ public void close() {
211
214
}
212
215
}
213
216
214
- /**
215
- * Populate the record headers with a serialized {@link DeserializationException}.
216
- * @param headers the headers.
217
- * @param data the data.
218
- * @param ex the exception.
219
- * @param isForKeyArg true if this is a key deserialization problem, otherwise value.
220
- * @since 2.8
221
- */
222
- public static void deserializationException (Headers headers , byte [] data , Exception ex , boolean isForKeyArg ) {
223
- ByteArrayOutputStream stream = new ByteArrayOutputStream ();
224
- DeserializationException exception =
225
- new DeserializationException ("failed to deserialize" , data , isForKeyArg , ex );
226
- try (ObjectOutputStream oos = new ObjectOutputStream (stream )) {
227
- oos .writeObject (exception );
228
- }
229
- catch (IOException ioex ) {
230
- stream = new ByteArrayOutputStream ();
231
- try (ObjectOutputStream oos = new ObjectOutputStream (stream )) {
232
- exception = new DeserializationException ("failed to deserialize" ,
233
- data , isForKeyArg , new RuntimeException ("Could not deserialize type "
234
- + ioex .getClass ().getName () + " with message " + ioex .getMessage ()
235
- + " failure: " + ioex .getMessage ()));
236
- oos .writeObject (exception );
237
- }
238
- catch (IOException ex2 ) {
239
- throw new IllegalStateException ("Could not serialize a DeserializationException" , ex2 ); // NOSONAR
240
- }
241
- }
242
- headers .add (
243
- new RecordHeader (isForKeyArg
244
- ? KEY_DESERIALIZER_EXCEPTION_HEADER
245
- : VALUE_DESERIALIZER_EXCEPTION_HEADER ,
246
- stream .toByteArray ()));
247
- }
248
-
249
217
}
0 commit comments