Last active
September 4, 2019 17:29
-
-
Save arvind-pal/e146ed8aa6459d1f5d3ad5efaab13ff1 to your computer and use it in GitHub Desktop.
generic code to call SOAP service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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