Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public FileFetcher(String apiUrl, String categoryName, boolean subcategories) {
*/
public void getCallResults(String category) throws IOException {

OkHttpClient client = new OkHttpClient.Builder().build();
OkHttpClient client = HttpClient.getClient();
urlBase = HttpUrl.parse(apiUrl).newBuilder()
.addQueryParameter("action", "query")
.addQueryParameter("list", "categorymembers")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.openrefine.extensions.commons.importer;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class HttpClient {

private static final String USER_AGENT = "OpenRefine-Commons-Extension/0.1.* (https://github.com/OpenRefine/CommonsExtension)";

public static OkHttpClient getClient() {
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new UserAgentInterceptor(USER_AGENT)).build();
return client;
}

static class UserAgentInterceptor implements Interceptor {

private final String userAgent;

public UserAgentInterceptor(String userAgent) {
this.userAgent = userAgent;
}

@Override
public Response intercept(Chain chain) throws IOException {
return chain.proceed(chain.request().newBuilder()
.header("User-Agent", userAgent)
.build());
}
}
private static OkHttpClient client;
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public List<List<String>> getRelatedCategories(List <FileRecord> fileRecordOrigi
while (titlesIndex < fileRecordOriginal.size()) {
titles += "|" + fileRecordOriginal.get(titlesIndex++).fileName;
}
OkHttpClient client = new OkHttpClient.Builder().build();
OkHttpClient client = HttpClient.getClient();
HttpUrl urlRelatedCategoriesBase = HttpUrl.parse(apiUrl).newBuilder()
.addQueryParameter("action", "query")
.addQueryParameter("prop", "categories")
Expand Down