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.test.naming.ejb;
023:
024: import javax.ejb.CreateException;
025: import javax.ejb.EJBException;
026: import javax.ejb.SessionBean;
027: import javax.ejb.SessionContext;
028: import javax.naming.InitialContext;
029: import javax.rmi.PortableRemoteObject;
030:
031: import org.jboss.logging.Logger;
032: import org.jboss.test.naming.interfaces.TestEjbLinkHome;
033: import org.jboss.test.naming.interfaces.TestEjbLink;
034: import org.jboss.test.naming.interfaces.TestEjbLinkLocalHome;
035: import org.jboss.test.naming.interfaces.TestEjbLinkLocal;
036: import org.jboss.test.util.Debug;
037:
038: /** A bean that tests ejb-link works
039:
040: @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian.Brock</a>
041: @version $Revision: 60317 $
042: */
043: public class TestEjbLinkBean implements SessionBean {
044: private static final long serialVersionUID = 1;
045: static Logger log = Logger.getLogger(TestEjbLinkBean.class);
046:
047: public void ejbCreate() throws CreateException {
048: }
049:
050: // --- Begin SessionBean interface methods
051: public void ejbActivate() {
052: }
053:
054: public void ejbPassivate() {
055: }
056:
057: public void ejbRemove() {
058: }
059:
060: public void setSessionContext(SessionContext sessionContext)
061: throws EJBException {
062: }
063:
064: public String testEjbLinkCaller(String jndiName) {
065: try {
066: InitialContext initial = new InitialContext();
067: Object object = initial.lookup(jndiName);
068: log.debug("jndiName=" + jndiName);
069:
070: StringBuffer results = new StringBuffer(
071: "testEjbLinkCaller Proxy info\n");
072: Debug.displayClassInfo(object.getClass(), results);
073: log.debug(results.toString());
074:
075: results.setLength(0);
076: results
077: .append("testEjbLinkCaller TestEjbLinkLocalHome.class info\n");
078: Debug.displayClassInfo(TestEjbLinkLocalHome.class, results);
079: log.debug(results.toString());
080:
081: TestEjbLinkHome home = (TestEjbLinkHome) PortableRemoteObject
082: .narrow(object, TestEjbLinkHome.class);
083: TestEjbLink bean = home.create();
084: return bean.testEjbLinkCalled();
085: } catch (Exception e) {
086: log.debug("failed", e);
087: return "Failed";
088: }
089: }
090:
091: public String testEjbLinkCallerLocal(String jndiName) {
092: try {
093: InitialContext initial = new InitialContext();
094: Object object = initial.lookup(jndiName);
095: log.debug("jndiName=" + jndiName);
096:
097: StringBuffer results = new StringBuffer(
098: "testEjbLinkCallerLocal Proxy info\n");
099: Debug.displayClassInfo(object.getClass(), results);
100: log.debug(results.toString());
101:
102: results.setLength(0);
103: results
104: .append("testEjbLinkCallerLocal TestEjbLinkLocalHome.class info\n");
105: Debug.displayClassInfo(TestEjbLinkLocalHome.class, results);
106: log.debug(results.toString());
107:
108: TestEjbLinkLocalHome home = (TestEjbLinkLocalHome) PortableRemoteObject
109: .narrow(object, TestEjbLinkLocalHome.class);
110: TestEjbLinkLocal bean = home.create();
111: return bean.testEjbLinkCalled();
112: } catch (Exception e) {
113: log.debug("failed", e);
114: return "Failed";
115: }
116: }
117:
118: public String testEjbLinkCalled() {
119: return "Works";
120: }
121:
122: }
|