Consuming Soap 1.2 Service

1
0
-1

Hello,

BPM: 6.4.2 java: 1.7 Operation System: Windows 7

I'm trying to use the 1.2 Soap Service Connector to consume a mock service that I've built. I've create a java object in the process data on the pool called "versionResponse" with type java.util.String.

I then created a service step with a soap connector. I setup a soapUI mock service with a simple version service (see below).

Request:

Response will be: 1.1.0

I have Returns body 'checked'

Output Operations: responseDocumentEnv Created script with

import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; import org.w3c.dom.Document; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.sax.SAXSource; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMResult; try{ StringWriter sw = new StringWriter(); TransformerFactory tf = TransformerFactory.newInstance(); Transformer transformer = tf.newTransformer(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); transformer.transform((SAXSource) sourceResponse, new StreamResult(sw)); String result = sw.toString(); if(result!=null && !result.isEmpty()) { return sw.toString(); } } catch(Exception e) { return e.toString() }

Should I store the XML into a variable then parse thru the XML? What types should I use? Should I parse thru the XML on a display step?

I read thru this issue, but having issues (http://community.bonitasoft.com/answers/bonita-bpm-6x-consume-soap-call-...)

I also tried this code, but incurring some issues.

import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource;

// Clean response xml document responseDocumentBody.normalizeDocument(); // Get result node NodeList resultList = responseDocumentBody.getElementsByTagName("wsdl:GetVersionResponse"); Element resultElement = (Element) resultList.item(0); String getVersionAsXML = resultElement.getTextContent();

// Check for empty result if ("Data Not Found".equalsIgnoreCase(getVersionAsXML)) return null;

// Parse embedded XML of result DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputSource inputSource = new InputSource(); inputSource.setCharacterStream(new StringReader(getVersionAsXML)); Document getVersionDocument = documentBuilder.parse(inputSource); Node versionNode = getVersionDocument.getDocumentElement();

// Save version data Map<String,String> data = new HashMap<String,String>(); NodeList childNodes = versionNode.getChildNodes(); for (int i=0; i<childNodes.getLength(); i++) { Node node = childNodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { String key = node.getNodeName(); String value = node.getTextContent(); data.put(key, value); } } return data;

But receive this issue

return data;, returnType=java.lang.String, dependencies=[SExpressionImpl [name=responseDocumentBody, content=responseDocumentBody, returnType=org.w3c.dom.Document, dependencies=[], expressionKind=ExpressionKind [interpreter=NONE, type=TYPE_INPUT]]], expressionKind=ExpressionKind [interpreter=GROOVY, type=TYPE_READ_ONLY_SCRIPT]] at org.bonitasoft.engine.core.connector.impl.ConnectorServiceImpl.executeOutputOperation(ConnectorServiceImpl.java:214) at org.bonitasoft.engine.connector.ConnectorServiceDecorator.executeOutputOperation(ConnectorServiceDecorator.java:105) at org.bonitasoft.engine.execution.work.ExecuteConnectorWork.evaluateOutput(ExecuteConnectorWork.java:103) at org.bonitasoft.engine.execution.work.ExecuteConnectorOfActivity.evaluateOutput(ExecuteConnectorOfActivity.java:72) at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateConnectorOutputsTxContent.call(ExecuteConnectorWork.java:281) at org.bonitasoft.engine.execution.work.ExecuteConnectorWork$EvaluateConnectorOutputsTxContent.call(ExecuteConnectorWork.java:264) at com.bonitasoft.engine.transaction.JTATransactionServiceExt.executeInTransaction(JTATransactionServiceExt.java:55) at org.bonitasoft.engine.execution.work.ExecuteConnectorWork.work(ExecuteConnectorWork.java:128) at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42) at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42) at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42) at org.bonitasoft.engine.execution.work.failurewrapping.TxInHandleFailureWrappingWork.work(TxInHandleFailureWrappingWork.java:42) at org.bonitasoft.engine.execution.work.FailureHandlingBonitaWork.work(FailureHandlingBonitaWork.java:66) at org.bonitasoft.engine.work.BonitaWork.run(BonitaWork.java:56) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: org.bonitasoft.engine.core.operation.exception.SOperationExecutionException: org.bonitasoft.engine.expression.exception.SExpressionEvaluationException: Groovy script throws an exception of type class org.xml.sax.SAXParseException with message = Content is not allowed in prolog. Expression : SExpressionImpl [name=responseDocumentEnvelope, content=import javax.xml.parsers.DocumentBuilder;

Thank you

Comments

Submitted by antoine.mottier on Tue, 03/31/2015 - 12:06

Maybe the process example I create might help you.

1 answer

1
0
-1

NodeList resultList = responseDocumentBody.getElementsByTagName("yourWebMethodResult");
Element resultElement = (Element) resultList.item(0);
Node infoADNode = resultElement;
Map<String,String> data = new HashMap<String,String>();
NodeList childNodes = infoADNode.getChildNodes();

for (int i=0; i<childNodes.getLength(); i++)
{
Node node = childNodes.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE)
{
String key = node.getNodeName();
String value = node.getTextContent();
data.put(key, value);
returnData = returnData + "|" + key + "," + value ;
if (key == "specialValue") {specialValue = value;}
}
}

Notifications