use of javax.naming.LinkRef in project tomee by apache.
the class JavaLookupTest method testLinking.
public void testLinking() throws Exception {
final Assembler assembler = new Assembler();
final ConfigurationFactory config = new ConfigurationFactory();
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
final InitialContext context = new InitialContext();
final Context javaContext = (Context) context.lookup("java:");
javaContext.bind("java:TransactionManager", new JndiUrlReference("java:comp/TransactionManager"));
javaContext.bind("java:TransactionManagerLink", new LinkRef("java:comp/TransactionManager"));
assertTrue(context.lookup("java:TransactionManager") instanceof TransactionManager);
assertTrue(context.lookup("java:TransactionManagerLink") instanceof TransactionManager);
new InitialContext().bind("java:foo", new LinkRef("java:comp/TransactionManager"));
assertTrue(context.lookup("java:foo") instanceof TransactionManager);
}
use of javax.naming.LinkRef in project tomee by apache.
the class TomcatJndiBuilder method normalize.
/**
* LinkRef addresses need to be prefixed with java: or they won't resolve
*
* OpenEJB is fine with this, but Tomcat needs them
*
* @param value
* @return
*/
private static Object normalize(final Object value) {
try {
if (!(value instanceof LinkRef)) {
return value;
}
final LinkRef ref = (LinkRef) value;
final RefAddr refAddr = ref.getAll().nextElement();
final String address = refAddr.getContent().toString();
if (address.startsWith("openejb:")) {
return value;
}
if (!address.startsWith("java:")) {
return new LinkRef("java:" + address);
}
} catch (final Exception e) {
// no-op
}
return value;
}
Aggregations