aboutsummaryrefslogtreecommitdiff
path: root/juick-crosspost/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'juick-crosspost/src/main/java/com/juick')
-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;
- }
}