V1.4.6 Fill in the missing CloseableHttpClient configuration

master
Ng Yat Yan 3 weeks ago
parent 0d3750aa49
commit 2e98db494e

@ -1,5 +1,5 @@
ssh-server: ssh-server:
port: 22 port: 2022
private-key: private-key:
location: "conf/private.key" location: "conf/private.key"
hash-replies: hash-replies:

@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.example.sshd</groupId> <groupId>com.example.sshd</groupId>
<artifactId>echo-sshd-server</artifactId> <artifactId>echo-sshd-server</artifactId>
<version>1.4.5</version> <version>1.4.6</version>
<name>ECHO SSH SERVER</name> <name>ECHO SSH SERVER</name>
<description>Learning Apache Mina SSHD library</description> <description>Learning Apache Mina SSHD library</description>
<parent> <parent>

@ -5,6 +5,8 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
import org.apache.hc.client5.http.impl.async.HttpAsyncClients; import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.reactor.IOReactorConfig; import org.apache.hc.core5.reactor.IOReactorConfig;
import org.apache.sshd.common.Session; import org.apache.sshd.common.Session;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
@ -34,4 +36,9 @@ public class AppConfig {
client.start(); client.start();
return client; return client;
} }
@Bean
public CloseableHttpClient httpClient() {
return HttpClients.createDefault();
}
} }

@ -51,14 +51,18 @@ public class GeoIpLocator {
@Override @Override
public String handleResponse(ClassicHttpResponse result) throws HttpException, IOException { public String handleResponse(ClassicHttpResponse result) throws HttpException, IOException {
String body = new String(result.getEntity().getContent().readAllBytes(), StandardCharsets.UTF_8); String body = new String(result.getEntity().getContent().readAllBytes(), StandardCharsets.UTF_8);
logger.info("[{}] asyncClient.execute completed, response code: {}, body: {}", remoteIpAddress, logger.info("[{}] httpClient.execute completed, response code: {}, body: {}", remoteIpAddress,
result.getCode(), body); result.getCode(), body);
ipInfoMapping.put(remoteIpAddress, body);
int inserted = jdbcService.insertRemoteIpInfo(remoteIpAddress, body);
ipInfoLogger.info("[{}] {}, inserted = {}", remoteIpAddress, ipInfoMapping.get(remoteIpAddress),
inserted);
return body; return body;
} }
}); });
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); logger.error("[getIpLocationInfo] IO Exception has occurred!", e);
return null; return null;
} }
} }

Loading…
Cancel
Save