String serviceURL = “https://<Service URL of external service/microservice>”;
String batchUri = "";
// Build URI
batchUri = serviceURL.concat("$batch").trim();
String requestContent = "";
requestContent = requestContent.concat(“BookId='”).concat(“Test_Book”)
.concat("'") .concat(“BookName='”).concat(“SAP Cloud Foundry”).concat("'")
.concat(“Quantity='”).concat(“1”).concat("'");
Map<String, String> changeSetHeadersRequest = new HashMap<String, String>();
changeSetHeadersRequest.put("sap-contextid-accept", "header");
changeSetHeadersRequest.put("Accept", "application/json");
changeSetHeadersRequest.put("Accept-Language", "en-US");
changeSetHeadersRequest.put("DataServiceVersion", "2.0");
changeSetHeadersRequest.put("MaxDataServiceVersion", "2.0");
changeSetHeadersRequest.put("sap-cancel-on-close", "true");
changeSetHeadersRequest.put("content-type", "application/json");
BatchChangeSetPart changeRequest = BatchChangeSetPart.method("POST")
.uri("CreateOrderForBook?" + requestContent).headers(changeSetHeadersRequest).build();
BatchChangeSet changeSet = BatchChangeSet.newBuilder().build();
changeSet.add(changeRequest);
List<BatchPart> batchParts = new ArrayList<BatchPart>();
batchParts.add(changeSet);
InputStream payload= EntityProvider.writeBatchRequest(batchParts, "batch_123");
String requestContent = IOUtils.toString(payload, StandardCharsets.UTF_8.toString());
HttpHeaders headers = new HttpHeaders();
String jToken = "Bearer ";
jToken = jToken.concat(jwtToken);
headers.set("Authorization", jToken);
String contentType = “multipart/mixed;boundary=batch_123”;
headers.setContentType(MediaType.valueOf(contentType));
HttpEntity<String> requestEntity = new HttpEntity<String>(requestContent, headers);
ResponseEntity<String> response=restTemplate.exchange(batchUri, HttpMethod.POST, requestEntity, String.class);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
4 | |
4 | |
4 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 |