Author: jlaskowski
Date: Tue Oct 23 15:02:39 2007
New Revision: 587671
URL: http://svn.apache.org/viewvc?rev=587671&view=rev
Log:
OPENEJB-710 @Resource TimerService injection is not supported
Submitted by: Jarek Gawor
Added:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerServiceWrapper.java
(with props)
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/TimerContainerTest.java
(with props)
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java?rev=587671&r1=587670&r2=587671&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java
Tue Oct 23 15:02:39 2007
@@ -33,10 +33,12 @@
import org.apache.openejb.core.ivm.naming.SystemComponentReference;
import org.apache.openejb.core.ivm.naming.CrossClassLoaderJndiReference;
import org.apache.openejb.core.ivm.naming.URLReference;
+import org.apache.openejb.core.timer.TimerServiceWrapper;
import org.apache.xbean.naming.context.WritableContext;
import org.omg.CORBA.ORB;
import javax.ejb.EJBContext;
+import javax.ejb.TimerService;
import javax.ejb.spi.HandleDelegate;
import javax.naming.Context;
import javax.naming.LinkRef;
@@ -147,6 +149,9 @@
bindings.put("java:comp/UserTransaction", userTransaction);
}
+ // bind TimerService
+ bindings.put("java:comp/TimerService", new TimerServiceWrapper());
+
for (EjbReferenceInfo referenceInfo : jndiEnc.ejbReferences) {
Reference reference = null;
@@ -251,6 +256,11 @@
continue;
} else if (WebServiceContext.class.equals(type)) {
String jndiName = "java:comp/WebServiceContext";
+ linkRef = new LinkRef(jndiName);
+ bindings.put(normalize(referenceInfo.resourceEnvRefName),
linkRef);
+ continue;
+ } else if (TimerService.class.equals(type)) {
+ String jndiName = "java:comp/TimerService";
linkRef = new LinkRef(jndiName);
bindings.put(normalize(referenceInfo.resourceEnvRefName),
linkRef);
continue;
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=587671&r1=587670&r2=587671&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java
Tue Oct 23 15:02:39 2007
@@ -168,7 +168,8 @@
"javax.transaction.UserTransaction",
"javax.jms.Queue",
"javax.jms.Topic",
- "javax.xml.ws.WebServiceContext"
+ "javax.xml.ws.WebServiceContext",
+ "javax.ejb.TimerService"
));
public static final Set<String> knownEnvironmentEntries = new
TreeSet<String>(Arrays.asList(
@@ -317,7 +318,8 @@
"javax.transaction.UserTransaction",
"javax.jms.Queue",
"javax.jms.Topic",
- "javax.xml.ws.WebServiceContext"
+ "javax.xml.ws.WebServiceContext",
+ "javax.ejb.TimerService"
));
public static final Set<String> knownEnvironmentEntries = new
TreeSet<String>(Arrays.asList(
Modified:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java?rev=587671&r1=587670&r2=587671&view=diff
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
(original)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java
Tue Oct 23 15:02:39 2007
@@ -77,6 +77,7 @@
ignoredReferenceTypes.add("java.net.URL");
// User transaction is automatically handled
ignoredReferenceTypes.add("javax.transaction.UserTransaction");
+ ignoredReferenceTypes.add("javax.ejb.TimerService");
}
private final ConfigurationFactory configFactory;
Added:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerServiceWrapper.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerServiceWrapper.java?rev=587671&view=auto
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerServiceWrapper.java
(added)
+++
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerServiceWrapper.java
Tue Oct 23 15:02:39 2007
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.core.timer;
+
+import javax.ejb.EJBException;
+import javax.ejb.Timer;
+import javax.ejb.TimerService;
+
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.core.ThreadContext;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Date;
+
+public class TimerServiceWrapper implements TimerService {
+
+ public TimerServiceWrapper() {
+ }
+
+ public Timer createTimer(Date initialExpiration, long intervalDuration,
Serializable info) throws IllegalArgumentException, IllegalStateException,
EJBException {
+ return getTimerService().createTimer(initialExpiration,
intervalDuration, info);
+ }
+
+ public Timer createTimer(Date expiration, Serializable info) throws
IllegalArgumentException, IllegalStateException, EJBException {
+ return getTimerService().createTimer(expiration, info);
+ }
+
+ public Timer createTimer(long initialDuration, long intervalDuration,
Serializable info) throws IllegalArgumentException, IllegalStateException,
EJBException {
+ return getTimerService().createTimer(initialDuration,
intervalDuration, info);
+ }
+
+ public Timer createTimer(long duration, Serializable info) throws
IllegalArgumentException, IllegalStateException, EJBException {
+ return getTimerService().createTimer(duration, info);
+ }
+
+ public Collection getTimers() throws IllegalStateException, EJBException {
+ return getTimerService().getTimers();
+ }
+
+ private TimerService getTimerService() throws IllegalStateException {
+ ThreadContext threadContext = ThreadContext.getThreadContext();
+ DeploymentInfo deploymentInfo = threadContext.getDeploymentInfo();
+ EjbTimerService timerService = deploymentInfo.getEjbTimerService();
+ if (timerService == null) {
+ throw new IllegalStateException("This ejb does not support timers
" + deploymentInfo.getDeploymentID());
+ }
+ return new TimerServiceImpl(timerService,
threadContext.getPrimaryKey());
+ }
+}
Propchange:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerServiceWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerServiceWrapper.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/timer/TimerServiceWrapper.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/TimerContainerTest.java
URL:
http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/TimerContainerTest.java?rev=587671&view=auto
==============================================================================
---
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/TimerContainerTest.java
(added)
+++
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/TimerContainerTest.java
Tue Oct 23 15:02:39 2007
@@ -0,0 +1,111 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.timer;
+
+import javax.annotation.Resource;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+import javax.ejb.TimerService;
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+import org.apache.openejb.assembler.classic.Assembler;
+import org.apache.openejb.assembler.classic.ProxyFactoryInfo;
+import org.apache.openejb.assembler.classic.SecurityServiceInfo;
+import org.apache.openejb.assembler.classic.StatelessSessionContainerInfo;
+import org.apache.openejb.assembler.classic.TransactionServiceInfo;
+import org.apache.openejb.config.ConfigurationFactory;
+import org.apache.openejb.core.ivm.naming.InitContextFactory;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.StatelessBean;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class TimerContainerTest extends TestCase {
+
+ public void testTimerServiceInjection() throws Exception {
+ InitialContext ctx = new InitialContext();
+
+ Object object = ctx.lookup("WidgetBeanLocal");
+
+ assertTrue("instanceof widget", object instanceof Widget);
+
+ Widget widget = (Widget) object;
+
+ // Do a business method...
+ assertTrue("Timer was not injected", widget.isTimerSet());
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
InitContextFactory.class.getName());
+
+ ConfigurationFactory config = new ConfigurationFactory();
+ Assembler assembler = new Assembler();
+
+
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
+
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
+
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
+
+ // containers
+ StatelessSessionContainerInfo statelessContainerInfo =
config.configureService(StatelessSessionContainerInfo.class);
+ statelessContainerInfo.properties.setProperty("TimeOut", "10");
+ statelessContainerInfo.properties.setProperty("PoolSize", "0");
+ statelessContainerInfo.properties.setProperty("StrictPooling",
"false");
+ assembler.createContainer(statelessContainerInfo);
+
+ // Setup the descriptor information
+
+ StatelessBean bean = new StatelessBean(WidgetBean.class);
+ bean.addBusinessLocal(Widget.class.getName());
+ bean.addBusinessRemote(RemoteWidget.class.getName());
+
+ EjbJar ejbJar = new EjbJar();
+ ejbJar.addEnterpriseBean(bean);
+
+ assembler.createApplication(config.configureApplication(ejbJar));
+
+ }
+
+ public static interface Widget {
+ boolean isTimerSet();
+ }
+
+ public static interface RemoteWidget extends Widget {
+ }
+
+ @Stateless
+ public static class WidgetBean implements Widget, RemoteWidget {
+
+ @Resource TimerService timer;
+
+ public WidgetBean() {
+ }
+
+ public void setSessionContext(SessionContext sessionContext) {
+ }
+
+ public boolean isTimerSet() {
+ return timer != null;
+ }
+
+ }
+}
Propchange:
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/TimerContainerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/TimerContainerTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange:
openejb/trunk/openejb3/container/openejb-core/src/test/java/org/apache/openejb/timer/TimerContainerTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain