在单个smooks实例上应用顾问程序时发生异常

时间:2013-11-11 17:27:13

标签: freemarker smooks

需要任何人的建议。

if you look at the below code,every time I am creating the new object for smooks as ftlname dynamically get populated.
        try {
              Smooks smooks1 = new Smooks("smooks-config.xml");
            if (ftlName != null) {
                inputStream = new ByteArrayInputStream(xmlMessage.toString()
                        .getBytes());
                outStream = new ByteArrayOutputStream();
                smooks1.addVisitor(new FreeMarkerTemplateProcessor(
                        new TemplatingConfiguration(ftlName)));
                smooks1.filterSource(new StreamSource(inputStream),
                        new StreamResult(outStream));
                resultString = outStream.toString();
                inputStream.close();
                outStream.close();
            }
        } catch (Exception ee) { }

每次创建一个smooks对象时,这真的达到了性能,当我尝试使用单个smooks实例时,低于错误。

java.lang.UnsupportedOperationException: Unsupported call to Smooks instance configuration method after Smooks instance has created an ExecutionContext.
     at org.milyn.Smooks.assertIsConfigurable(Smooks.java:588) [milyn-smooks-all-1.5.1.jar:]
     at org.milyn.Smooks.addVisitor(Smooks.java:262) [milyn-smooks-all-1.5.1.jar:]
     at org.milyn.Smooks.addVisitor(Smooks.java:241) [milyn-smooks-all-1.5.1.jar:]

can you please provide your advice on it.
smooks version :- 1.5.1

1 个答案:

答案 0 :(得分:0)

我的猜测(未经证实)是您无法使用XML文件(在构造函数中)配置Smooks实例,然后通过addVisitor()继续添加更多访问者impls。

您是否有理由在smooks配置中配置freemarker模板?