on 10-06-2014 12:13 PM
Hi all,
I have developed a custom adapter module to read excel file in sap pi 7.3.1 SP09. I have deployed the project successfully on PI server. But in communication channel monitoring, i can see the following error
Error: javax.TransactionRolledbackLocalException: nested exception is: java.lang.RuntimeException: java.lang.NoClassDefFoundError: jxl/Workbook; nested exception is: java.lang.RuntimeException: java.lang.NoClassDefFoundEror: jxl/Workbook; nested exception is: javax.ejb.EJBTranasctionRolledbackException: nested exception is: java.lang.RuntimeException: java.lang.NoClassDefFoundError: jxl/Workbook; nested exception is: javax.ejb.EJBException: nested exception.
System is unable to get the reference of jxl jar file during runtime. Can u please tell me how to solve the above error.
Regards
Shilpa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Inaki,
Thank you. I have used the following code to read excel file and convert it into xml
/**
*
*/
package com.sap.adaptermodule;
import java.rmi.RemoteException;
import java.io.ByteArrayInputStream;
import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import jxl.Cell;
import jxl.Workbook;
import com.sap.aii.af.lib.mp.module.Module;
import com.sap.aii.af.lib.mp.module.ModuleContext;
import com.sap.aii.af.lib.mp.module.ModuleData;
import com.sap.aii.af.lib.mp.module.ModuleException;
import com.sap.engine.interfaces.messaging.api.Message;
import com.sap.engine.interfaces.messaging.api.MessageKey;
import com.sap.engine.interfaces.messaging.api.MessageDirection;
import com.sap.engine.interfaces.messaging.api.XMLPayload;
import com.sap.aii.af.service.auditlog.Audit;
/*import com.sap.aii.af.service.auditlog.AuditDirection;
import com.sap.aii.af.service.auditlog.AuditLogStatus;
import com.sap.aii.af.service.auditlog.AuditMessageKey;
*/
import com.sap.engine.interfaces.messaging.api.auditlog.AuditLogStatus;
/**
* @author pradeep.s.pawar
*
*/
public class ExcelToXMLBean implements SessionBean, Module
{
private SessionContext myContext;
MessageKey amk;
public void ejbRemove()
{
}
public void ejbActivate()
{
}
public void ejbPassivate()
{
}
public void setSessionContext(SessionContext context)
{
myContext = context;
}
public void ejbCreate() throws CreateException
{
}
public ModuleData process(
ModuleContext mc,
ModuleData imd)
throws ModuleException {
Object obj = null;
Message msg = null;
String msgType = null;
String nameSpace = null;
try {
obj = imd.getPrincipalData();
msg = (Message) obj;
msgType = (String) mc.getContextData("msgType");
nameSpace = (String) mc.getContextData("nameSpace");
if (msg.getMessageDirection()== MessageDirection.INBOUND)
amk = new
MessageKey(msg.getMessageId(),MessageDirection.INBOUND);
else
amk = new
MessageKey(msg.getMessageId(),MessageDirection.OUTBOUND);
XMLPayload xp = msg.getDocument();
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"AO: Now got the xml payload object.");
if (xp != null)
{
Audit.addAuditLogEntry(amk,AuditLogStatus.SUCCESS,"AO: Now calling the Convert Method to convert Excel to XML.");
byte by[] = convert(xp.getContent(),msgType,nameSpace);
Audit.addAuditLogEntry(amk,AuditLogStatus.SUCCESS,"AO: Conversion Done Successfully.");
xp.setContent(by);
}
imd.setPrincipalData(msg);
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"AO: Principle data is set successfully.");
} catch (Exception e)
{
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"AO: Module Exception Caught .");
ModuleException me = new ModuleException(e);
throw me;
}
return imd;
}
public byte[] convert(byte src[],String msgType,String nameSpace) throws Exception
{
String xmldata = "";
try
{
ByteArrayInputStream byteArr= new ByteArrayInputStream(src);
Workbook wb = Workbook.getWorkbook(byteArr);
Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,"AO: Conversion Started.");
xmldata ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"+ "<ns0:"+msgType+" "+"xmlns:ns0=\""+nameSpace+"\">";
Cell[] cells ;
Cell[] cellNames ;
cellNames = wb.getSheet(0).getRow(0);
for(int j=1;j<wb.getSheet(0).getRows();j++)
{
xmldata = xmldata+"<Record>";
cells = wb.getSheet(0).getRow(j);
for(int i=0;i<wb.getSheet(0).getColumns();i++)
{
xmldata =
xmldata+"<"+cellNames[i].getContents()+">"+cells[i].getContents()+"</"+cellNames[i].getContents()+">";
}
xmldata = xmldata+"</Record>";
}
xmldata = xmldata+"</ns0:"+msgType+">";
wb.close();
}
catch (Exception e)
{
Audit.addAuditLogEntry(amk,AuditLogStatus.SUCCESS,"AO: Exception in Convert Method.");
}
return xmldata.getBytes();
}
}
So ... yo mean to say that i have to add the following import statements to the above pieceof code.
import jxl.CellView;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
Correct me if i am wrong.
Regads
Shilpa
Hi Shilpa,
In your piece of code if you can compile it you won't need to add the imports.
You would need to add the library jar as Surender Dahiya mentioned: Re: File Upolad in a DC using jxl.jar with the difference that you are not developing a wwebdynpro
Regards.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
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.