Search in sources :

Example 1 with ThreePidInviteIO

use of io.kamax.mxisd.storage.ormlite.ThreePidInviteIO in project mxisd by kamax-io.

the class InvitationManager method postConstruct.

@PostConstruct
private void postConstruct() {
    gson = new Gson();
    log.info("Loading saved invites");
    Collection<ThreePidInviteIO> ioList = storage.getInvites();
    ioList.forEach(io -> {
        log.info("Processing invite {}", gson.toJson(io));
        ThreePidInvite invite = new ThreePidInvite(new MatrixID(io.getSender()), io.getMedium(), io.getAddress(), io.getRoomId(), io.getProperties());
        ThreePidInviteReply reply = new ThreePidInviteReply(getId(invite), invite, io.getToken(), "");
        invitations.put(reply.getId(), reply);
    });
    // FIXME export such madness into matrix-java-sdk with a nice wrapper to talk to a homeserver
    try {
        SSLContext sslContext = SSLContextBuilder.create().loadTrustMaterial(new TrustSelfSignedStrategy()).build();
        HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
        SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
        client = HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build();
    } catch (Exception e) {
        // FIXME do better...
        throw new RuntimeException(e);
    }
    log.info("Setting up invitation mapping refresh timer");
    refreshTimer = new Timer();
    refreshTimer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            try {
                lookupMappingsForInvites();
            } catch (Throwable t) {
                log.error("Error when running background mapping refresh", t);
            }
        }
    }, 5000L, TimeUnit.MILLISECONDS.convert(cfg.getResolution().getTimer(), TimeUnit.MINUTES));
}
Also used : NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) ThreePidInviteIO(io.kamax.mxisd.storage.ormlite.ThreePidInviteIO) Gson(com.google.gson.Gson) SSLContext(javax.net.ssl.SSLContext) SSLConnectionSocketFactory(org.apache.http.conn.ssl.SSLConnectionSocketFactory) MappingAlreadyExistsException(io.kamax.mxisd.exception.MappingAlreadyExistsException) BadRequestException(io.kamax.mxisd.exception.BadRequestException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) HostnameVerifier(javax.net.ssl.HostnameVerifier) MatrixID(io.kamax.matrix.MatrixID) TrustSelfSignedStrategy(org.apache.http.conn.ssl.TrustSelfSignedStrategy) PostConstruct(javax.annotation.PostConstruct)

Aggregations

Gson (com.google.gson.Gson)1 MatrixID (io.kamax.matrix.MatrixID)1 BadRequestException (io.kamax.mxisd.exception.BadRequestException)1 MappingAlreadyExistsException (io.kamax.mxisd.exception.MappingAlreadyExistsException)1 ThreePidInviteIO (io.kamax.mxisd.storage.ormlite.ThreePidInviteIO)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 PostConstruct (javax.annotation.PostConstruct)1 HostnameVerifier (javax.net.ssl.HostnameVerifier)1 SSLContext (javax.net.ssl.SSLContext)1 NoopHostnameVerifier (org.apache.http.conn.ssl.NoopHostnameVerifier)1 SSLConnectionSocketFactory (org.apache.http.conn.ssl.SSLConnectionSocketFactory)1 TrustSelfSignedStrategy (org.apache.http.conn.ssl.TrustSelfSignedStrategy)1