From 6efc3d0aaa31b250c9dfef04ece02f7d6c1d782b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 11 Nov 2016 15:26:04 +0300 Subject: xmpp-ft: detect tomcat and add user factory for juick urls if present --- .../main/java/com/juick/components/XMPPFTServer.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) 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)); -- cgit v1.2.3