aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/configuration/XMPPConfiguration.java
diff options
context:
space:
mode:
Diffstat (limited to 'juick-www/src/main/java/com/juick/configuration/XMPPConfiguration.java')
-rw-r--r--juick-www/src/main/java/com/juick/configuration/XMPPConfiguration.java43
1 files changed, 43 insertions, 0 deletions
diff --git a/juick-www/src/main/java/com/juick/configuration/XMPPConfiguration.java b/juick-www/src/main/java/com/juick/configuration/XMPPConfiguration.java
new file mode 100644
index 00000000..91f55759
--- /dev/null
+++ b/juick-www/src/main/java/com/juick/configuration/XMPPConfiguration.java
@@ -0,0 +1,43 @@
+package com.juick.configuration;
+
+import com.juick.Message;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import rocks.xmpp.core.XmppException;
+import rocks.xmpp.core.session.Extension;
+import rocks.xmpp.core.session.XmppSessionConfiguration;
+import rocks.xmpp.core.session.debug.LogbackDebugger;
+import rocks.xmpp.extensions.component.accept.ExternalComponent;
+
+@Configuration
+public class XMPPConfiguration {
+ private static Logger logger = LoggerFactory.getLogger(XMPPConfiguration.class);
+ @Value("${xmpp_host:localhost}")
+ private String xmppHost;
+ @Value("${xmpp_password:secret}")
+ private String xmppPassword;
+ @Value("${www_xmpp_jid:www.juick.local}")
+ private String xmppJid;
+ @Value("${xmpp_port:5347}")
+ private int xmppPort;
+ @Value("${xmpp_disabled:false}")
+ private boolean isXmppDisabled;
+ @Bean
+ public ExternalComponent xmpp() {
+ XmppSessionConfiguration configuration = XmppSessionConfiguration.builder()
+ .extensions(Extension.of(Message.class))
+ .debugger(LogbackDebugger.class)
+ .build();
+ ExternalComponent xmpp = ExternalComponent.create(xmppJid, xmppPassword, configuration, xmppHost, xmppPort);
+ xmpp.addConnectionListener(e -> logger.error(e.toString(), e.getCause()));
+ if (!isXmppDisabled) try {
+ xmpp.connect();
+ } catch (XmppException e) {
+ logger.error("xmpp extension", e);
+ }
+ return xmpp;
+ }
+}