OFX4J: Java Web Service APIs for Interfacing with Financial Institutions
Join the DZone community and get the full member experience.
Join For FreeOFX4J has been released!
OFX4J is a Java implementation of Open Financial Exchange, which defines web service APIs for interfacing with financial institutions. The OFX4J library includes support for both client-side and server-side implementations of both version 1 and version 2 of the OFX specification.
As an example, let's consider the OFX4J client-side interface, which can be used, for example, to download your financial transactions from your bank or credit card institution. OFX4J comes with an initial set of financial institution data, but you can load your own if your financial institution isn't included.
Consider the following code for downloading your bank statement:
//the financial institution data is loaded or created
//the FinancialInstitutionData interface defines
//what is required to interface with a financial institution.
FinancialInstitutionData data = ...;
FinancialInstitutionService service
= new FinancialInstitutionServiceImpl();
FinancialInstitution fi = service.getFinancialInstitution(data);
//get a reference to a specific bank account at the FI
BankAccountDetails bankAccountDetails
= new BankAccountDetails();
//routing number to the bank.
bankAccountDetails.setRoutingNumber("11111111");
//bank account number.
bankAccountDetails.setAccountNumber("1234-5678");
//it's a checking account
bankAccountDetails.setAccountType(AccountType.CHECKING);
BankAccount bankAccount
= fi.loadBankAccount(bankAccountDetails, "username", "password");
//read the statement (transaction details, etc.)
// for a given time period.
Date startDate = ...;
Date endDate = ...;
AccountStatement statement
= bankAccount.readStatement(startDate, endDate);
// get a reference to a specific credit card
// account at your FI
CreditCardAccountDetails ccDetails
= new CreditCardAccountDetails();
ccDetails.setAccountNumber("1234-567890-1111");
CreditCardAccount ccAccount
= fi.loadCreditCardAccount(ccDetails, "username", "password");
// read the statement (transaction details, etc.)
// for a given time period.
Date startDate = ...;
Date endDate = ...;
AccountStatement statement
= ccAccount.readStatement(startDate, endDate);
Server-side development is just straightforward, consisting of implementing a simple interface and publishing it with a simple Servlet implementation:
/**
* Basic interface for an OFX server.
*
* @author Ryan Heaton
*/
public interface OFXServer {
/**
* Get a response for the given request.
*
* @param request The request.
* @return The response.
*/
ResponseEnvelope getResponse(RequestEnvelope request);
}
Opinions expressed by DZone contributors are their own.
Comments