Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
duniter4j
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
jm
duniter4j
Commits
eab3d48b
Commit
eab3d48b
authored
7 years ago
by
Benoit Lavenier
Browse files
Options
Downloads
Patches
Plain Diff
[fix ]User event WS: id was not serialized - fix #12
parent
c9be06a7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/websocket/WebsocketUserEventEndPoint.java
+19
-1
19 additions, 1 deletion
...sticsearch/user/websocket/WebsocketUserEventEndPoint.java
with
19 additions
and
1 deletion
duniter4j-es-user/src/main/java/org/duniter/elasticsearch/user/websocket/WebsocketUserEventEndPoint.java
+
19
−
1
View file @
eab3d48b
...
...
@@ -38,6 +38,8 @@ package org.duniter.elasticsearch.user.websocket;
limitations under the License.
*/
import
com.fasterxml.jackson.annotation.JsonInclude
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
org.duniter.core.client.model.bma.Constants
;
import
org.duniter.core.util.StringUtils
;
import
org.duniter.elasticsearch.user.PluginSettings
;
...
...
@@ -59,6 +61,7 @@ import java.util.regex.Pattern;
public
class
WebsocketUserEventEndPoint
implements
UserEventService
.
UserEventListener
{
public
static
Locale
defaultLocale
;
public
static
ObjectMapper
mapper
;
public
static
class
Init
{
...
...
@@ -67,6 +70,10 @@ public class WebsocketUserEventEndPoint implements UserEventService.UserEventLis
webSocketServer
.
addEndPoint
(
WebsocketUserEventEndPoint
.
class
);
defaultLocale
=
pluginSettings
.
getI18nLocale
();
if
(
defaultLocale
==
null
)
defaultLocale
=
new
Locale
(
"en"
,
"GB"
);
// Define a static mapper
mapper
=
new
ObjectMapper
();
mapper
.
setSerializationInclusion
(
JsonInclude
.
Include
.
NON_NULL
);
}
}
...
...
@@ -100,7 +107,18 @@ public class WebsocketUserEventEndPoint implements UserEventService.UserEventLis
@Override
public
void
onEvent
(
UserEvent
event
)
{
session
.
getAsyncRemote
().
sendText
(
event
.
toJson
(
locale
));
try
{
UserEvent
copy
=
new
UserEvent
(
event
);
copy
.
setMessage
(
copy
.
getLocalizedMessage
(
locale
));
String
json
=
mapper
.
writeValueAsString
(
copy
);
// Force to serialized 'id' (skip @JsonIgnore) - fix #12
json
=
"{\"id\":\""
+
event
.
getId
()+
"\","
+
json
.
substring
(
1
);
session
.
getAsyncRemote
().
sendText
(
json
);
}
catch
(
IOException
e
)
{
// silent
}
}
@Override
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment