aboutsummaryrefslogtreecommitdiff
path: root/juick-xmpp-ft/src/main
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-11-11 15:26:04 +0300
committerGravatar Vitaly Takmazov2016-11-11 15:26:04 +0300
commit6efc3d0aaa31b250c9dfef04ece02f7d6c1d782b (patch)
tree222f457bcf2abea2d627c144b871d1d9d69f8481 /juick-xmpp-ft/src/main
parenta541e0aeed343cba2056d44f7de27bfae04ef38e (diff)
xmpp-ft: detect tomcat and add user factory for juick urls if present
Diffstat (limited to 'juick-xmpp-ft/src/main')
-rw-r--r--juick-xmpp-ft/src/main/java/com/juick/components/XMPPFTServer.java18
1 files changed, 17 insertions, 1 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 4a85b046..05f2b465 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
@@ -16,6 +16,8 @@ import rocks.xmpp.extensions.filetransfer.FileTransferManager;
import rocks.xmpp.extensions.oob.model.x.OobX;
import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.*;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -30,7 +32,21 @@ public class XMPPFTServer {
private static final Logger logger = LoggerFactory.getLogger(XMPPFTServer.class);
public XMPPFTServer(Environment env) {
- URL.setURLStreamHandlerFactory(new JuickURLStreamHandlerFactory());
+ try {
+ Class tomcathfc = Class.forName("org.apache.catalina.webresources.TomcatURLStreamHandlerFactory");
+ if (tomcathfc != null) {
+ try {
+ Method m = tomcathfc.getMethod("getInstance");
+ Object tomcathfo = m.invoke(null);
+ m = tomcathfo.getClass().getMethod("addUserFactory", URLStreamHandlerFactory.class);
+ m.invoke(tomcathfo, new JuickURLStreamHandlerFactory());
+ } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
+ logger.error("init error", e);
+ }
+ }
+ } catch (ClassNotFoundException e) {
+ 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));