cancel
Showing results for 
Search instead for 
Did you mean: 

Throw Exception from Adapter Module

Former Member
0 Kudos

Hi All,

I am creating an adapter module and with in the module I am validating the content of the payload. On erroneous conditions, I need to stop the whole message flow. How can I achive this?

I could write error message in Audit Log but this will not be an error. The message processing will still continue passing the standard adapter module. I do not want this to happen.

I have added throws ModuleException to my process method signature and with in the method I am using the statements

ModuleException m = new ModuleException("Stopped Message Flow");

throw m;

But this does not have any impact on the Message Flow at all.

Regards,

Jaishankar

Accepted Solutions (1)

Accepted Solutions (1)

GabrielSagaya
Active Contributor
0 Kudos

Please use

throw new ModuleException("Stopped Message Flow");

instead of

ModuleException m = new ModuleException("Stopped Message Flow");

throw new m;

/people/alessandro.guarneri/blog/2006/01/26/throwing-smart-exceptions-in-xi-graphical-mapping

Former Member
0 Kudos

Gabriel,

Both the statements create a new ModuleException object with string "Message Flow Stopped". So I dont think this is the reason. Am I missing some thing here?

My code snippet would lokk some thing like this

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

try {

Message msg = (Message) inputModuleData.getPrincipalData();

XMLPayload xmlPayload = msg.getDocument();

AuditMessageKey amk = new AuditMessageKey(msg.getMessageId(), AuditDirection.OUTBOUND);

Audit.addAuditLogEntry(amk, AuditLogStatus.ERROR,"Custom module: Created Exception");

throw new ModuleException("Stopped Message Flow");

}

catch (Exception e){

e.printStackTrace();

}

return inputModuleData;

}

GabrielSagaya
Active Contributor
0 Kudos

Hi

Paste throw new ModuleException("Stopped Message Flow");

in catch block.

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

try {

Message msg = (Message) inputModuleData.getPrincipalData();

XMLPayload xmlPayload = msg.getDocument();

AuditMessageKey amk = new AuditMessageKey(msg.getMessageId(), AuditDirection.OUTBOUND);

Audit.addAuditLogEntry(amk, AuditLogStatus.ERROR,"Custom module: Created Exception");

}

catch (Exception e){

throw new ModuleException("Stopped Message Flow");

}

return inputModuleData;

}

Former Member
0 Kudos

Gabriel,

I tried it. I still get the same result.

Regards,

Jaishankar

GabrielSagaya
Active Contributor
0 Kudos

/people/ganesh.karicharla2/blog/2008/02/20/adapter-module-development-module-configuration

Just check with the below code

public ModuleData process(ModuleContext moduleContext,

ModuleData inputModuleData)

throws ModuleException {

//Handler to get Message object

Message msg = null;

try {

//Fetch the PrincipalData

msg = (Message)inputModuleData.getPrincipalData();

if (msg.getMessageDirection()

== MessageDirection.INBOUND)

amk = new AuditMessageKey(msg.getMessageId(),

AuditDirection.INBOUND);

else

amk = new AuditMessageKey(msg.getMessageId(),

AuditDirection.OUTBOUND);

XMLPayload xmlpayload = msg.getDocument();

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,

"AO: Now got the xml payload object.");

String xmltxt = xmlpayload.getText();

String convertedtext = swiftRead(xmltxt);

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,

"AO: Value returned after calling swiftRead:");

xmlpayload.setText(convertedtext);

inputModuleData.setPrincipalData(msg);

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,

"AO: Text put into inputModuleData");

} catch (Exception e) {

Audit.addAuditLogEntry(amk, AuditLogStatus.SUCCESS,

"AO: Module Exception caught:");

ModuleException me = new ModuleException(e);

throw me;

}

return inputModuleData;

}

Answers (0)