升级smooks 1.4到1.5中断CSV解析(空输入)

时间:2012-02-15 17:45:46

标签: java csv smooks

在使用smooks bean绑定和CSV映射进行了一些努力之后,我设法解析了一个具有空值的特定CSV,如in this question所示。不知何故,由于xml配置文件验证,我在创建smooks实例时遇到了一些奇怪的错误(期望一个不同的xml文档结构,所以它抛出“期望的blahblah / abstract-resource-config”的东西)。所以我更新到smooks 1.5,基本上它停止过滤输入数据。 ¿¿我应该更改什么才能使其从 messagePath 路径获取CSV并使用给定的配置对其进行过滤?

代码块是这个

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;
}

配置文件就像这样

<?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>

我尝试解析的每个文件的错误日志是:

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)

1 个答案:

答案 0 :(得分:0)

它已被修复,因为你可以升级到随修复程序发布的1.5.1。

请参阅http://jira.codehaus.org/browse/MILYN-636