Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for javax.naming.Reference is missing #16

Open
GoogleCodeExporter opened this issue Mar 14, 2015 · 1 comment
Open

Support for javax.naming.Reference is missing #16

GoogleCodeExporter opened this issue Mar 14, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Create converter which returns a javax.naming.Reference populated with the 
correct class and factory class (implementing ObjectFactory).
2. Retrieve Reference

What is the expected output? What do you see instead?
a. expected result: a class built by the factory class using the ObjectFactory 
interface
b. actual result: just the Reference object

What version of the product are you using? On what operating system?
11.4.1 on Linux

Please provide any additional information below.
if I use the standard Java RefFSContextFactory as JNDI provider, this
works well:
1. Create Reference
2. bind()
3. lookup() returns specific object, here WSMQConnectionFactory

Also, the Glassfish custom resource are implemented that way.

In summary, I see two issues here:

1. References should be returned as actual objects
2. simple-jndi should provide a default converter for the Reference object:

public class SimpleJndiObjectFactoryConverter implements Converter {

    private static final String OBJECT_FACTORY_NAME = "objectFactoryName";

    /* (non-Javadoc)
     * @see org.osjava.sj.loader.convert.Converter#convert(java.util.Properties, java.lang.String)
     */
    public Object convert( final Properties properties, final String type ) {

        final String factoryName = ( String ) properties.get( OBJECT_FACTORY_NAME );
        final Reference ref = new Reference( type, factoryName, null );

        for ( final Entry <Object, Object> entry : properties.entrySet() ) {
            final String key = (String) entry.getKey();
            if ( OBJECT_FACTORY_NAME.equals( key ) ) {
                continue;
            }
            ref.add( new StringRefAddr( key, (String) entry.getValue() ) );
        }
        return ref;
    }

}

Thanks, Jörg

Original issue reported on code.google.com by jfaram...@gmail.com on 25 May 2012 at 12:30

@GoogleCodeExporter
Copy link
Author

Instead of "return ref" I would use:

        try {
            final Class<?> factoryClass = Class.forName( factoryName );
            final ObjectFactory of = (ObjectFactory) factoryClass.newInstance();
            return of.getObjectInstance( ref, null, null, null );
        } catch ( Exception e ) {
            return null;
        }

The Issue (1) is solved here. But IMHO this should work in general.

And: Is "Class.forName()" correct here? Should we use the thread-context 
classloader instead?

Cheers, Jörg

Original comment by jfaram...@gmail.com on 25 May 2012 at 2:59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant