geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From darvs <d...@iinet.net.au>
Subject JavaMail NoSuchProviderException
Date Wed, 28 May 2014 05:53:52 GMT
Help!!,
I am migrating an MDB which uses the Java Mail service, from geronimo 2.2 to
3.0.1 and I get the NoSuchProviderException. The user documentation has
chapter on migration from 2.2 to 3.0 which has a rather short section on
changes to be made for JavaMail. However I have not been successful. I
should mention that it worked fine on Geronimo 2.2. I am relatively green
with these technologies, so please excuse my ignorance.

I would greatly appreciate the help of anyone who has successfully used the
default java mail session on geronimo 3.0 from an ejb or mdb.


The mail session is defined as follows in the program.

	@Resource(name = "mail/TOMSignupMailSrv")
	private Session mailSession;

My deployment plan openejb-jar.xml has the following dependencies:
	<sys:dependency>
                <sys:groupId>org.apache.geronimo.configs</sys:groupId>
                <sys:artifactId>javamail</sys:artifactId>
                <type>car</type>
       </sys:dependency> 
	<sys:dependency>
		<groupId>org.apache.geronimo.javamail</groupId>
		<artifactId>geronimo-javamail_1.4_mail</artifactId>
		<type>jar</type>
	</sys:dependency>  
	
and the following resource reference

	<resource-ref>
        
        		<ref-name>mail/TOMSignupMailSrv</ref-name>
        
        		<resource-link>mail/MailSession</resource-link>
    	</resource-ref>

I have tried importing the transport package without success.

<import-package>org.apache.geronimo.javamail.transport.smtp</import-package>

I have also tried defining the mail package classes as non-overrideable so
as to prevent the OSGi module class loader from attempting to load them as
follows. 

	<non-overridable-classes>
 		<filter>javax.mail</filter>
 		<filter>org.apache.geronimo.javamail</filter>
  	</non-overridable-classes>

TRACE:

javax.mail.NoSuchProviderException: Unable to locate provider for protocol:
smtp
	at javax.mail.Session.getProvider(Session.java:237)
	at javax.mail.Session.getTransport(Session.java:346)
	at javax.mail.Session.getTransport(Session.java:376)
	at javax.mail.Transport.send(Transport.java:67)
	at javax.mail.Transport.send(Transport.java:48)
	at com.infotek.fwk.ejbmail.MailService.sendMail(MailService.java:185)
	at com.infotek.fwk.ejbmail.MailService.onMessage(MailService.java:50)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method).....


I have found a similar problem on the forum at 
http://apache-geronimo.328035.n3.nabble.com/Trouble-with-Geronimo-s-javax-mail-under-OSGi-td858884.html


I tried the suggested solution as below, and it would successfully retrieve
the providers, however I get an IllegalStateException: Can't overwrite
cause,

	ClassLoader bakCL = Thread.currentThread().getContextClassLoader();
			Thread.currentThread().setContextClassLoader(null);
       try {
           	Transport.send(message);
	            	
        } catch (Exception e) {
		LogUtil.log(this.getClass().getName(),
			"Mail service system Exception raised.", Level.SEVERE);
	 	e.printStackTrace ();
  	 } finally {
	       Thread.currentThread().setContextClassLoader(bakCL);
        }

Trace:

java.lang.IllegalStateException: Can't overwrite cause
	at java.lang.Throwable.initCause(Throwable.java:320)
	at
javax.mail.MessagingException.setNextException(MessagingException.java:51)
	at javax.mail.Transport.send(Transport.java:109)
	at javax.mail.Transport.send(Transport.java:48)
	at com.infotek.fwk.ejbmail.MailService.sendMail(MailService.java:190)
	at
com.infotek.fwk.ejbmail.MailService.onMessage(MailService.java:50)........


I feel there must be a better way of loading the providers instead of the
code above. I would appreciate any help.

Thanks.




--
View this message in context: http://apache-geronimo.328035.n3.nabble.com/JavaMail-NoSuchProviderException-tp3987997.html
Sent from the Users mailing list archive at Nabble.com.

Mime
View raw message