@Test public void testChangeSetResponse() throws Exception { List<BatchResponsePart> parts = new ArrayList<BatchResponsePart>(); ODataResponse changeSetResponse = ODataResponse.status(HttpStatusCodes.NO_CONTENT).build(); List<ODataResponse> responses = new ArrayList<ODataResponse>(1); responses.add(changeSetResponse); parts.add(BatchResponsePart.responses(responses).changeSet(true).build()); BatchResponseWriter writer = new BatchResponseWriter(); ODataResponse batchResponse = writer.writeResponse(parts); assertEquals(202, batchResponse.getStatus().getStatusCode()); assertNotNull(batchResponse.getEntity()); BatchLineReader reader = new BatchLineReader(batchResponse.getEntityAsStream()); List<Line> lines = reader.toLineList(); reader.close(); int index = 0; assertTrue(lines.get(index++).toString().startsWith("--batch")); assertTrue(lines.get(index++).toString().startsWith("Content-Type: multipart/mixed; boundary=changeset_")); assertEquals(CRLF, lines.get(index++).toString()); assertTrue(lines.get(index++).toString().startsWith("--changeset")); assertEquals("Content-Type: application/http" + CRLF, lines.get(index++).toString()); assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(index++).toString()); assertEquals(CRLF, lines.get(index++).toString()); assertEquals("HTTP/1.1 204 No Content" + CRLF, lines.get(index++).toString()); assertEquals(CRLF, lines.get(index++).toString()); assertEquals(CRLF, lines.get(index++).toString()); assertTrue(lines.get(index++).toString().startsWith("--changeset")); assertTrue(lines.get(index).toString().startsWith("--batch")); }
public ODataResponse writeResponse(final List<BatchResponsePart> batchResponseParts) throws BatchException { String boundary = BatchHelper.generateBoundary("batch"); appendResponsePart(batchResponseParts, boundary); final Object batchResponseBody; int length = 0; if(writeEntityAsInputStream) { batchResponseBody = writer.getContentAsStream(); length = writer.calculateLength(batchResponseBody); } else { batchResponseBody = writer.getContentAsString(BatchHelper.DEFAULT_CHARSET); length = writer.calculateLength(batchResponseBody); } return ODataResponse.entity(batchResponseBody).status(HttpStatusCodes.ACCEPTED) .header(HttpHeaders.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + "; boundary=" + boundary) .header(HttpHeaders.CONTENT_LENGTH, String.valueOf(length)) .build(); }
BatchResponseWriter { public ODataResponse writeResponse(final List<BatchResponsePart> batchResponseParts) throws BatchException { String boundary = BatchHelper.generateBoundary("batch"); appendResponsePart(batchResponseParts, boundary); final Object batchResponseBody; int length = 0; if(writeEntityAsInputStream) { batchResponseBody = writer.getContentAsStream(); length = writer.calculateLength(batchResponseBody); } else { batchResponseBody = writer.getContentAsString(BatchHelper.DEFAULT_CHARSET); length = writer.calculateLength(batchResponseBody); } return ODataResponse.entity(batchResponseBody).status(HttpStatusCodes.ACCEPTED) .header(HttpHeaders.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + "; boundary=" + boundary) .header(HttpHeaders.CONTENT_LENGTH, String.valueOf(length)) .build(); } }
BatchResponseWriter { public ODataResponse writeResponse(final List<BatchResponsePart> batchResponseParts) throws BatchException { String boundary = BatchHelper.generateBoundary("batch"); appendResponsePart(batchResponseParts, boundary); final Object batchResponseBody; int length = 0; if(writeEntityAsInputStream) { batchResponseBody = writer.getContentAsStream(); length = writer.calculateLength(batchResponseBody); } else { batchResponseBody = writer.getContentAsString(BatchHelper.DEFAULT_CHARSET); length = writer.calculateLength(batchResponseBody); } return ODataResponse.entity(batchResponseBody).status(HttpStatusCodes.ACCEPTED) .header(HttpHeaders.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + "; boundary=" + boundary) .header(HttpHeaders.CONTENT_LENGTH, String.valueOf(length)) .build(); } BatchResponseWriter();  BatchResponseWriter(boolean writeEntityAsInputStream); }
BatchResponseWriter { public ODataResponse writeResponse(final List<BatchResponsePart> batchResponseParts) throws BatchException { String boundary = BatchHelper.generateBoundary("batch"); appendResponsePart(batchResponseParts, boundary); final Object batchResponseBody; int length = 0; if(writeEntityAsInputStream) { batchResponseBody = writer.getContentAsStream(); length = writer.calculateLength(batchResponseBody); } else { batchResponseBody = writer.getContentAsString(BatchHelper.DEFAULT_CHARSET); length = writer.calculateLength(batchResponseBody); } return ODataResponse.entity(batchResponseBody).status(HttpStatusCodes.ACCEPTED) .header(HttpHeaders.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + "; boundary=" + boundary) .header(HttpHeaders.CONTENT_LENGTH, String.valueOf(length)) .build(); } BatchResponseWriter();  BatchResponseWriter(boolean writeEntityAsInputStream); ODataResponse writeResponse(final List<BatchResponsePart> batchResponseParts); }
BatchResponseWriter { public ODataResponse writeResponse(final List<BatchResponsePart> batchResponseParts) throws BatchException { String boundary = BatchHelper.generateBoundary("batch"); appendResponsePart(batchResponseParts, boundary); final Object batchResponseBody; int length = 0; if(writeEntityAsInputStream) { batchResponseBody = writer.getContentAsStream(); length = writer.calculateLength(batchResponseBody); } else { batchResponseBody = writer.getContentAsString(BatchHelper.DEFAULT_CHARSET); length = writer.calculateLength(batchResponseBody); } return ODataResponse.entity(batchResponseBody).status(HttpStatusCodes.ACCEPTED) .header(HttpHeaders.CONTENT_TYPE, HttpContentType.MULTIPART_MIXED + "; boundary=" + boundary) .header(HttpHeaders.CONTENT_LENGTH, String.valueOf(length)) .build(); } BatchResponseWriter();  BatchResponseWriter(boolean writeEntityAsInputStream); ODataResponse writeResponse(final List<BatchResponsePart> batchResponseParts);  }