public Map<String, String> batch(final BatchRequest batchRequest) { List<BatchRequestItem> batchRequestItems = new ArrayList<>(batchRequest.getItems()); Map<String, String> result = new LinkedHashMap<>(); try { List<BatchResponseItem> batchResponseItems = batchRequest.commit().getItems(); for (int i = 0; i < batchResponseItems.size(); i++) { String status = getStatus(batchResponseItems.get(i).getStatus()); if (batchRequestItems.get(i).getRequestURI().endsWith("/status")) { result.put(StringUtils.substringAfterLast( StringUtils.substringBefore(batchRequestItems.get(i).getRequestURI(), "/status"), "/"), status); } else { result.put(StringUtils.substringAfterLast( batchRequestItems.get(i).getRequestURI(), "/"), status); } } } catch (IOException e) { LOG.error("While processing Batch response", e); } return result; } }
/** * Sends the current request, with items accumulated by invoking methods on proxies obtained via * {@link #getService(java.lang.Class)}, to the Batch service, and awaits for a synchronous or asynchronous * response, depending on the {@code async} parameter. * It also clears out the accumulated items, in case of reuse of this instance for subsequent requests. * * @param async whether asynchronous Batch process is requested, or not * @return batch response */ public BatchResponse commit(final boolean async) { String boundary = "--batch_" + UUID.randomUUID().toString(); WebClient webClient = WebClient.create(bcfb.getAddress()).path("batch"). header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt). type(RESTHeaders.multipartMixedWith(boundary.substring(2))); if (async) { webClient.header(RESTHeaders.PREFER, Preference.RESPOND_ASYNC); } String body = BatchPayloadGenerator.generate(bcfb.getBatchRequestItems(), boundary); LOG.debug("Batch request body:\n{}", body); initBatchClientFactoryBean(); return new BatchResponse(boundary, jwt, webClient.post(body)); } }
/** * Sends the current request, with items accumulated by invoking methods on proxies obtained via * {@link #getService(java.lang.Class)}, to the Batch service, and awaits for a synchronous or asynchronous * response, depending on the {@code async} parameter. * It also clears out the accumulated items, in case of reuse of this instance for subsequent requests. * * @param async whether asynchronous Batch process is requested, or not * @return batch response */ public BatchResponse commit(final boolean async) { String boundary = "--batch_" + UUID.randomUUID().toString(); WebClient webClient = WebClient.create(bcfb.getAddress()).path("batch"). header(HttpHeaders.AUTHORIZATION, "Bearer " + jwt). type(RESTHeaders.multipartMixedWith(boundary.substring(2))); if (async) { webClient.header(RESTHeaders.PREFER, Preference.RESPOND_ASYNC); } String body = BatchPayloadGenerator.generate(bcfb.getBatchRequestItems(), boundary); LOG.debug("Batch request body:\n{}", body); initBatchClientFactoryBean(); return new BatchResponse(boundary, jwt, webClient.post(body)); } }
@Override public Map<String, String> batch(final BatchRequest batchRequest) { List<BatchRequestItem> batchRequestItems = new ArrayList<>(batchRequest.getItems()); Map<String, String> result = new LinkedHashMap<>(); try { List<BatchResponseItem> batchResponseItems = batchRequest.commit().getItems(); for (int i = 0; i < batchResponseItems.size(); i++) { String status = getStatus(batchResponseItems.get(i).getStatus()); if (batchRequestItems.get(i).getRequestURI().contains("/execute")) { result.put(StringUtils.substringAfterLast( StringUtils.substringBefore(batchRequestItems.get(i).getRequestURI(), "/execute"), "/"), status); } else { result.put(StringUtils.substringAfterLast( batchRequestItems.get(i).getRequestURI(), "/"), status); } } } catch (IOException e) { LOG.error("While processing Batch response", e); } return result; } }
@Override public Map<String, String> batch(final BatchRequest batchRequest) { List<BatchRequestItem> batchRequestItems = new ArrayList<>(batchRequest.getItems()); Map<String, String> result = new LinkedHashMap<>(); try { List<BatchResponseItem> batchResponseItems = batchRequest.commit().getItems(); for (int i = 0; i < batchResponseItems.size(); i++) { String status = getStatus(batchResponseItems.get(i).getStatus()); if (batchRequestItems.get(i).getRequestURI().contains("/execute")) { result.put(StringUtils.substringAfterLast( StringUtils.substringBefore(batchRequestItems.get(i).getRequestURI(), "/execute"), "/"), status); } else { result.put(StringUtils.substringAfterLast( batchRequestItems.get(i).getRequestURI(), "/"), status); } } } catch (IOException e) { LOG.error("While processing Batch response", e); } return result; } }