fix #1000 add content-type to json request

This commit is contained in:
Shinsuke Sugaya 2017-04-18 23:27:39 +09:00
parent 6c23fbc2f5
commit 4676815d47
3 changed files with 20 additions and 17 deletions

View file

@ -81,14 +81,16 @@ public class AdminBackupAction extends FessAdminAction {
logger.warn("Failed to process system.properties file: " + form.bulkFile.getFileName(), e);
}
} else {
try (CurlResponse response = Curl.post(ResourceUtil.getElasticsearchHttpUrl() + "/_bulk").onConnect((req, con) -> {
con.setDoOutput(true);
try (InputStream in = form.bulkFile.getInputStream(); OutputStream out = con.getOutputStream()) {
CopyUtil.copy(in, out);
} catch (IOException e) {
throw new IORuntimeException(e);
}
}).execute()) {
try (CurlResponse response =
Curl.post(ResourceUtil.getElasticsearchHttpUrl() + "/_bulk").header("Content-Type", "application/json")
.onConnect((req, con) -> {
con.setDoOutput(true);
try (InputStream in = form.bulkFile.getInputStream(); OutputStream out = con.getOutputStream()) {
CopyUtil.copy(in, out);
} catch (IOException e) {
throw new IORuntimeException(e);
}
}).execute()) {
if (logger.isDebugEnabled()) {
logger.debug("Bulk Response:\n" + response.getContentAsString());
}
@ -127,8 +129,8 @@ public class AdminBackupAction extends FessAdminAction {
return asStream(filename).contentTypeOctetStream().stream(
out -> {
try (CurlResponse response =
Curl.get(ResourceUtil.getElasticsearchHttpUrl() + "/" + index + "/_data").param("format", "json")
.execute()) {
Curl.get(ResourceUtil.getElasticsearchHttpUrl() + "/" + index + "/_data")
.header("Content-Type", "application/json").param("format", "json").execute()) {
out.write(response.getContentAsStream());
}
});

View file

@ -82,7 +82,7 @@ public class AdminEsreqAction extends FessAdminAction {
return asListHtml(() -> saveToken());
});
} else {
try (final CurlResponse response = curlRequest.body(buf.toString()).execute()) {
try (final CurlResponse response = curlRequest.header("Content-Type", "application/json").body(buf.toString()).execute()) {
final File tempFile = File.createTempFile("esreq_", ".json");
try (final InputStream in = response.getContentAsStream()) {
CopyUtil.copy(in, tempFile);

View file

@ -50,8 +50,9 @@ public class DictionaryManager {
public DictionaryFile<? extends DictionaryItem>[] getDictionaryFiles() {
try (CurlResponse response =
Curl.get(ResourceUtil.getElasticsearchHttpUrl() + "/_configsync/file").param("fields", "path,@timestamp")
.param("size", ComponentUtil.getFessConfig().getPageDictionaryMaxFetchSize()).execute()) {
Curl.get(ResourceUtil.getElasticsearchHttpUrl() + "/_configsync/file").header("Content-Type", "application/json")
.param("fields", "path,@timestamp").param("size", ComponentUtil.getFessConfig().getPageDictionaryMaxFetchSize())
.execute()) {
final Map<String, Object> contentMap = response.getContentAsMap();
@SuppressWarnings("unchecked")
final List<Map<String, Object>> fileList = (List<Map<String, Object>>) contentMap.get("file");
@ -96,8 +97,8 @@ public class DictionaryManager {
// TODO use stream
try (CurlResponse response =
Curl.post(ResourceUtil.getElasticsearchHttpUrl() + "/_configsync/file").param("path", dictFile.getPath())
.body(FileUtil.readUTF8(file)).execute()) {
Curl.post(ResourceUtil.getElasticsearchHttpUrl() + "/_configsync/file").header("Content-Type", "application/json")
.param("path", dictFile.getPath()).body(FileUtil.readUTF8(file)).execute()) {
final Map<String, Object> contentMap = response.getContentAsMap();
if (!Constants.TRUE.equalsIgnoreCase(contentMap.get("acknowledged").toString())) {
throw new DictionaryException("Failed to update " + dictFile.getPath());
@ -113,8 +114,8 @@ public class DictionaryManager {
public InputStream getContentInputStream(final DictionaryFile<? extends DictionaryItem> dictFile) {
try {
return Curl.get(ResourceUtil.getElasticsearchHttpUrl() + "/_configsync/file").param("path", dictFile.getPath()).execute()
.getContentAsStream();
return Curl.get(ResourceUtil.getElasticsearchHttpUrl() + "/_configsync/file").header("Content-Type", "application/json")
.param("path", dictFile.getPath()).execute().getContentAsStream();
} catch (final IOException e) {
throw new DictionaryException("Failed to access " + dictFile.getPath(), e);
}