cancel
Showing results for 
Search instead for 
Did you mean: 

Java Mapping Issue

Former Member
0 Kudos

Hi All,<br>

I am working on Java mapping in PI 7.1. Here in Java mapping i am trying to make my Flat file into XML. I have checked my program using Eclipse its working fine and got the XML from flat file. After that generated the jar file and imported in to the IR and use in the OperationMapping and tested. Here in SXMB_MONI i can see the payload in the Inbound message but after mapping step Nothing is there in the Payload.(its not generated the XML). and its not giving any error. I couldnt under stand the issue. <br>Can any plz help me on this? <br><br>

the code what i uesd:

<br><br>

<pre>import java.io.BufferedReader;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStream;

import java.io.InputStreamReader;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.util.Map;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.transform.OutputKeys;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerConfigurationException;

import javax.xml.transform.sax.SAXTransformerFactory;

import javax.xml.transform.sax.TransformerHandler;

import javax.xml.transform.stream.StreamResult;

import org.xml.sax.SAXException;

import org.xml.sax.helpers.AttributesImpl;

import com.sap.aii.mapping.api.AbstractTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

import com.sap.aii.mapping.api.TransformationInput;

import com.sap.aii.mapping.api.TransformationOutput;

import java.util.HashMap;

public class JavaMapping extends AbstractTransformation {

TransformerHandler th;

AttributesImpl atts;

/*private Map map;

public void getTrace(Map param) {

map = param;

}*/

private Map param = null;

public void setParameter (Map param) {

this.param = param;

if (param == null) {

this.param = new HashMap();

}

}

/*public static void main(String[] args) {

try {

InputStream in = new FileInputStream(new File("c:
tmp
in.txt"));

OutputStream out = new FileOutputStream(new File("c:
tmp
res.xml"));

JavaMapping myMapping = new JavaMapping();

myMapping.execute(in, out);

}

catch (Exception e) {

e.printStackTrace();

}

}*/

public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {

this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());

}

public void execute(InputStream in, OutputStream out) throws StreamTransformationException {

try {

String EntryHeader[] = new String[5];

String LineValues[] = new String[6];

EntryHeader[0] = "EntryNumber";

EntryHeader[1] = "EntryDate";

EntryHeader[2] = "VocherNumber";

EntryHeader[3] = "JournalCode";

EntryHeader[4] = "NoOfLinesOfTheEntry";

LineValues[0] = "LineTypeString";

LineValues[1] = "LineText";

LineValues[2] = "ClientCode";

LineValues[3] = "ClientCurrency";

LineValues[4] = "AuxiliaryCode";

LineValues[5] = "AuxiliaryCurrencyCode";

BufferedReader bin = new BufferedReader(new InputStreamReader(in));

StreamResult sout = new StreamResult();

//sout = new StreamResult("c:
tmp
res1.xml");

initXML(sout);

String str;

int i = 0;

String[] Values = new String[5];

boolean bEntryHeader = false;

boolean bLineValues = false;

while ((str = bin.readLine()) != null) {

if (";<START OF ENTRY>".equalsIgnoreCase(str)) {

atts.clear();

if (bLineValues) {

th.endElement("", "", "DETAILS");

}

th.startElement("", "", "DETAILS", atts);

th.startElement("", "", "EntryHeaderFormat", atts);

i = 0;

Values = EntryHeader;

bEntryHeader = true;

bLineValues = false;

}

else if (";<END OF ENTRY>".equalsIgnoreCase(str)) {

th.endElement("", "", "EntryHeaderFormat");

th.endDocument();

}

else if (";<start of line>".equalsIgnoreCase(str)) {

atts.clear();

th.startElement("", "", "LINE", atts);

i = 0;

Values = LineValues;

bEntryHeader = false;

bLineValues = true;

}

else if (";<end of line>".equalsIgnoreCase(str)) {

th.endElement("", "", "LINE");

th.endDocument();

}

else {

process(str, Values, i);

i++;

if (bEntryHeader) {

if (i == 5) {

i = 0;

}

}

else if (bLineValues) {

if (i == 6) {

i = 0;

}

}

}

}

in.close();

closeXML();

}

catch (Exception e) {

e.printStackTrace();

}

}

public void initXML(StreamResult out) throws ParserConfigurationException,TransformerConfigurationException, SAXException {

SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();

th = tf.newTransformerHandler();

Transformer serializer = th.getTransformer();

serializer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");

serializer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

serializer.setOutputProperty(OutputKeys.INDENT, "yes");

th.setResult(out);

th.startDocument();

atts = new AttributesImpl();

th.startElement("", "", "ROOT", atts);

}

public void process(String s, String v[], int i) throws SAXException {

atts.clear();

th.startElement("", "", v<i>, atts);

th.characters(s.toCharArray(), 0, (s.toCharArray()).length);

th.endElement("", "", v<i>);

}

public void closeXML() throws SAXException {

th.endElement("", "", "DETAILS");

th.endElement("", "", "ROOT");

th.endDocument();

}

}</pre><br><br>

Thanks in advance<br>

Karthik.

<br><br>

Edited by: Karthikeya T on Jun 10, 2009 4:42 PM

<br><br>

Edited by: Karthikeya T on Jun 10, 2009 4:45 PM

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Thanks To all

Former Member
0 Kudos

Hi,

If it works in operation mapping test it should also work in scenario. May be a cache update issue?

former_member200962
Active Contributor
0 Kudos

can you post your code which is readable.....may be some formatting is needed...

Former Member
0 Kudos

This message was moderated.

former_member200962
Active Contributor
0 Kudos

enclose you code within your java mapping remove the spaces within the curly brackets

maintain line-breaks and it will be visible properly :).....leaving for the day....other experts can help you:)

Abhishek.

matt
Active Contributor
0 Kudos

There is a limit of about 2500 characters that can be posted at one time.

matt