-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from btison/outbox
ERDEMO-105: use outbox for all Kafka messages from process service
- Loading branch information
Showing
3 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...m/redhat/emergency/response/incident/consumer/serialization/QuotedStringDeserializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.redhat.emergency.response.incident.consumer.serialization; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.util.Map; | ||
|
||
import org.apache.commons.text.StringEscapeUtils; | ||
import org.apache.kafka.common.errors.SerializationException; | ||
import org.apache.kafka.common.serialization.Deserializer; | ||
|
||
public class QuotedStringDeserializer implements Deserializer<String> { | ||
|
||
private String encoding = "UTF8"; | ||
|
||
@Override | ||
public void configure(Map<String, ?> configs, boolean isKey) { | ||
String propertyName = isKey ? "key.deserializer.encoding" : "value.deserializer.encoding"; | ||
Object encodingValue = configs.get(propertyName); | ||
if (encodingValue == null) | ||
encodingValue = configs.get("deserializer.encoding"); | ||
if (encodingValue instanceof String) | ||
encoding = (String) encodingValue; | ||
} | ||
|
||
@Override | ||
public String deserialize(String topic, byte[] data) { | ||
try { | ||
if (data == null) { | ||
return null; | ||
} | ||
else { | ||
String deserialized = new String(data, encoding); | ||
if (deserialized.startsWith("\"")) { | ||
String unescaped = StringEscapeUtils.unescapeJson(deserialized); | ||
return unescaped.substring(1, unescaped.length()-1); | ||
} | ||
return deserialized; | ||
} | ||
} catch (UnsupportedEncodingException e) { | ||
throw new SerializationException("Error when deserializing byte[] to string due to unsupported encoding " + encoding); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
// nothing to do | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters