<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    injecting env-entry into interceptor by @Resource does not work
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/gunterze">gunter zeilinger</a> in <i>EJB3</i> - <a href="https://community.jboss.org/message/744771#744771">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>I use an Interceptor to initialize a POJO Service deployed as EJB Singleton:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public class LdapDicomConfigurationInterceptor {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @Resource(name="ldapURL") String ldapURL;</p><p>&#160;&#160;&#160; @Resource(name="userDN") String userDN;</p><p>&#160;&#160;&#160; @Resource(name="password") String password;</p><p>&#160;&#160;&#160; @Resource(name="baseDN") String baseDN;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @PostConstruct</p><p>&#160;&#160;&#160; void init(InvocationContext ctx) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; LdapDicomConfiguration dc = (LdapDicomConfiguration) ctx.getTarget();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; LdapEnv env = new LdapEnv();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; env.setUrl(ldapURL);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; env.setUserDN(userDN);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; env.setPassword(password);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; dc.init(env, baseDN);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (Exception e) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new RuntimeException(e);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; @PreDestroy</p><p>&#160;&#160;&#160; void close(InvocationContext ctx) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; LdapDicomConfiguration dc = (LdapDicomConfiguration) ctx.getTarget();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; dc.close();</p><p>&#160;&#160;&#160; }</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ejb-jar.xml:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&lt;ejb-jar</p><p><span>&#160; xmlns="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee" target="_blank">http://java.sun.com/xml/ns/javaee</a><span>" </span></p><p><span>&#160; xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>"</span></p><p><span>&#160; xsi:schemaLocation="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee" target="_blank">http://java.sun.com/xml/ns/javaee</a><span> </span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd" target="_blank">http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd</a><span>"</span></p><p>&#160; version="3.1"&gt;</p><p>&#160; &lt;enterprise-beans&gt;</p><p>&#160;&#160;&#160; &lt;session&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;ejb-name&gt;DicomConfiguration&lt;/ejb-name&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;ejb-class&gt;org.dcm4che.conf.ldap.LdapDicomConfiguration&lt;/ejb-class&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;session-type&gt;Singleton&lt;/session-type&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;init-on-startup&gt;true&lt;/init-on-startup&gt;</p><p>&#160;&#160;&#160; &lt;/session&gt;</p><p>&#160; &lt;/enterprise-beans&gt;</p><p>&#160; &lt;interceptors&gt;</p><p>&#160;&#160;&#160; &lt;interceptor&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;interceptor-class&gt;org.dcm4chee.conf.ldap.LdapDicomConfigurationInterceptor&lt;/interceptor-class&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;env-entry&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-name&gt;ldapURL&lt;/env-entry-name&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-value&gt;ldap://localhost:389&lt;/env-entry-value&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;/env-entry&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;env-entry&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-name&gt;userDN&lt;/env-entry-name&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-value&gt;cn=admin,dc=nodomain&lt;/env-entry-value&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;/env-entry&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;env-entry&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-name&gt;password&lt;/env-entry-name&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-value&gt;admin&lt;/env-entry-value&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;/env-entry&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;env-entry&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-name&gt;baseDN&lt;/env-entry-name&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-value&gt;dc=nodomain&lt;/env-entry-value&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;/env-entry&gt;</p><p>&#160;&#160;&#160; &lt;/interceptor&gt;</p><p>&#160; &lt;/interceptors&gt;</p><p>&#160; &lt;assembly-descriptor&gt;</p><p>&#160;&#160;&#160; &lt;container-transaction&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;method&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;ejb-name&gt;DicomConfiguration&lt;/ejb-name&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;method-name&gt;*&lt;/method-name&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;/method&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;trans-attribute&gt;NotSupported&lt;/trans-attribute&gt;</p><p>&#160;&#160;&#160; &lt;/container-transaction&gt;</p><p>&#160;&#160;&#160; &lt;interceptor-binding&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;ejb-name&gt;DicomConfiguration&lt;/ejb-name&gt;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;interceptor-class&gt;org.dcm4chee.conf.ldap.LdapDicomConfigurationInterceptor&lt;/interceptor-class&gt;</p><p>&#160;&#160;&#160; &lt;/interceptor-binding&gt;</p><p>&#160; &lt;/assembly-descriptor&gt;</p><p>&lt;/ejb-jar&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>But LdapDicomConfigurationInterceptor fields does not get injected.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Specifiying injection fields in ejb-jar.xml by</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160; &lt;env-entry&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-name&gt;password&lt;/env-entry-name&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-type&gt;java.lang.String&lt;/env-entry-type&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;env-entry-value&gt;admin&lt;/env-entry-value&gt;</p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;injection-target&gt;</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;injection-target-class&gt;org.dcm4chee.conf.ldap.LdapDicomConfigurationInterceptor&lt;/injection-target-class&gt;</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;injection-target-name&gt;password&lt;/injection-target-name&gt;</em></p><p><em>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/injection-target&gt;</em></p><p>&#160;&#160;&#160;&#160;&#160; &lt;/env-entry&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>instead of @Resource works.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>AS: jboss-as-7.1.1.Final </p><p>JAVA: OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode</p><p>OS: Linux amd64 3.3.7-1-ARCH</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/744771#744771">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in EJB3 at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>