diff --git a/CHANGELOG.md b/CHANGELOG.md index 05b5643fa..3b51e0600 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to AET will be documented in this file. ## Unreleased **List of changes that are finished but not yet released in any final version.** +- [PR-469](https://github.com/Cognifide/aet/pull/469) Fix WebAPI issues([#425](https://github.com/Cognifide/aet/issues/425)) - [PR-439](https://github.com/Cognifide/aet/pull/439) Fixed duplicating line and column numbers in accessibility tab - [PR-360](https://github.com/Cognifide/aet/pull/360) Keyboard shortcuts for 'Accept/Revert url/test' buttons ([#317](https://github.com/Cognifide/aet/issues/317)) - [PR-432](https://github.com/Cognifide/aet/pull/432) Fixed issue with lack of clear message for erroneous suite definition. diff --git a/core/datastorage/src/main/java/com/cognifide/aet/vs/artifacts/ArtifactsDAOMongoDBImpl.java b/core/datastorage/src/main/java/com/cognifide/aet/vs/artifacts/ArtifactsDAOMongoDBImpl.java index 6c3afba8a..f8be7b332 100644 --- a/core/datastorage/src/main/java/com/cognifide/aet/vs/artifacts/ArtifactsDAOMongoDBImpl.java +++ b/core/datastorage/src/main/java/com/cognifide/aet/vs/artifacts/ArtifactsDAOMongoDBImpl.java @@ -98,10 +98,12 @@ public Artifact getArtifact(DBKey dbKey, String objectID) { GridFS gfs = getGridFS(dbKey); BasicDBObject query = new BasicDBObject(); - query.put(ID_FIELD_NAME, new ObjectId(objectID)); - GridFSDBFile file = gfs.findOne(query); - if (file != null) { - artifact = new Artifact(file.getInputStream(), file.getContentType()); + if (ObjectId.isValid(objectID)) { + query.put(ID_FIELD_NAME, new ObjectId(objectID)); + GridFSDBFile file = gfs.findOne(query); + if (file != null) { + artifact = new Artifact(file.getInputStream(), file.getContentType()); + } } return artifact; } diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/ArtifactServlet.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/ArtifactServlet.java index a20cf2520..320e54821 100644 --- a/rest-endpoint/src/main/java/com/cognifide/aet/rest/ArtifactServlet.java +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/ArtifactServlet.java @@ -50,11 +50,10 @@ protected void process(DBKey dbKey, HttpServletRequest req, HttpServletResponse String id = req.getParameter(Helper.ID_PARAM); resp.setCharacterEncoding("UTF-8"); Artifact artifact = artifactsDAO.getArtifact(dbKey, id); - artifactsDAO.getArtifact(dbKey, id); if (artifact != null) { sendArtifact(req, resp, artifact); } else { - sendErrorMessage(dbKey, resp, id); + sendNotFoundMessage(dbKey, resp, id); } } @@ -70,12 +69,12 @@ private void sendArtifact(HttpServletRequest req, HttpServletResponse resp, Arti output.flush(); } - private void sendErrorMessage(DBKey dbKey, HttpServletResponse resp, String id) + private void sendNotFoundMessage(DBKey dbKey, HttpServletResponse resp, String id) throws IOException { - resp.setStatus(HttpURLConnection.HTTP_BAD_REQUEST); + resp.setStatus(HttpURLConnection.HTTP_NOT_FOUND); resp.setContentType("application/json"); resp.getWriter().write( - responseAsJson(GSON, "Unable to get artifact with id : %s form %s", id, dbKey.toString())); + responseAsJson(GSON, "Unable to get artifact with id: %s for %s", id, dbKey.toString())); } @Override diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/ConfigsServlet.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/ConfigsServlet.java index 218930078..e3fbd8b8e 100644 --- a/rest-endpoint/src/main/java/com/cognifide/aet/rest/ConfigsServlet.java +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/ConfigsServlet.java @@ -45,6 +45,8 @@ public class ConfigsServlet extends HttpServlet { private static final Logger LOGGER = LoggerFactory.getLogger(ConfigsServlet.class); + private static final Gson GSON = new Gson(); + public static final String LOCKS_PARAM = "locks"; public static final String LIST_PARAM = "list"; @@ -82,7 +84,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) { if (COMMUNICATION_SETTINGS_PARAM.equals(configType)) { CommunicationSettings communicationSettings = new CommunicationSettings(reportDomain); - responseWriter.write(new Gson().toJson(communicationSettings)); + responseWriter.write(GSON.toJson(communicationSettings)); } else if (LIST_PARAM.equals(configType)) { resp.setContentType("text/html; charset=utf-8"); resp.setHeader("User-Agent", @@ -121,7 +123,7 @@ private void flushResponseBuffer(HttpServletRequest req, HttpServletResponse res } private String getLocks() { - return lockService.getAllLocks().toString(); + return GSON.toJson(lockService.getAllLocks()); } @Override diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/MetadataServlet.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/MetadataServlet.java index d6fbfbaea..2cf90e5a1 100644 --- a/rest-endpoint/src/main/java/com/cognifide/aet/rest/MetadataServlet.java +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/MetadataServlet.java @@ -108,9 +108,7 @@ protected void process(DBKey dbKey, HttpServletRequest req, HttpServletResponse resp.setContentType("application/json"); resp.getWriter().write(result); } else { - resp.setStatus(HttpURLConnection.HTTP_BAD_REQUEST); - resp.getWriter() - .write(responseAsJson(GSON,"Unable to get Suite Metadata for %s", dbKey.toString())); + createNotFoundResponse(resp, correlationId, suiteName, suiteVersion, dbKey); } } @@ -192,6 +190,21 @@ private void checkLock(String suiteIdentifier) throws AETException { } } + private void createNotFoundResponse(HttpServletResponse response, String correlationId, String suiteName, String suiteVersion, DBKey dbKey) throws IOException { + response.setStatus(HttpURLConnection.HTTP_NOT_FOUND); + String paramsValuesMessage = ""; + if (correlationId != null) { + paramsValuesMessage = String.format("correlationId: %s", correlationId); + } else if (suiteName != null) { + paramsValuesMessage = String.format("suite name: %s", suiteName); + if (suiteVersion != null) { + paramsValuesMessage = String.format("%s, version: %s", paramsValuesMessage, suiteVersion); + } + } + response.getWriter() + .write(responseAsJson(GSON, "Unable to get Suite Metadata with %s for %s", paramsValuesMessage, dbKey.toString())); + } + @Activate public void start() { register(Helper.getMetadataPath());