Good Day,
I have created a java class in Adapter IBM Mobilefirst Platform that will get response from the Jax-ws service.
// read direct to soap service - 4/4/2017
protected JSONObject createJsonObjectFrmSOAPRequest(Map mapsData) throws IOException, SOAPException {
JSONObject jsonObj = new JSONObject();
String responseSoap="";
// Create SOAP Connection
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
try {
// Send SOAP Message to SOAP Server
String url = "http://XXXXX:001/test-pvr-ws/empl_get";
SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(mapsData), url);
// Process the SOAP Response
responseSoap = printSOAPResponse(soapResponse);
// how to convert to jsonobject, the output is in xml string
// XMLToJSONTransformer.transform(responseSoap); - don't know how to use XMLToJSONTransformer
//JSONObject.parse(responseSoap); // convert String to JSONObject
logger.info("jsonObject : " + jsonObj);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return jsonObj;
}
protected String printSOAPResponse(SOAPMessage soapResponse) throws Exception {
String finalstringEnv = "";
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
Source sourceContent = soapResponse.getSOAPPart().getContent();
System.out.print("\nResponse SOAP Message = ");
//create a StringWriter for the output
StringWriter outWriter = new StringWriter();
// StreamResult result = new StreamResult(System.out); // this is for print line output
StreamResult result = new StreamResult(outWriter);
transformer.transform(sourceContent, result);
// how to convert Transformer.transform() to String java
StringBuffer sb = outWriter.getBuffer();
finalstringEnv = sb.toString();
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return finalstringEnv;
}
2 . This code will get the Response in XML string, but I don't know how to use library com.ibm.json.*. Which I wanted to convert the String Response to JSONObject.
2.1. Result Response in XML Soap Envelope (example successful Result i got).
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<a:getTheResponse xmlns:a="http://XXXXX:001/test-pvr-ws/empl_get/">
<getTheRecord>
<statusCode>0</statusCode>
<getTheRecord>
<userid>1212</userid>
</a:getTheResponse>
</soapenv:Body>
</soapenv:Envelope>
2.2. responseSoap String variable i need to convert String XML Soap response To JSONObject
// Process the SOAP Response
responseSoap = printSOAPResponse(soapResponse);
//.............. code to convert String XML Soap response To JSONObject
JSON? Isn't theXMLricher?