Skip to Content
avatar image
Former Member

J2EE Adapter Engine Module for XML-to-Excel Conversion

Hi all

I have been trying to implement a J2EE adapter engine module for XML-to-Excel conversion using the JExcel api without success. I have been using various resource that I've found on SDN to create the module. Nevertheless, PI appears to be ignoring what is in the module even though message monitor tells me that it has been processed successfully. I am fairly new at Java, so maybe somebody can help.

This is my Java code example where I am currently ignoring the content of the payload, and just want to create an Excel output file with a header row:

	public ModuleData process(ModuleContext moduleContext,
			ModuleData inputModuleData)
			throws ModuleException {

		Object obj = null;
		Message msg = null;
		OutputStream outStream = null;

		try {
			obj = inputModuleData.getPrincipalData();
			msg = (Message) obj;
		} catch (Exception e) {
			// raise exception, when an error occured
			ModuleException me = new ModuleException(e);
			throw me;
		}

		try {
			XMLPayload xmlpayload = msg.getDocument();
   			int counter = 0;
   			WritableWorkbook workbook = Workbook.createWorkbook(outStream);
   			WritableSheet sheet = workbook.createSheet("Prices", 0);
   			String header[] = new String[3];
  			header[0] = "Product Hierarchy";
   			header[1] = "Item Id";
   			header[2] = "Item Description";

   			for (int i = 0; i < header.length; i++) {
	   			Label label = new Label(i, 0, header<i>);
	   			sheet.addCell(label);
	   			WritableCell cell = sheet.getWritableCell(i, 0);
	   			cell.setCellFormat(cellFormat);
   			}

			workbook.write();
			workbook.close();
			byte[] byteArray = outStream.toString().getBytes();
			xmlpayload.setContent(byteArray);
			inputModuleData.setPrincipalData(msg);
				
		} catch (Exception e) {
		  // raise exception, when an error occured
		  ModuleException me = new ModuleException(e);
		}
		return inputModuleData;
	}
}

As mentioned before, message monitor tells me that the module was called successfully:

2009-07-14 04:23:54 Success MP: Entering module processor

2009-07-14 04:23:54 Success MP: Processing local module localejbs/ConvertToExcel

2009-07-14 04:23:54 Success Module Name: ConvertToExcel, Type : Local Enterprise Bean is Called

2009-07-14 04:23:54 Success MP: Processing local module localejbs/CallSapAdapter

But nothing has been done looking at the generated file. Any help or example would be appreciated.

Thank you, Daniel

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Jul 14, 2009 at 12:15 PM

    I am not well versed with custom modules but I thought of sharing some inputs

    Try to add the logs where ever possible to know upto which step it has got executed.

    If possible to test in NWDS test the same by adding log files

    Rajesh

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jul 14, 2009 at 02:29 PM

    Hi Daniel,

    You are forgetting put the following line:

    xmlpayload.setContent(byteArray);

    msg.setDocument(xmlpayload);

    inputModuleData.setPrincipalData(msg);

    Regards

    Ivan

    Add comment
    10|10000 characters needed characters exceeded