001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.test.mdb;
023:
024: import javax.ejb.ActivationConfigProperty;
025: import javax.interceptor.AroundInvoke;
026: import javax.interceptor.InvocationContext;
027: import javax.ejb.MessageDriven;
028: import javax.ejb.MessageDrivenContext;
029: import javax.ejb.EJB;
030: import javax.annotation.PostConstruct;
031: import javax.annotation.PreDestroy;
032: import javax.annotation.Resource;
033: import javax.jms.Message;
034: import javax.jms.MessageListener;
035: import javax.naming.InitialContext;
036:
037: import javax.annotation.security.RunAs;
038:
039: import org.jboss.annotation.security.SecurityDomain;
040: import org.jboss.logging.Logger;
041:
042: /**
043: * Comment
044: *
045: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
046: * @version $Revision: 63408 $
047: */
048: @MessageDriven(name="QueueMDB",messageListenerInterface=MessageListener.class,activationConfig={@ActivationConfigProperty(propertyName="destinationType",propertyValue="javax.jms.Queue"),@ActivationConfigProperty(propertyName="destination",propertyValue="queue/mdbtest")})
049: @RunAs("TestRole")
050: @SecurityDomain("other")
051: public class QueueTestMDB extends AbstractQueueTestMDB implements
052: MessageListener, QueueTestInterface {
053: private static final Logger log = Logger
054: .getLogger(QueueTestMDB.class);
055:
056: @EJB(beanName="LocalStateless")
057: Stateless localStateless;
058:
059: public int count = 0;
060:
061: @Resource
062: MessageDrivenContext ctx;
063:
064: public void onMessage(Message recvMsg) {
065: if (ctx == null)
066: throw new RuntimeException("FAILED ON CTX LOOKUP");
067: ++count;
068: ++TestStatusBean.queueRan;
069: TestStatusBean.messageCount = count;
070:
071: System.out.println("+++ QueueTestMDB onMessage "
072: + TestStatusBean.queueRan + " " + count + " " + this );
073:
074: testInjections();
075:
076: try {
077: InitialContext jndiContext = new InitialContext();
078: Stateless stateless = (Stateless) jndiContext
079: .lookup("Stateless");
080: stateless.setState("Set");
081: } catch (Exception e) {
082: e.printStackTrace();
083: }
084: System.out.println("--- QueueTestMDB onMessage "
085: + TestStatusBean.queueRan + " " + count + " " + this );
086:
087: }
088:
089: protected void testInjections() {
090: localStateless.setState("testing");
091: }
092:
093: @AroundInvoke
094: public Object intercept(InvocationContext ctx) throws Exception {
095: TestStatusBean.interceptedQueue = true;
096: return ctx.proceed();
097: }
098:
099: @PostConstruct
100: public void postConstruct() {
101: TestStatusBean.postConstruct = true;
102: }
103:
104: @PreDestroy
105: public void preDestroy() {
106: TestStatusBean.preDestroy = true;
107: }
108:
109: public void dummy1() {
110:
111: }
112: }
|