on 06-26-2008 8:19 AM
Hi.
I have a small issue, creating a RFC call from java.
To be specific, I'm updating a table in the backend, using an adapter module.
When creating the request using DOM, I get this error:
Exception:
Exception: error while processing message to remote system:
com.sap.aii.af.rfc.core.client.RfcClientException: could not get functionname from XML requst:
com.sap.aii.af.rfc.RfcAdapterException: failed to read funtionname from XML document: missing namespace declaration(2).
I've seen a few places in the forum, that there's a simular problem in UDF, where you have to create the request string in one line. Else you get the same error.
The question is, what is the difference between these two functions, and why is the DOM function failing when the other one works?
The request should look like this:
<?xml version="1.0" encoding="UTF-8"?>
<rfc:Z_MON_SURV_UPDATE xmlns:ns1="urn:sap-com:document:sap:rfc:functions">
<ID>1</ID>
</rfc:Z_MON_SURV_UPDATE>
Function 1:
private NodeList buildRequestXml(String id) {
try {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Node docRoot = doc.appendChild(doc.createElementNS("urn:sap-com:document:sap:rfc:functions","rfc:Z_MON_SURV_UPDATE"));
Element ID = doc.createElement("ID");
docRoot.appendChild(ID).appendChild(doc.createTextNode(id));
return doc.getChildNodes();
} catch (Exception e) {
throw new RuntimeException("Error while building request XML", e);}
}
Function 2:
private NodeList buildRequestXml(String id) throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError {
String res = "<rfc:Z_MON_SURV_UPDATE xmlns:rfc=\"urn:sap-com:document:sap:rfc:functions\"><ID>"id"</ID></rfc:Z_MON_SURV_UPDATE>";
Document XMLDoc= DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(res)));
return XMLDoc.getChildNodes();
}
Regards...
Peter
Hi,
Can you try something like this, just for an idea.
Element rootEle = outdoc.createElement("ns0:MT_Student_Receiver1");
rootEle.setAttribute("xmlns:ns0","http:
simplejavamapping_avg.com");
outdoc.appendChild(rootEle);
System.out.println("Root element added");
Regards
Aashish Sinha
PS : reward points if helpful
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aashish.
Your right, thanks.
Just tried the something like, what you suggest.
In my case the result method looks like this:
private NodeList buildRequestXml(String id) {
try {
Document doc =
DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.newDocument();
Node docRoot = doc;
Element Z_MON_SURV_UPDATE = doc.createElement("rfc:Z_MON_SURV_UPDATE");
Z_MON_SURV_UPDATE.setAttribute("xmlns:ns1","urn:sap-com:document:sap:rfc:functions");
docRoot = doc.appendChild(Z_MON_SURV_UPDATE);
Element ID = doc.createElement("ID");
docRoot.appendChild(ID).appendChild(doc.createTextNode(id));
return doc.getChildNodes();
} catch (Exception e) {
throw new RuntimeException("Error while building request XML", e);
}
}
Regards...
Peter
Hi,
I think the problem is that you try to alter the namespace referenceres in the line.
Node docRoot = doc.appendChild(doc.createElementNS("urn:sap-com:document:sap:rfc:functions","rfc:Z_MON_SURV_UPDATE"));
change to
Node docRoot = doc.appendChild(doc.createElementNS("urn:sap-com:document:sap:rfc:functions","Z_MON_SURV_UPDATE"));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.