Hi Jason,
The error is occurring from the within the JavaMail API when you call
javax.mail.Transport.send(msg):
Caused by: java.lang.NoClassDefFoundError: javax/mail/MessagingException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
at java.lang.Class.getConstructor0(Class.java:2671)
at java.lang.Class.newInstance0(Class.java:321)
at java.lang.Class.newInstance(Class.java:303)
at
javax
.activation
.MailcapCommandMap.createDataContentHandler(MailcapCommandMap.java:470)
at
javax.activation.DataHandler.getDataContentHandler(DataHandler.java:255)
at javax.activation.DataHandler.writeTo(DataHandler.java:76)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1142)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1112)
at
org
.apache
.geronimo
.javamail.transport.smtp.SMTPTransport.sendData(SMTPTransport.java:1419)
at
org
.apache
.geronimo
.javamail.transport.smtp.SMTPTransport.sendMessage(SMTPTransport.java:
648)
at javax.mail.Transport.send(Transport.java:95)
at javax.mail.Transport.send(Transport.java:48)
at
com.cjs.jaxrs.resource.CvMailerResource.sendMail(CvMailerResource.java:
86)
I cannot explain the error except that the OSGi bundling may be
incorrect, or there is something from within the JavaMail API itself
that does not work correctly with OSGi because if some class loading
specifics of JavaMail.
Perhaps you could ask on the users_at_glassfish.dev.java.net alias ? as
someone with more knowledge of JavaMail might be able to help.
Paul.
On May 14, 2009, at 11:45 PM, Jason Davidson wrote:
> I'm using the Jersery Multipart API to handle file upload and
> downloads within the Jersey OSGi bundle. Everything is working in
> that respect and I'm able consume and produce multipart messages
> within a Jersery resource.
>
> From within my Jersey resource I'm able to send text emails that do
> not use multipart e-mail - e.g:
> Properties props = System.getProperties();
> props.put("mail.smtp.host", "myhost.com");
> javax.mail.Session mailSess =
> javax.mail.Session.getInstance(props);
> mailSess.setDebug(true);
> javax.mail.Message msg = new
> javax.mail.internet.MimeMessage(mailSess);
> msg.setFrom(new
> javax.mail.internet.InternetAddress("some_at_address"));
> msg.setRecipient(javax.mail.Message.RecipientType.TO, new
> javax.mail.internet.InternetAddress("some_at_address"));
> msg.setSentDate(new Date());
> msg.setSubject("TEST");
> msg.setText("TEST");
> javax.mail.Transport.send(msg);
>
> That code works.
>
> However, things get ugly when I try to send a multipart e-mail within
> any Jersery resource now. This code throws a
> java.lang.NoClassDefFoundError: javax/mail/MessagingException. The
> Jersey bundle was updated to include the javax.mail and
> javax.activation plugins. I'm seeing those packages resolved in my
> OSGi container (Equinox) so I'm sure the class is available.
>
> I'm at a loss here and would appreciate if anyone has any input!
>
> Here's the code that causes the NoClassDefFoundError exception (stack
> dump follows):
>
> @POST
> @Consumes(MediaType.TEXT_XML)
> @Produces(MediaType.TEXT_XML)
> @Path("/mail")
> public Response sendMail(byte[] data) throws AddressException,
> MessagingException
> {
> Properties props = System.getProperties();
> props.put("mail.smtp.host", "my.host");
> javax.mail.Session mailSess =
> javax.mail.Session.getInstance(props);
> mailSess.setDebug(true);
> javax.mail.Message msg = new
> javax.mail.internet.MimeMessage(mailSess);
>
> msg.setFrom(new
> javax.mail.internet.InternetAddress("some_at_address"));
> msg.setRecipient(javax.mail.Message.RecipientType.TO,
> new javax.mail.internet.InternetAddress("some_at_address"));
>
> msg.setSubject("Notification");
> msg.setSentDate(new Date());
>
> MimeBodyPart mbp1 = new MimeBodyPart();
> mbp1.setText("Data Attached.");
>
> Multipart mp = new MimeMultipart();
> mp.addBodyPart(mbp1);
>
> String myFile="123123";
> MimeBodyPart mbp2 = new MimeBodyPart();
> DataSource ds = new ByteArrayDataSource(myFile.getBytes(),
> "application/txt");
> mbp2.setDataHandler(new DataHandler(ds));
> mbp2.setFileName("testfile.txt");
> mbp2.setDisposition(Part.ATTACHMENT);
> mp.addBodyPart(mbp2);
> msg.setContent(mp);
> Transport.send(msg);
> ResponseBuilder rb = Response.ok();
> return rb.build();
> }
>
> I
> com.sun.jersey.api.container.MappableContainerException:
> java.lang.NoClassDefFoundError: javax/mail/MessagingException
> at
> com
> .sun
> .jersey
> .server
> .impl
> .model
> .method
> .dispatch
> .ResourceJavaMethodDispatcher
> .dispatch(ResourceJavaMethodDispatcher.java:74)
> at
> com
> .sun
> .jersey
> .server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:154)
> at
> com
> .sun
> .jersey
> .server
> .impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
> at
> com
> .sun
> .jersey
> .server
> .impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:71)
> at
> com
> .sun
> .jersey
> .server
> .impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:111)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .uri
> .rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:63)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl._handleRequest(WebApplicationImpl.java:556)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:515)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .application
> .WebApplicationImpl.handleRequest(WebApplicationImpl.java:506)
> at
> com
> .sun
> .jersey.spi.container.servlet.WebComponent.service(WebComponent.java:
> 307)
> at
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.service(ServletContainer.java:424)
> at
> com
> .sun
> .jersey
> .spi
> .container.servlet.ServletContainer.service(ServletContainer.java:589)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> at
> org
> .eclipse
> .equinox
> .http
> .servlet
> .internal.ServletRegistration.handleRequest(ServletRegistration.java:
> 90)
> at
> org
> .eclipse
> .equinox
> .http.servlet.internal.ProxyServlet.processAlias(ProxyServlet.java:
> 111)
> at
> org
> .eclipse
> .equinox
> .http.servlet.internal.ProxyServlet.service(ProxyServlet.java:67)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> at org.eclipse.equinox.http.jetty.internal.HttpServerManager
> $InternalHttpServiceServlet.service(HttpServerManager.java:255)
> at
> org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
> at
> org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
> 362)
> at
> org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
> 181)
> at
> org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
> 726)
> at
> org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
> 139)
> at org.mortbay.jetty.Server.handle(Server.java:324)
> at
> org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
> 505)
> at org.mortbay.jetty.HttpConnection
> $RequestHandler.content(HttpConnection.java:842)
> at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:648)
> at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
> at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
> at
> org
> .mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
> 395)
> at org.mortbay.thread.BoundedThreadPool
> $PoolThread.run(BoundedThreadPool.java:450)
> Caused by: java.lang.NoClassDefFoundError: javax/mail/
> MessagingException
> at java.lang.Class.getDeclaredConstructors0(Native Method)
> at java.lang.Class.privateGetDeclaredConstructors(Class.java:2357)
> at java.lang.Class.getConstructor0(Class.java:2671)
> at java.lang.Class.newInstance0(Class.java:321)
> at java.lang.Class.newInstance(Class.java:303)
> at
> javax
> .activation
> .MailcapCommandMap.createDataContentHandler(MailcapCommandMap.java:
> 470)
> at
> javax.activation.DataHandler.getDataContentHandler(DataHandler.java:
> 255)
> at javax.activation.DataHandler.writeTo(DataHandler.java:76)
> at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1142)
> at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1112)
> at
> org
> .apache
> .geronimo
> .javamail.transport.smtp.SMTPTransport.sendData(SMTPTransport.java:
> 1419)
> at
> org
> .apache
> .geronimo
> .javamail
> .transport.smtp.SMTPTransport.sendMessage(SMTPTransport.java:648)
> at javax.mail.Transport.send(Transport.java:95)
> at javax.mail.Transport.send(Transport.java:48)
> at
> com
> .cjs.jaxrs.resource.CvMailerResource.sendMail(CvMailerResource.java:
> 86)
> 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:585)
> at
> com
> .sun
> .jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider
> $ResponseOutInvoker._dispatch(EntityParamDispatchProvider.java:157)
> at
> com
> .sun
> .jersey
> .server
> .impl
> .model
> .method
> .dispatch
> .ResourceJavaMethodDispatcher
> .dispatch(ResourceJavaMethodDispatcher.java:67)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>