cancel
Showing results for 
Search instead for 
Did you mean: 

Java Mapping - PO System

silentbull
Participant
0 Kudos
192

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

Accepted Solutions (1)

Accepted Solutions (1)

silentbull
Participant
0 Kudos

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;

former_member190293
Active Contributor
0 Kudos

Hi Sam!

Previous assumption was wrong.

What class is used to work with Excel files?

Regards, Evgeniy.

silentbull
Participant
0 Kudos

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)

former_member190293
Active Contributor
0 Kudos

Hi Sam!

At first let me say that your must consider rewritting your current java code as it uses deprecated interface StreamTransformation.

Wouldn't you provide full source code of your class?

Regards, Evgeniy.

silentbull
Participant
0 Kudos

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;

  }

}

former_member190293
Active Contributor
0 Kudos

Hi Sam!

Your java code uses Value Mapping Groups (XIVMService) to retreive data from Java cache. Have you set it up on your new PO system?

Regards, Evgeniy.

silentbull
Participant
0 Kudos

Hello Eve

Fantastic find!

Where should i look or set it up in NWA in the new PO system?

Alternatively, where should i check the same in old xi system?

Regards

Sam

former_member190293
Active Contributor
0 Kudos

Hi Sam!

Value Mappimg Groups can be found in Integration Builder.

Regards, Evgeniy.

silentbull
Participant
0 Kudos

Hello Eve

I am getting the same error even after maintaining the values.

Regards

Sam

silentbull
Participant
0 Kudos

The thing is the same error is coming in the old environment test system and the new PO environment.

But the old environment production is working fine, am i missing something ?

Ryan-Crosby
Active Contributor
0 Kudos

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

silentbull
Participant
0 Kudos

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

silentbull
Participant
0 Kudos

Hello

Further, I had renamed the tab as Sheet1 and it did work fine, So , i can positively say that the value map is not retrieving the values in the new PO environment.

former_member190293
Active Contributor
0 Kudos

Hi Sam!

I think, in this case you have to debug your java code by adding info to trace, for example, to check if the transformation constant "Interface" is filled with correct value and if VM lookup function returns any result. This will define your further steps.

Regards, Evgeniy.

silentbull
Participant
0 Kudos

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

former_member190293
Active Contributor
0 Kudos

Hi Sam!

You should see that trace in message monitor.

What value does it return for retVal?

Regards, Evgeniy.

silentbull
Participant
0 Kudos

i made a mistake

When i imported the value maps into the new environment, i forgot to activate it.

It is all working now. Thanks for the patience

Answers (2)

Answers (2)

silentbull
Participant
0 Kudos

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

former_member186851
Active Contributor
0 Kudos

Hello Sam,

How do you move the mapping?using Jar file import from old to new system.

Also check the point mentioned by Eve.

former_member186851
Active Contributor
0 Kudos

Hello,

Also ensure if any jar files need to be imported.