You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by Fan Zeng <fa...@gmail.com> on 2006/03/23 18:27:23 UTC

Need help with "java.lang.Exception: Template.merge() failure"

Hi,

I've got the following on a very busy system:

   java.lang.Exception: Template.merge() failure. The document is
null, most likely due to parsing error.

This has happened only once in the past few weeks when we generated
hundreds of thousands of messages. Only a couple of VTL templates were
used for the messages. We use velocity 1.4.

The comments in the Velocity source code say "this shouldn't happen
either, but just in case."

What can I do to prevent the exception from happening.

The methods below are copied from our source code. It should provide
some ideas on how we use Velocity.


    private String transform(String normalizedName, VtlNotifyData
vtlNotifyData) throws GLException {
        StringWriter writer = new StringWriter();
        VelocityContext context = vtlNotifyData.getVelocityContext();

        Template template = getTemplate(normalizedName);
        try {
            template.merge(context, writer);
        }
        catch (Exception e) {
            throw GLException.factory(e);
        }

        return writer.toString();
    }

    private Template getTemplate(String templateName) throws GLException {
        // theNotifyVelocityEngine is a static member
        if (theNotifyVelocityEngine == null) {
            try {
                theNotifyVelocityEngine = new VelocityEngine();
               
theNotifyVelocityEngine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM,
                        new VelocityLogSystem());
                // set other properties
                ...
                }

                theNotifyVelocityEngine.init();
            }
            catch (Exception e) {
                throw GLException.factory(e);
            }
        }

            return theNotifyVelocityEngine.getTemplate(templateName);
    }

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Need help with "java.lang.Exception: Template.merge() failure"

Posted by Fan Zeng <fa...@gmail.com>.
Hi Will,

Here is the stack trace. As you can see, most of the lines are inside
our application code. Unfortunately this is the only one I have.

Fan Zeng

-----------------------

java.lang.Exception: Template.merge() failure. The document is null,
most likely due to parsing error.
	at org.apache.velocity.Template.merge(Lorg.apache.velocity.context.Context;Ljava.io.Writer;)V(Optimized
Method)
	at glog.server.workflow.notify.impl.VelocityTransformer.transform(Lglog.server.workflow.notify.NotifyMethod;Lglog.server.workflow.notify.NotifyData;Lglog.util.jdbc.T2SharedConnection;)Lglog.server.workflow.notify.MessageData;(Optimized
Method)
	at glog.server.workflow.notify.RouterWithTransformation.routeNonConsolidated(Lglog.server.workflow.notify.NotifyBundle;Lglog.util.jdbc.T2SharedConnection;)Lglog.server.workflow.notify.RouterResults;(Optimized
Method)
	at glog.server.workflow.notify.RouterWithTransformation.route(Lglog.server.workflow.notify.NotifyBundle;Lglog.util.jdbc.T2SharedConnection;)Lglog.server.workflow.notify.RouterResults;(Optimized
Method)
	at glog.server.dataqueue.notify.NotifyExecutor.batch(Ljava.util.Collection;Lglog.server.dataqueue.DataQueue;Lglog.util.jdbc.T2SharedConnection;)Z(Optimized
Method)
	at glog.server.dataqueue.DataQueue.execute(Ljava.util.Collection;Lglog.util.jdbc.T2SharedConnection;)V(Optimized
Method)
	at glog.server.dataqueue.DataQueueRunnable.run()V(DataQueueRunnable.java:76)
	at java.lang.Thread.run()V(Unknown Source)
	at java.lang.Thread.startThreadFromVM(Ljava.lang.Thread;)V(Optimized Method)

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org


Re: Need help with "java.lang.Exception: Template.merge() failure"

Posted by Will Glass-Husain <wg...@forio.com>.
Can you send a stack trace?

On 3/23/06, Fan Zeng <fa...@gmail.com> wrote:
> Hi,
>
> I've got the following on a very busy system:
>
>    java.lang.Exception: Template.merge() failure. The document is
> null, most likely due to parsing error.
>
> This has happened only once in the past few weeks when we generated
> hundreds of thousands of messages. Only a couple of VTL templates were
> used for the messages. We use velocity 1.4.
>
> The comments in the Velocity source code say "this shouldn't happen
> either, but just in case."
>
> What can I do to prevent the exception from happening.
>
> The methods below are copied from our source code. It should provide
> some ideas on how we use Velocity.
>
>
>     private String transform(String normalizedName, VtlNotifyData
> vtlNotifyData) throws GLException {
>         StringWriter writer = new StringWriter();
>         VelocityContext context = vtlNotifyData.getVelocityContext();
>
>         Template template = getTemplate(normalizedName);
>         try {
>             template.merge(context, writer);
>         }
>         catch (Exception e) {
>             throw GLException.factory(e);
>         }
>
>         return writer.toString();
>     }
>
>     private Template getTemplate(String templateName) throws GLException {
>         // theNotifyVelocityEngine is a static member
>         if (theNotifyVelocityEngine == null) {
>             try {
>                 theNotifyVelocityEngine = new VelocityEngine();
>
> theNotifyVelocityEngine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM,
>                         new VelocityLogSystem());
>                 // set other properties
>                 ...
>                 }
>
>                 theNotifyVelocityEngine.init();
>             }
>             catch (Exception e) {
>                 throw GLException.factory(e);
>             }
>         }
>
>             return theNotifyVelocityEngine.getTemplate(templateName);
>     }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
>
>


--
Forio Business Simulations

Will Glass-Husain
wglass@forio.com
www.forio.com

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org