aboutsummaryrefslogtreecommitdiff
path: root/juick-crosspost/src/main/java/com/juick/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2017-11-02 16:02:17 +0300
committerGravatar Vitaly Takmazov2017-11-02 16:12:40 +0300
commitee20020d9c576a48173c13b68b03d349c0ec3e47 (patch)
tree7c59dcac74cde4e5b819a245dc0fbbb315020f10 /juick-crosspost/src/main/java/com/juick/service
parent61c6a3fe338a5cbbef55081f8ac26011c053125d (diff)
server-web: base websocket component with autoreconnect
Diffstat (limited to 'juick-crosspost/src/main/java/com/juick/service')
-rw-r--r--juick-crosspost/src/main/java/com/juick/service/Crosspost.java14
1 files changed, 5 insertions, 9 deletions
diff --git a/juick-crosspost/src/main/java/com/juick/service/Crosspost.java b/juick-crosspost/src/main/java/com/juick/service/Crosspost.java
index a8458439..6bcf7c81 100644
--- a/juick-crosspost/src/main/java/com/juick/service/Crosspost.java
+++ b/juick-crosspost/src/main/java/com/juick/service/Crosspost.java
@@ -16,8 +16,8 @@
*/
package com.juick.service;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.juick.Message;
+import com.juick.server.component.MessageEvent;
import com.juick.util.MessageUtils;
import org.apache.commons.codec.CharEncoding;
import org.apache.commons.io.IOUtils;
@@ -26,11 +26,9 @@ import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.ApplicationListener;
import org.springframework.social.twitter.api.Twitter;
import org.springframework.social.twitter.api.impl.TwitterTemplate;
-import org.springframework.web.socket.TextMessage;
-import org.springframework.web.socket.WebSocketSession;
-import org.springframework.web.socket.handler.TextWebSocketHandler;
import javax.inject.Inject;
import javax.net.ssl.HttpsURLConnection;
@@ -42,7 +40,7 @@ import java.nio.charset.StandardCharsets;
/**
* @author Ugnich Anton
*/
-public class Crosspost extends TextWebSocketHandler {
+public class Crosspost implements ApplicationListener<MessageEvent> {
final static String FBURL = "https://graph.facebook.com/me/feed";
final static String VKURL = "https://api.vk.com/method/wall.post";
@@ -55,12 +53,10 @@ public class Crosspost extends TextWebSocketHandler {
private String twitter_consumer_key;
@Value("${twitter_consumer_secret:}")
private String twitter_consumer_secret;
- @Inject
- private ObjectMapper jsonMapper;
@Override
- protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
- Message msg = jsonMapper.readValue(message.asBytes(), Message.class);
+ public void onApplicationEvent(MessageEvent event) {
+ Message msg = event.getMessage();
if (msg.getMid() > 0 && msg.getRid() == 0) {
if (StringUtils.isNotEmpty(crosspostService.getTwitterName(msg.getUser().getUid()))) {
if (msg.getTags().stream().noneMatch(t -> t.getName().equals("notwitter"))) {