Skip to content

Instantly share code, notes, and snippets.

@arvind-pal
Last active September 4, 2019 17:29
Show Gist options
  • Save arvind-pal/e146ed8aa6459d1f5d3ad5efaab13ff1 to your computer and use it in GitHub Desktop.
Save arvind-pal/e146ed8aa6459d1f5d3ad5efaab13ff1 to your computer and use it in GitHub Desktop.
generic code to call SOAP service
@PostMapping(path="generic/rest")
public ResponseEntity<?> getBusinessValue(@RequestBody String soapRequest, @PathVariable("service") String service) throws ClientProtocolException, IOException {
HttpClient client = HttpClients.custom().build();
HttpEntity httpEntity = new StringEntity(soapRequest);
HttpPost postRequest = new HttpPost(service_path);
postRequest.setEntity(httpEntity);
HttpResponse httpResponse = client.execute(postRequest);
HttpEntity responseEntity = httpResponse.getEntity();
String entiryString = EntityUtils.toString(responseEntity);
JsonNode response = fetchFromSoapResponse(entiryString);
return new ResponseEntity<>(response, responseHeaders, HttpStatus.OK);
}
public static JsonNode fetchFromSoapResponse(String xmlString) throws IOException {
XmlMapper xmlMapper = new XmlMapper();
JsonNode node = xmlMapper.readTree(xmlString.getBytes());
return node;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment