code: protected void commitResponse(final SecurityContext securityContext, final HttpServletRequest request, final HttpServletResponse response, final RestMethodResult result, final boolean wrapSingleResultInArray) {
  
  		final String outputDepthSrc       = request.getParameter(REQUEST_PARAMTER_OUTPUT_DEPTH);
  		final int outputDepth             = Services.parseInt(outputDepthSrc, config.getOutputNestingDepth());
  		final String baseUrl              = request.getRequestURI();
  		final Map<String, String> headers = result.getHeaders();
  
  		// set headers
  		for (final Entry<String, String> header : headers.entrySet()) {
  			response.setHeader(header.getKey(), header.getValue());
  		}
  
  		// set  response code
  		response.setStatus(result.getResponseCode());
  
  		try {
  
  			final List<Object> content = result.getContent();
  			if (content != null) {
  
  				writeJson(securityContext, response, new PagingIterable(content), baseUrl, outputDepth, wrapSingleResultInArray);
  
  			} else {
  
  				final String message = result.getMessage();
  				if (message != null) {
  
  					writeStatus(response, result.getResponseCode(), message);
  
  				} else {
  
  					final Object nonGraphObjectResult = result.getNonGraphObjectResult();
  					writeJson(securityContext, response, new PagingIterable(Arrays.asList(nonGraphObjectResult)), baseUrl, outputDepth, wrapSingleResultInArray);
  				}
  
  			}
  
  		} catch (JsonIOException | IOException t) {
  
  			logger.warn("Unable to commit HttpServletResponse", t);
  		}
  	}
docs: ----- protected methods -----