on 01-08-2016 7:08 AM
Hi Experts,
I have a scenario where I have to read an Excel(.xls) file and in the target side a xml file needs to be created. So I am using a Java map to convert from Excel to xml.
When I am testing the Java map Locally it is working and xml is getting created in the target side but when I am testing it end to end a 0 Byte xml file is getting created. It seems that the java map is not getting called during end to end testing. I am working on SAP PI7.4 Single Stack and using ICO. Below I am providing the java map code.
I have already gone through many links related to this in SDN but unfortunately nothing worked to resolve this..
Please help me to resolve this issue.
Java Map Code:
===============
package com.sap.excel2xml;
//import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
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;
public class convertExcel2XML extends AbstractTransformation
{
//@Override
public void transform(TransformationInput input, TransformationOutput output)throws StreamTransformationException
{
//getTrace.addWarning("JAVA Pogram to convert Excel to XML is initiated");
// TODO Auto-generated method stub
try
{
String xmldata = "";
InputStream ins=input.getInputPayload().getInputStream();
getTrace().addInfo("I am after getInputPayload");
HSSFWorkbook wb=new HSSFWorkbook(ins);
getTrace().addInfo("I am after HSSFWorkbook(ins)");
xmldata ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"+ "<ns0:"+"MT_ExcelRead"+" "+"xmlns:ns0=\""+"urn:ibm:com:arindamatanupoc"+"\">";
getTrace().addInfo("I am after initial xmldata");
HSSFRow rows;
HSSFRow rownames;
rownames=wb.getSheetAt(0).getRow(8);
for(int i=1;i<wb.getSheetAt(0).getPhysicalNumberOfRows();i++)
{
xmldata = xmldata+"<Record>";
getTrace().addInfo("I am after adding first <Record> Tag");
rows = wb.getSheetAt(0).getRow((8+i));
for(int j=0;j<rows.getPhysicalNumberOfCells();j++)
{
//System.out.println(rows.getCell((8+j)).getStringCellValue());
if(rows.getCell(8+j).getCellType()==rows.getCell(8+j).CELL_TYPE_NUMERIC)
{
int rowsvalue=(int)rows.getCell((8+j)).getNumericCellValue();
getTrace().addInfo("I am after rowsvalue");
xmldata = xmldata+"<"+rownames.getCell((8+j)).getStringCellValue()+">"+rowsvalue+"</"+rownames.getCell((8+j)).getStringCellValue()+">";
getTrace().addInfo("I am after adding first creating xmldata within If");
}
else
{
xmldata = xmldata+"<"+rownames.getCell((8+j)).getStringCellValue()+">"+rows.getCell((8+j)).getStringCellValue()+"</"+rownames.getCell((8+j)).getStringCellValue()+">";
getTrace().addInfo("I am after adding first creating xmldata within else");
}
}
xmldata=xmldata+"</Record>";
getTrace().addInfo("I am after adding end tag </Record>");
}
xmldata = xmldata+"</ns0:"+"MT_ExcelRead"+">";
getTrace().addInfo("I am after adding end tag </MT_ExcelRead>");
output.getOutputPayload().getOutputStream().write(xmldata.getBytes("UTF-8"));
getTrace().addInfo("I am after writing output");
}catch(Exception e)
{
getTrace().addWarning("Failed in try part where completexml is formed as Output Stream"+e.getMessage());
}
}
}
===================================================================================
Thanks and Regards
Anik
Hello Anik,
When its working locally it should work end-end as well.
Make sure Operation mapping is added in ICO and its activated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
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.