You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Alexander Blotny <Al...@fokus.fraunhofer.de> on 2010/03/18 11:38:53 UTC

commons-mail with apache felix

Hi,

I am trying to use commons-email-1.2 with apache Felix.
I have started the bundle mail-1.4.jar (including javamail) because
commons-email uses this library. Then I am starting commons-email and there
are no errors.

A third bundle is accessing the SimpleEmail class of commons-email and sends
a mail.
I get following error:

org.apache.commons.mail.EmailException: Unable to locate provider for
protocol: pop3
    at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1111)
    at org.apache.commons.mail.Email.send(Email.java:1162)
    at 
de.fhg.fokus.ngni.xposer.see.service.email.impl.EmailImpl.send(EmailImpl.jav
a:80)
    at 
de.fhg.fokus.ngni.xposer.see.service.email.impl.EmailImpl.send(EmailImpl.jav
a:33)
    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 
de.fhg.fokus.ngni.xposer.see.bundle.BundleEventHandler$MyTimerTask.run(Bundl
eEventHandler.java:164)
    at java.util.TimerThread.mainLoop(Timer.java:512)
    at java.util.TimerThread.run(Timer.java:462)
Caused by: javax.mail.NoSuchProviderException: Unable to locate provider for
protocol: pop3
    at javax.mail.Session.getProvider(Session.java:229)
    at javax.mail.Session.getStore(Session.java:270)
    at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1105)


I guess that some properties cannot be loaded because of the classloading in
OSGi but how can I change that?

The source code is:

        smtpHost = MailSettings.smtpHost;        userName =
MailSettings.smtpUsername;        pw = MailSettings.smtpPassword;
emailAddress = MailSettings.fromAddress;        pop3Host =
MailSettings.pop3Host;                        toAddress = emailAddress;
try {            SimpleEmail email=new SimpleEmail();
email.setHostName(smtpHost);            email.setAuthentication(userName,
pw);            email.setFrom(emailAddress, user);
email.addTo(toAddress);
email.setPopBeforeSmtp(true, pop3Host, userName, pw);
email.setSubject(subject);            email.setMsg(message);
email.send();        } catch (EmailException e) {
e.printStackTrace();            return false;        }

Thx,
Alex

Re: commons-mail with apache felix

Posted by Guillaume Nodet <gn...@gmail.com>.
Have a look at servicemix bundles:

http://repo2.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.javax.mail/1.4.1_2/org.apache.servicemix.bundles.javax.mail-1.4.1_2.jar

It has been modified to work in OSGi.

On Thu, Mar 18, 2010 at 11:38, Alexander Blotny <
Alexander.Blotny@fokus.fraunhofer.de> wrote:

> Hi,
>
> I am trying to use commons-email-1.2 with apache Felix.
> I have started the bundle mail-1.4.jar (including javamail) because
> commons-email uses this library. Then I am starting commons-email and there
> are no errors.
>
> A third bundle is accessing the SimpleEmail class of commons-email and
> sends
> a mail.
> I get following error:
>
> org.apache.commons.mail.EmailException: Unable to locate provider for
> protocol: pop3
>    at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1111)
>    at org.apache.commons.mail.Email.send(Email.java:1162)
>    at
>
> de.fhg.fokus.ngni.xposer.see.service.email.impl.EmailImpl.send(EmailImpl.jav
> a:80)
>    at
>
> de.fhg.fokus.ngni.xposer.see.service.email.impl.EmailImpl.send(EmailImpl.jav
> a:33)
>     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
>
> de.fhg.fokus.ngni.xposer.see.bundle.BundleEventHandler$MyTimerTask.run(Bundl
> eEventHandler.java:164)
>    at java.util.TimerThread.mainLoop(Timer.java:512)
>    at java.util.TimerThread.run(Timer.java:462)
> Caused by: javax.mail.NoSuchProviderException: Unable to locate provider
> for
> protocol: pop3
>    at javax.mail.Session.getProvider(Session.java:229)
>    at javax.mail.Session.getStore(Session.java:270)
>    at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1105)
>
>
> I guess that some properties cannot be loaded because of the classloading
> in
> OSGi but how can I change that?
>
> The source code is:
>
>        smtpHost = MailSettings.smtpHost;        userName =
> MailSettings.smtpUsername;        pw = MailSettings.smtpPassword;
> emailAddress = MailSettings.fromAddress;        pop3Host =
> MailSettings.pop3Host;                        toAddress = emailAddress;
> try {            SimpleEmail email=new SimpleEmail();
> email.setHostName(smtpHost);            email.setAuthentication(userName,
> pw);            email.setFrom(emailAddress, user);
> email.addTo(toAddress);
> email.setPopBeforeSmtp(true, pop3Host, userName, pw);
> email.setSubject(subject);            email.setMsg(message);
> email.send();        } catch (EmailException e) {
> e.printStackTrace();            return false;        }
>
> Thx,
> Alex
>



