NoSuchProviderException: smtp with log4j SMTP appender - java

I am using log4j to send an email when there is an exception. below is my log4j properties file configuration.
log4j.rootLogger=WARN, R, email
log4j.appender.R=org.apache.log4j.ConsoleAppender
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{HH:mm:ss} %-5p [%c{1}]: %m%n
log4j.appender.email=org.apache.log4j.net.SMTPAppender
log4j.appender.email.BufferSize=10
log4j.appender.email.SMTPHost=myhost.com
log4j.appender.email.From=abc#some.com
log4j.appender.email.To=abc#some.com
log4j.appender.email.Subject=Error
log4j.appender.email.layout=org.apache.log4j.PatternLayout
mine is maven project i have added dependencies for mail.jar, activation.jar and smtp.jar. But on application server startup itself i get below error:
[ERROR] log4j:ERROR Error occured while sending e-mail notification.
[ERROR] javax.mail.NoSuchProviderException: smtp
[ERROR] at javax.mail.Session.getService(Session.java:782)
[ERROR] at javax.mail.Session.getTransport(Session.java:708)
[ERROR] at javax.mail.Session.getTransport(Session.java:651)
[ERROR] at javax.mail.Session.getTransport(Session.java:631)
[ERROR] at javax.mail.Session.getTransport(Session.java:686)
[ERROR] at javax.mail.Transport.send0(Transport.java:166)
Am i missing any thing here? What is the root cause of the error? is it because of incorrect SMTP host name? or is it because of any missing/conflicting dependencies?

You don't need smtp.jar and mail.jar - everything in smtp.jar is also in mail.jar. Get rid of smtp.jar, although I doubt that will solve your problem.
Also, make sure you don't have any other jar files with JavaMail classes in your classpath, such as javaee.jar or j2ee.jar.
This is most likely a classpath problem of some sort. JavaMail uses the class loader to find the configuration file that configures the providers such as "smtp". If the class loader handles resource lookups incorrectly, this problem can occur.

Upgrade your JavaMail to 1.5.3 which contains the fix for Bug 6668 -skip unusable Store and Transport classes. From the bug report:
In complex class loading situations, it can be possible for there to be
multiple copies of the JavaMail classes. A Store or Transport defined
by one copy may be loaded by another copy, but it won't be usable because
they're in different ClassLoaders. In this case, JavaMail should skip
over the unusable class and try to load the class from another ClassLoader.
This can happen, for example, in GlassFish if the application includes the
JavaMail classes, the application class loader is configured to prefer
application classes over system classes, and the app server itself tries
to use JavaMail when running in the context of the application.
You can download the latest snapshot and official releases from the JavaMail reference implementation home page.

You probably want to export smtp.jar to be usable by your webapp.

Related

Do I need log4j-core when using log4j-core-2.4.1

I am getting the following error:
ERROR StatusLogger Log4j2 could not find a logging implementation.
Please add log4j-core to the classpath. Using SimpleLogger to log to
the console.
I am using eclipse V4.3.2 in a GWT application.
Both log4j-api-2.4.1.jar and log4j-core-2.4.1.jar are on the class path.
I've seen other postings similar to my error but it's not clear to me what I am doing wrong if anything.
Thanks
Classpath is not enough (and actually wrong), you need server code within the WAR's WEB-INF (WEB-INF/lib to be exact here).

java.lang.SecurityException: signer information does not match signer information of other classes in the same package

We have renewed security certificates in our java applications and suddenly we have started receiving below mentioned exception:
java.lang.SecurityException: class "org.hibernate.cfg.Configuration"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:806) [rt.jar:1.6.0_37]
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:487) [rt.jar:1.6.0_37]
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:625) [rt.jar:1.6.0_37]
at java.lang.ClassLoader.defineClass(ClassLoader.java:615) [rt.jar:1.6.0_37]
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:344)
We use ANT tool to build our code. I found some links over the SO describing the similar issue. Bur I am not sure how to resolve issue which is related to hibernate jars. Please let me know, if you have any idea.
Might be that your class org.hibernate.cfg.Configuration doesn't get loaded from the jar that you're expecting to do so.
Had the same problem when our program was loading some utility classes for JavaMail and it turned out that after switching over to Maven for project configuration management, some of our Jetty dependencies were including the jar javax.mail.glassfish, thus conflicting with the explicit mail dependencies.
To find out which jars are actually loaded when launching the java program from console, you can use the -verbose:class option when starting the Java VM (as described here).
I had an additional jar file in WEB-INF/lib/wsdl4j.jar

How to fix exception: Failed to instantiate SLF4J LoggerFactory?

