aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp-ft/src/main/java/com/juick/components
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-11 15:04:04 +0300
committerGravatar Vitaly Takmazov2016-11-11 15:04:04 +0300
commita541e0aeed343cba2056d44f7de27bfae04ef38e (patch)
tree2f5cdef572ed0ff18a132d7ac0a52480f6d5b3f4 /juick-xmpp-ft/src/main/java/com/juick/components
parentfcbf13dae35f024ceace25bcbf81a3cd05d6243a (diff)
xmpp-ft: add boilerplate to support juick URL scheme (remove when OobX will be fixed)
Diffstat (limited to 'juick-xmpp-ft/src/main/java/com/juick/components')
-rw-r--r--juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java7
-rw-r--r--juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLConnection.java18
-rw-r--r--juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLStreamHandler.java16
-rw-r--r--juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLStreamHandlerFactory.java17
4 files changed, 54 insertions, 4 deletions
diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java b/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java
index 6726a156..4a85b046 100644
--- a/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java
+++ b/juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java
@@ -1,5 +1,6 @@
package com.juick.components;
+import com.juick.components.url.JuickURLStreamHandlerFactory;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.math.NumberUtils;
@@ -15,10 +16,7 @@ import rocks.xmpp.extensions.filetransfer.FileTransferManager;
import rocks.xmpp.extensions.oob.model.x.OobX;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
+import java.net.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -32,6 +30,7 @@ public class XMPPFTServer {
private static final Logger logger = LoggerFactory.getLogger(XMPPFTServer.class);
public XMPPFTServer(Environment env) {
+ URL.setURLStreamHandlerFactory(new JuickURLStreamHandlerFactory());
ExternalComponent component = ExternalComponent.create(env.getProperty("component_name", "files"),
env.getProperty("component_password", "secret"), env.getProperty("component_host", "localhost"),
NumberUtils.toInt(env.getProperty("component_port", "5347"), 5347));
diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLConnection.java b/juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLConnection.java
new file mode 100644
index 00000000..f467f75b
--- /dev/null
+++ b/juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLConnection.java
@@ -0,0 +1,18 @@
+package com.juick.components.url;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+
+/**
+ * Created by vitalyster on 11.11.2016.
+ */
+public class JuickURLConnection extends URLConnection {
+ protected JuickURLConnection(URL url) {
+ super(url);
+ }
+ @Override
+ public void connect() throws IOException {
+
+ }
+}
diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLStreamHandler.java b/juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLStreamHandler.java
new file mode 100644
index 00000000..0a4d2ae3
--- /dev/null
+++ b/juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLStreamHandler.java
@@ -0,0 +1,16 @@
+package com.juick.components.url;
+
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLStreamHandler;
+
+/**
+ * Created by vitalyster on 11.11.2016.
+ */
+public class JuickURLStreamHandler extends URLStreamHandler {
+ @Override
+ protected URLConnection openConnection(URL u) throws IOException {
+ return new JuickURLConnection(u);
+ }
+}
diff --git a/juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLStreamHandlerFactory.java b/juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLStreamHandlerFactory.java
new file mode 100644
index 00000000..d7c9559e
--- /dev/null
+++ b/juick-xmpp-ft/src/main/java/com/juick/components/url/JuickURLStreamHandlerFactory.java
@@ -0,0 +1,17 @@
+package com.juick.components.url;
+
+import java.net.URLStreamHandler;
+import java.net.URLStreamHandlerFactory;
+
+/**
+ * Created by vitalyster on 11.11.2016.
+ */
+public class JuickURLStreamHandlerFactory implements URLStreamHandlerFactory {
+ @Override
+ public URLStreamHandler createURLStreamHandler(String protocol) {
+ if ("juick".equals(protocol)) {
+ return new JuickURLStreamHandler();
+ }
+ return null;
+ }
+}