/** * Transfers data from an {@code ODataResponse} into an {@code HttpServletResponse}. * * @param oDataResponse The {@code ODataResponse}. * @param servletResponse The {@code HttpServletResponse} * @throws java.io.IOException If an I/O error occurs. */ private void fillServletResponse(ODataResponse oDataResponse, HttpServletResponse servletResponse) throws IOException, ODataException { servletResponse.setStatus(oDataResponse.getStatus().getCode()); for (Map.Entry<String, String> entry : oDataResponse.getHeaders().entrySet()) { servletResponse.setHeader(entry.getKey(), entry.getValue()); } byte[] body = oDataResponse.getBody(); if (body != null && body.length != 0) { OutputStream out = servletResponse.getOutputStream(); out.write(oDataResponse.getBody()); out.flush(); } else if (oDataResponse.getStreamingContent() != null) { oDataResponse.getStreamingContent().write(servletResponse); } }
private void buildException(ODataException ex, StringBuilder sb, ProcessorResult result) { LOG.debug("{} was found. Start to create an error batch request"); if (result != null) { sb.append(HTTP_VERSION + " ").append(result.getStatus().toString().replace("_", " ")).append(NEW_LINE); } else if (ex.getCode() != null) { if (ex.getCode().toString().equals("ENTITY_NOT_FOUND_ERROR")) { sb.append(HTTP_VERSION + " ") .append(ODataResponse.Status.NOT_FOUND.toString().replace("_", " ")).append(NEW_LINE); } else { sb.append(HTTP_VERSION + " ") .append(ODataResponse.Status.BAD_REQUEST.toString().replace("_", " ")).append(NEW_LINE); } } sb.append(CONTENT_TYPE_HTTP).append(NEW_LINE); sb.append(CONTENT_LENGTH).append(COLON).append(contentLength).append(NEW_LINE).append(NEW_LINE); sb.append(ex.getMessage()).append(NEW_LINE); }
/** * Gets the status value for the given code. * * @param code The code to get the status value for. * @return The status value corresponding to the specified code. * @throws java.lang.IllegalArgumentException If there is no status value corresponding to the specified code. */ public static Status forCode(int code) { for (Status status : Status.values()) { if (status.code == code) { return status; } } throw new IllegalArgumentException("Invalid status code: " + code); }
/** * Transfers data from an {@code ODataResponse} into an {@code HttpServletResponse}. * * @param oDataResponse The {@code ODataResponse}. * @param servletResponse The {@code HttpServletResponse} * @throws java.io.IOException If an I/O error occurs. */ private void fillServletResponse(ODataResponse oDataResponse, HttpServletResponse servletResponse) throws IOException, ODataException { servletResponse.setStatus(oDataResponse.getStatus().getCode()); for (Map.Entry<String, String> entry : oDataResponse.getHeaders().entrySet()) { servletResponse.setHeader(entry.getKey(), entry.getValue()); } byte[] body = oDataResponse.getBody(); if (body != null && body.length != 0) { OutputStream out = servletResponse.getOutputStream(); out.write(oDataResponse.getBody()); out.flush(); } else if (oDataResponse.getStreamingContent() != null) { oDataResponse.getStreamingContent().write(servletResponse); } }
private Map<String, String> buildRenderedData(ProcessorResult result) throws ODataException { LOG.debug("Start to render the data"); Map<String, String> resultMap = new HashMap<>(); if (result.getStatus().getCode() < ODataResponse.Status.NO_CONTENT.getCode()) { String contentType = result.getHeaders().get(CONTENT_TYPE); if (!result.getHeaders().containsKey(CONTENT_TYPE) || contentType.startsWith(MediaType.ATOM_XML.toString())) { // render XML resultMap.put(FORMAT, MediaType.ATOM_XML.toString()); resultMap.put(BODY, getRenderedXML(result)); } else if (contentType.startsWith(MediaType.JSON.toString())) { // render JSON resultMap.put(FORMAT, MediaType.JSON.toString()); resultMap.put(BODY, getRenderedJSON(result)); } } else { resultMap.put(FORMAT, MediaType.HTTP.getSubType()); resultMap.put(BODY, (String) result.getData()); } return resultMap; }
private Map<String, String> buildRenderedData(ProcessorResult result) throws ODataException { LOG.debug("Start to render the data"); Map<String, String> resultMap = new HashMap<>(); if (result.getStatus().getCode() < ODataResponse.Status.NO_CONTENT.getCode()) { String contentType = result.getHeaders().get(CONTENT_TYPE); if (!result.getHeaders().containsKey(CONTENT_TYPE) || contentType.startsWith(MediaType.ATOM_XML.toString())) { // render XML resultMap.put(FORMAT, MediaType.ATOM_XML.toString()); resultMap.put(BODY, getRenderedXML(result)); } else if (contentType.startsWith(MediaType.JSON.toString())) { // render JSON resultMap.put(FORMAT, MediaType.JSON.toString()); resultMap.put(BODY, getRenderedJSON(result)); } } else { resultMap.put(FORMAT, MediaType.HTTP.getSubType()); resultMap.put(BODY, (String) result.getData()); } return resultMap; }
private void buildObjectData(StringBuilder sb, ProcessorResult result, Map<String, String> renderMap) { String location = result.getHeaders().get(LOCATION); sb.append(HTTP_VERSION + " ").append(result.getStatus().toString().replace("_", " ")).append(NEW_LINE); sb.append(CONTENT_TYPE).append(COLON).append(renderMap.get(FORMAT)).append(NEW_LINE); if (location != null) { sb.append(LOCATION).append(COLON).append(location).append(NEW_LINE); } sb.append(CONTENT_LENGTH).append(COLON).append(contentLength).append(NEW_LINE); sb.append(NEW_LINE); if (renderMap.get(BODY) != null) { sb.append(renderMap.get(BODY)).append(NEW_LINE).append(NEW_LINE); } else { // DELETE shouldn't contain message inside the batch body sb.append(NEW_LINE); } }
private void buildException(ODataException ex, StringBuilder sb, ProcessorResult result) { LOG.debug("{} was found. Start to create an error batch request"); if (result != null) { sb.append(HTTP_VERSION + " ").append(result.getStatus().toString().replace("_", " ")).append(NEW_LINE); } else if (ex.getCode() != null) { if (ex.getCode().toString().equals("ENTITY_NOT_FOUND_ERROR")) { sb.append(HTTP_VERSION + " ") .append(ODataResponse.Status.NOT_FOUND.toString().replace("_", " ")).append(NEW_LINE); } else { sb.append(HTTP_VERSION + " ") .append(ODataResponse.Status.BAD_REQUEST.toString().replace("_", " ")).append(NEW_LINE); } } sb.append(CONTENT_TYPE_HTTP).append(NEW_LINE); sb.append(CONTENT_LENGTH).append(COLON).append(contentLength).append(NEW_LINE).append(NEW_LINE); sb.append(ex.getMessage()).append(NEW_LINE); }
private void buildObjectData(StringBuilder sb, ProcessorResult result, Map<String, String> renderMap) { String location = result.getHeaders().get(LOCATION); sb.append(HTTP_VERSION + " ").append(result.getStatus().toString().replace("_", " ")).append(NEW_LINE); sb.append(CONTENT_TYPE).append(COLON).append(renderMap.get(FORMAT)).append(NEW_LINE); if (location != null) { sb.append(LOCATION).append(COLON).append(location).append(NEW_LINE); } sb.append(CONTENT_LENGTH).append(COLON).append(contentLength).append(NEW_LINE); sb.append(NEW_LINE); if (renderMap.get(BODY) != null) { sb.append(renderMap.get(BODY)).append(NEW_LINE).append(NEW_LINE); } else { // DELETE shouldn't contain message inside the batch body sb.append(NEW_LINE); } }
/** * Gets the status value for the given code. * * @param code The code to get the status value for. * @return The status value corresponding to the specified code. * @throws java.lang.IllegalArgumentException If there is no status value corresponding to the specified code. */ public static Status forCode(int code) { for (Status status : Status.values()) { if (status.code == code) { return status; } } throw new IllegalArgumentException("Invalid status code: " + code); }
@Override public String toString() { return code + " " + name(); } }
@Override public String toString() { return status.toString(); } }
@Override public String toString() { return status.toString(); } }
@Override public String toString() { return code + " " + name(); } }