I'd like to use a ServletFilter that reads it configuration from the java:comp/env/ JNDI namespace. As the value will be different on devel and production servers, it should not be hardcoded via in web.xml but instead be configured in the application server.
I already tried the following places but none seemed to be right:
How can I set a custom JNDI variable in Glassfish 4.1?
I installed only the Glassfish 4.1 Web Edition. While it has JNDI support, the web GUI comlpetely lacked the Resources -> JNDI menu to configure own variables!
In the Web Profile Glassfish, custom JNDI variables can be written in the domain.xml, they seem to survive other changes via the Admin GUI:
<resources>
...
<custom-resource res-type="java.lang.String" jndi-name="cas/serverName" factory-class="org.glassfish.resources.custom.factory.PrimitivesAndStringFactory">
<property name="value" value="https://sso.example.com/"></property>
</custom-resource>
</resources>
...
<servers>
<server name="server" config-ref="server-config">
...
<resource-ref ref="cas/serverName"></resource-ref>
</server>
</servers>
After adding a JNDI variable to Glassfish, it's only availble with InitialContext.doLookup("cas/serverName") though, not within the java:comp/env namespace. To get that, I had to add the following to my web.xml (it did not work in glassfish-web.xml!):
<resource-ref>
<res-ref-name>cas/serverName</res-ref-name>
<res-type>java.lang.String</res-type>
<lookup-name>cas/serverName</lookup-name>
</resource-ref>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.