Skip to content

Commit

Permalink
MNT-23927 Handle JsonMappingException and JsonGenerationException (#2289
Browse files Browse the repository at this point in the history
)

* Throw JSON exceptions as IO exceptions to be properly handled
* Log null prop keys
* Fix test to have the mocked response different than null
  • Loading branch information
evasques authored Nov 8, 2023
1 parent 6065c6f commit a3ccafb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,9 @@ public void withWriter(OutputStream outStream, Writer writer) throws IOException
JsonGenerator generator = objectMapper.getFactory().createGenerator(outStream, encoding);
writer.writeContents(generator, objectMapper);
}
catch (JsonMappingException error)
catch (JsonMappingException | JsonGenerationException error)
{
logger.error("Failed to write Json output", error);
}
catch (JsonGenerationException generror)
{
logger.error("Failed to write Json output", generror);
throw new IOException("Failed to write Json output", error);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,15 @@ public void testInvokeAbstract() throws IOException
{
AbstractResourceWebScript executor = getExecutor();
Map<String, String> templateVars = new HashMap();

WebScriptResponse response = mockResponse();
templateVars.put("apiScope", "private");
templateVars.put("apiVersion", "1");
templateVars.put("apiName", "alfrescomock");
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "sheep");
executor.execute(ApiAssistant.determineApi(templateVars), mockRequest(templateVars,new HashMap<String, List<String>>(1)), mock(WebScriptResponse.class));
executor.execute(ApiAssistant.determineApi(templateVars), mockRequest(templateVars,new HashMap<String, List<String>>(1)), response);

WebScriptResponse response = mockResponse();
response = mockResponse();
templateVars.put(ResourceLocator.COLLECTION_RESOURCE, "bad");
executor.execute(api, mockRequest(templateVars,new HashMap<String, List<String>>(1)), response);
//throws a runtime exception so INTERNAL_SERVER_ERROR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,10 @@ else if (container instanceof Map<?, ?>)
{
Map<Serializable, Serializable> map = (Map<Serializable, Serializable>) container;
Serializable mapKey = getPropertyValueById(keyPropId).getSecond();
if(mapKey == null)
{
logger.error("Found null key for id " + keyPropId + " with value " + value);
}
map.put(mapKey, value);
}
else if (container instanceof Collection<?>)
Expand Down

0 comments on commit a3ccafb

Please sign in to comment.