Skip to Content
0

Read Entire Input file data into single field to the sender message type in SAP PI 7.1

Nov 29, 2016 at 11:27 AM

88

avatar image

Hi PI Experts,

I have a requirement to read entire file content into the single field, then after i have to do few transformations.

I have tried few Java codes to read entire file into the string, but i am getting a below error

<SAP:Category>XIServer</SAP:Category> <SAP:Code area="RCVR_DETERMINATION">CX_RD_PLSRV</SAP:Code> <SAP:P1>Problem while determining receivers using interface mapping: Error while determining root tag of XML: BOM / charset detection failed</SAP:P1> <SAP:P2 /> <SAP:P3 /> <SAP:P4 /> I have followed below blogs and have used the below code.

https://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=60653713

https://wiki.scn.sap.com/wiki/display/Snippets/Java+Mapping+-+Convert+the+Input+xml+to+String?original_fqdn=wiki.sdn.sap.com

package com.xxx.xxx; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.Map; import com.sap.aii.mapping.api.StreamTransformation; import com.sap.aii.mapping.api.StreamTransformationException; import com.sap.aii.mapping.api.TransformationInput; import com.sap.aii.mapping.api.TransformationOutput; public class PI implements StreamTransformation { public static void main(String args[]) throws Exception { } public void setParameter(Map param) { Map map = param; } public void transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException { try { String source = ""; String targetxml = ""; String line = ""; InputStream ins = in.getInputPayload().getInputStream(); BufferedReader br = new BufferedReader( new InputStreamReader(ins)); while ((line = br.readLine()) != null) source += line+'\n'; br.close(); String XML_START_TAG = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:MT_Sender xmlns:ns0=\"urn:textron:apriso:Sender/\">"; String XML_END_TAG = "</ns0:MT_Sender>"; targetxml = XML_START_TAG+ "<ns0:stringinp>"+source+"</ns0:stringinp>" + XML_END_TAG; out.getOutputPayload().getOutputStream().write(targetxml.getBytes()); } catch (Exception e) { throw new StreamTransformationException(e.getMessage()); } } public void execute(InputStream arg0, OutputStream arg1) throws StreamTransformationException { // TODO Auto-generated method stub } }

Could you please check and provide me a java code which will read entire source file into a string.

error.png

Thanks in Advance.

Thank you,

Chakradhar

error.png (21.2 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Iñaki Vila Nov 29, 2016 at 01:07 PM
0
Show 3 Share
10 |10000 characters needed characters left characters exceeded

Hi Inaki Vila,

Thanks for letting me know.

Actually, I have tried the above code too but getting same Receiver Determination error.

Thank you,

Chakradhar

0

you either need to change the outbound service interface to XI 3.0 Stateless or either remove the SWCV from Reciever determination

1

Thanks Manoj K, issue got resolved after removing SWCV from Reciever determination.

0
Evgeniy Kolmakov Nov 30, 2016 at 07:39 AM
0

Hi Chakradhar!

It seems that your XML result has incorrect encoding.

I would start with using some constant structure inside your XML in java mapping just to test if message is transferred normaly. If so - problem is in your source file data. If not - your XML structure has wrong format.

Regards, Evgeniy.

Share
10 |10000 characters needed characters left characters exceeded
Chakradhar Nunna Dec 08, 2016 at 10:05 AM
0

Hi All,

Thank you all for your valuable suggestions.

Issue got resolved after removing SWCV from Reciever determination.

Thanks Manoj K, for providing solution for this issue.

Thank you,

Chakradhar N

Share
10 |10000 characters needed characters left characters exceeded