From a44a9d32a6b1d485e37e5c9773ebefd690a0ca0f Mon Sep 17 00:00:00 2001 From: JOSHUA Date: Wed, 3 Jan 2024 13:13:07 +0300 Subject: [PATCH 1/9] O3-310: allow Put operations on an application-writable config.json file There should be a `config.json` file that the application is allowed to manage, which lives in the application data directory. --- .../FrontendJsonConfigController1_9.java | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java new file mode 100644 index 000000000..b846017e3 --- /dev/null +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java @@ -0,0 +1,136 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public License, + * v. 2.0. If a copy of the MPL was not distributed with this file, You can + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. + * + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS + * graphic logo is a trademark of OpenMRS Inc. + */ +package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.charset.StandardCharsets; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.openmrs.User; +import org.openmrs.api.AdministrationService; +import org.openmrs.api.context.Context; +import org.openmrs.module.webservices.rest.web.RestConstants; +import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; +import org.openmrs.util.OpenmrsUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.codehaus.jackson.JsonProcessingException; +import org.codehaus.jackson.map.ObjectMapper; + +@Controller +@RequestMapping(value = "/rest/" + RestConstants.VERSION_1 + "/frontend/config.json") +public class FrontendJsonConfigController1_9 extends BaseRestController { + + private static final String DEFAULT_FRONTEND_DIRECTORY = "frontend"; + private static final String GP_LOCAL_DIRECTORY = "spa.local.directory"; + private static final String JSON_CONFIG_FILE_NAME = "config.json"; + + private static final Logger log = LoggerFactory.getLogger(FrontendJsonConfigController1_9.class); + + @RequestMapping(method = RequestMethod.GET) + public void getFrontendConfigFile(HttpServletRequest request, HttpServletResponse response) throws IOException { + File jsonConfigFile = getJsonConfigFile(); + if (!jsonConfigFile.exists()) { + log.debug("Configuration file does not exist"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Configuration file does not exist"); + } + try { + InputStream inputStream = new FileInputStream(jsonConfigFile); + OutputStream outStream = response.getOutputStream(); + OpenmrsUtil.copyFile(inputStream, outStream); + + response.setContentType("application/json"); + response.setHeader("Content-Disposition", "attachment; filename=" + jsonConfigFile.getName()); + response.setStatus(HttpServletResponse.SC_OK); + } catch (IOException e) { + log.error("Error reading Configuration file: " + jsonConfigFile.getAbsolutePath(), e); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error reading Configuration file: " + jsonConfigFile.getPath()); + } + } + + @RequestMapping(method = RequestMethod.POST) + @ResponseStatus(HttpStatus.OK) + public void saveFrontendConfigFile(HttpServletRequest request, HttpServletResponse response) throws IOException { + User user = Context.getAuthenticatedUser(); + if (user == null || !user.isSuperUser()) { + log.error("Authorization error while creating a config.json file"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, "Authorization error while creating a config.json file"); + return; + } + saveJsonConfigFile(request, response); + } + + private void saveJsonConfigFile(HttpServletRequest request, HttpServletResponse response) throws IOException { + File jsonConfigFile = getJsonConfigFile(); + try { + BufferedReader reader = request.getReader(); + StringBuilder stringBuilder = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + stringBuilder.append(line); + } + String requestBody = stringBuilder.toString(); + + // verify that is in a valid JSON format + new ObjectMapper().readTree(requestBody); + + InputStream inputStream = new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8)); + OutputStream outStream = Files.newOutputStream(jsonConfigFile.toPath()); + OpenmrsUtil.copyFile(inputStream, outStream); + + if (jsonConfigFile.exists()) { + log.debug("file: '{}' written successfully", jsonConfigFile.getAbsolutePath()); + response.setStatus(HttpServletResponse.SC_OK); + } + } catch (JsonProcessingException e) { + log.error("Invalid JSON format", e); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid JSON format"); + } + } + + private File getJsonConfigFile() throws IOException { + File folder = getSpaStaticFilesDir(); + if (!folder.isDirectory()) { + log.debug("Unable to find the OpenMRS SPA module frontend directory hence creating it at: " + folder.getAbsolutePath()); + if (!folder.mkdirs()) { + throw new IOException("Failed to create the OpenMRS SPA module frontend directory at: " + folder.getPath()); + } + } + return new File(folder.getAbsolutePath(), JSON_CONFIG_FILE_NAME); + } + + private File getSpaStaticFilesDir() { + AdministrationService as = Context.getAdministrationService(); + String folderName = as.getGlobalProperty(GP_LOCAL_DIRECTORY, DEFAULT_FRONTEND_DIRECTORY); + + // try to load the repository folder straight away. + File folder = new File(folderName); + + // if the property wasn't a full path already, assume it was intended to be a + // folder in the application directory + if (!folder.exists()) { + folder = new File(OpenmrsUtil.getApplicationDataDirectory(), folderName); + } + return folder; + } +} From 9c6d3eab1cbef01dc67a9b9a2244678579c8d525 Mon Sep 17 00:00:00 2001 From: JOSHUA Date: Thu, 11 Jan 2024 20:39:20 +0300 Subject: [PATCH 2/9] use IOUtils for oneline line reading --- .../FrontendJsonConfigController1_9.java | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java index b846017e3..f2bd2a2bb 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java @@ -34,6 +34,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseStatus; +import org.apache.commons.io.IOUtils; import org.codehaus.jackson.JsonProcessingException; import org.codehaus.jackson.map.ObjectMapper; @@ -52,7 +53,7 @@ public void getFrontendConfigFile(HttpServletRequest request, HttpServletRespons File jsonConfigFile = getJsonConfigFile(); if (!jsonConfigFile.exists()) { log.debug("Configuration file does not exist"); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Configuration file does not exist"); + response.sendError(HttpServletResponse.SC_NOT_FOUND, "Configuration file does not exist"); } try { InputStream inputStream = new FileInputStream(jsonConfigFile); @@ -74,7 +75,7 @@ public void saveFrontendConfigFile(HttpServletRequest request, HttpServletRespon User user = Context.getAuthenticatedUser(); if (user == null || !user.isSuperUser()) { log.error("Authorization error while creating a config.json file"); - response.sendError(HttpServletResponse.SC_FORBIDDEN, "Authorization error while creating a config.json file"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, "Authorization error while saving a config.json file"); return; } saveJsonConfigFile(request, response); @@ -83,18 +84,12 @@ public void saveFrontendConfigFile(HttpServletRequest request, HttpServletRespon private void saveJsonConfigFile(HttpServletRequest request, HttpServletResponse response) throws IOException { File jsonConfigFile = getJsonConfigFile(); try { - BufferedReader reader = request.getReader(); - StringBuilder stringBuilder = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - stringBuilder.append(line); - } - String requestBody = stringBuilder.toString(); + InputStream inputStream = request.getInputStream(); + String requestBody = IOUtils.toString( inputStream , "UTF-8"); // verify that is in a valid JSON format new ObjectMapper().readTree(requestBody); - - InputStream inputStream = new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8)); + inputStream = new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8)); OutputStream outStream = Files.newOutputStream(jsonConfigFile.toPath()); OpenmrsUtil.copyFile(inputStream, outStream); @@ -120,8 +115,7 @@ private File getJsonConfigFile() throws IOException { } private File getSpaStaticFilesDir() { - AdministrationService as = Context.getAdministrationService(); - String folderName = as.getGlobalProperty(GP_LOCAL_DIRECTORY, DEFAULT_FRONTEND_DIRECTORY); + String folderName = Context.getAdministrationService().getGlobalProperty(GP_LOCAL_DIRECTORY, DEFAULT_FRONTEND_DIRECTORY); // try to load the repository folder straight away. File folder = new File(folderName); From 1abae4c9cc2b5b5ca8b54d721c5b832a43e7cee4 Mon Sep 17 00:00:00 2001 From: JOSHUA Date: Fri, 12 Jan 2024 08:17:41 +0300 Subject: [PATCH 3/9] makee the auth error message more helpful --- .../controller/openmrs1_9/FrontendJsonConfigController1_9.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java index f2bd2a2bb..462968a11 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java @@ -75,7 +75,7 @@ public void saveFrontendConfigFile(HttpServletRequest request, HttpServletRespon User user = Context.getAuthenticatedUser(); if (user == null || !user.isSuperUser()) { log.error("Authorization error while creating a config.json file"); - response.sendError(HttpServletResponse.SC_FORBIDDEN, "Authorization error while saving a config.json file"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, "Authorization error. Admin privileges required to save the config.json file"); return; } saveJsonConfigFile(request, response); From bf467007bcc752272bce6dcc04bdf0285a732931 Mon Sep 17 00:00:00 2001 From: JOSHUA Date: Fri, 12 Jan 2024 08:26:03 +0300 Subject: [PATCH 4/9] remove unrequired spaces --- .../controller/openmrs1_9/FrontendJsonConfigController1_9.java | 1 - 1 file changed, 1 deletion(-) diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java index 462968a11..cee201a78 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java @@ -45,7 +45,6 @@ public class FrontendJsonConfigController1_9 extends BaseRestController { private static final String DEFAULT_FRONTEND_DIRECTORY = "frontend"; private static final String GP_LOCAL_DIRECTORY = "spa.local.directory"; private static final String JSON_CONFIG_FILE_NAME = "config.json"; - private static final Logger log = LoggerFactory.getLogger(FrontendJsonConfigController1_9.class); @RequestMapping(method = RequestMethod.GET) From 6ffb3dd67b31f1f1c101bdaad8a3693ed3b97f35 Mon Sep 17 00:00:00 2001 From: JOSHUA Date: Fri, 12 Jan 2024 14:32:01 +0300 Subject: [PATCH 5/9] move json validation to a loner try --- .../FrontendJsonConfigController1_9.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java index cee201a78..6d81a0645 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java @@ -82,24 +82,23 @@ public void saveFrontendConfigFile(HttpServletRequest request, HttpServletRespon private void saveJsonConfigFile(HttpServletRequest request, HttpServletResponse response) throws IOException { File jsonConfigFile = getJsonConfigFile(); + InputStream inputStream = request.getInputStream(); + String requestBody = IOUtils.toString( inputStream , "UTF-8"); try { - InputStream inputStream = request.getInputStream(); - String requestBody = IOUtils.toString( inputStream , "UTF-8"); - // verify that is in a valid JSON format new ObjectMapper().readTree(requestBody); - inputStream = new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8)); - OutputStream outStream = Files.newOutputStream(jsonConfigFile.toPath()); - OpenmrsUtil.copyFile(inputStream, outStream); - - if (jsonConfigFile.exists()) { - log.debug("file: '{}' written successfully", jsonConfigFile.getAbsolutePath()); - response.setStatus(HttpServletResponse.SC_OK); - } } catch (JsonProcessingException e) { log.error("Invalid JSON format", e); response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid JSON format"); } + inputStream = new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8)); + OutputStream outStream = Files.newOutputStream(jsonConfigFile.toPath()); + OpenmrsUtil.copyFile(inputStream, outStream); + + if (jsonConfigFile.exists()) { + log.debug("file: '{}' written successfully", jsonConfigFile.getAbsolutePath()); + response.setStatus(HttpServletResponse.SC_OK); + } } private File getJsonConfigFile() throws IOException { From a78f76d4b8a518f1701957cdea8fa857fc4ce7be Mon Sep 17 00:00:00 2001 From: JOSHUA Date: Mon, 15 Jan 2024 16:04:10 +0300 Subject: [PATCH 6/9] add support for the download parameter --- .../FrontendJsonConfigController1_9.java | 64 +++++++++++-------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java index 6d81a0645..6023ca427 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java @@ -9,7 +9,6 @@ */ package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_9; -import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.File; @@ -22,7 +21,6 @@ import javax.servlet.http.HttpServletResponse; import org.openmrs.User; -import org.openmrs.api.AdministrationService; import org.openmrs.api.context.Context; import org.openmrs.module.webservices.rest.web.RestConstants; import org.openmrs.module.webservices.rest.web.v1_0.controller.BaseRestController; @@ -33,6 +31,7 @@ import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseStatus; import org.apache.commons.io.IOUtils; import org.codehaus.jackson.JsonProcessingException; @@ -48,23 +47,29 @@ public class FrontendJsonConfigController1_9 extends BaseRestController { private static final Logger log = LoggerFactory.getLogger(FrontendJsonConfigController1_9.class); @RequestMapping(method = RequestMethod.GET) - public void getFrontendConfigFile(HttpServletRequest request, HttpServletResponse response) throws IOException { - File jsonConfigFile = getJsonConfigFile(); - if (!jsonConfigFile.exists()) { - log.debug("Configuration file does not exist"); - response.sendError(HttpServletResponse.SC_NOT_FOUND, "Configuration file does not exist"); - } + public void getFrontendConfigFile(HttpServletRequest request, HttpServletResponse response, + @RequestParam(value = "download", required = false) String download) throws IOException { try { + File jsonConfigFile = getJsonConfigFile(); + if (!jsonConfigFile.exists()) { + log.warn("Configuration file does not exist"); + response.sendError(HttpServletResponse.SC_NOT_FOUND, "Configuration file does not exist"); + } InputStream inputStream = new FileInputStream(jsonConfigFile); OutputStream outStream = response.getOutputStream(); OpenmrsUtil.copyFile(inputStream, outStream); - - response.setContentType("application/json"); - response.setHeader("Content-Disposition", "attachment; filename=" + jsonConfigFile.getName()); + boolean isDownloadRequested = Boolean.parseBoolean(download); + if (isDownloadRequested | download != null && download.isEmpty()) { + response.setContentType("application/x-download"); + response.setHeader("Content-Disposition", "attachment; filename=" + jsonConfigFile.getName()); + } else { + response.setContentType("application/json"); + } response.setStatus(HttpServletResponse.SC_OK); } catch (IOException e) { - log.error("Error reading Configuration file: " + jsonConfigFile.getAbsolutePath(), e); - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error reading Configuration file: " + jsonConfigFile.getPath()); + log.error("Error reading Configuration file {}", JSON_CONFIG_FILE_NAME, e); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, + "Error reading Configuration file: " + JSON_CONFIG_FILE_NAME); } } @@ -73,32 +78,34 @@ public void getFrontendConfigFile(HttpServletRequest request, HttpServletRespons public void saveFrontendConfigFile(HttpServletRequest request, HttpServletResponse response) throws IOException { User user = Context.getAuthenticatedUser(); if (user == null || !user.isSuperUser()) { - log.error("Authorization error while creating a config.json file"); - response.sendError(HttpServletResponse.SC_FORBIDDEN, "Authorization error. Admin privileges required to save the config.json file"); + log.error("Authorization error while saving a config.json file"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, + "Authorization error. Admin privileges required to save the " + JSON_CONFIG_FILE_NAME + " file"); return; } saveJsonConfigFile(request, response); } private void saveJsonConfigFile(HttpServletRequest request, HttpServletResponse response) throws IOException { - File jsonConfigFile = getJsonConfigFile(); - InputStream inputStream = request.getInputStream(); - String requestBody = IOUtils.toString( inputStream , "UTF-8"); + String requestBody = IOUtils.toString( request.getInputStream() , "UTF-8"); + try { // verify that is in a valid JSON format new ObjectMapper().readTree(requestBody); - } catch (JsonProcessingException e) { - log.error("Invalid JSON format", e); - response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid JSON format"); - } - inputStream = new ByteArrayInputStream(requestBody.getBytes(StandardCharsets.UTF_8)); - OutputStream outStream = Files.newOutputStream(jsonConfigFile.toPath()); - OpenmrsUtil.copyFile(inputStream, outStream); - - if (jsonConfigFile.exists()) { + File jsonConfigFile = getJsonConfigFile(); + OutputStream outStream = Files.newOutputStream(jsonConfigFile.toPath()); + outStream.write(requestBody.getBytes(StandardCharsets.UTF_8)); log.debug("file: '{}' written successfully", jsonConfigFile.getAbsolutePath()); response.setStatus(HttpServletResponse.SC_OK); } + catch (JsonProcessingException e) { + log.error("Invalid JSON format when reading: {}", requestBody, e); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid JSON format"); + } + catch (IOException e) { + log.error("Error while saving a config.json file: {}", JSON_CONFIG_FILE_NAME, e); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Error while saving a config.json file"); + } } private File getJsonConfigFile() throws IOException { @@ -106,6 +113,7 @@ private File getJsonConfigFile() throws IOException { if (!folder.isDirectory()) { log.debug("Unable to find the OpenMRS SPA module frontend directory hence creating it at: " + folder.getAbsolutePath()); if (!folder.mkdirs()) { + log.debug("Failed to create the OpenMRS SPA module frontend directory at: " + folder.getPath()); throw new IOException("Failed to create the OpenMRS SPA module frontend directory at: " + folder.getPath()); } } @@ -120,7 +128,7 @@ private File getSpaStaticFilesDir() { // if the property wasn't a full path already, assume it was intended to be a // folder in the application directory - if (!folder.exists()) { + if (!folder.isAbsolute()) { folder = new File(OpenmrsUtil.getApplicationDataDirectory(), folderName); } return folder; From b426de64d1f617a11dc3842021238dc720d09449 Mon Sep 17 00:00:00 2001 From: JOSHUA Date: Mon, 15 Jan 2024 16:07:43 +0300 Subject: [PATCH 7/9] fix formarting issue --- .../controller/openmrs1_9/FrontendJsonConfigController1_9.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java index 6023ca427..50d416eda 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java @@ -87,7 +87,7 @@ public void saveFrontendConfigFile(HttpServletRequest request, HttpServletRespon } private void saveJsonConfigFile(HttpServletRequest request, HttpServletResponse response) throws IOException { - String requestBody = IOUtils.toString( request.getInputStream() , "UTF-8"); + String requestBody = IOUtils.toString(request.getInputStream() , "UTF-8"); try { // verify that is in a valid JSON format From b6ef2eb5d9f9f62256078adbbf96417ca1c8ed1a Mon Sep 17 00:00:00 2001 From: JOSHUA Date: Tue, 16 Jan 2024 01:03:45 +0300 Subject: [PATCH 8/9] reveret header content type to JSON --- .../openmrs1_9/FrontendJsonConfigController1_9.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java index 50d416eda..6b318f97f 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java @@ -59,12 +59,10 @@ public void getFrontendConfigFile(HttpServletRequest request, HttpServletRespons OutputStream outStream = response.getOutputStream(); OpenmrsUtil.copyFile(inputStream, outStream); boolean isDownloadRequested = Boolean.parseBoolean(download); - if (isDownloadRequested | download != null && download.isEmpty()) { - response.setContentType("application/x-download"); - response.setHeader("Content-Disposition", "attachment; filename=" + jsonConfigFile.getName()); - } else { - response.setContentType("application/json"); - } + if (isDownloadRequested | download != null && download.isEmpty()) { + response.setHeader("Content-Disposition", "attachment; filename=" + jsonConfigFile.getName()); + } + response.setContentType("application/json"); response.setStatus(HttpServletResponse.SC_OK); } catch (IOException e) { log.error("Error reading Configuration file {}", JSON_CONFIG_FILE_NAME, e); From 3abd011f79592557c51de76f91839a3799296284 Mon Sep 17 00:00:00 2001 From: jnsereko <58003327+jnsereko@users.noreply.github.com> Date: Tue, 16 Jan 2024 03:38:22 +0300 Subject: [PATCH 9/9] remove empty spaces --- .../openmrs1_9/FrontendJsonConfigController1_9.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java index 6b318f97f..4fd22c2ae 100644 --- a/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java +++ b/omod-1.9/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_9/FrontendJsonConfigController1_9.java @@ -47,7 +47,7 @@ public class FrontendJsonConfigController1_9 extends BaseRestController { private static final Logger log = LoggerFactory.getLogger(FrontendJsonConfigController1_9.class); @RequestMapping(method = RequestMethod.GET) - public void getFrontendConfigFile(HttpServletRequest request, HttpServletResponse response, + public void getFrontendConfigFile(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "download", required = false) String download) throws IOException { try { File jsonConfigFile = getJsonConfigFile(); @@ -69,7 +69,7 @@ public void getFrontendConfigFile(HttpServletRequest request, HttpServletRespons response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error reading Configuration file: " + JSON_CONFIG_FILE_NAME); } - } + } @RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK)