on 05-27-2014 8:07 AM
Hi All,
I have a soap lookup created in UDF in PI message mapping
I am taking material id from the source structure and use it as input parameter for the lookup webservice
Here is the UDF code which takes material number and returns the internal id
AbstractTrace trace = container.getTrace();
String matintid = "";
try {
//instance the channel to invoke the service.
Channel channel = LookupService.getChannel("BS_Bus","CC_SearchLookup");
SystemAccessor accessor = LookupService.getSystemAccessor(channel);
// The Request message in XML. THIS IS THE LOOKUP SERVICE
String SOAPxml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><searchTM_MATERIAL>xmlns:ns0=\"MDM_MAT_Search_MDM"><query><criteria><fTX_MATERIAL><constraint><value>"
+a
+ "</value><expressionOperator>equals</expressionOperator></constraint></fTX_MATERIAL></criteria></query><reposInfo><repositoryName>REP_MATERIALS</repositoryName><serverName>mdm6765</serverName></reposInfo></searchTM_MATERIAL>";
InputStream inputStream =new ByteArrayInputStream(SOAPxml.getBytes());
XmlPayload payload = LookupService.getXmlPayload(inputStream);
Payload SOAPOutPayload = null;
//The response will be a Payload. Parse this to get the response field out.
SOAPOutPayload = accessor.call(payload);
/* Parse the SOAPPayload to get the SOAP Response back. */
InputStream inp = SOAPOutPayload.getContent();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
/* Create DOM structure from input XML */
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(inp);
NodeList matlist = document.getElementsByTagName("tM_MATERIAL");
Element material = (Element) matlist.item(0);
NodeList recidlist = material.getElementsByTagName("recordIdentification");
Element recidnode = (Element)recidlist.item(0);
matintid = recidnode.getNodeValue();
trace.addInfo("matnid is" + matintid);
} catch (Exception e) {
trace.addWarning("Error" + e); }
trace.addInfo("Service XXX success executed");
return matintid;
This is giving a java null point error
Errorjava.lang.NullPointerException: while trying to invoke the method org.w3c.dom.Element.getElementsByTagName(java.lang.String) of a null object loaded from a local variable at slot 16 |
Any idea whats going on? I am able to get response for the webservice using SOAP UI
And here is the soap input and output in SOAP UI execution
Input
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:MDM_MAT_Search_MDM" xmlns:urn1="urn:com.sap.mdm.ws.beans.mdt_mat_search_mdm_in" xmlns:urn2="urn:com.sap.mdm.ws.beans" xmlns:urn3="urn:com.sap.mdm.core.beans">
<soapenv:Header/>
<soapenv:Body>
<urn:searchTM_MATERIAL>
<urn:query>
<!--Optional:-->
<urn1:criteria>
<!--Optional:-->
<urn1:fTX_MATERIAL>
<urn2:constraint>
<!--Optional:-->
<urn2:value>12345</urn2:value>
<!--Optional:-->
<urn2:expressionOperator>equals</urn2:expressionOperator>
</urn2:constraint>
</urn1:fTX_MATERIAL>
</urn1:criteria>
</urn:query>
<urn:reposInfo>
<urn3:repositoryName>REP_MATERIALS</urn3:repositoryName>
<urn3:serverName>mdm1234</urn3:serverName>
</urn:reposInfo>
</urn:searchTM_MATERIAL>
</soapenv:Body>
</soapenv:Envelope>
Output:
<SOAP-ENV:Envelope xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body xmlns:rpl="urn:MDM_MAT_Search_MDM">
<rpl:searchTM_MATERIALResponse xmlns:rn0="java:sap/standard" xmlns:rn1="urn:com.sap.mdm.ws.beans" xmlns:rn2="http://schemas.xmlsoap.org/soap/encoding/" xmlns:rn3="urn:com.sap.mdm.core.base" xmlns:rn4="urn:com.sap.mdm.ws.beans.mdt_mat_search_mdm_in" xmlns:rn5="urn:com.sap.mdm.core.beans">
<rpl:Response>
<rn1:executionStatus>
<rn1:status>OK</rn1:status>
<rn1:description>Search/Retrieve done successfully</rn1:description>
<rn1:dataObject>Records 1..1 of 1 found</rn1:dataObject>
</rn1:executionStatus>
<rn4:tM_MATERIAL>
<rn4:fTX_MATERIAL>12345</rn4:fTX_MATERIAL>
<rn4:recordIdentification>
<rn4:internalID>1267</rn4:internalID>
</rn4:recordIdentification>
</rn4:tM_MATERIAL>
</rpl:Response>
</rpl:searchTM_MATERIALResponse>
Thx
mike
Hi Mike,
What I suspect is, you get a null pointer exception because the XML tag name which you are trying to retrieve, has a namespace. Could you please instead try to use:
getElementsByTagNameNS(java.lang.String namespaceURI, java.lang.String localName)
Returns a NodeList
of all the Elements
with a given local name and namespace URI in document order.
Let us know if it works.
Regards,
Shweta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello experts.
In my target structure, there are more than one field having the name "recordIdentification". How do I use dom parser for extracting the value if there are more than one field having the same name?
<Material>
<record identification>
<internal id>
<data>
<record identification >
<internal id>
---
---
etc etc
thx
mike
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.