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.hello.ejb;
023:
024: import java.io.Serializable;
025: import javax.ejb.EJBException;
026: import javax.ejb.DuplicateKeyException;
027: import javax.ejb.FinderException;
028: import javax.naming.InitialContext;
029:
030: import org.jboss.test.util.ejb.SessionSupport;
031: import org.jboss.test.hello.interfaces.Hello;
032: import org.jboss.test.hello.interfaces.HelloData;
033: import org.jboss.test.hello.interfaces.HelloException;
034: import org.jboss.test.hello.interfaces.LocalHelloLogHome;
035: import org.jboss.test.hello.interfaces.LocalHelloLog;
036: import org.jboss.test.hello.interfaces.NotSerializable;
037:
038: /**
039: * @author Rickard Oberg
040: * @author Scott.Stark@jboss.org
041: * @version $Revision: 57211 $
042: */
043: public class HelloBean extends SessionSupport {
044: public String hello(String name) {
045: return "Hello " + name + "!";
046: }
047:
048: public String loggedHello(String name) {
049: long begin = System.currentTimeMillis();
050: LocalHelloLog bean = null;
051: LocalHelloLogHome home = null;
052: try {
053: InitialContext ctx = new InitialContext();
054: home = (LocalHelloLogHome) ctx
055: .lookup("java:comp/env/ejb/LocalHelloLogHome");
056: bean = home.create(name);
057: log.info("Created LocalHelloLog with key=" + name);
058: if (bean != null)
059: bean.setStartTime(begin);
060: } catch (DuplicateKeyException e) {
061: try {
062: bean = home.findByPrimaryKey(name);
063: log.info("Found LocalHelloLog with key=" + name);
064: if (bean != null)
065: bean.setStartTime(begin);
066: } catch (FinderException fe) {
067: log.debug("LocalHelloLog find failed", fe);
068: }
069: } catch (Exception e) {
070: log.debug("LocalHelloLog create failed", e);
071: }
072: String reply = "Hello " + name + "!";
073: long end = System.currentTimeMillis();
074: if (bean != null)
075: bean.setEndTime(end);
076:
077: return reply;
078: }
079:
080: public String helloException(String name) throws HelloException {
081: throw new HelloException("Catch me");
082: }
083:
084: public Hello helloHello(Hello hello) {
085: return hello;
086: }
087:
088: public String howdy(HelloData name) {
089: return "Howdy " + name.getName() + "!";
090: }
091:
092: public String sleepingHello(String name, long sleepTimeMS) {
093: if (sleepTimeMS <= 0)
094: sleepTimeMS = 1;
095: try {
096: Thread.sleep(sleepTimeMS);
097: } catch (InterruptedException ignore) {
098: }
099: return "Hello " + name + "!";
100: }
101:
102: public Object getCNFEObject() {
103: return new ServerData();
104: }
105:
106: public void throwException() {
107: throw new EJBException("Something went wrong");
108: }
109:
110: public void setNotSerializable(NotSerializable ignored) {
111: throw new RuntimeException("Should not get here");
112: }
113:
114: public NotSerializable getNotSerializable() {
115: return new NotSerializable();
116: }
117:
118: static class ServerData implements Serializable {
119: static final long serialVersionUID = 7590714293644921804L;
120: }
121: }
|