ClassNotFoundException: org.apache.naming.java.javaURLContextFactory

Panos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2014

Hi :)

I am trying to send an email with a plugin and i get the following exception:

com.atlassian.mail.MailException: javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.naming.java.javaURLContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory]

the problematic code is

private SMTPMailServer getServer() {
		List<SMTPMailServer> mailServers = mailServerManager
				.getSmtpMailServers();
		for (SMTPMailServer mailServer : mailServers) {
			if (mailServer.getName().equalsIgnoreCase("Gmail server")) {
				return mailServer;
			}
		}
		return null;
	}

	@Override
	public void sendDirectEmail(Email email) throws MailException {
		SMTPMailServer mailServer = getServer();
		email.setFrom(CONF_EMAIL);
		email.setFromName("[confluence]: NO-REPLY");
		email.setMimeType("text/html");
		mailServer.send(email); //here
	}

where gmail server is configured through jndi.

and declared in the atlassian-plugin.xml as

<component key="custom-email-service-impl"
		class="com.example.confluence.emailNotifier.components.CustomEmailServiceImpl"
		name="Custom Mail Service Impl" i18n-name-key="custom-email-service-impl.name">
		<description key="custom-mail-service-impl.description">The Custom Eail Service Impl Plugin
		</description>
		<interface>com.example.confluence.emailNotifier.components.CustomEmailService
		</interface>
	</component>
	<component-import key="task-manager"
		interface="com.atlassian.core.task.MultiQueueTaskManager" filter="" />
</atlassian-plugin>

Any ideas why this exception is thrown?

I can only assume that for some reason context of jndi mapping is not fetched. And that is weird since another plugin executing the same exactly code throws no exception.

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Boris Georgiev _Appfire_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2014

Where is this code called from ? This might be related to wrong classloader if you call the code from a REST service for example.

Panos
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 22, 2014

it comes from a

<component name="Comment Listener"
class="com.example.confluence.emailNotifier.listeners.CommentsListener" key="commentListener" />

and the class' constructor looks like

private CustomEmailService service;
public CommentsListener(EventPublisher eventPublisher,
			PageManager pageManager, BandanaManager bandanaManager,
			GroupManager groupManager, UserAccessor ua,
			MailServerManager msManager, MultiQueueTaskManager taskManager) {
		this.eventPublisher = eventPublisher;
		eventPublisher.register(this);
		this.pageManager = pageManager;
		this.bandanaManager = bandanaManager;
		this.groupManager = groupManager;
		this.ua = ua;
		emailRecipients = new HashSet<String>();
		service = new CustomEmailServiceImpl(taskManager, msManager);
	}

and a simple system.err.println of mailServer.getJndiLocation() returns java:comp/env/mail/Session

TAGS
AUG Leaders

Atlassian Community Events