Hi all, Regarding the issue [1] <https://wso2.org/jira/browse/UES-466>, the problem seems to be the buggy behavior of javax.activation and javax.mail in OSGI level [2]<http://www.spagoworld.org/jira/browse/SPAGIC-581?attachmentOrder=desc>. Hence at the class loading axis2 email transport picks which is exported from jaggery email host object.
I got to work both the jaggery email feature and axis2 email transport with the below changes in jaggery email host object [3]<https://github.com/wso2/jaggery/tree/master/components/hostobjects/org.jaggeryjs.hostobjects.email> as said in [4]<http://nostacktrace.com/dev/2010/6/24/sending-multipart-mail-in-an-osgi-container.html> . diff --git a/components/hostobjects/org.jaggeryjs.hostobjects.email/pom.xml b/components/hostobjects/org.jaggeryjs.hostobjects.email/pom.xml index 78e38f8..ae49602 100644 --- a/components/hostobjects/org.jaggeryjs.hostobjects.email/pom.xml +++ b/components/hostobjects/org.jaggeryjs.hostobjects.email/pom.xml @@ -60,10 +60,7 @@ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> <Bundle-Name>${project.artifactId}</Bundle-Name> <Export-Package> - com.sun.mail.imap;version="2.0.0.wso2v1", - com.sun.mail.pop3;version="2.0.0.wso2v1", - com.sun.mail.smtp;version="2.0.0.wso2v1", - org.jaggeryjs.hostobjects.email.*; + org.jaggeryjs.hostobjects.email.*; </Export-Package> <Import-Package> javax.net, diff --git a/components/hostobjects/org.jaggeryjs.hostobjects.email/src/main/java/org/jaggeryjs/hostobjects/email/SenderHostObject.java b/components/hostobjects/org.jaggeryjs.hostobjects.email/src/main/java/org/jaggeryjs/hostobjects/email/ index eaacf5e..0792c04 100644 --- a/components/hostobjects/org.jaggeryjs.hostobjects.email/src/main/java/org/jaggeryjs/hostobjects/email/SenderHostObject.java +++ b/components/hostobjects/org.jaggeryjs.hostobjects.email/src/main/java/org/jaggeryjs/hostobjects/email/SenderHostObject.java @@ -396,11 +396,15 @@ public class SenderHostObject extends ScriptableObject { * </pre> */ public void jsFunction_send() throws ScriptException { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(javax.mail.Session.class.getClassLoader()); try { message.setContent(multipart); Transport.send(message); } catch (MessagingException e) { throw new ScriptException(e); + } finally { + Thread.currentThread().setContextClassLoader(classLoader); } } If anybody knows a better solution please let me know. [1] https://wso2.org/jira/browse/UES-466 [2]http://www.spagoworld.org/jira/browse/SPAGIC-581?attachmentOrder=desc [3] https://github.com/wso2/jaggery/tree/master/components/hostobjects/org.jaggeryjs.hostobjects.email [4] http://nostacktrace.com/dev/2010/6/24/sending-multipart-mail-in-an-osgi-container.html Thanks, Tanya On Mon, Dec 23, 2013 at 10:10 AM, Tanya Madurapperuma <[email protected]>wrote: > Hi, > > Regarding the above issue I tried several approaches to get the jaggery > email feature to work by removing the following section from the <export > package> section as Amani has confirmed that Axis2 Email transport is > working when that snippet is not there. > > com.sun.mail.imap;version="2.0.0.wso2v1", > com.sun.mail.pop3;version="2.0.0.wso2v1", > com.sun.mail.smtp;version="2.0.0.wso2v1", > > *Approach 1* > Added the removed export package headers to the embed dependency section > of the pom file. > But it failed with the following exception. > > [2013-12-23 10:09:21,599] ERROR > {org.jaggeryjs.scriptengine.engine.RhinoEngine} - > org.mozilla.javascript.WrappedException: Wrapped > org.jaggeryjs.scriptengine.exceptions.ScriptException: > javax.mail.NoSuchProviderException: smtp (/Test//Test.jag#13) > [2013-12-23 10:09:21,600] ERROR > {org.jaggeryjs.jaggery.core.manager.WebAppManager} - > org.mozilla.javascript.WrappedException: Wrapped > org.jaggeryjs.scriptengine.exceptions.ScriptException: > javax.mail.NoSuchProviderException: smtp (/Test//Test.jag#13) > > *Approach 2* > Tried with the following pom file but failed with the below exception. > > <project xmlns="http://maven.apache.org/POM/4.0.0" > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 > http://maven.apache.org/maven-v4_0_0.xsd"> > <parent> > <groupId>org.jaggeryjs</groupId> > <artifactId>hostobjects</artifactId> > <version>0.9.0-SNAPSHOT</version> > <relativePath>../pom.xml</relativePath> > </parent> > <modelVersion>4.0.0</modelVersion> > <artifactId>org.jaggeryjs.hostobjects.email</artifactId> > <packaging>bundle</packaging> > <name>Email HostObject</name> > <url>http://wso2.org</url> > > <dependencies> > <dependency> > <groupId>rhino.wso2</groupId> > <artifactId>js</artifactId> > </dependency> > > <dependency> > <groupId>org.wso2.carbon</groupId> > <artifactId>org.wso2.carbon.utils</artifactId> > </dependency> > > <dependency> > <groupId>org.jaggeryjs</groupId> > <artifactId>org.jaggeryjs.hostobjects.file</artifactId> > <version>${project.version}</version> > </dependency> > <dependency> > <groupId>javax.activation</groupId> > <artifactId>activation</artifactId> > </dependency> > <dependency> > <groupId>javax.mail</groupId> > <artifactId>mail</artifactId> > </dependency> > <dependency> > <groupId>org.apache.geronimo.specs</groupId> > <artifactId>geronimo-javamail_1.4_spec</artifactId> > </dependency> > > > </dependencies> > > <build> > <plugins> > <plugin> > <groupId>org.apache.felix</groupId> > <artifactId>maven-scr-plugin</artifactId> > </plugin> > <plugin> > <groupId>org.apache.felix</groupId> > <artifactId>maven-bundle-plugin</artifactId> > <extensions>true</extensions> > <configuration> > <instructions> > > <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> > <Bundle-Name>${project.artifactId}</Bundle-Name> > <Export-Package> > com.sun.mail.handlers;version="1.4.2", > org.jaggeryjs.hostobjects.email.*; > </Export-Package> > <Import-Package> > com.sun.mail.handlers, > javax.net, > javax.net.ssl, > javax.security.auth.callback, > javax.security.sasl, > org.apache.axiom.om, > org.apache.commons.logging, > org.mozilla.javascript, > org.jaggeryjs.hostobjects.file, > org.jaggeryjs.scriptengine.exceptions, > *;resolution:=optional > </Import-Package> > <Embed-Dependency> > > <!--mail;scope=compile|runtime;inline=false;,--> > > <!--activation;scope=compile|runtime;inline=false;--> > </Embed-Dependency> > <Private-Package> > > com.sun.activation;uses:="com.sun.mail.handlers", > com.sun.mail.iap, > com.sun.mail.imap.protocol, > com.sun.mail.util, > com.sun.mail.smtp, > com.sun.mail.pop3, > com.sun.mail.imap > </Private-Package> > </instructions> > </configuration> > </plugin> > </plugins> > </build> > </project> > > [2013-12-23 09:54:20,458] ERROR > {org.jaggeryjs.scriptengine.engine.RhinoEngine} - > org.mozilla.javascript.WrappedException: Wrapped > org.jaggeryjs.scriptengine.exceptions.ScriptException: > javax.mail.MessagingException: IOException while sending message; > nested exception is: > javax.activation.UnsupportedDataTypeException: no object DCH for MIME type > multipart/mixed; > boundary="----=_Part_0_1755306561.1387772655287" (/Test//Test.jag#13) > > > This link[1] has suggested some answers for the above exception, but > couldn't get it to work with those. > > *Approach 3* > Tried with the different modifications in pom.xml file such as removing > all mail, activation related dependencies but all those failed with the > same exception as above. > > And from googling [2] found out that above exception is due to two > activation jars in class path. But was not able to locate from where those > two coming. > > > *Approach 4* > Downgraded above exports to 1.4.0 from 2.0.0 as axiom is exporting 1.4.0 > of above headers. Then again failed with the below exception. > > [2013-12-23 10:09:21,599] ERROR > {org.jaggeryjs.scriptengine.engine.RhinoEngine} - > org.mozilla.javascript.WrappedException: Wrapped > org.jaggeryjs.scriptengine.exceptions.ScriptException: > javax.mail.NoSuchProviderException: smtp (/Test//Test.jag#13) > [2013-12-23 10:09:21,600] ERROR > {org.jaggeryjs.jaggery.core.manager.WebAppManager} - > org.mozilla.javascript.WrappedException: Wrapped > org.jaggeryjs.scriptengine.exceptions.ScriptException: > javax.mail.NoSuchProviderException: smtp (/Test//Test.jag#13) > > > Appreciate any help to solve the above issue. > > [1] > http://forum.spring.io/forum/osgi-related/dm-server-general/61205-problems-sending-mime-multipart-mails > [2] > http://stackoverflow.com/questions/4612673/messagingexceptionioexception-while-sending-message-in-java > > Thanks, > Tanya. > -- Tanya Madurapperuma Software Engineer, WSO2 Inc. : wso2.com Mobile : +94718184439 Blog : http://tanyamadurapperuma.blogspot.com
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
