cancel
Showing results for 
Search instead for 
Did you mean: 

Error in Module Processing- java.lang.NullPointerException

Former Member
0 Kudos

Hi all,

I've a scenario which reads a PDF file. I'm following the blog "/people/sap.user72/blog/2005/07/31/xi-read-data-from-pdf-file-in-sender-adapter for that.

I am new to Java. <b>I used the same code given in the blog for my Bean(the function process) without any changes but imported necessary packages</b>.<i>After deploying the ear file, i am getting the error :java.lang.NullPointerException.</i>

Please find below my XI Configuration details :

In the Sender communication channel -> Module tab ->

Under Processing Sequence

<b>Module Name: localejbs/EJB_Class

Module Key : Convert</b>

Can u pls let me know if i should modify something in the code or what else i should do?

Thanks & Regards,

Mani

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member185846
Active Participant
0 Kudos

Hi Amol,

When do you get this exception? Is it at the time when you activate your scenario and the module gets called?

Yes.

Please find below the code that we use. Also, we only changed the function "process". Rest we left as it is.

public ModuleData process(ModuleContext moduleContext,

ModuleData inputModuleData)

throws ModuleException {

Object obj = null;

Message msg = null;

String msgType = null;

String nameSpace = null;

try {

obj = inputModuleData.getPrincipalData();

msg = (Message) obj;

msgType = (String) moduleContext.getContextData("msgType");

nameSpace = (String) moduleContext.getContextData("nameSpace");

XMLPayload xmlpayload = msg.getDocument();

if (xmlpayload != null) {

xmlpayload.setContent(convertToText(xmlpayload,msgType,nameSpace));

inputModuleData.setPrincipalData(msg);

}

}

catch (Exception e) {

ModuleException me = new ModuleException(e);

throw me;

}

return inputModuleData;

}

private byte[] convertToText(XMLPayload xmlpayload,

String msgType,

String nameSpace)

throws Exception {

String textData = null;

String encoding = null;

int startPage = 1;

int endPage = Integer.MAX_VALUE;

PDDocument document = null;

String retXMLData = null;

try{

// Get PDDocument from the file content

document = PDDocument.load (xmlpayload.getInputStream());

ByteArrayOutputStream by = new ByteArrayOutputStream();

OutputStreamWriter out = new OutputStreamWriter(by);

PDFTextStripper stripper = null;

stripper = new PDFTextStripper();

stripper.setStartPage( startPage );

stripper.setEndPage( endPage );

stripper.writeText( document, out );

textData = by.toString();

retXMLData =

"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" +

"<ns:" +

msgType +

" xmlns:ns=\"" +

nameSpace +

"\">\n" +

"<TextData>" +

textData +

"</TextData>\n" +

"</ns:" +

msgType +

">";

}

catch (Exception e) {}

return retXMLData.getBytes();

}

}

Thanks,

Jothivel.

Message was edited by: Jothivel Sundaram

Former Member
0 Kudos

Well...I would in that case suggest you to put debug statements in your code. For this you would need to carry out certain steps which are :

1. In NWDS , create a new file in the META-INF folder of Enterprise Project. The name of the file should be <i>log-configuration.xml.</i>Paste the following content in this file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log-configuration SYSTEM "log-configuration.dtd">
<log-configuration>
<log-formatters>
<!-- This formatter produces human readable messages. -->
<log-formatter
name="trc"
pattern="%26d %150l [%t] %10s: %m"
type="TraceFormatter"/>
</log-formatters>
<log-destinations>
<!-- Destination for Trace Information of this sample -->
<log-destination
count="5"
effective-severity="DEBUG"
limit="2000000"
name="sample.trc"
pattern="./log/applications/sample/default.trc"
type="FileLog">
<formatter-ref
name="trc"/>
</log-destination>
</log-destinations>
<log-controllers>
<!-- Trace Location sample -->
<log-controller
effective-severity="DEBUG"
name="sample">
<associated-destinations>
<destination-ref
association-type="LOG"
name="sample.trc"/>
</associated-destinations>
</log-controller>
<!-- Logging Category: none, use the default XILog -->
</log-controllers>
</log-configuration>

2. In your process method, add following statement

AuditMessageKey auditMKey =
			new AuditMessageKey(message.getMessageId(), AuditDirection.INBOUND);
		Audit.addAuditLogEntry(
			auditMKey,
			AuditLogStatus.SUCCESS,
			"CustomModule :: process method started");

This would send the statement "CustomModule :: process method started" to the Audit Log of XI server and you would be in a position to see upto which step your code is executing sucessfully. Audit log can be viewed at

http://<host>:<port>/MessagingSystem/monitor/monitor.jsp. you need to know the message ID for your transaction in this case.

Hope this helps.

Amol

Former Member
0 Kudos

<b>.After deploying the ear file, i am getting the error :java.lang.NullPointerException.</b>

When do you get this exception? Is it at the time when you activate your scenario and the module gets called? In that case please paste the code here.

You get a NullPointerException when you try to invoke a method on uninitialized references.

~ Amol