Index: resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/ResourceMethodRegistry.java =================================================================== --- resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/ResourceMethodRegistry.java (revision 1244) +++ resteasy-jaxrs/src/main/java/org/jboss/resteasy/core/ResourceMethodRegistry.java (working copy) @@ -52,9 +52,9 @@ addResourceFactory(new SingletonResource(singleton), basePath); } - public void addJndiResource(String jndiName) + public void addJndiResource(String jndiName, boolean create) { - addResourceFactory(new JndiResourceFactory(jndiName)); + addResourceFactory(new JndiResourceFactory(jndiName,create)); } public void addJndiResource(String jndiName, String basePath) Index: resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/resourcefactory/JndiResourceFactory.java =================================================================== --- resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/resourcefactory/JndiResourceFactory.java (revision 1244) +++ resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/resourcefactory/JndiResourceFactory.java (working copy) @@ -5,6 +5,9 @@ import org.jboss.resteasy.spi.InjectorFactory; import org.jboss.resteasy.spi.ResourceFactory; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + import javax.naming.InitialContext; import javax.naming.NamingException; @@ -16,10 +19,17 @@ { private String jndiName; private InitialContext ctx; - + private boolean create; + public JndiResourceFactory(String jndiName) { + this(jndiName,false); + } + + public JndiResourceFactory(String jndiName, boolean create) + { this.jndiName = jndiName; + this.create = create; try { this.ctx = new InitialContext(); @@ -38,7 +48,12 @@ { try { - return ctx.lookup(jndiName); + Object obj = ctx.lookup(jndiName); + if(create) + { + obj = create(obj); + } + return obj; } catch (NamingException e) { @@ -55,6 +70,10 @@ try { Object obj = ctx.lookup(jndiName); + if(create) + { + obj = create(obj); + } return obj.getClass(); } catch (NamingException e) @@ -66,5 +85,33 @@ public void requestFinished(HttpRequest request, HttpResponse response, Object resource) { } + + + private Object create(Object obj) + { + Method declaredMethod = null; + Object returnObject = null; + try + { + declaredMethod = obj.getClass().getDeclaredMethod("create", null); + } + catch (SecurityException e) { } + catch (NoSuchMethodException e) { } + if(declaredMethod != null) + { + try + { + returnObject = declaredMethod.invoke(obj, null); + } + catch (IllegalArgumentException e) { } + catch (IllegalAccessException e) { } + catch (InvocationTargetException e) { } + } + if(returnObject == null && obj != null) + { + returnObject = obj; + } + return returnObject; + } } Index: resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/ConfigurationBootstrap.java =================================================================== --- resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/ConfigurationBootstrap.java (revision 1244) +++ resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/ConfigurationBootstrap.java (working copy) @@ -194,7 +194,10 @@ String jndiResources = getParameter(ResteasyContextParameters.RESTEASY_JNDI_RESOURCES); if (jndiResources != null) { - processJndiResources(jndiResources); + boolean create = false; + String ejbCreate = getParameter(ResteasyContextParameters.RESTEASY_EJB_CREATE); + create = Boolean.valueOf(ejbCreate); + processJndiResources(jndiResources,create); } String jndiComponentResources = getParameter(ResteasyContextParameters.RESTEASY_JNDI_COMPONENT_RESOURCES); @@ -288,13 +291,14 @@ return parsed; } - protected void processJndiResources(String jndiResources) + protected void processJndiResources(String jndiResources, boolean create) { + deployment.setEjbCreate(create); String[] resources = jndiResources.trim().split(","); for (String resource : resources) { deployment.getJndiResources().add(resource); - } + } } protected void processJndiComponentResources(String jndiResources) Index: resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/ResteasyContextParameters.java =================================================================== --- resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/ResteasyContextParameters.java (revision 1244) +++ resteasy-jaxrs/src/main/java/org/jboss/resteasy/plugins/server/servlet/ResteasyContextParameters.java (working copy) @@ -20,6 +20,7 @@ String RESTEASY_SCAN = "resteasy.scan"; String RESTEASY_SCAN_RESOURCES = "resteasy.scan.resources"; String RESTEASY_JNDI_RESOURCES = "resteasy.jndi.resources"; + String RESTEASY_EJB_CREATE = "resteasy.ejb.create"; String RESTEASY_RESOURCES = "resteasy.resources"; String RESTEASY_MEDIA_TYPE_MAPPINGS = "resteasy.media.type.mappings"; String RESTEASY_LANGUAGE_MAPPINGS = "resteasy.language.mappings"; Index: resteasy-jaxrs/src/main/java/org/jboss/resteasy/spi/Registry.java =================================================================== --- resteasy-jaxrs/src/main/java/org/jboss/resteasy/spi/Registry.java (revision 1244) +++ resteasy-jaxrs/src/main/java/org/jboss/resteasy/spi/Registry.java (working copy) @@ -44,7 +44,7 @@ * * @param clazz */ - void addJndiResource(String jndiName); + void addJndiResource(String jndiName, boolean create); /** * Add a JAX-RS endpoint that exists in JNDI. Index: resteasy-jaxrs/src/main/java/org/jboss/resteasy/spi/ResteasyDeployment.java =================================================================== --- resteasy-jaxrs/src/main/java/org/jboss/resteasy/spi/ResteasyDeployment.java (revision 1244) +++ resteasy-jaxrs/src/main/java/org/jboss/resteasy/spi/ResteasyDeployment.java (working copy) @@ -58,6 +58,7 @@ protected Dispatcher dispatcher; protected ResteasyProviderFactory providerFactory; protected String paramMapping; + private boolean ejbCreate; private final static Logger logger = LoggerFactory.getLogger(ResteasyDeployment.class); public void start() @@ -266,10 +267,10 @@ // interceptors must exist as they are applied only once when the resource is registered. if (jndiResources != null) - { + { for (String resource : jndiResources) { - registry.addJndiResource(resource.trim()); + registry.addJndiResource(resource.trim(),ejbCreate); } } if (resourceClasses != null) @@ -665,4 +666,9 @@ { this.defaultContextObjects = defaultContextObjects; } + + public void setEjbCreate(boolean create) + { + this.ejbCreate = create; + } }