Я пишу серверный сервлет REST API с Джерси, и у меня есть некоторые проблемы с использованием jndi для настройки отправки почты.NameNotfoundException в Jetty 9 на ресурсе почтового сеанса JNDI lookup
Вот мой WEB-INF/Причал-env.xml:
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
<New id="mail" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg><Ref refid="wac"/></Arg>
<Arg>mail/Session</Arg>
<Arg>
<New class="org.eclipse.jetty.jndi.factories.MailSessionReference">
<Set name="user">MY_USER</Set>
<Set name="password">MY_PASS</Set>
<Set name="properties">
<New class="java.util.Properties">
<Put name="mail.smtp.host">MY_HOST</Put>
<Put name="mail.from">MY_SENDER</Put>
<Put name="mail.debug">true</Put>
</New>
</Set>
</New>
</Arg>
</New>
</Configure>
А вот как я пытаюсь посмотреть его:
Session session = (Session) new InitialContext().lookup("java:comp/env/mail/Session");
Однако, я получаю:
javax.naming.NameNotFoundException; remaining name 'mail/Session'
at org.eclipse.jetty.jndi.local.localContextRoot.lookup(localContextRoot.java:487)
Из журналов DEBUG после перезагрузки служебного причала:
20-01-2015 10:10:39 DEBUG jndi:183 - SAVE mail/Session in [email protected]{/finalcountdown.backend,file:/tmp/jetty-0.0.0.0-8085-finalcountdown.backend.war-_finalcountdown.backend-any-2063340985085206547.dir/webapp/,STARTING}{/finalcountdown.backend.war}
20-01-2015 10:10:39 DEBUG jndi:79 - InitialContextFactory.getInitialContext()
20-01-2015 10:10:39 DEBUG jndi:82 - Created initial context delegate for local namespace:[email protected]
20-01-2015 10:10:39 DEBUG jndi:79 - InitialContextFactory.getInitialContext()
20-01-2015 10:10:39 DEBUG jndi:82 - Created initial context delegate for local namespace:[email protected]
20-01-2015 10:10:39 DEBUG jndi:411 - Looking up name="[email protected]"
20-01-2015 10:10:39 DEBUG jndi:137 - supportDeepBinding=false
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with [email protected] [email protected][[email protected],[email protected]7ce6a65d,bindings.size=0] for context=null as [email protected]: org.eclipse.jetty.jndi.NamingContext:[email protected][[email protected],[email protected]7ce6a65d,bindings.size=0]
20-01-2015 10:10:39 DEBUG jndi:82 - Subcontext [email protected] created
20-01-2015 10:10:39 DEBUG jndi:464 - Looking up name="__"
20-01-2015 10:10:39 DEBUG jndi:137 - supportDeepBinding=false
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with key=__ [email protected][name=__,[email protected],bindings.size=0] for [email protected] as __: org.eclipse.jetty.jndi.NamingContext:[email protected][name=__,[email protected],bindings.size=0]
20-01-2015 10:10:39 DEBUG jndi:82 - Subcontext __ created
20-01-2015 10:10:39 DEBUG jndi:464 - Looking up name="mail"
20-01-2015 10:10:39 DEBUG jndi:137 - supportDeepBinding=false
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with key=mail [email protected][name=mail,[email protected],bindings.size=0] for context=__ as mail: org.eclipse.jetty.jndi.NamingContext:[email protected][name=mail,[email protected],bindings.size=0]
20-01-2015 10:10:39 DEBUG jndi:82 - Subcontext mail created
20-01-2015 10:10:39 DEBUG jndi:1327 - Removing binding with key=Session
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with key=Session obj=mail/Session for context=mail as Session: org.eclipse.jetty.plus.jndi.Resource:mail/Session
20-01-2015 10:10:39 DEBUG jndi:88 - Bound object to Session
20-01-2015 10:10:39 DEBUG jndi:411 - Looking up name="[email protected]"
20-01-2015 10:10:39 DEBUG jndi:76 - Subcontext [email protected] already exists
20-01-2015 10:10:39 DEBUG jndi:464 - Looking up name="mail"
20-01-2015 10:10:39 DEBUG jndi:137 - supportDeepBinding=false
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with key=mail [email protected][name=mail,[email protected],bindings.size=0] for [email protected] as mail: org.eclipse.jetty.jndi.NamingContext:[email protected][name=mail,[email protected],bindings.size=0]
20-01-2015 10:10:39 DEBUG jndi:82 - Subcontext mail created
20-01-2015 10:10:39 DEBUG jndi:1327 - Removing binding with key=Session
20-01-2015 10:10:39 DEBUG jndi:1280 - Adding binding with key=Session obj=Reference Class Name: javax.mail.Session
Так что это должно быть связано. Что мне здесь не хватает?
Спасибо! Я новичок в этой области и не нашел ни одного учебника, а только фрагментов в документах, но ничего не сказал о части ресурса-ref. Вы могли бы указать мне на это? – azyoot
http://www.eclipse.org/jetty/documentation/current/using-jetty-jndi.html#defining-jndi-naming-entries – Jan