Search in sources :

Example 31 with LinkRef

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);
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) TransactionManager(javax.transaction.TransactionManager) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) InitialContext(javax.naming.InitialContext) LinkRef(javax.naming.LinkRef)

Example 32 with LinkRef

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;
}
Also used : RefAddr(javax.naming.RefAddr) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) NameNotFoundException(javax.naming.NameNotFoundException) MalformedURLException(java.net.MalformedURLException) LinkRef(javax.naming.LinkRef)

Aggregations

LinkRef (javax.naming.LinkRef)32 Context (javax.naming.Context)23 NamingException (javax.naming.NamingException)18 InitialContext (javax.naming.InitialContext)17 NameNotFoundException (javax.naming.NameNotFoundException)17 Reference (javax.naming.Reference)15 NotContextException (javax.naming.NotContextException)11 OperationNotSupportedException (javax.naming.OperationNotSupportedException)11 CompositeName (javax.naming.CompositeName)10 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)8 Name (javax.naming.Name)7 Referenceable (javax.naming.Referenceable)4 Test (org.junit.Test)4 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2 Binding (javax.naming.Binding)2 CannotProceedException (javax.naming.CannotProceedException)2 CompoundName (javax.naming.CompoundName)2 Provider (com.google.inject.Provider)1 IOException (java.io.IOException)1