@Test public void testBatchChangeSetUtf8() throws IOException, BatchException { List<BatchPart> batch = new ArrayList<BatchPart>(); Map<String, String> headers = new HashMap<String, String>(); headers.put("content-type", "application/json; charset=utf-8"); BatchChangeSetPart request = BatchChangeSetPart.method(PUT) .uri("Employees('2')") .body("{\"Age\":40, \"Name\": \"Wälter Winter\"}") .headers(headers) .contentId("111") .build(); BatchChangeSet changeSet = BatchChangeSet.newBuilder().build(); changeSet.add(request); batch.add(changeSet); BatchRequestWriter writer = new BatchRequestWriter(); InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY); BatchLineReader reader = new BatchLineReader(batchRequest); 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("Content-Id: 111" + CRLF, lines.get(index++).toString()); assertEquals(CRLF, lines.get(index++).toString()); assertEquals("PUT Employees('2') HTTP/1.1" + CRLF, lines.get(index++).toString()); assertEquals("Content-Length: 36" + CRLF, lines.get(index++).toString()); assertEquals("content-type: application/json; charset=utf-8" + CRLF, lines.get(index++).toString()); assertEquals(CRLF, lines.get(index++).toString()); assertEquals("{\"Age\":40, \"Name\": \"Wälter Winter\"}" + CRLF, lines.get(index++).toString()); assertTrue(lines.get(index++).toString().startsWith("--changeset")); assertTrue(lines.get(index++).toString().startsWith("--batch")); }
public InputStream writeBatchRequest(final List<BatchPart> batchParts, final String boundary) { if (boundary.matches(REG_EX_BOUNDARY)) { batchBoundary = boundary; } else { throw new IllegalArgumentException(); } for (BatchPart batchPart : batchParts) { writer.append("--").append(boundary).append(CRLF); if (batchPart instanceof BatchChangeSet) { appendChangeSet((BatchChangeSet) batchPart); } else if (batchPart instanceof BatchQueryPart) { BatchQueryPart request = (BatchQueryPart) batchPart; appendRequestBodyPart(request); } } writer.append("--").append(boundary).append("--"); InputStream batchRequestBody; batchRequestBody = new ByteArrayInputStream(writer.getContent()); return batchRequestBody; }
BatchRequestWriter { public InputStream writeBatchRequest(final List<BatchPart> batchParts, final String boundary) { if (boundary.matches(REG_EX_BOUNDARY)) { batchBoundary = boundary; } else { throw new IllegalArgumentException(); } for (BatchPart batchPart : batchParts) { writer.append("--").append(boundary).append(CRLF); if (batchPart instanceof BatchChangeSet) { appendChangeSet((BatchChangeSet) batchPart); } else if (batchPart instanceof BatchQueryPart) { BatchQueryPart request = (BatchQueryPart) batchPart; appendRequestBodyPart(request); } } writer.append("--").append(boundary).append("--"); InputStream batchRequestBody; batchRequestBody = new ByteArrayInputStream(writer.getContent()); return batchRequestBody; } }
BatchRequestWriter { public InputStream writeBatchRequest(final List<BatchPart> batchParts, final String boundary) { if (boundary.matches(REG_EX_BOUNDARY)) { batchBoundary = boundary; } else { throw new IllegalArgumentException(); } for (BatchPart batchPart : batchParts) { writer.append("--").append(boundary).append(CRLF); if (batchPart instanceof BatchChangeSet) { appendChangeSet((BatchChangeSet) batchPart); } else if (batchPart instanceof BatchQueryPart) { BatchQueryPart request = (BatchQueryPart) batchPart; appendRequestBodyPart(request); } } writer.append("--").append(boundary).append("--"); InputStream batchRequestBody; batchRequestBody = new ByteArrayInputStream(writer.getContent()); return batchRequestBody; }  }
BatchRequestWriter { public InputStream writeBatchRequest(final List<BatchPart> batchParts, final String boundary) { if (boundary.matches(REG_EX_BOUNDARY)) { batchBoundary = boundary; } else { throw new IllegalArgumentException(); } for (BatchPart batchPart : batchParts) { writer.append("--").append(boundary).append(CRLF); if (batchPart instanceof BatchChangeSet) { appendChangeSet((BatchChangeSet) batchPart); } else if (batchPart instanceof BatchQueryPart) { BatchQueryPart request = (BatchQueryPart) batchPart; appendRequestBodyPart(request); } } writer.append("--").append(boundary).append("--"); InputStream batchRequestBody; batchRequestBody = new ByteArrayInputStream(writer.getContent()); return batchRequestBody; }  InputStream writeBatchRequest(final List<BatchPart> batchParts, final String boundary); }
BatchRequestWriter { public InputStream writeBatchRequest(final List<BatchPart> batchParts, final String boundary) { if (boundary.matches(REG_EX_BOUNDARY)) { batchBoundary = boundary; } else { throw new IllegalArgumentException(); } for (BatchPart batchPart : batchParts) { writer.append("--").append(boundary).append(CRLF); if (batchPart instanceof BatchChangeSet) { appendChangeSet((BatchChangeSet) batchPart); } else if (batchPart instanceof BatchQueryPart) { BatchQueryPart request = (BatchQueryPart) batchPart; appendRequestBodyPart(request); } } writer.append("--").append(boundary).append("--"); InputStream batchRequestBody; batchRequestBody = new ByteArrayInputStream(writer.getContent()); return batchRequestBody; }  InputStream writeBatchRequest(final List<BatchPart> batchParts, final String boundary); static final String BOUNDARY_PREAMBLE; static final String HTTP_1_1; }