Start structural port from Spring Boot to Undertow
This commit is contained in:
@@ -20,16 +20,15 @@
|
||||
|
||||
package io.kamax.mxisd.directory;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import io.kamax.matrix.MatrixErrorInfo;
|
||||
import io.kamax.matrix.json.GsonUtil;
|
||||
import io.kamax.mxisd.config.DirectoryConfig;
|
||||
import io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchRequest;
|
||||
import io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult;
|
||||
import io.kamax.mxisd.dns.ClientDnsOverwrite;
|
||||
import io.kamax.mxisd.exception.HttpMatrixException;
|
||||
import io.kamax.mxisd.exception.InternalServerError;
|
||||
import io.kamax.mxisd.util.GsonUtil;
|
||||
import io.kamax.mxisd.http.io.UserDirectorySearchRequest;
|
||||
import io.kamax.mxisd.http.io.UserDirectorySearchResult;
|
||||
import io.kamax.mxisd.util.RestClientUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@@ -40,8 +39,6 @@ import org.apache.http.entity.ContentType;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -49,25 +46,19 @@ import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class DirectoryManager {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(DirectoryManager.class);
|
||||
private transient final Logger log = LoggerFactory.getLogger(DirectoryManager.class);
|
||||
|
||||
private DirectoryConfig cfg;
|
||||
private ClientDnsOverwrite dns;
|
||||
private CloseableHttpClient client;
|
||||
private List<IDirectoryProvider> providers;
|
||||
|
||||
private ClientDnsOverwrite dns;
|
||||
private Gson gson;
|
||||
|
||||
@Autowired
|
||||
private CloseableHttpClient client;
|
||||
|
||||
@Autowired
|
||||
public DirectoryManager(DirectoryConfig cfg, List<IDirectoryProvider> providers, ClientDnsOverwrite dns) {
|
||||
public DirectoryManager(DirectoryConfig cfg, ClientDnsOverwrite dns, CloseableHttpClient client, List<? extends IDirectoryProvider> providers) {
|
||||
this.cfg = cfg;
|
||||
this.dns = dns;
|
||||
this.gson = GsonUtil.build();
|
||||
this.client = client;
|
||||
this.providers = providers.stream().filter(IDirectoryProvider::isEnabled).collect(Collectors.toList());
|
||||
|
||||
log.info("Directory providers:");
|
||||
@@ -98,7 +89,7 @@ public class DirectoryManager {
|
||||
String body = IOUtils.toString(res.getEntity().getContent(), charset);
|
||||
|
||||
if (status != 200) {
|
||||
MatrixErrorInfo info = gson.fromJson(body, MatrixErrorInfo.class);
|
||||
MatrixErrorInfo info = GsonUtil.get().fromJson(body, MatrixErrorInfo.class);
|
||||
if (StringUtils.equals("M_UNRECOGNIZED", info.getErrcode())) { // FIXME no hardcoding, use Enum
|
||||
log.warn("Homeserver does not support Directory feature, skipping");
|
||||
} else {
|
||||
@@ -107,7 +98,7 @@ public class DirectoryManager {
|
||||
}
|
||||
}
|
||||
|
||||
UserDirectorySearchResult resultHs = gson.fromJson(body, UserDirectorySearchResult.class);
|
||||
UserDirectorySearchResult resultHs = GsonUtil.get().fromJson(body, UserDirectorySearchResult.class);
|
||||
log.info("Found {} match(es) in HS for '{}'", resultHs.getResults().size(), query);
|
||||
result.getResults().addAll(resultHs.getResults());
|
||||
if (resultHs.isLimited()) {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* mxisd - Matrix Identity Server Daemon
|
||||
* Copyright (C) 2018 Kamax Sàrl
|
||||
*
|
||||
* https://www.kamax.io/
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.kamax.mxisd.directory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DirectoryProviders {
|
||||
|
||||
private static final List<Supplier<? extends IDirectoryProvider>> suppliers = new ArrayList<>();
|
||||
|
||||
public static void register(Supplier<? extends IDirectoryProvider> supplier) {
|
||||
suppliers.add(supplier);
|
||||
}
|
||||
|
||||
public static List<? extends IDirectoryProvider> get() {
|
||||
return suppliers.stream().map(Supplier::get).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
package io.kamax.mxisd.directory;
|
||||
|
||||
import io.kamax.mxisd.controller.directory.v1.io.UserDirectorySearchResult;
|
||||
import io.kamax.mxisd.http.io.UserDirectorySearchResult;
|
||||
|
||||
public interface IDirectoryProvider {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user