Couldn't create OMElement from string value
Hi,
We have upgraded to new environment . Application A calls our Service and and We in turn call Application B's Service
We pass on the same request parameters.
But when calling service for Application B [it is java application] in invokeAxis2 activity, I am getting below error,
Couldn't create OMElement from string value
The Code snippet as follows,
**************************************************
com.pega.apache.axis2.client.OperationClient client =
(com.pega.apache.axis2.client.OperationClient)opClient;
com.pega.apache.axis2.context.MessageContext msgContext = null;
// Get the outbound message context
try
{
msgContext = client.getMessageContext("Out");
}
catch (com.pega.apache.axis2.AxisFault e)
{
throw new ConnectorException("Couldn't get SOAP request message context", e);
}
Hi,
We have upgraded to new environment . Application A calls our Service and and We in turn call Application B's Service
We pass on the same request parameters.
But when calling service for Application B [it is java application] in invokeAxis2 activity, I am getting below error,
Couldn't create OMElement from string value
The Code snippet as follows,
**************************************************
com.pega.apache.axis2.client.OperationClient client =
(com.pega.apache.axis2.client.OperationClient)opClient;
com.pega.apache.axis2.context.MessageContext msgContext = null;
// Get the outbound message context
try
{
msgContext = client.getMessageContext("Out");
}
catch (com.pega.apache.axis2.AxisFault e)
{
throw new ConnectorException("Couldn't get SOAP request message context", e);
}
boolean isSOAP2 = myStepPage.getString("pySOAPVersion").equals("2");
com.pega.apache.axiom.soap.SOAPFactory soapFactory = null;
if (isSOAP2)
soapFactory = new com.pega.apache.axiom.soap.impl.llom.soap12.SOAP12Factory();
else
soapFactory = new com.pega.apache.axiom.soap.impl.llom.soap11.SOAP11Factory();
com.pega.apache.axiom.om.OMFactory omFactory =
com.pega.apache.axiom.om.OMAbstractFactory.getOMFactory();
javax.xml.stream.XMLInputFactory xmlFactory =
javax.xml.stream.XMLInputFactory.newInstance();
// Create the SOAP envelope node
com.pega.apache.axiom.soap.SOAPEnvelope soapEnvelope =
soapFactory.createSOAPEnvelope();
com.pega.apache.axiom.om.OMNamespace xsdNS =
soapEnvelope.declareNamespace("http://www.w3.org/2001/XMLSchema", "xsd");
com.pega.apache.axiom.om.OMNamespace xsiNS =
soapEnvelope.declareNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi");
com.pega.apache.axiom.om.OMNamespace soapencNS =
omFactory.createOMNamespace("http://schemas.xmlsoap.org/soap/encoding/", "soapenc");
com.pega.apache.axiom.om.OMNamespace blankNS =
omFactory.createOMNamespace("", "");
// Add SOAP request header values
Map headerVals = (Map)reqHeaderVals;
if (headerVals.size() > 0)
{
// Create the SOAP header node
com.pega.apache.axiom.soap.SOAPHeader soapHeader =
soapFactory.createSOAPHeader(soapEnvelope);
ClipboardProperty reqHeaders = myStepPage.getProperty("pyRequestHeaders");
int reqHeaderCount = reqHeaders.size();
for (int i=1; i<=reqHeaderCount; i++)
{
ClipboardPage headerPage = reqHeaders.getPageValue(i);
String headerKey = headerPage.getString("pyParameterName");
String headerVal = (String)headerVals.get(headerKey);
if (headerVal == null)
throw new ConnectorException("SOAP header value is null");
// Convert the literal XML value to an AXIOM element
try
{
java.io.StringReader stringReader = new java.io.StringReader(headerVal);
javax.xml.stream.XMLInputFactory inputFactory =
javax.xml.stream.XMLInputFactory.newInstance();
javax.xml.stream.XMLStreamReader streamReader =
inputFactory.createXMLStreamReader(stringReader);
com.pega.apache.axiom.om.impl.builder.StAXOMBuilder builder =
new com.pega.apache.axiom.om.impl.builder.StAXOMBuilder(streamReader);
// Add the AXIOM element to the outgoing SOAP message
com.pega.apache.axiom.soap.SOAPHeaderBlock headerBlock = soapHeader.addHeaderBlock(builder.getDocumentElement().getLocalName(),builder.getDocumentElement().getNamespace());
java.util.Iterator attributeItr = builder.getDocumentElement().getAllAttributes();
if (headerBlock !=null){
while (attributeItr.hasNext()){
headerBlock.addAttribute((com.pega.apache.axiom.om.OMAttribute) attributeItr.next());
}
}
java.util.Iterator childItr = builder.getDocumentElement().getChildren();
if (headerBlock !=null) {
while (childItr.hasNext()){
headerBlock.addChild((com.pega.apache.axiom.om.OMNode) childItr.next());
}
}
}
catch (Exception e)
{
throw new ConnectorException("Couldn't create OMElement from string value", e);
}
}
}
// Create the SOAP body node
com.pega.apache.axiom.soap.SOAPBody soapBody =
soapFactory.createSOAPBody(soapEnvelope);
// Add the SOAP request parameter values
List paramVals = (List)reqParamVals;
ClipboardProperty reqParams = myStepPage.getProperty("pyRequestParameters");
boolean isRPC = myStepPage.getString("pyOperationStyle").equals("rpc");
com.pega.apache.axiom.om.OMElement contextElem = soapBody;
if (isRPC)
{
// Create the SOAP operation node
String methodURI = myStepPage.getString("pySOAPURI");
String methodName = myStepPage.getString("pySOAPMethod");
com.pega.apache.axiom.om.OMNamespace methodNS =
omFactory.createOMNamespace(methodURI, "ns1");
contextElem = omFactory.createOMElement(methodName, methodNS, soapBody);
// Bug-20640 - set the SOAP encodingStyle attribute
contextElem.addAttribute("encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/", soapEnvelope.getNamespace());
}
for (int i=0; i<paramVals.size(); i++)
{
ClipboardPage paramPage = reqParams.getPageValue(i+1);
String paramName = paramPage.getString("pyParameterName");
String dataType = paramPage.getString("pyDataType");
Object paramVal = paramVals.get(i);
if (dataType.equals("literal"))
{
if (paramVal == null)
throw new ConnectorException("XML Literal value is null");
// Convert the literal XML value to an AXIOM element
try
{
java.io.StringReader stringReader =
new java.io.StringReader((String)paramVal);
javax.xml.stream.XMLInputFactory inputFactory =
javax.xml.stream.XMLInputFactory.newInstance();
javax.xml.stream.XMLStreamReader streamReader =
inputFactory.createXMLStreamReader(stringReader);
com.pega.apache.axiom.om.impl.builder.StAXOMBuilder builder =
new com.pega.apache.axiom.om.impl.builder.StAXOMBuilder(streamReader);
// Add the AXIOM element to the outgoing SOAP message
contextElem.addChild(builder.getDocumentElement());
}
catch (Exception e)
{
throw new ConnectorException("Couldn't create OMElement from string value", e);
}
}
else
{
// Create the parameter element
com.pega.apache.axiom.om.OMElement paramElem =
omFactory.createOMElement(paramName, blankNS, contextElem);
if (paramVal != null)
{
// Add attributes and content based on the data type
if (dataType.endsWith("[]"))
{
if (paramVal.getClass().isArray())
{
String arrayType = dataType.substring(0,dataType.length()-2);
int arrayLength = java.lang.reflect.Array.getLength(paramVal);
// Add the type and arrayType attributes
paramElem.addAttribute("type", "soapenc:Array", xsiNS);
paramElem.addAttribute("arrayType", "xsd:" + arrayType + '[' + arrayLength + ']', soapencNS);
// Create an item element for each array value
for (int j=0; j<arrayLength; j++)
{
Object arrayVal = java.lang.reflect.Array.get(paramVal, j);
com.pega.apache.axiom.om.OMElement itemElem =
omFactory.createOMElement("item", blankNS, paramElem);
// Create a string value with the correct format
String stringVal = "";
if (arrayType.equals("date"))
{
if (arrayVal instanceof java.util.Date)
stringVal = PRDateFormat.formatXSDDate((java.util.Date)arrayVal);
else
throw new ConnectorException("Unexpected type for XSD date value: " + arrayVal.getClass().getName());
}
else if (arrayType.equals("dateTime"))
{
if (arrayVal instanceof java.util.Calendar)
stringVal = PRDateFormat.formatXSDDateTime(((java.util.Calendar)arrayVal).getTime());
else
throw new ConnectorException("Unexpected type for XSD dateTime value: " + arrayVal.getClass().getName());
}
else
{
stringVal = arrayVal.toString();
}
// Add the character content
itemElem.setText(stringVal);
}
}
else
throw new ConnectorException("Unexpected type for array value: " + paramVal.getClass().getName());
}
else
{
// Create a string value with the correct format
String stringVal = "";
if (dataType.equals("date"))
{
if (paramVal instanceof java.util.Date)
stringVal = PRDateFormat.formatXSDDate((java.util.Date)paramVal);
else
throw new ConnectorException("Unexpected type for XSD date value: " + paramVal.getClass().getName());
}
else if (dataType.equals("dateTime"))
{
if (paramVal instanceof java.util.Calendar)
stringVal = PRDateFormat.formatXSDDateTime(((java.util.Calendar)paramVal).getTime());
else
throw new ConnectorException("Unexpected type for XSD dateTime value: " + paramVal.getClass().getName());
}
else
{
stringVal = paramVal.toString();
}
// Add the type attribute and the character content
paramElem.addAttribute("type", "xsd:" + dataType, xsiNS);
paramElem.setText(stringVal);
}
}
}
}
if (oLog.isDebugEnabled())
oLog.debug("SOAP Request Envelope:\n" + soapEnvelope);
// Set the SOAP envelope in the outbound message context
try
{
msgContext.setEnvelope(soapEnvelope);
}
catch (com.pega.apache.axis2.AxisFault e)
{
throw new ConnectorException("Couldn't add SOAP envelope to outbound message context", e);
}
// Added condition to consider the new implementation of request page.
// This is to ensure backward Compatibility after removing the Send Attachment checkbox
// in the request tab of connect rule form.
boolean isOldConnector = false;
String attachPageName = "pyRequestAttachmentPage";
if (myStepPage.getProperty("pySendAttachments").toBoolean())
{
isOldConnector = true;
attachPageName = "pyAttachmentPage";
}
// Add any binary attachments
if (isOldConnector || (tools.findPage("pyRequestAttachmentPage")!=null)) {
ClipboardPage attachPage = tools.findPage(attachPageName);
if (attachPage != null)
{
ClipboardProperty attachKeys = attachPage.getProperty("pyAttachNames");
ClipboardProperty attachVals = attachPage.getProperty("pyAttachValues");
ClipboardProperty attachTypes = attachPage.getProperty("pyAttachTypes");
int attachCount = attachKeys.size();
if (oLog.isDebugEnabled())
oLog.debug("Adding " + attachCount + " binary attachment(s)");
boolean hasTypes = (attachTypes.size() == attachCount);
for (int i=1; i<=attachCount; i++)
{
String attachKey = attachKeys.getStringValue(i);
String attachVal = attachVals.getStringValue(i);
byte[] buf = Base64Util.decodeToByteArray(attachVal);
javax.activation.DataSource dataSource = null;
if (hasTypes)
{
String attachType = attachTypes.getStringValue(i);
dataSource = new com.pega.apache.axiom.attachments.ByteArrayDataSource(buf, attachType);
}
else
{
dataSource = new com.pega.apache.axiom.attachments.ByteArrayDataSource(buf);
}
javax.activation.DataHandler dataHandler =
new javax.activation.DataHandler(dataSource);
msgContext.addAttachment(attachKey, dataHandler);
}
}
}
************************************************************************************
It is working in all other enviroments, Same code is present in all other env,
Do We need to check any DB Table or anything else
regards,
Surekha
***Updated by moderator: Lochan to add Categories***