public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Context contextProxy = (Context) proxy; final String methodName = method.getName(); if (log.isDebugEnabled()) { log.debug("invoking [ " + methodName + "(" + argsString(args) + ") ] on [ " + delegate + " ]"); } if ("createSubContext".equals(methodName)) { Context context = (Context) method.invoke(delegate, args); return new JNDIContextHandler(context); } else { final Object result = method.invoke(delegate, args); if (result instanceof Reference) { Reference ref = (Reference) result; ObjectFactory f = (ObjectFactory) contextProxy.lookup(ref.getFactoryClassLocation()); final Object res = f.getObjectInstance(ref, null, null, null); System.out.println(res); return res; } else { return result; } } }
if (reference.getFactoryClassLocation() != null) writer.writeAttribute(FACTORY_LOCATION_ATTR, reference.getFactoryClassLocation());
/** * Check whether object factory code base is trusted. * Classes may only be loaded from an arbitrary URL code base when * the system property com.sun.jndi.rmi.object.trustURLCodebase * has been set to "true". */ public static boolean isObjectFactoryTrusted(Object obj) throws NamingException { // Extract Reference, if possible Reference ref = null; if (obj instanceof Reference) { ref = (Reference) obj; } else if (obj instanceof Referenceable) { ref = ((Referenceable)(obj)).getReference(); } if (ref != null && ref.getFactoryClassLocation() != null && !CNCtx.trustURLCodebase) { throw new ConfigurationException( "The object factory is untrusted. Set the system property" + " 'com.sun.jndi.cosnaming.object.trustURLCodebase' to 'true'."); } return true; }
/** * @deprecated nesting references seemed useful until I realized that * references are Serializable and can be stored in a BinaryRefAddr. * Oops. */ public static void appendToReference(Reference appendTo, Reference orig) throws NamingException { int len = orig.size(); appendTo.add( new StringRefAddr( REFADDR_VERSION, String.valueOf( CURRENT_REF_VERSION ) ) ); appendTo.add( new StringRefAddr( REFADDR_CLASSNAME, orig.getClassName() ) ); appendTo.add( new StringRefAddr( REFADDR_FACTORY, orig.getFactoryClassName() ) ); appendTo.add( new StringRefAddr( REFADDR_FACTORY_CLASS_LOCATION, orig.getFactoryClassLocation() ) ); appendTo.add( new StringRefAddr( REFADDR_SIZE, String.valueOf(len) ) ); for (int i = 0; i < len; ++i) appendTo.add( orig.get(i) ); }
String fClassLocation = ref.getFactoryClassLocation();
String fClassLocation = ref.getFactoryClassLocation();
String fClassLocation = ref.getFactoryClassLocation();
/** * @deprecated nesting references seemed useful until I realized that * references are Serializable and can be stored in a BinaryRefAddr. * Oops. */ public static void appendToReference(Reference appendTo, Reference orig) throws NamingException { int len = orig.size(); appendTo.add( new StringRefAddr( REFADDR_VERSION, String.valueOf( CURRENT_REF_VERSION ) ) ); appendTo.add( new StringRefAddr( REFADDR_CLASSNAME, orig.getClassName() ) ); appendTo.add( new StringRefAddr( REFADDR_FACTORY, orig.getFactoryClassName() ) ); appendTo.add( new StringRefAddr( REFADDR_FACTORY_CLASS_LOCATION, orig.getFactoryClassLocation() ) ); appendTo.add( new StringRefAddr( REFADDR_SIZE, String.valueOf(len) ) ); for (int i = 0; i < len; ++i) appendTo.add( orig.get(i) ); }
/** * @deprecated nesting references seemed useful until I realized that * references are Serializable and can be stored in a BinaryRefAddr. * Oops. */ public static void appendToReference(Reference appendTo, Reference orig) throws NamingException { int len = orig.size(); appendTo.add( new StringRefAddr( REFADDR_VERSION, String.valueOf( CURRENT_REF_VERSION ) ) ); appendTo.add( new StringRefAddr( REFADDR_CLASSNAME, orig.getClassName() ) ); appendTo.add( new StringRefAddr( REFADDR_FACTORY, orig.getFactoryClassName() ) ); appendTo.add( new StringRefAddr( REFADDR_FACTORY_CLASS_LOCATION, orig.getFactoryClassLocation() ) ); appendTo.add( new StringRefAddr( REFADDR_SIZE, String.valueOf(len) ) ); for (int i = 0; i < len; ++i) appendTo.add( orig.get(i) ); }
@Test public void testJNDIReference() throws Exception { final EntityManagerFactory emf = Persistence.createEntityManagerFactory( "ogm", TestHelper.getDefaultTestSettings() ); SessionFactory factory = (SessionFactory) emf; Reference reference = factory.getReference(); assertThat( reference.getClassName() ).isEqualTo( OgmSessionFactoryImpl.class.getName() ); assertThat( reference.getFactoryClassName() ).isEqualTo( ObjectFactoryImpl.class.getName() ); assertThat( reference.get( 0 ) ).isNotNull(); assertThat( reference.getFactoryClassLocation() ).isNull(); ObjectFactory objFactory = new ObjectFactoryImpl(); SessionFactory factoryFromRegistry = (SessionFactory) objFactory.getObjectInstance( reference, null, null, null ); assertThat( factoryFromRegistry.getClass() ).isEqualTo( OgmSessionFactoryImpl.class ); assertThat( factoryFromRegistry.getReference() ).isEqualTo( factory.getReference() ); emf.close(); }
@Test public void testGetReferenceImplementation() throws Exception { final Session session = openSession(); SessionFactory factory = session.getSessionFactory(); assertThat( factory.getClass() ).isEqualTo( OgmSessionFactoryImpl.class ); Reference reference = factory.getReference(); assertThat( reference.getClassName() ).isEqualTo( OgmSessionFactoryImpl.class.getName() ); assertThat( reference.getFactoryClassName() ).isEqualTo( ObjectFactoryImpl.class.getName() ); assertThat( reference.get( 0 ) ).isNotNull(); assertThat( reference.getFactoryClassLocation() ).isNull(); ObjectFactory objFactory = new ObjectFactoryImpl(); SessionFactory factoryFromRegistry = (SessionFactory) objFactory.getObjectInstance( reference, null, null, null ); assertThat( factoryFromRegistry.getClass() ).isEqualTo( OgmSessionFactoryImpl.class ); assertThat( factoryFromRegistry.getReference() ).isEqualTo( factory.getReference() ); session.close(); }