cancel
Showing results for 
Search instead for 
Did you mean: 

RFC Look Up in Java mapping for PI 7.1

Former Member
0 Kudos

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??

Accepted Solutions (1)

Accepted Solutions (1)

VijayKonam
Active Contributor
0 Kudos

Are you not writing the exception message to the trace? That would help understanding the problem.

VJ

Former Member
0 Kudos

Yes , i have written the exception message.

Any other clue...

Answers (4)

Answers (4)

Former Member
0 Kudos

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.

former_member190293
Active Contributor
0 Kudos

Hi!

What happens if you comment:

getTrace().addInfo("RFC PAyload:"+rfcOutPayload.getContent().read()); ?

I have a guess that getContent() uses StreamReader wich may close Stream resources after processing.

Former Member
0 Kudos

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.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>> 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());

Former Member
0 Kudos

yes bhaskar.. i am getting value

RFC PAyload:60

in the trace

Former Member
0 Kudos

Any Idea.. how to convert the input stream in to string

baskar_gopalakrishnan2
Active Contributor
0 Kudos

I think your string variable rfcxml has some syntax issues... cut and paste data and check in xmlspy

Also use printstacktrace in the catch block to elaborate more errors.

Hope that helps.

Former Member
0 Kudos

i have used e.printStackTrace(); in my code.

also the RFC XML is fine :).I have double checked.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

>

> 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>