Переглянути джерело

fix #1000 add content-type to json request

Shinsuke Sugaya 8 роки тому
батько
коміт
4676815d47

+ 12 - 10
src/main/java/org/codelibs/fess/app/web/admin/backup/AdminBackupAction.java

@@ -81,14 +81,16 @@ public class AdminBackupAction extends FessAdminAction {
                     logger.warn("Failed to process system.properties file: " + form.bulkFile.getFileName(), e);
                     logger.warn("Failed to process system.properties file: " + form.bulkFile.getFileName(), e);
                 }
                 }
             } else {
             } 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()) {
                     if (logger.isDebugEnabled()) {
                         logger.debug("Bulk Response:\n" + response.getContentAsString());
                         logger.debug("Bulk Response:\n" + response.getContentAsString());
                     }
                     }
@@ -127,8 +129,8 @@ public class AdminBackupAction extends FessAdminAction {
                 return asStream(filename).contentTypeOctetStream().stream(
                 return asStream(filename).contentTypeOctetStream().stream(
                         out -> {
                         out -> {
                             try (CurlResponse response =
                             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());
                                 out.write(response.getContentAsStream());
                             }
                             }
                         });
                         });

+ 1 - 1
src/main/java/org/codelibs/fess/app/web/admin/esreq/AdminEsreqAction.java

@@ -82,7 +82,7 @@ public class AdminEsreqAction extends FessAdminAction {
                 return asListHtml(() -> saveToken());
                 return asListHtml(() -> saveToken());
             });
             });
         } else {
         } 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");
                 final File tempFile = File.createTempFile("esreq_", ".json");
                 try (final InputStream in = response.getContentAsStream()) {
                 try (final InputStream in = response.getContentAsStream()) {
                     CopyUtil.copy(in, tempFile);
                     CopyUtil.copy(in, tempFile);

+ 7 - 6
src/main/java/org/codelibs/fess/dict/DictionaryManager.java

@@ -50,8 +50,9 @@ public class DictionaryManager {
 
 
     public DictionaryFile<? extends DictionaryItem>[] getDictionaryFiles() {
     public DictionaryFile<? extends DictionaryItem>[] getDictionaryFiles() {
         try (CurlResponse response =
         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();
             final Map<String, Object> contentMap = response.getContentAsMap();
             @SuppressWarnings("unchecked")
             @SuppressWarnings("unchecked")
             final List<Map<String, Object>> fileList = (List<Map<String, Object>>) contentMap.get("file");
             final List<Map<String, Object>> fileList = (List<Map<String, Object>>) contentMap.get("file");
@@ -96,8 +97,8 @@ public class DictionaryManager {
 
 
             // TODO use stream
             // TODO use stream
                 try (CurlResponse response =
                 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();
                     final Map<String, Object> contentMap = response.getContentAsMap();
                     if (!Constants.TRUE.equalsIgnoreCase(contentMap.get("acknowledged").toString())) {
                     if (!Constants.TRUE.equalsIgnoreCase(contentMap.get("acknowledged").toString())) {
                         throw new DictionaryException("Failed to update " + dictFile.getPath());
                         throw new DictionaryException("Failed to update " + dictFile.getPath());
@@ -113,8 +114,8 @@ public class DictionaryManager {
 
 
     public InputStream getContentInputStream(final DictionaryFile<? extends DictionaryItem> dictFile) {
     public InputStream getContentInputStream(final DictionaryFile<? extends DictionaryItem> dictFile) {
         try {
         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) {
         } catch (final IOException e) {
             throw new DictionaryException("Failed to access " + dictFile.getPath(), e);
             throw new DictionaryException("Failed to access " + dictFile.getPath(), e);
         }
         }