0

need a advice from any one.

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) { }

this is really hitting the performance as every time creating a smooks object, when I have try to use the single smooks instance, getting below error.

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
Ananth
  • 65
  • 1
  • 7

1 Answers1

0

My guess (unverified) is that you can't configure the Smooks instance with an XML file (in the constructor) and then proceed to add more Visitor impls via addVisitor().

Is there a reason you're not configuring the freemarker template in the smooks config?

Tom Fennelly
  • 286
  • 1
  • 2
  • 7
  • Hi Tom, Thanks for your time to watch question. the name of the ftl will be fetched based on some criteria,so I could not put the ftl names in side the smooks config. – Ananth Nov 13 '13 at 02:19
  • Hmmm... that means you're creating the Smooks instance for every call? That'll kill your performance as creating a Smooks instance every time is not cheap. How many .ftl files are there? You could include all of them in the smooks config file and then execute the appropriate one (using a on the freemarker config in the smooks config file) according to a parameter you bind into the bean context before execution. – Tom Fennelly Nov 13 '13 at 06:53