-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com

Re: commons-mail with apache felix

Posted by Alexander Blotny <Al...@fokus.fraunhofer.de>.
I forgot to say that I am working with reflection for getting the class that
implements the send method in the third bundle.
I tried it now without reflection and it works.

Has anyone experience with the side effects of using reflection in the OSGi
environment? Maybe it is a bad idea to use it at all. What I want to achieve
is a dynamic environment in which users can add bundles with certain
functionality (methods). These methods can be combined with an orchestration
language. And for calling a single method I am using reflection as I am only
aware of method names and the belonging classes.

Thx
Alex

Am 18.03.10 11:38 schrieb "Alexander Blotny" unter
<Al...@fokus.fraunhofer.de>:

> Hi,
> 
> I am trying to use commons-email-1.2 with apache Felix.
> I have started the bundle mail-1.4.jar (including javamail) because
> commons-email uses this library. Then I am starting commons-email and there
> are no errors.
> 
> A third bundle is accessing the SimpleEmail class of commons-email and sends
> a mail.
> I get following error:
> 
> org.apache.commons.mail.EmailException: Unable to locate provider for
> protocol: pop3
>     at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1111)
>     at org.apache.commons.mail.Email.send(Email.java:1162)
>     at 
> de.fhg.fokus.ngni.xposer.see.service.email.impl.EmailImpl.send(EmailImpl.jav
> a:80)
>     at 
> de.fhg.fokus.ngni.xposer.see.service.email.impl.EmailImpl.send(EmailImpl.jav
> a:33)
>     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 
> de.fhg.fokus.ngni.xposer.see.bundle.BundleEventHandler$MyTimerTask.run(Bundl
> eEventHandler.java:164)
>     at java.util.TimerThread.mainLoop(Timer.java:512)
>     at java.util.TimerThread.run(Timer.java:462)
> Caused by: javax.mail.NoSuchProviderException: Unable to locate provider for
> protocol: pop3
>     at javax.mail.Session.getProvider(Session.java:229)
>     at javax.mail.Session.getStore(Session.java:270)
>     at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1105)
> 
> 
> I guess that some properties cannot be loaded because of the classloading in
> OSGi but how can I change that?
> 
> The source code is:
> 
>         smtpHost = MailSettings.smtpHost;        userName =
> MailSettings.smtpUsername;        pw = MailSettings.smtpPassword;
> emailAddress = MailSettings.fromAddress;        pop3Host =
> MailSettings.pop3Host;                        toAddress = emailAddress;
> try {            SimpleEmail email=new SimpleEmail();
> email.setHostName(smtpHost);            email.setAuthentication(userName,
> pw);            email.setFrom(emailAddress, user);
> email.addTo(toAddress);
> email.setPopBeforeSmtp(true, pop3Host, userName, pw);
> email.setSubject(subject);            email.setMsg(message);
> email.send();        } catch (EmailException e) {
> e.printStackTrace();            return false;        }
> 
> Thx,
> Alex


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org