aboutsummaryrefslogtreecommitdiff
path: root/juick-www/src/main/java/com/juick/www/configuration/XMPPConfiguration.java
blob: 8afddf2d1231f061077ddf769bc41ddd9e46e62f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.juick.www.configuration;

import com.juick.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
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;
    @Bean
    @ConditionalOnMissingBean(type = "rocks.xmpp.extensions.component.accept.ExternalComponent")
    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()));
        try {
            xmpp.connect();
        } catch (XmppException e) {
            logger.error("xmpp extension", e);
        }
        return xmpp;
    }
}