Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
memoriav
Memobase 2020
services
postprocessing
Fedora Metadata Extractor
Commits
17e25bde
Commit
17e25bde
authored
Jul 21, 2020
by
Jonas Waeber
Browse files
Add json parser exception handling.
Drop and log messages which cannot be parsed.
parent
6c8a61bf
Pipeline
#11779
passed with stages
in 6 minutes and 16 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
src/main/kotlin/KafkaTopology.kt
View file @
17e25bde
...
...
@@ -18,6 +18,8 @@
package
org.memobase
import
com.fasterxml.jackson.core.JsonParseException
import
com.fasterxml.jackson.databind.JsonMappingException
import
com.fasterxml.jackson.databind.ObjectMapper
import
com.fasterxml.jackson.module.kotlin.registerKotlinModule
import
org.apache.jena.rdf.model.Model
...
...
@@ -64,7 +66,7 @@ class KafkaTopology(
val
stream
=
builder
.
stream
<
String
,
String
>(
settings
.
inputTopic
)
val
objectBranches
=
stream
.
m
apValues
{
value
->
parseMessage
(
value
)
}
.
flatM
apValues
{
value
->
parseMessage
(
value
)
}
.
branch
(
// TODO: Add actual values.
Predicate
{
_
,
value
->
value
.
objectType
==
"rico:Record"
},
...
...
@@ -101,8 +103,16 @@ class KafkaTopology(
return
builder
.
build
()
}
private
fun
parseMessage
(
data
:
String
):
EventMessage
{
return
objectMapper
.
readValue
(
data
,
EventMessage
::
class
.
java
)
private
fun
parseMessage
(
data
:
String
):
List
<
EventMessage
>
{
return
try
{
listOf
(
objectMapper
.
readValue
(
data
,
EventMessage
::
class
.
java
))
}
catch
(
ex
:
JsonParseException
)
{
log
.
error
(
"Invalid json found: $data"
)
emptyList
()
}
catch
(
ex
:
JsonMappingException
)
{
log
.
error
(
"Could not parse the json object as an event message: $data"
)
emptyList
()
}
}
private
fun
requestPrimaryResource
(
message
:
EventMessage
):
Pair
<
EventMessage
,
String
>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment