Search in sources :

Example 11 with Context

use of javax.naming.Context in project camel by apache.

the class MethodFilterTest method createJndiContext.

@Override
protected Context createJndiContext() throws Exception {
    Context context = super.createJndiContext();
    context.bind("myBean", new MyBean());
    return context;
}
Also used : Context(javax.naming.Context)

Example 12 with Context

use of javax.naming.Context in project camel by apache.

the class JndiContext method lookup.

public Object lookup(String name) throws NamingException {
    if (name.length() == 0) {
        return this;
    }
    Object result = treeBindings.get(name);
    if (result == null) {
        result = bindings.get(name);
    }
    if (result == null) {
        int pos = name.indexOf(':');
        if (pos > 0) {
            String scheme = name.substring(0, pos);
            Context ctx = NamingManager.getURLContext(scheme, environment);
            if (ctx == null) {
                throw new NamingException("scheme " + scheme + " not recognized");
            }
            return ctx.lookup(name);
        } else {
            // Split out the first name of the path
            // and look for it in the bindings map.
            CompositeName path = new CompositeName(name);
            if (path.size() == 0) {
                return this;
            } else {
                String first = path.get(0);
                Object value = bindings.get(first);
                if (value == null) {
                    throw new NameNotFoundException(name);
                } else if (value instanceof Context && path.size() > 1) {
                    Context subContext = (Context) value;
                    value = subContext.lookup(path.getSuffix(1));
                }
                return value;
            }
        }
    }
    if (result instanceof Provider) {
        Provider provider = (Provider) result;
        result = provider.get();
    }
    if (result instanceof LinkRef) {
        LinkRef ref = (LinkRef) result;
        result = lookup(ref.getLinkName());
    }
    if (result instanceof Reference) {
        try {
            result = NamingManager.getObjectInstance(result, null, null, this.environment);
        } catch (NamingException e) {
            throw e;
        } catch (Exception e) {
            throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
        }
    }
    if (result instanceof JndiContext) {
        String prefix = getNameInNamespace();
        if (prefix.length() > 0) {
            prefix = prefix + SEPARATOR;
        }
        result = new JndiContext((JndiContext) result, environment, prefix + name);
    }
    return result;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NotContextException(javax.naming.NotContextException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) NameNotFoundException(javax.naming.NameNotFoundException) Provider(com.google.inject.Provider) LinkRef(javax.naming.LinkRef)

Example 13 with Context

use of javax.naming.Context in project camel by apache.

the class JacksonBindingTest method createJndiContext.

@Override
protected Context createJndiContext() throws Exception {
    Context context = super.createJndiContext();
    JacksonXMLDataFormat format = new JacksonXMLDataFormat(TestPojo.class);
    context.bind("jsonmq", new BindingComponent(new DataFormatBinding(format), "file:target/"));
    return context;
}
Also used : Context(javax.naming.Context) DataFormatBinding(org.apache.camel.processor.binding.DataFormatBinding) BindingComponent(org.apache.camel.component.binding.BindingComponent)

Example 14 with Context

use of javax.naming.Context in project camel by apache.

the class JacksonBindingTest method createJndiContext.

@Override
protected Context createJndiContext() throws Exception {
    Context context = super.createJndiContext();
    JacksonDataFormat format = new JacksonDataFormat(TestPojo.class);
    context.bind("jsonmq", new BindingComponent(new DataFormatBinding(format), "file:target/"));
    return context;
}
Also used : Context(javax.naming.Context) DataFormatBinding(org.apache.camel.processor.binding.DataFormatBinding) BindingComponent(org.apache.camel.component.binding.BindingComponent)

Example 15 with Context

use of javax.naming.Context in project camel by apache.

the class JacksonNameBindingTest method createJndiContext.

@Override
protected Context createJndiContext() throws Exception {
    Context context = super.createJndiContext();
    JacksonDataFormat format = new JacksonDataFormat(TestPojo.class);
    context.bind("jackson", new DataFormatBinding(format));
    return context;
}
Also used : Context(javax.naming.Context) DataFormatBinding(org.apache.camel.processor.binding.DataFormatBinding)

Aggregations

Context (javax.naming.Context)507 InitialContext (javax.naming.InitialContext)250 Test (org.junit.Test)173 NamingException (javax.naming.NamingException)156 DataSource (javax.sql.DataSource)72 Properties (java.util.Properties)67 Connection (java.sql.Connection)62 NameNotFoundException (javax.naming.NameNotFoundException)52 UserTransaction (javax.transaction.UserTransaction)48 SQLException (java.sql.SQLException)46 IOException (java.io.IOException)44 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)44 Statement (java.sql.Statement)42 Name (javax.naming.Name)38 Hashtable (java.util.Hashtable)35 NameAlreadyBoundException (javax.naming.NameAlreadyBoundException)27 BeanContext (org.apache.openejb.BeanContext)27 Binding (javax.naming.Binding)25 Reference (javax.naming.Reference)25 NotContextException (javax.naming.NotContextException)23