Emails with unexpanded templates

Problems with installing LogicalDOC? No problems, the solution is closer than you think.

Moderator: car031

mgedmin
Posts: 10
Joined: Tue Nov 17, 2015 10:51 am

Emails with unexpanded templates

Thu Nov 19, 2015 3:51 pm

I've installed LogicalDOC Community Edition 7.3 on an Ubuntu 12.04 LTS virtual machine (Vagrant), for testing. I've a problem with outgoing emails.

My VM has postfix installed but no actual connectivity, to avoid accidents, so I'm looking at emails that are stuck in the outgoing queue in the VM, and this is what I see:

Code: Select all

*** MESSAGE CONTENTS /var/spool/postfix/deferred/B/B030842B04 ***
Received: from vagrant-ubuntu-precise-64 (localhost [127.0.0.1])
    by vagrant-ubuntu-precise-64 (Postfix) with ESMTP id B030842B04
    for <admin@admin.net>; Thu, 19 Nov 2015 11:09:25 +0000 (UTC)
From: logicaldoc@acme.com
To: admin@admin.net
Message-ID: <839557298.3.1447931365722.JavaMail.logicaldoc@vagrant-ubuntu-precise-64>
Subject: $product - $I18N.get('emailnotifyaccountobject')
MIME-Version: 1.0
Content-Type: multipart/mixed; 
    boundary="----=_Part_2_636999199.1447931365689"
Date: Thu, 19 Nov 2015 11:09:25 +0000 (UTC)

------=_Part_2_636999199.1447931365689
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

$I18N.format('emailnotifyaccount', $user.fullName) <br/> $I18N.get('username'): <b>$user.userName</b> <br/> $I18N.get('password'): <b>$password</b> <br/> $I18N.get('clickhere'): <a href="$url">$url</a>
------=_Part_2_636999199.1447931365689--
*** HEADER EXTRACTED /var/spool/postfix/deferred/B/B030842B04 ***
*** MESSAGE FILE END /var/spool/postfix/deferred/B/B030842B04 ***
You can see how the template is not expanded:

Code: Select all

Subject: $product - $I18N.get('emailnotifyaccountobject')

Code: Select all

$I18N.format('emailnotifyaccount', $user.fullName) <br/> $I18N.get('username'): <b>$user.userName</b> <br/> $I18N.get('password'): <b>$password</b> <br/> $I18N.get('clickhere'): <a href="$url">$url</a>
I spent maybe an hour trying to figure this out, and I'm about to give up. As far as I can tell, the source code for email formatting (community/logicaldoc/logicaldoc-core/src/main/java/com/logicaldoc/core/communication/MessageTemplate.java) does this:

Code: Select all

		StringWriter writer = new StringWriter();
		try {
			Velocity.evaluate(context, writer, getName(), text.replace("\n", "${nl}"));
			return writer.toString();
		} catch (Exception e) {
			return text;
		}
i.e. if any error happens during Velocity.evaluate(), that error is silently swallowed and not recorded in any log file.

Any advice for debugging this? Anything simpler than editing out that try/catch and learning how to build the entire product so I can see what the underlying error is?
car031
Posts: 154
Joined: Tue Apr 17, 2012 8:27 am

Re: Emails with unexpanded templates

Thu Nov 19, 2015 4:07 pm

Hi, there is nothing simpler i fear, you would have to put your debug in the cathc section and recompile
mgedmin
Posts: 10
Joined: Tue Nov 17, 2015 10:51 am

Re: Emails with unexpanded templates

Fri Nov 20, 2015 9:52 am

I've added some logging code but couldn't find the log messages anywhere.

Then I added code to smuggle the exception information via the outgoing emails and now I see the problem is with my logging configuration:

java.lang.RuntimeException: Velocity could not be initialized!
at org.apache.velocity.runtime.RuntimeInstance.requireInitialization(RuntimeInstance.java:295)
...
Caused by: org.apache.velocity.exception.VelocityException: Failed to initialize an instance of org.apache.velocity.runtime.log.Log4JLogChute with the current runtime configuration.
...
Caused by: java.lang.RuntimeException: Error configuring Log4JLogChute :
...
Caused by: java.io.FileNotFoundException: velocity.log (Permission denied)
...

I've modified the startup script to change the unix user because I don't trust large blobs of Java code running as root, especially after the recent series of security advisories in one of the common Java libraries:

Code: Select all

 if [ x"$(id -un)" != xlogicaldoc ]; then
     exec sudo -Hu logicaldoc "$0" "$@"
 fi
Now all I need to do is figure out where it's trying to create the velocity.log file, because /opt/logicaldoc/tomcat/logs is writable to the logicaldoc user, and I see catalina logging stuff there. And then I need to figure out how to tell it to log elsewhere.
mgedmin
Posts: 10
Joined: Tue Nov 17, 2015 10:51 am

Re: Emails with unexpanded templates

Fri Nov 20, 2015 10:03 am

I've added some logging code but couldn't find the log messages anywhere.
I was looking in /opt/logicaldoc/tomcat/logs/*.

The messages I was logging actually showed up in /opt/logicaldoc/repository/logs/dms.log.
mgedmin
Posts: 10
Joined: Tue Nov 17, 2015 10:51 am

Re: Emails with unexpanded templates

Fri Nov 20, 2015 10:04 am

Now all I need to do is figure out where it's trying to create the velocity.log file
The root directory, apparently, since that's the cwd of the java process, according to lsof.
mgedmin
Posts: 10
Joined: Tue Nov 17, 2015 10:51 am

Re: Emails with unexpanded templates

Fri Nov 20, 2015 1:19 pm

Code: Select all

And then I need to figure out how to tell it to log elsewhere.
*skip hours of reading documentation and diving through source code*

Basically, this works: http://kris-itproblems.blogspot.lt/2010 ... enied.html

I installed LogicalDOC into /opt/logicaldoc, so I had to create a /opt/logicaldoc/tomcat/webapps/ROOT/WEB-INF/classes/org/apache/velocity/runtime/defaults/velocity.properties, which I did by extracting the original from the velocity-1.6.4.jar file and replacing

Code: Select all

runtime.log = velocity.log
with

Code: Select all

runtime.log = /opt/logicaldoc/repository/logs/velocity.log
And now password recovery works.
car031
Posts: 154
Joined: Tue Apr 17, 2012 8:27 am

Re: Emails with unexpanded templates

Fri Nov 20, 2015 2:02 pm

The best thing is to redirect the log of velocity to one of the existing Loggers in LogicalDOC, we just committed this
mgedmin
Posts: 10
Joined: Tue Nov 17, 2015 10:51 am

Re: Emails with unexpanded templates

Tue Nov 24, 2015 11:49 am

Is the source repository for LogicalDOC Community Edition publically available? I couldn't find it on SourceForge.

(Why don't you use GitHub?)
car031
Posts: 154
Joined: Tue Apr 17, 2012 8:27 am

Re: Emails with unexpanded templates

Tue Nov 24, 2015 11:53 am

mgedmin
Posts: 10
Joined: Tue Nov 17, 2015 10:51 am

Re: Emails with unexpanded templates

Wed Nov 25, 2015 7:53 am

Thank you!

Return to “Installation”

Who is online

Users browsing this forum: No registered users and 25 guests