I am trying to write a java web crawler for semantic web using jena library. I have build project using Netbeans. I am receiving two errors:
Failed to instantiate SLF4J LoggerFactory
Reported exception:
java.lang.NoClassDefFoundError: org/apache/log4j/Level
Could not initialize class com.hp.hpl.jena.rdf.model.impl.ModelCom
at org.slf4j.LoggerFactory.bind(LoggerFactory.java:128)
I have included slf4j-api and slf4j-log both libraries.
You should also include log4j library as slf4j-log4j is just a static binder.
You should include slf4j-api-x.x.x.jar and slf4j-simple-x.x.x.jar in your classpath.
As error suggested:
Failed to instantiate SLF4J LoggerFactory
you need to place your corresponding slf4j-*-*.jar binding files into your classpath folder.
You can locate them by locate slf4j if present.
As of SLF4J version 1.6.0, if no binding is found on the class path, then slf4j-api will default to a no-operation implementation discarding all log requests.
Tomcat
If using Tomcat, these files you can copy either into /usr/share/tomcat7/lib or your webapp folder /var/lib/tomcat7/webapps/*/WEB-INF/lib.
Solr
If you're using Solr or you want use the files from there (which are included by default), you can find them in dist/solrj-lib and example/lib/ext.
See: The Simple Logging Facade for Java (SLF4J) user manual
I tried all permutation and combination but finally slf4j-api- and slf4j-simple- worked well.

Using Coda Hale Yammer Metrics library in Websphere Application Server 7

I am trying to add metrics library to existing webservice on WAS 7. I am getting below error
Error 404: javax.servlet.UnavailableException: SRVE0203E: Servlet [AdminServlet]: com.yammer.metrics.reporting.AdminServlet was found, but is missing another required class. SRVE0206E: This error typically implies that the servlet was originally compiled with classes which cannot be located by the server. SRVE0187E: Check your class path to ensure that all classes required by the servlet are present.SRVE0210I: This problem can be debugged by recompiling the servlet using only the classes in the application's runtime class path SRVE0234I
What are the other run-time dependencies required for metrics-servlet-2.2.0?
I have metrics-core-2.2.0.jar and metrics-servlet-2.2.0.jar in my WEB-INF\lib folder.
Threads, ping and healthcheck servlets work fine.
I think your missing some more required jars, are you not using maven or gradle for dependency management
Please refer here to know all required jars that metrics-servlet-2.2.0.jar depends on. http://mvnrepository.com/artifact/com.yammer.metrics/metrics-servlets/3.0.0-BETA1
My suggestion is, it is always difficult to maintain dependencies without Maven/Gradle or any other build tools :).

How do I correct a Java LinkageError exception?

I am developing an application for WebSphere 6.1 which uses a Java servlet. Within my servlet, I have defined a serial vesion ID of 1L. Upon deploying and running my application, I am receiving a LinkageError of the following type (from the server log):
[5/9/11 15:14:26:868 EDT] 0000001c WebApp
E [Servlet Error]-[ManageRecordsConsumerServlet]: java.lang.Exception:
java.lang.LinkageError: LinkageError while defining class:
<redacted>.docindexupdate.batch.servlet.ManageRecordsConsumerServlet
Could not be defined due to: (<redacted>/docindexupdate/batch/servlet
/ManageRecordsConsumerServlet) class name must be a string at offset=2074
This is often caused by having a class defined at multiple
locations within the classloader hierarchy. Other potential causes
include compiling against an older or newer version of the class
that has an incompatible method signature.
I'm not sure what the issue is. I was seeing this previously before defining a serial version uid and figured that by defining that and being consistent, future updates to the class file would run successfully. There are no errors during compilation or deployment to the server. Is it possible that an older version of the servlet is cached somewhere on the WebSphere instance (I am only deploying on my dev machine at the moment)?
The
class name must be a string at offset=2074
line is also confusing.
I am suspecting you have a jar that is being loaded in two different classloaders. By that I mean, your websphere server on startup loads that jar or has an endorsed directory with that jar. Also your EAR you are deploying has that jar in its lib. The two can conflict at runtime
What I would suggest is to find out which jar ManageRecordsConsumerServlet belongs to and either remove it from your EAR lib or your Websphere endorsed lib (best would be your EAR lib).
It may be versioning, but I don't thing so.
When two classes loaded by different classloader, a ClassNotFoundException is normally thrown.
When a class is passed over a wire/loaded from disk cache, VersionMismatchException is normally thrown.
When a class with different method signatures is used, NoSuchMethodError or alike is thrown.
I think this case is a corrupted class file. Could be corrupted in cache or in the JAR.

Categories

Resources