Skip to main content
May 21, 2010
Question

CF9 Problem using log4j when sending an email (org.apache.log4j.net.SMTPAppender)

  • May 21, 2010
  • 2 replies
  • 3775 views

Hi,

i've problem using log4j  when i sending email with log4j on CF9 (org.apache.log4j.net.SMTPAppender). The code under works fine with CF8 (version   8,0,0,176276)  :

<cfset parameters = structnew()>

<cfset parameters.category="MyCategory">

<cfset parameters.message="#randRange(1000, 100000)# Test Error">

<cfscript>

configurator = CreateObject("java", "org.apache.log4j.PropertyConfigurator");

configurator.configure('C:/cflog4j/cflog4j.properties');

category = CreateObject("java", "org.apache.log4j.Category");

logger = category.getInstance(parameters.category);

logger.error(parameters.message);

</cfscript>

Here the stack trace in the coldfusion runtime log (coldfusion-out.log):

log4j:ERROR Error occured while sending e-mail notification.java.lang.ClassCastException: com.sun.mail.handlers.text_plain cannot be cast to javax.activation.DataContentHandler at javax.activation.MailcapCommandMap.getDataContentHandler(MailcapCommandMap.java:581)at javax.activation.MailcapCommandMap.createDataContentHandler(MailcapCommandMap.java:535)at javax.activation.DataHandler.getDataContentHandler(DataHandler.java:597)at javax.activation.DataHandler.writeTo(DataHandler.java:301)at javax.mail.internet.MimeUtility.getEncoding(MimeUtility.java:264)at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1299)at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1008)at javax.mail.internet.MimeMultipart.updateHeaders(MimeMultipart.java:414)at javax.mail.internet.MimeBodyPart.updateHeaders(MimeBodyPart.java:1285)at javax.mail.internet.MimeMessage.updateHeaders(MimeMessage.java:2071)at javax.mail.internet.MimeMessage.saveChanges(MimeMessage.java:2039)at javax.mail.Transport.send(Transport.java:119)at org.apache.log4j.net.SMTPAppender.sendBuffer(Unknown Source)at org.apache.log4j.net.SMTPAppender.append(Unknown Source)at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:221)at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:57)at org.apache.log4j.Category.callAppenders(Category.java:187)at org.apache.log4j.Category.forcedLog(Category.java:372)at org.apache.log4j.Category.error(Category.java:286)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at coldfusion.runtime.StructBean.invoke(StructBean.java:502)at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2393)at cflogError22ecfm1601859185.runPage(D:\projets\phswebservice\global\web_phs_front\test\logError2.cfm:14)at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231)at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416)at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:342)at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)at coldfusion.filter.PathFilter.invoke(PathFilter.java:87)at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74)at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:53)at coldfusion.CfmServlet.service(CfmServlet.java:200)at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)at jrun.servlet.FilterChain.service(FilterChain.java:101)at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

Here the cflog4j.properties file :

log4j.category.MyCategory=

frontAppender, mail

#file appender works fine

log4j.appender.frontAppender =org.apache.log4j.RollingFileAppender

log4j.appender.frontAppender.File=D:/front.log

log4j.appender.frontAppender.layout=org.apache.log4j.PatternLayout

log4j.appender.frontAppender.layout.ConversionPattern=

%-5p %c %d - %m%n

log4j.appender.frontAppender.MaxFileSize=1024KB

#SMPT appender

log4j.appender.mail=org.apache.log4j.net.SMTPAppender

log4j.appender.mail.SMTPHost=

smtp.mysite.com

log4j.appender.mail.Subject=

Error Message

log4j.appender.mail.From=

erreur@cgin

log4j.appender.mail.To=

error@mysite.com

log4j.appender.mail.BufferSize=10

log4j.appender.mail.Threshold=

info

log4j.appender.mail.layout=

org.apache.log4j.PatternLayout

log4j.appender.mail.layout.ConversionPattern=

%-5p %c %d{ISO8601} - %m%n

If i look at CF8 Classpath, CF8 seems not to use javax.activation.jar and so mail.jar does not seem to be the same as in CF9.

If someone have any idea to resolve this problem, thanks a lot !

This topic has been closed for replies.

2 replies

Inspiring
July 1, 2011

We had a similar problem with sending java-based email from a coldfusion page. The problem is that mail.jar and activation.jar in the ../WEB-INF/cfusion/lib directory contain mail-related classes, while /JRun4/lib/jrun.jar already contains them too.

So we just removed the two jars from the ../WEB-INF/cfusion/lib directory, and now Java works and CFMAIL still works too.

It sounds like Adobe made a configuration mistake.

Inspiring
July 2, 2011

It sounds like Adobe made a configuration mistake.

Thanks for the follow up. Interesting, I knew there were duplicate libraries, but was not adventurous enough to mess with the paths. You might consider filing a bug report . So if it is a mistake it could be fixed in future versions. If not at least we would find out why it was included and what it impacts

http://cfbugs.adobe.com/

Inspiring
May 24, 2010

I suspect it is due to the WEB-INF\lib\cfmx_bootstrap.jar. The CF9 properties include a bunch of mail packages to be loaded by the bootstrap class loader, (CF8 did not). Some of the mail packages are contained in multiple jars. Example javax.activation.* classes are found in both the \lib\rt.jar and \lib\mail.jar. So the jvm/logger may be getting confused and falling down when faced with multiple versions.

You could update the appropriate *.properties file in cfmx_bootstrap.jar, and move the necessary packages to from the bootstrap section to the App Server class loader section. That might work. But I have no idea what it might break in the process ...

Message was edited by: -==cfSearching==-

New Participant
May 25, 2010

This seems that a really serious issue : it would mean that in order to use any java package that could send mail one has to

tweak ColdFusion 9 at a very low level with the risk of breaking ColdFusion itself. It would mean the end of use of many external java packages because lot of them potentially send email if they use log4j for example.

Maybe there is an Adobe supported way to do this kind of things in ColdFusion 9 ?

Inspiring
May 25, 2010

norbertAdobe wrote:

It would mean the end of use of many external java packages because lot of them potentially send email if they use log4j for example.

Why would you say that? The issue described does not stop log4j or external libraries from working, just the email feature.

Unfortunately, Issues with log4j + other java applications are not new.  There are some common class loader conflicts that can occur in any java application due to how class loaders work and how log4j is designed.  In thinking about it further, that may be what is happening here.  So it might be worth trying the ignoreTCL flag and/or adding the appenders to the main log4j.properties used by CF.