on 2016 Aug 15 11:28 AM
Hi
I have a single stack PO and currently working for a migration project. We have an interface with java mapping which works fine in old system. the same file used to test in PO is not working.
As soon as it goes for the operation mapping, it gives error mentioning Details: java.lang.NullPointerException; Sheet1SheetName Not Defined, NullPointerException: Sheet1SheetName Not Defined.
I have a java mapping to convert Excel sheet into XML . Please note that I am not much knowledageable in java mapping. Any help is appreciated here.
Regards
Sam
Hello
Further update on this is that I believe there is a piece of code below which is shooting the error.
I believe for some reason, it is not able to retrieve the sender file adapter filename. I have ensured that the Adapter specific attributes are ticket in the sender channel.
The error i get is the following. failed to execute: MappingException: Mapping failed in runtimeRuntime Exception when executing application mapping program com/sap/MapExcelToXML/MapExcelToXML; Details: java.lang.NullPointerException; Sheet1SheetName Not Defined, ApplicationRuntimeException: Runtime Exception when executing application mapping program com/sap/MapExcelToXML/MapExcelToXML; Details: java.lang.NullPointerException; Sheet1SheetName Not Defined, NullPointerException: Sheet1SheetName Not Defined
Piece of Code:
// Get the filename from FileAdapter
String[] sheetNames = lookupWorkSheets(intName, wb);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
Document docout;
TransformerFactory tf;
try {
int rows = 0;
int cols = 0;
int i = 0;
int j = 0;
db = dbf.newDocumentBuilder();
docout = db.newDocument();
Element root = docout.createElement(XMLName);
root.setAttribute(attrName,attrValue);
docout.appendChild(root);
for (int x = 0; x < sheetNames.length; x++ ) {
trace.addInfo("SheetName = " + sheetNames[x]);
Element xmlString = docout.createElement(elementTagName);
xmlString.setAttribute(elementAttribName, sheetNames[x]);
root.appendChild(xmlString);
Sheet st = wb.getSheet(sheetNames[x]);
if (st == null) {
throw new NullPointerException(sheetNames[x] + "SheetName Not Defined");
}
rows = st.getRows();
cols = st.getColumns();
Element xmlHeader = null;
Element xmlString1 = null;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Ev
This is the class code. Please note that I simply imported the SWCV from old to new system which came along with the imported archives containing the class and java files.
public class MapExcelToXML extends Object implements StreamTransformation {
// ---------- declared fields ------
private static Map param
private static AbstractTrace trace
// ---------- declared constructors ------
public MapExcelToXML()
// ---------- declared methods ------
public void setParameter(Map)
public void execute(InputStream,OutputStream) throws StreamTransformationException
private static String[] lookupWorkSheets(String,Workbook)
Hello Eve
As mentioned earlier, I am not an expert in Java mapping and just migrating the existing interface from old XI environmen to new PO environment. Any help on this or alternative is welcome.
The requirement is to capture a particular tab in the xls file and convert it to xml file as per the structure.
Please find the full source code of the java. You already have the code for the class.
package com.sap.MapExcelToXML;
import java.io.*;
import java.util.Map;
import javax.xml.parsers.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.*;
import jxl.*;
import jxl.read.biff.BiffException;
import org.w3c.dom.*;
import com.sap.aii.mapping.api.*;
import com.sap.aii.mapping.value.api.*;
public class MapExcelToXML implements StreamTransformation {
private static Map param;
private static AbstractTrace trace;
public void setParameter(Map param) {
MapExcelToXML.param = param;
trace = (AbstractTrace) param.get(StreamTransformationConstants.MAPPING_TRACE);
}
public void execute(InputStream in, OutputStream out) throws StreamTransformationException {
// Declare the required parameters
trace.addInfo("Execute Method Started --- ");
String XMLName = "MTExcelFileXML";
String attrName = "xmlns";
String attrValue = "urn://test.co.uk/ReadExcelFiles/MSOffice97-2003/jxl";
String intName = (String) param.get(StreamTransformationConstants.INTERFACE);
String elementTagName = "WorkSheet";
String elementAttribName = "name";
String subElementTagName = "Row";
String colName = "C";
try {
Workbook wb = Workbook.getWorkbook(in);
// Get the filename from FileAdapter
String[] sheetNames = lookupWorkSheets(intName, wb);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db;
Document docout;
TransformerFactory tf;
try {
int rows = 0;
int cols = 0;
int i = 0;
int j = 0;
db = dbf.newDocumentBuilder();
docout = db.newDocument();
Element root = docout.createElement(XMLName);
root.setAttribute(attrName,attrValue);
docout.appendChild(root);
for (int x = 0; x < sheetNames.length; x++ ) {
trace.addInfo("SheetName = " + sheetNames[x]);
Element xmlString = docout.createElement(elementTagName);
xmlString.setAttribute(elementAttribName, sheetNames[x]);
root.appendChild(xmlString);
Sheet st = wb.getSheet(sheetNames[x]);
if (st == null) {
throw new NullPointerException(sheetNames[x] + "SheetName Not Defined");
}
rows = st.getRows();
cols = st.getColumns();
Element xmlHeader = null;
Element xmlString1 = null;
while (i < rows) {
xmlString1 = docout.createElement(subElementTagName);
xmlString.appendChild(xmlString1);
j = 0;
while (j < cols) {
// xmlHeader = docout.createElement(replaceSplChars(st.getCell(j, a).getContents().trim()));
xmlHeader = docout.createElement(colName.concat(String.valueOf(j + 1)));
xmlString1.appendChild(xmlHeader);
xmlHeader.appendChild(docout.createTextNode(st.getCell(j, i).getContents().trim()));
j++;
}
i++;
xmlHeader = null;
}
}
DOMSource domS = new DOMSource(docout);
try {
tf = TransformerFactory.newInstance();
Transformer transform = tf.newTransformer();
try {
transform.transform((domS), new StreamResult(out));
} catch (TransformerException e) {
e.printStackTrace();
}
} catch (TransformerConfigurationException e1) {
e1.printStackTrace();
}
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
} catch (IOException e) {
e.printStackTrace();
} catch (BiffException e) {
e.printStackTrace();
}
trace.addInfo("Execute Method Ended");
}
private static String[] lookupWorkSheets(String s, Workbook w){
String srcAgency = "SAPXI";
String srcScheme = "InterfaceName";
String targAgency = "ReadExcel";
String targScheme = "WorkSheetName";
String[] defaultSheet = { "Sheet1" };
int flag = -1;
int xx = 1;
int yy = 1;
IFIdentifier srcIdentifier = XIVMFactory.newIdentifier(srcAgency , srcScheme);
IFIdentifier targIdentifier = XIVMFactory.newIdentifier(targAgency , targScheme);
IFRequest req = XIVMFactory.newRequest(srcIdentifier, targIdentifier, s);
IFResponse resp = null;
try {
resp = XIVMService.executeMapping(req);
} catch (ValueMappingException e) {
e.printStackTrace();
}
if (resp.hasTargetValues()) {
xx = resp.countGroups();
yy = resp.countTargetValues();
}
String[] retVal = new String[xx * yy];
String[][] values = new String[xx][yy];
if (resp.hasTargetValues()) {
values = resp.getGroupedTargetValues();
int a = 0;
for (int x = 0; x < values.length; x++) {
for (int y = 0; y < values[x].length; y++) {
retVal[a] = values[x][y];
a++;
}
}
for (int i = 0; i < retVal.length; i++) {
if (retVal[i].trim().equals("ALL")) {
flag = 1;
}
}
if (flag == 1) {
retVal = w.getSheetNames();
}
} else {
retVal = defaultSheet;
}
trace.addInfo("retVal = " + retVal);
return retVal;
}
}
Hi Sam,
Based on the output of your mapping I would say there is something going on in relation to this logic. In the method the variable defaultSheet is given the value of "Sheet1" and since that is what is being passed back then flag != 1. I would suggest looking closer at that logic to understand the purpose of what is being done there.
Sam Anderson wrote:
if (flag == 1) {
retVal = w.getSheetNames();
}
} else {
retVal = defaultSheet;
}
trace.addInfo("retVal = " + retVal);
return retVal;
}
}
Regards,
Ryan Crosby
Hello Eve/Ryan
I just managed to sort out the old environment where the valuemap had a capital letter issue and is working fine.
But looking at the new environment, I believe the value map is not getting retrieved at all and the default value sheet1 is being added which in turn gives the error Sheet1SheetName not defined.
Is there anything that the XIVMFactory needs to be modified for the new PO environment? I believe the value map is not getting populated in the new PO environment.
Regards
Sam
Hello Eve
If you check the code , there is a statement below
trace.addInfo("retVal = " + retVal);
return retVal;
But looking at the error, i can't see any infor on that.
Your prediction of value maps worked fine in my old system test environment. But even though i have added the same in my new PO, it is not working.
Regards
Sam
Hello Raghu
If i see the ESR, i can see two files in the imported archives.
One is a class file and another is a java file. Do you think i might need to import this somewhere else in NWA?
Regards
Sam
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Also ensure if any jar files need to be imported.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
68 | |
9 | |
8 | |
7 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.