@Override public String getMethod() { return batchItem.getMethod(); }
@Override public String getQueryString() { return batchItem.getQueryString(); }
@Override public String getRequestURI() { return batchItem.getRequestURI(); }
payload.append(bri.getMethod()).append(' ').append(bri.getRequestURI()); if (bri.getQueryString() != null) { payload.append('?').append(bri.getQueryString()); BatchResponseItem bri = BatchResponseItem.class.cast(item); payload.append(HTTP_1_1).append(' '). append(bri.getStatus()).append(' '). append(Response.Status.fromStatusCode(bri.getStatus()).getReasonPhrase()). append('\n'); if (item.getHeaders() != null && !item.getHeaders().isEmpty()) { item.getHeaders().forEach((key, values) -> { values.forEach(value -> { payload.append(key).append(": ").append(value).append('\n'); if (item.getContent() != null) { payload.append(item.getContent()).append('\n');
private List<BatchResponseItem> parseBatchResponse(final Response response) throws IOException { return BatchPayloadParser.parse( (InputStream) response.getEntity(), response.getMediaType(), new BatchResponseItem()); }
public static <T extends BatchItem> List<T> parse( final InputStream in, final MediaType multipartMixed, final T template) throws IOException { List<BatchPayloadLine> lines; try (BatchPayloadLineReader lineReader = new BatchPayloadLineReader(in, multipartMixed)) { lines = lineReader.read(); } return split(lines, multipartMixed.getParameters().get(RESTHeaders.BOUNDARY_PARAMETER)).stream(). map(bodyPart -> { LOG.debug("Body part:\n{}", bodyPart); T item = SerializationUtils.clone(template); consumeHeaders(bodyPart, item); item.setContent( bodyPart.stream().map(BatchPayloadLine::toString).collect(Collectors.joining())); return item; }).collect(Collectors.toList()); }
private static BatchPayloadLine removeEndingCRLF(final BatchPayloadLine line) { Matcher matcher = PATTERN_LAST_CRLF.matcher(line.toString()); return matcher.matches() ? new BatchPayloadLine(matcher.group(1), line.getLineNumber()) : line; }
public List<BatchPayloadLine> read() throws IOException { List<BatchPayloadLine> result = new ArrayList<>(); String currentLine = readLine(); if (currentLine != null) { currentBoundary = currentLine.trim(); int counter = 1; result.add(new BatchPayloadLine(currentLine, counter++)); while ((currentLine = readLine()) != null) { result.add(new BatchPayloadLine(currentLine, counter++)); } } return result; }
private static void removeEndingCRLFFromList(final List<BatchPayloadLine> lines) { if (!lines.isEmpty()) { BatchPayloadLine lastLine = lines.remove(lines.size() - 1); lines.add(removeEndingCRLF(lastLine)); } }
private static void consumeBlankLine(final List<BatchPayloadLine> bodyPart) { if (!bodyPart.isEmpty() && PATTERN_BLANK_LINE.matcher(bodyPart.get(0).toString()).matches()) { bodyPart.remove(0); } }
@Override public String getContentType() { return batchItem.getHeaders().containsKey(HttpHeaders.CONTENT_TYPE) ? batchItem.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0).toString() : MediaType.ALL_VALUE; }
payload.append(bri.getMethod()).append(' ').append(bri.getRequestURI()); if (bri.getQueryString() != null) { payload.append('?').append(bri.getQueryString()); BatchResponseItem bri = BatchResponseItem.class.cast(item); payload.append(HTTP_1_1).append(' '). append(bri.getStatus()).append(' '). append(Response.Status.fromStatusCode(bri.getStatus()).getReasonPhrase()). append('\n'); if (item.getHeaders() != null && !item.getHeaders().isEmpty()) { item.getHeaders().forEach((key, values) -> { values.forEach(value -> { payload.append(key).append(": ").append(value).append('\n'); if (item.getContent() != null) { payload.append(item.getContent()).append('\n');
/** * Parses the latest Response received into a list of {@link BatchResponseItem}s. * * @return the Batch Response parsed as list of {@link BatchResponseItem}s * @throws IOException if there are issues when reading the response body */ public List<BatchResponseItem> getItems() throws IOException { String body = IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8.name()); LOG.debug("Batch response body:\n{}", body); return BatchPayloadParser.parse( new ByteArrayInputStream(body.getBytes()), response.getMediaType(), new BatchResponseItem()); } }
public static <T extends BatchItem> List<T> parse( final InputStream in, final MediaType multipartMixed, final T template) throws IOException { List<BatchPayloadLine> lines; try (BatchPayloadLineReader lineReader = new BatchPayloadLineReader(in, multipartMixed)) { lines = lineReader.read(); } return split(lines, multipartMixed.getParameters().get(RESTHeaders.BOUNDARY_PARAMETER)).stream(). map(bodyPart -> { LOG.debug("Body part:\n{}", bodyPart); T item = SerializationUtils.clone(template); consumeHeaders(bodyPart, item); item.setContent( bodyPart.stream().map(BatchPayloadLine::toString).collect(Collectors.joining())); return item; }).collect(Collectors.toList()); }
private static BatchPayloadLine removeEndingCRLF(final BatchPayloadLine line) { Matcher matcher = PATTERN_LAST_CRLF.matcher(line.toString()); return matcher.matches() ? new BatchPayloadLine(matcher.group(1), line.getLineNumber()) : line; }
public List<BatchPayloadLine> read() throws IOException { List<BatchPayloadLine> result = new ArrayList<>(); String currentLine = readLine(); if (currentLine != null) { currentBoundary = currentLine.trim(); int counter = 1; result.add(new BatchPayloadLine(currentLine, counter++)); while ((currentLine = readLine()) != null) { result.add(new BatchPayloadLine(currentLine, counter++)); } } return result; }
private static void removeEndingCRLFFromList(final List<BatchPayloadLine> lines) { if (!lines.isEmpty()) { BatchPayloadLine lastLine = lines.remove(lines.size() - 1); lines.add(removeEndingCRLF(lastLine)); } }
private static void consumeBlankLine(final List<BatchPayloadLine> bodyPart) { if (!bodyPart.isEmpty() && PATTERN_BLANK_LINE.matcher(bodyPart.get(0).toString()).matches()) { bodyPart.remove(0); } }
@Override public int getContentLength() { return batchItem.getHeaders().containsKey(HttpHeaders.CONTENT_LENGTH) ? Integer.valueOf(batchItem.getHeaders().get(HttpHeaders.CONTENT_LENGTH).get(0).toString()) : 0; }
/** * Parses the latest Response received into a list of {@link BatchResponseItem}s. * * @return the Batch Response parsed as list of {@link BatchResponseItem}s * @throws IOException if there are issues when reading the response body */ public List<BatchResponseItem> getItems() throws IOException { String body = IOUtils.toString((InputStream) response.getEntity(), StandardCharsets.UTF_8.name()); LOG.debug("Batch response body:\n{}", body); return BatchPayloadParser.parse( new ByteArrayInputStream(body.getBytes()), response.getMediaType(), new BatchResponseItem()); } }