@Test public void testGetRequest() throws IOException { List<BatchPart> batch = new ArrayList<BatchPart>(); Map<String, String> headers = new HashMap<String, String>(); headers.put("Accept", "application/json"); BatchPart request = BatchQueryPart.method(GET).uri("Employees").headers(headers).contentId("123").build(); batch.add(request); batch.add(request); BatchRequestWriter writer = new BatchRequestWriter(); InputStream batchRequest = writer.writeBatchRequest(batch, BOUNDARY); BatchLineReader reader = new BatchLineReader(batchRequest); List<Line> lines = reader.toLineList(); reader.close(); int line = 0; assertEquals("--" + BOUNDARY + CRLF, lines.get(line++).toString()); assertEquals("Content-Type: application/http" + CRLF, lines.get(line++).toString()); assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(line++).toString()); assertEquals("Content-Id: 123" + CRLF, lines.get(line++).toString()); assertEquals(CRLF, lines.get(line++).toString()); assertEquals("GET Employees HTTP/1.1" + CRLF, lines.get(line++).toString()); assertEquals("Accept: application/json" + CRLF, lines.get(line++).toString()); assertEquals(CRLF, lines.get(line++).toString()); assertEquals(CRLF, lines.get(line++).toString()); assertEquals("--" + BOUNDARY + CRLF, lines.get(line++).toString()); assertEquals("Content-Type: application/http" + CRLF, lines.get(line++).toString()); assertEquals("Content-Transfer-Encoding: binary" + CRLF, lines.get(line++).toString()); assertEquals("Content-Id: 123" + CRLF, lines.get(line++).toString()); assertEquals(CRLF, lines.get(line++).toString()); assertEquals("GET Employees HTTP/1.1" + CRLF, lines.get(line++).toString()); assertEquals("Accept: application/json" + CRLF, lines.get(line++).toString()); assertEquals(CRLF, lines.get(line++).toString()); assertEquals(CRLF, lines.get(line++).toString()); assertEquals("--" + BOUNDARY + "--", lines.get(line++).toString()); assertEquals(19, lines.size()); }
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; }