Question

After some struggle with smooks bean binding and CSV mapping, I managed to parse a specific CSV with empty values as shown in this question. Somehow, I got some odd errors while creating smooks instance due to xml config file validation (expects a different xml document structure so it throws "expected blahblah/abstract-resource-config" thing). So I updated to smooks 1.5 and basically it stopped filtering input data. ¿¿What should I change in order to make it work getting the CSV from the messagePath path and filtering it using the given config??

The code block is this

protected List runSmooksTransform(int intType) throws IOException, SAXException, SmooksException {
    Smooks smooks = null;
    try {
        switch (intType) {
            case 0:
                // Header
                smooks = new Smooks("smooks-config_enc.xml");
                break;
            case 1:
                // Detail list
                smooks = SmooksFactoryServicio.getInstance().getSmooksDetalle();
                break;
            default:
                LogServicio.doLog("[CSVParserServicio, runSmooksTransform] Tipo de archivo a procesar no reconocido.", LogServicio.CErrorLvl);
                return null;
        }
        JavaResult javaResult = new JavaResult();

        File f = new File(messagePath);
        InputStream is = new FileInputStream(messagePath);
        StreamSource ss = new StreamSource( is );

        smooks.filterSource(ss, javaResult); //tried with file and inputstream to streamsource...

        LogServicio.doLog("[CSVParserServicio, runSmooksTransform] Finaliza procesamiento archivo"+ messagePath , LogServicio.CInfoLvl);
        return (List) javaResult.getBean("movimientoList");

    } catch (Exception e) {
        LogServicio.doLog("[CSVParserServicio, runSmooksTransform] Excepción procesando archivo: " + e.getMessage(), LogServicio.CErrorLvl);
        e.printStackTrace();
    } finally {
        smooks.close();
    }

    return null;
}

The config file is like this

<?xml version="1.0"?>
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
                      xmlns:csv1="http://www.milyn.org/xsd/smooks/csv-1.5.xsd"
                      xmlns:jb="http://www.milyn.org/xsd/smooks/javabean-1.4.xsd"
                      xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.3.xsd">

    <!-- <core:filterSettings type="SAX" /> -->

    <csv1:reader fields="c01_ClaveBanco,c02_Cuenta,c03_Consecutivo,c04_FechaMovimientos,c05_ClaveMoneda,
    c06_SaldoInicial,c07_TotalDebitos, c08_TotalCreditos,c09_SaldoFinal,c10_TipoCuenta,c11,c12,c13,c14,
    c15,c16,c17,c18_NumeroMovs" separator=";" />

    <jb:bean beanId="movimiento" class="com.correval.conciliacion.procesador.bean.MulticashEncabezado"
     createOnElement="csv-record">

        <jb:value property="c01_ClaveBanco" data="csv-record/c01_ClaveBanco" />
        <jb:value property="c02_Cuenta" data="csv-record/c02_Cuenta" />
        <jb:value property="c03_Consecutivo" data="csv-record/c03_Consecutivo" decoder="Integer" default="0" />
        <jb:value property="c04_FechaMovimientos" data="csv-record/c04_FechaMovimientos" />
        <jb:value property="c05_ClaveMoneda" data="csv-record/c05_ClaveMoneda" />
        <jb:value property="c06_SaldoInicial" data="csv-record/c06_SaldoInicial" decoder="Double" default="0.0" />
        <jb:value property="c07_TotalDebitos" data="csv-record/c07_TotalDebitos" decoder="Double" default="0.0" />
        <jb:value property="c08_TotalCreditos" data="csv-record/c08_TotalCreditos" decoder="Double" default="0.0" />
        <jb:value property="c09_SaldoFinal" data="csv-record/c09_SaldoFinal" decoder="Double" default="0.0" />

        <jb:value property="c10_TipoCuenta" data="csv-record/c10_TipoCuenta" />
        <jb:value property="c11" data="csv-record/c11" />
        <jb:value property="c12" data="csv-record/c12" />
        <jb:value property="c13" data="csv-record/c13" />
        <jb:value property="c14" data="csv-record/c14" />
        <jb:value property="c15" data="csv-record/c15" />
        <jb:value property="c15" data="csv-record/c16" />
        <jb:value property="c16" data="csv-record/c17" />
        <jb:value property="c18_NumeroMovs" data="csv-record/c18_NumeroMovs" decoder="Integer" default="0" />
    </jb:bean>

    <jb:bean beanId="movimientoList" class="java.util.ArrayList" createOnElement="csv-set">
        <jb:wiring beanIdRef="movimiento" />
    </jb:bean>

</smooks-resource-list>

The error log for each file I try to parse is this:

2012-02-15 12:37:41,291 [-] [http-apr-9090-exec-4] ERROR LogServicio [CSVParserServicio, runSmooksTransform] Excepci¾n procesando archivo: F
ailed to filter source.
org.milyn.SmooksException: Failed to filter source.
        at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:97)
        at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:64)
        at org.milyn.Smooks._filter(Smooks.java:526)
        at org.milyn.Smooks.filterSource(Smooks.java:482)
        at org.milyn.Smooks.filterSource(Smooks.java:456)
        at com.correval.conciliacion.procesador.servicios.CSVParserServicio.runSmooksTransform(CSVParserServicio.java:92)
        at com.correval.conciliacion.procesador.servicios.CSVParserServicio.parseCSVFile(CSVParserServicio.java:33)
        at com.correval.conciliacion.procesador.servicios.ArchivoServicio.extractMulticashData(ArchivoServicio.java:502)
        at com.correval.conciliacion.logica.servlet.ProcesaBancoServlet.getMulticashHeaders(ProcesaBancoServlet.java:130)
        at com.correval.conciliacion.logica.servlet.ProcesaBancoServlet.doPost(ProcesaBancoServlet.java:68)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
        at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1824)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalArgumentException: null or empty 'value' arg in method call.
        at org.milyn.assertion.AssertArgument.isNotNullAndNotEmpty(AssertArgument.java:78)
        at org.milyn.flatfile.Field.<init>(Field.java:39)
        at org.milyn.flatfile.variablefield.VariableFieldRecordParser.nextRecord(VariableFieldRecordParser.java:190)
        at org.milyn.flatfile.FlatFileReader.parse(FlatFileReader.java:132)
        at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:76)
        at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:86)
Was it helpful?

Solution

It has been fixed since, you can upgrade to 1.5.1 which is released with the fix.

See http://jira.codehaus.org/browse/MILYN-636

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top