Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Problems with JNDI and MailSession

Thanks for the help. I basically copied the ee10-demo-jndi.mod and
created my own mod. I installed the mod without problems, all files
copied and the Datasource works without problems. 

The MailSession still does not work.

Instead of returning jakarta.mail.Session still returning MailSessionReference 
even though the documentation says that lookup for  java:comp/env/mail/Session 
at runtime would obtains a  jakarta.mail.Session.

I get the following exception:

java.lang.ClassCastException: class org.eclipse.jetty.ee10.jndi.factories.MailSessionReference cannot be cast to class jakarta.mail.Session (org.eclipse.jetty.ee10.jndi.factories.MailSessionReference and jakarta.mail.Session are in unnamed module of loader java.net.URLClassLoader @557caf28)

This is what I have in my web.xml for the datasource and mailsession

<resource-ref>
    <res-ref-name>jdbc/DataSource</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
    <res-ref-name>mail/Session</res-ref-name>
    <res-type>jakarta.mail.Session</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

These are my my_webapp.mod,my_webapp.properties and my_webapp.xml files

-- my_webapp.mod --

 [description]
        My Webapp (Module for Jetty)
[environment]
        ee10
[tags]
        webapp
[depends]
        ee10-deploy
        ext
        jdbc
        ee10-plus
        ee10-jndi
[files]
        webapps/my_webapp.war
        webapps/my_webapp.xml 
        webapps/my_webapp.ini 
        maven://jakarta.mail/jakarta.mail-api/2.1.5/jar|lib/ee10/jakarta.mail-api-2.1.5.jar
        maven://jakarta.activation/jakarta.activation-api/2.1.4/jar|lib/ee10/jakarta.activation-api-2.1.4.jar
        maven://org.eclipse.angus/angus-activation/2.0.3/jar|lib/ee10/angus-activation-2.0.3.jar
        maven://org.eclipse.angus/angus-mail/2.0.5/jar|lib/ee10/angus-mail-2.0.5.jar
        maven://com.mchange/c3p0/0.11.2/jar|lib/ee10/c3p0-0.11.2.jar
        maven://com.mchange/mchange-commons-java/0.3.2/jar|lib/ee10/mchange-commons-java-0.3.2.jar
[lib]
        lib/ee10/jakarta.mail-api-2.1.5.jar
        lib/ee10/jakarta.activation-api-2.1.4.jar
        lib/ee10/angus-activation-2.0.3.jar
        lib/ee10/angus-mail-2.0.5.jar
        lib/ee10/c3p0-0.11.2.jar
        lib/ee10/mchange-commons-java-0.3.2.jar
        lib/ee10/jdbcdriver.jar 

--- my_webapp.properties

    environment: ee10

--- my_webapp.xml

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://jetty.org/configure_10_0.dtd">

<Configure id="wac" class="org.eclipse.jetty.ee10.webapp.WebAppContext">

  <Set name="contextPath">/</Set>
  <Set name="war"><Property name="jetty.webapps" default="." />/my_webapp.war
  </Set>
  <Set name="extractWAR">true</Set>
  <Set name="copyWebDir">false</Set>
  <Set name="configurationDiscovered">true</Set>

  <New id="db" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg>
      <Ref refid="wac" />
    </Arg>
    <Arg>jdbc/DataSource</Arg>
    <Arg>
        <New class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <Set name="DriverClass">???</Set>
            <Set name="JdbcUrl">???</Set>
            <Set name="User">???</Set>
            <Set name="Password">???</Set>
        </New>
    </Arg>
  </New>

  <New id="mailer" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg>
      <Ref refid="wac" />
    </Arg>
    <Arg>mail/Session</Arg>
    <Arg>
      <New class="org.eclipse.jetty.ee10.jndi.factories.MailSessionReference">
        <Set name="user">???</Set>
        <Set name="password">???</Set>
        <Set name="properties">
          <New class="java.util.Properties">
            <Put name="mail.smtp.auth">false</Put> <!-- change to true if you want to authenticate -->
            <Put name="mail.smtp.host">???</Put>
            <Put name="mail.from">???</Put>
            <Put name="mail.debug">false</Put>
          </New>
        </Set>
      </New>
    </Arg>
  </New>

</Configure>

Back to the top