aboutsummaryrefslogtreecommitdiff
path: root/juick-crosspost/src/main
diff options
context:
space:
mode:
authorGravatar Alexander Alexeev2016-11-11 01:48:49 +0700
committerGravatar Vitaly Takmazov2016-11-11 17:27:59 +0300
commitc0b9f667e25a9f23ff753c39a0366180a4a758c9 (patch)
tree75ccc2cf7e0e63c942358affb152f6be85312394 /juick-crosspost/src/main
parent6604dc96558028c0095f33eca1852de5e61f8466 (diff)
formatted
Diffstat (limited to 'juick-crosspost/src/main')
-rw-r--r--juick-crosspost/src/main/java/com/juick/components/Crosspost.java40
1 files changed, 22 insertions, 18 deletions
diff --git a/juick-crosspost/src/main/java/com/juick/components/Crosspost.java b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java
index ad667534..35623c40 100644
--- a/juick-crosspost/src/main/java/com/juick/components/Crosspost.java
+++ b/juick-crosspost/src/main/java/com/juick/components/Crosspost.java
@@ -31,11 +31,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.core.env.Environment;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.stereotype.Component;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
-import javax.inject.Inject;
import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.Socket;
@@ -46,23 +44,21 @@ import java.util.UUID;
import java.util.concurrent.ExecutorService;
/**
- *
* @author Ugnich Anton
*/
public class Crosspost implements DisposableBean, Stream.StreamListener, Message.MessageListener {
-
- private static Logger logger = LoggerFactory.getLogger(Crosspost.class);
-
public final static String TWITTERURL = "https://api.twitter.com/1.1/statuses/update.json";
public final static String FBURL = "https://graph.facebook.com/me/feed";
public final static String VKURL = "https://api.vk.com/method/wall.post";
+
+ private static Logger logger = LoggerFactory.getLogger(Crosspost.class);
+
JdbcTemplate jdbc;
Stream xmpp;
String twitter_consumer_key;
String twitter_consumer_secret;
ExecutorService service;
- @Inject
public Crosspost(Environment env, ExecutorService service, JdbcTemplate jdbc) {
this.service = service;
this.jdbc = jdbc;
@@ -79,6 +75,15 @@ public class Crosspost implements DisposableBean, Stream.StreamListener, Message
}
}
+ public static String percentEncode(String s) {
+ String ret = "";
+ try {
+ ret = URLEncoder.encode(s, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
+ } catch (UnsupportedEncodingException e) {
+ }
+ return ret;
+ }
+
@Override
public void destroy() {
logger.info("component destroyed");
@@ -102,7 +107,10 @@ public class Crosspost implements DisposableBean, Stream.StreamListener, Message
}
@Override
- public void onStreamFail(Exception e) {logger.error("XMPP STREAM FAIL", e);}
+ public void onStreamFail(Exception e) {
+ logger.error("XMPP STREAM FAIL", e);
+ }
+
@Override
public void onMessage(com.juick.xmpp.Message msg) {
JuickMessage jmsg = (JuickMessage) msg.getChild(JuickMessage.XMLNS);
@@ -129,7 +137,12 @@ public class Crosspost implements DisposableBean, Stream.StreamListener, Message
boolean ret = false;
try {
- String body = "access_token=" + URLEncoder.encode(token, "UTF-8") + "&message=" + URLEncoder.encode(status, "UTF-8") + "&link=http%3A%2F%2Fjuick.com%2F" + jmsg.getMID();
+ String body = "access_token="
+ + URLEncoder.encode(token, "UTF-8")
+ + "&message="
+ + URLEncoder.encode(status, "UTF-8")
+ + "&link=http%3A%2F%2Fjuick.com%2F"
+ + jmsg.getMID();
HttpsURLConnection conn = (HttpsURLConnection) new URL(FBURL).openConnection();
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
@@ -295,13 +308,4 @@ public class Crosspost implements DisposableBean, Stream.StreamListener, Message
}
return hashtags;
}
-
- public static String percentEncode(String s) {
- String ret = "";
- try {
- ret = URLEncoder.encode(s, "UTF-8").replace("+", "%20").replace("*", "%2A").replace("%7E", "~");
- } catch (UnsupportedEncodingException e) {
- }
- return ret;
- }
}