on 03-08-2011 3:12 PM
Hi Experts,
I am doing a Java mapping and in that i have to call a RFC look up.
here is the part of the code where i am facing problem
Channel channel = LookupService.getChannel(SERVICE,Channel);
getTrace().addInfo("channel is:"+channel.toString());
RfcAccessor accessor = LookupService.getRfcAccessor(channel);
// SystemAccessor accessor = LookupService.getSystemAccessor(channel);
getTrace().addInfo("accessor is:"+accessor.toString());
InputStream inputStream =new ByteArrayInputStream(rfcXML.getBytes());
getTrace().addInfo("inputStream is:"+inputStream.toString());
XmlPayload payload = LookupService.getXmlPayload(inputStream);
getTrace().addInfo("payload is:"+payload.toString());
rfcOutPayload = accessor.call(payload);
getTrace().addInfo("RFC PAyload:"+rfcOutPayload.getContent().read());
/*if (!rfcOutPayload.toString().equals("null"))
{
getTrace().addInfo("RFC accessor is called:");
}*/
InputStream in = rfcOutPayload.getContent();
getTrace().addInfo("input stram executed");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
getTrace().addInfo("dBuilder executed");
try {
Document doc = dBuilder.parse(in);
getTrace().addInfo("doc executed");
NodeList nList = doc.getElementsByTagName("STATUS").item(0).getChildNodes();
getTrace().addInfo("NodeList executed");
When i checked the trace in SXMB_MONI the following line is not executing
Document doc = dBuilder.parse(in);
it is catching an exception.
Any clue, what is wring in the code??
Are you not writing the exception message to the trace? That would help understanding the problem.
VJ
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi all, thanks for your time.
Still i couldn't figure it out why i am getting wrong XML from lookup.
i found another workaround. i am converting the input stream into String and then used String search to get the required value.now its working fine.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You want to convert inputstrean to String .
Try this ....
import com.sap.aii.utilxi.core.io.IOUtil;
InputStream input;
aString = IOUtil.copyToString(input, "UTF-8");
Regards
Prabhat Sharma.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>> Document doc = dBuilder.parse(in);
when parser try to create document from the inputstream it is failing..
Reason could be syntax error in your RFCpayload or even empty..
You assign RFCpayload to the inputstream 'in' here... so please check... the following
Do you get value for the below line ? Check first
getTrace().addInfo("RFC PAyload:"+rfcOutPayload.getContent().read());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Check your import statements.. Whether you use open source any xml parsers for dom classes or jdk api...
Plus the code for converting stream to string
public void convertStreamtoString(InputStream is){
Writer writer = new StringWriter();
char[] buffer = new char[1024];
try {
Reader reader = new BufferedReader(
new InputStreamReader(is, "UTF-8"));
int n;
while ((n = reader.read(buffer)) != -1) {
writer.write(buffer, 0, n);
}
}catch(IOException io){
io.printStackTrace();
}
}
Hope this helps.
I have used getTrace() to debug each line and found the issue is in the following line of code
Document doc = dBuilder.parse(in);
1) My input XML (rfcXML)is fine.
2) RFC look up was successful as i converted the RFC response input stream to string.
But when i see the convetred response String in trace i can see < is missing in the start of the XML and thats the reason DOM is unable to parse the XML .
So now the question is why RFC look provided a response with misssing <. Apart from this open tag , all information is there in XML.
As of now i have used substring and other function to find the value of STATUS.( but this is nit the right way)
i want to parse the inputstream and then get the desired value using DOM.
interestingly when i write a UDF in Graphical mapping for same RFC , it is giving proper XML.
any thoughts...what could be the issue??
Edited by: biplab das on Mar 10, 2011 9:14 AM
>
> Hi Experts,
>
> I am doing a Java mapping and in that i have to call a RFC look up.
> here is the part of the code where i am facing problem
>
>
Channel channel = LookupService.getChannel(SERVICE,Channel); > getTrace().addInfo("channel is:"+channel.toString()); > > RfcAccessor accessor = LookupService.getRfcAccessor(channel); > // SystemAccessor accessor = LookupService.getSystemAccessor(channel); > > getTrace().addInfo("accessor is:"+accessor.toString()); > InputStream inputStream =new ByteArrayInputStream(rfcXML.getBytes()); > getTrace().addInfo("inputStream is:"+inputStream.toString()); > > XmlPayload payload = LookupService.getXmlPayload(inputStream); > getTrace().addInfo("payload is:"+payload.toString()); > rfcOutPayload = accessor.call(payload); > getTrace().addInfo("RFC PAyload:"+rfcOutPayload.getContent().read()); > > /*if (!rfcOutPayload.toString().equals("null")) > { > getTrace().addInfo("RFC accessor is called:"); > }*/ > > InputStream in = rfcOutPayload.getContent(); > getTrace().addInfo("input stram executed"); > > > DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); > DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); > getTrace().addInfo("dBuilder executed"); > try { > Document doc = dBuilder.parse(in); > getTrace().addInfo("doc executed"); > > NodeList nList = doc.getElementsByTagName("STATUS").item(0).getChildNodes(); > getTrace().addInfo("NodeList executed");
>
> When i checked the trace in SXMB_MONI the following line is not executing
>
>
Document doc = dBuilder.parse(in);
>
> it is catching an exception.
>
>
> Any clue, what is wring in the code??
It look like right....
Maybe.... it can't create the XML document in statement <DocumentBuilder>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.