use of org.alfresco.rest.framework.jacksonextensions.JacksonHelper in project alfresco-remote-api by Alfresco.
the class ResponseWriter method renderErrorResponse.
/**
* Renders a JSON error response
*
* @param errorResponse The error
* @param res web script response
* @throws IOException
*/
default void renderErrorResponse(final ErrorResponse errorResponse, final WebScriptResponse res, final JacksonHelper jsonHelper) throws IOException {
String logId = "";
if (Status.STATUS_INTERNAL_SERVER_ERROR == errorResponse.getStatusCode() || resWriterLogger().isDebugEnabled()) {
logId = org.alfresco.util.GUID.generate();
resWriterLogger().error(logId + " : " + errorResponse.getStackTrace());
}
String stackMessage = I18NUtil.getMessage(DefaultExceptionResolver.STACK_MESSAGE_ID);
final ErrorResponse errorToWrite = new ErrorResponse(errorResponse.getErrorKey(), errorResponse.getStatusCode(), errorResponse.getBriefSummary(), stackMessage, logId, errorResponse.getAdditionalState(), DefaultExceptionResolver.ERROR_URL);
setContentInfoOnResponse(res, DEFAULT_JSON_CONTENT);
// Status must be set before the response is written by Jackson (which will by default close and commit the response).
// In a r/w txn, web script buffered responses ensure that it doesn't really matter but for r/o txns this is important.
res.setStatus(errorToWrite.getStatusCode());
jsonHelper.withWriter(res.getOutputStream(), new JacksonHelper.Writer() {
@SuppressWarnings("unchecked")
@Override
public void writeContents(JsonGenerator generator, ObjectMapper objectMapper) throws JsonGenerationException, JsonMappingException, IOException {
JSONObject obj = new JSONObject();
obj.put("error", errorToWrite);
objectMapper.writeValue(generator, obj);
}
});
}
use of org.alfresco.rest.framework.jacksonextensions.JacksonHelper in project alfresco-remote-api by Alfresco.
the class JsonJacksonTests method setupTests.
@BeforeClass
public static void setupTests() throws Exception {
jsonHelper = new JacksonHelper();
RestJsonModule module = new RestJsonModule();
jsonHelper.setModule(module);
jsonHelper.afterPropertiesSet();
}
use of org.alfresco.rest.framework.jacksonextensions.JacksonHelper in project alfresco-remote-api by Alfresco.
the class ParamsExtractorTests method setupTests.
@BeforeClass
public static void setupTests() throws Exception {
jsonHelper = new JacksonHelper();
RestJsonModule module = new RestJsonModule();
jsonHelper.setModule(module);
jsonHelper.afterPropertiesSet();
assistant = new ApiAssistant();
assistant.setJsonHelper(jsonHelper);
}
Aggregations