Bom dia a todos,
Eu estou fazendo um modulo para conciliação bancária usando ofx4j. Quando baixei o ofx4j veio junto alguns arquivos ofx.
Quando eu executo o código abaixo, a leitura desses arquivos funcionam. Mas quando eu tento ler o arquvio ofx da caixa federal apresenta o erro que está abaixo.
Pergunto, o padrao ofx é internacional ou muda de pais para pais?
Att. Vinicius
Erro
net.sf.ofx4j.io.OFXSyntaxException: Unexpected end aggregate CODE. (Perhaps STATUS is an element with an empty value, making it impossible to parse.)
Código fonto do projeto
package br.com.pentagono.conciliacaobancaria;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
import java.util.List;
import net.sf.ofx4j.domain.data.MessageSetType;
import net.sf.ofx4j.domain.data.ResponseEnvelope;
import net.sf.ofx4j.domain.data.ResponseMessageSet;
import net.sf.ofx4j.domain.data.banking.BankStatementResponse;
import net.sf.ofx4j.domain.data.banking.BankStatementResponseTransaction;
import net.sf.ofx4j.domain.data.banking.BankingResponseMessageSet;
import net.sf.ofx4j.domain.data.common.Transaction;
import net.sf.ofx4j.domain.data.signon.SignonResponse;
import net.sf.ofx4j.io.AggregateUnmarshaller;
import net.sf.ofx4j.io.OFXParseException;
public class LerArquivoOFX {
public static void main(String[] args) throws IOException, OFXParseException {
//AggregateUnmarshaller a = new AggregateUnmarshaller(ResponseEnvelope.class);
AggregateUnmarshaller a = new AggregateUnmarshaller(ResponseEnvelope.class);
ResponseEnvelope re = null;
try {
//File entrada = new File("C:\\Users\\Vinicius\\Desktop\\7CXI4C2gsHj+GVwtzCDdxoUfwA.nodelx467_nbcinter06a-lx467.ofc");
File entrada = new File("C:\\Users\\Vinicius\\Downloads\\7C4ZByvOLKchMhwAmrIyglZ3vO.nodelx003_nbcinter06a-lx003.ofx");
//File entrada = new File("C:\\Users\\Vinicius\\Downloads\\ofx4j-master\\ofx4j-master\\src\\test\\resources\\com\\webcohesion\\ofx4j\\io\\bank-of-america-profile.ofx");
//File entrada = new File("C:\\Users\\Vinicius\\Desktop\\estrato caixa.ofx");
FileInputStream inputStream = new FileInputStream(entrada);
Reader reader = new InputStreamReader(inputStream, Charset.forName("UTF-8"));
re = (ResponseEnvelope) a.unmarshal(reader);
} catch (IOException | OFXParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//objeto contendo informações como instituição financeira, idioma, data da conta.
SignonResponse sr = re.getSignonResponse();
System.out.println("Banco: " + sr.getFinancialInstitution().getOrganization());
//como não existe esse get "BankStatementResponse bsr = re.getBankStatementResponse();"
//fiz esse codigo para capturar a lista de transações
MessageSetType type = MessageSetType.banking;
ResponseMessageSet message = re.getMessageSet(type);
if (message != null) {
//List bank = ((BankingResponseMessageSet) message).getStatementResponses();
List<BankStatementResponseTransaction> bank = ((BankingResponseMessageSet) message).getStatementResponses();
for (BankStatementResponseTransaction b : bank) {
System.out.println("cc: " + b.getMessage().getAccount().getAccountNumber());
System.out.println("ag: " + b.getMessage().getAccount().getBranchId());
System.out.println("balanço final: " + b.getMessage().getLedgerBalance().getAmount());
System.out.println("dataDoArquivo: " + b.getMessage().getLedgerBalance().getAsOfDate());
//List list = b.getMessage().getTransactionList().getTransactions();
List<Transaction> list = b.getMessage().getTransactionList().getTransactions();
System.out.println("TRANSAÇÕES\n");
for (Transaction transaction : list) {
System.out.println("tipo: " + transaction.getTransactionType().name());
System.out.println("id: " + transaction.getId());
System.out.println("data: " + transaction.getDatePosted());
System.out.println("valor: " + transaction.getAmount());
System.out.println("descricao: " + transaction.getMemo());
System.out.println("");
}
}
}
}
}