Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove http client #626

Merged
merged 3 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
<!-- TODO: [ES] hazelcast 3.6 loses data on node shutdown. See hazelcast branch -->
<hazelcast.version>2.6.10</hazelcast.version>
<hamcrest.version>1.3</hamcrest.version>
<httpclient.version>4.5.12</httpclient.version>

<jaxb.version>2.2.11</jaxb.version>
<jflex.version>1.6.1</jflex.version>
Expand Down Expand Up @@ -418,11 +417,6 @@
<artifactId>velocity-engine-core</artifactId>
<version>${velocity.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>

<!-- jsoup HTML parser library @ http://jsoup.org/ -->
<dependency>
Expand Down
4 changes: 0 additions & 4 deletions whois-scheduler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>

<!-- testing -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@
import net.ripe.db.whois.common.rpsl.transform.FilterChangedFunction;
import net.ripe.db.whois.common.source.SourceContext;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.config.SocketConfig;
import org.apache.http.impl.client.HttpClients;
import org.glassfish.jersey.client.ClientProperties;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -50,6 +47,8 @@ class LacnicGrsSource extends GrsSource {
private final String userId;
private final String password;

private Client client;

@Autowired
LacnicGrsSource(
@Value("${grs.import.lacnic.source:}") final String source,
Expand All @@ -63,12 +62,17 @@ class LacnicGrsSource extends GrsSource {

this.userId = userId;
this.password = password;

this.client = ClientBuilder.newBuilder()
.property(ClientProperties.CONNECT_TIMEOUT, TIMEOUT)
.property(ClientProperties.READ_TIMEOUT, TIMEOUT)
.build();
}

@Override
public void acquireDump(final Path path) throws IOException {
final Document loginPage = parse(get("http://lacnic.net/cgi-bin/lacnic/stini?lg=EN"));
final String loginAction = "http://lacnic.net" + loginPage.select("form").attr("action");
final Document loginPage = parse(get("https://lacnic.net/cgi-bin/lacnic/stini?lg=EN"));
final String loginAction = "https://lacnic.net" + loginPage.select("form").attr("action");

post(loginAction);

Expand All @@ -77,38 +81,16 @@ public void acquireDump(final Path path) throws IOException {
downloader.downloadTo(logger, new URL(downloadAction), path);
}

private String get(final String url) throws IOException {
final HttpClient client = HttpClients
.custom()
.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(TIMEOUT).build())
.build();
final HttpUriRequest request = RequestBuilder
.get()
.setUri(url)
.setConfig(RequestConfig.custom().setConnectTimeout(TIMEOUT).build())
.build();
return IOUtils.toString(
client.execute(request)
.getEntity()
.getContent());
private String get(final String url) {
return client.target(url).request().get(String.class);
}

private String post(final String url) throws IOException {
final HttpClient client = HttpClients
.custom()
.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(TIMEOUT).build())
.build();
final HttpUriRequest request = RequestBuilder
.post()
.addParameter("handle", userId)
.addParameter("passwd", password)
.setUri(url)
.setConfig(RequestConfig.custom().setConnectTimeout(TIMEOUT).build())
.build();
return IOUtils.toString(
client.execute(request)
.getEntity()
.getContent());
private String post(final String url) {
return client.target(url)
.queryParam("handle", userId)
.queryParam("passwd", password)
.request()
.post(null, String.class);
}

private static Document parse(final String data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.springframework.test.annotation.DirtiesContext;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand All @@ -43,7 +42,7 @@ public class GrsImporterLacnicManualIntegrationTest extends AbstractSchedulerInt
private static final File tempDirectory = Files.createTempDir();

@BeforeClass
public static void setup_database() throws IOException {
public static void setup_database() {
DatabaseHelper.addGrsDatabases("LACNIC-GRS");

System.setProperty("grs.import.lacnic.source", "LACNIC-GRS");
Expand All @@ -55,7 +54,7 @@ public static void setup_database() throws IOException {
}

@AfterClass
public static void cleanup() throws Exception {
public static void cleanup() {
FileHelper.delete(tempDirectory);
}

Expand All @@ -76,7 +75,7 @@ public void import_lacnic_grs_download_dump() throws Exception {
}

@Test
public void import_lacnic_grs_use_downloaded_dump() throws Exception {
public void import_lacnic_grs_use_downloaded_dump() {
grsSourceImporter.grsImport(lacnicGrsSource, false);

assertThat(query("-s LACNIC-GRS SOME-MNT"), containsString("mntner: SOME-MNT"));
Expand All @@ -90,7 +89,7 @@ private void awaitAll(final List<Future> futures) throws ExecutionException, Int
}
}

private String query(final String query) throws Exception {
private String query(final String query) {
return TelnetWhoisClient.queryLocalhost(QueryServer.port, query);
}
}