Skip to content

Instantly share code, notes, and snippets.

View esaounkine's full-sized avatar

Ilya Saunkin esaounkine

View GitHub Profile
@esaounkine
esaounkine / ValidateMTTest.java
Created March 14, 2014 08:16
parsing and validation an MT (more examples http://wiki.datamation.gr/x/OIBH)
protected void testMessage(String messageContent) throws InvalidMessageFormatException {
//parse message string to the SwiftMessage object
SwiftMessage message = new SwiftMsgProcessor().ParseMsgStringToObject(messageContent);
//validate SwiftMessage (parsed from String or built programmatically)
SwiftMsgValidator validator = new SwiftMsgValidator();
SwiftValidObj validation = validator.validateMsg(message);
//swift mt text
String mtMessageText = validation.getMessage();
//obtain list of errors from the validation object
@esaounkine
esaounkine / Msg103.java
Created March 10, 2014 09:08
build MT103 using bare methods (more examples at http://wiki.datamation.gr/x/OIBH)
public SwiftMessage buildMT103() {
SwiftMessage message = new SwiftMessage();
// Set Tags for block1
message.setArgApplid("F");
message.setArgServid("01");
message.setArgLTaddrBlk1("COPZBEB0AXXX");
// Set Tags for block2
message.setArgInoutind("O");
@esaounkine
esaounkine / Msg103.java
Last active August 29, 2015 13:57
build MT103 using additional methods (more examples at http://wiki.datamation.gr/x/OIBH)
public SwiftMessage buildMT103() {
SwiftMessage message = new SwiftMessage();
// Set Tags for block1
message.setArgApplid("F");
message.setArgServid("01");
message.setArgLTaddrBlk1("COPZBEB0AXXX");
// Set Tags for block2
message.setArgInoutind("O");
@esaounkine
esaounkine / MxMessageProcessingService.java
Created January 28, 2014 13:39
code snippet to parse XML string into a valid MX message object
public Message parseMessage(String msgText) throws Exception {
String namespace = msgText.replaceAll("(?s).*?xmlns=\"(.*?)\".*", "$1");
return CoreMessage.parseXML(msgText, namespace);
}
@esaounkine
esaounkine / SampleMessageCreation.java
Last active January 2, 2016 15:18
sample code to create SWIFT MT 205COV using the Datamation SMV (more examples at http://wiki.datamation.gr/x/OIBH)
@Test
public void testCreating205COV() {
SwiftMessage message = new SwiftMessage();
// Set Tags for block1
message.setArgApplid("F");
message.setArgServid("01");
message.setArgLTaddrBlk1("AAAABEBBAXXX");
// Set Tags for block2
@esaounkine
esaounkine / ValidateMTTest.java
Created December 9, 2013 14:54
SMV multi-error sample (more examples at http://wiki.datamation.gr/x/OIBH)
SwiftMessage message = new SwiftMsgProcessor().ParseMsgStringToObject(messageContent);
SwiftMsgValidator validator = new SwiftMsgValidator(DEFAULT_CRLF);
SwiftValidObj validation = validator.validateMsg(message);
for(ValidationError error : validation.getValidationErrorList()) {
System.out.println(error.getTagName() + " => " + error.getDescription());
}
@esaounkine
esaounkine / SepaMessageProcessingService.java
Last active December 27, 2015 11:49
pacs 008 001 auto reply with 004
//Initialize a payment return (pacs.004)
PaymentReturn paymentReturn = new PaymentReturn();
//message id is commonly auto-generated by each system
paymentReturn.set_GrpHdr_MsgId("OURMESSAGEID");
//The settlement date for our return
paymentReturn.set_GrpHdr_IntrBkSttlmDt(Calendar.getInstance());
//In most cases this is set to CLRG...
paymentReturn.set_GrpHdr_SttlmInf_SttlmMtd("CLRG");
//and Clearing system is set to ST2
paymentReturn.set_GrpHdr_SttlmInf_ClrSys_Prtry("ST2");
@esaounkine
esaounkine / SepaMessageProcessingService.java
Last active December 27, 2015 11:49
pacs 008 001 auto reply with 056
//Initialize a request for recall message (camt.056) with default values
FIToFIPaymentCancellationRequest fiToFIPaymentCancellationRequest = new FIToFIPaymentCancellationRequest(
"GENERATEDASSIGNMENTID", // the assignment id
"XXXXXBIC", // the assigner bank BIC
"YYYYYBIC" // the assignee bank BIC
);
//Construct the message reply information
//Here we are requesting a recall for a message with reason code DUPL (dulicate sending)
Vector<MsgReplyInfo> msgReplyInfo = new Vector<MsgReplyInfo>();
ReasonCode rc = new ReasonCode(ReasonCode.CD, "DUPL", null, null);
@esaounkine
esaounkine / SepaMessageProcessingService.java
Created November 5, 2013 13:49
pacs 008 001 parse and validate
FIToFICustomerCreditTransfer fiToFICustomerCreditTransfer = new FIToFICustomerCreditTransfer();
fiToFICustomerCreditTransfer.parseMessageFromXML(msgText);
List<String> validationErrors = fiToFICustomerCreditTransfer.validate();
@esaounkine
esaounkine / IndexController.java
Created October 14, 2013 10:45
validate SWIFT message example
SwiftMessage parsedMessage = swiftMessageProcessingService.parseSwiftMessage(messageText);
SwiftValidObj validatedMessage = swiftMessageProcessingService.validateSwiftMessage(parsedMessage);
//validatedMessage will contain the SWIFT message object and text, as well as error message in case the message is not valid