[Beginners Corner] - Re: Referencing EJBs from Scheduler w/JBOSS 4.2.2GA
by mjhammel
I still don't have injection working, but I've managed to get my Schedulable working using the same (slightly modified) technique that the Web Services class is using. In the Web Services class I retrieved a UserTransaction by doing a lookup of java:/comp/UserTransaction. This worked in the Web Services class but not in the the Schedulable. After much googling, I found that doing the lookup as simply UserTransaction (no java:/comp prefix) works in both places. So my Schedulable now looks like this:
package com.cei.crunch.schedulers;
|
| import java.util.Date;
| import org.jboss.varia.scheduler.Schedulable;
| import org.apache.log4j.Logger;
|
| import javax.ejb.*;
|
| /* Crunch classes. */
| import com.cei.crunch.ejb.*;
|
| /**
| * A simple Schedulable example.
| * @author Michael J. Hammel
| * @version $Revision: 1.3 $
| */
| @Stateless
| public class CronSchedulable implements Schedulable
| {
| private static final Logger log = Logger.getLogger(CronSchedulable.class);
|
| private String name;
| private long value;
|
| public CronSchedulable(String name, long value)
| {
| this.name = name;
| this.value = value;
| log.info("ctor, name: " + name + ", value: " + value);
| }
|
| public void perform(Date now, long remainingRepetitions)
| {
| SubscriberBean sb = null;
| Subscriber s = null;
|
| log.info("perform, now: " + now +
| ", remainingRepetitions: " + remainingRepetitions +
| ", name: " + name + ", value: " + value);
|
| sb = new SubscriberBean();
| if ( sb == null )
| log.info("Failed to get SubscriberBean.");
| else
| {
| s = sb.findSubscriber("CRUNCH-DEFAULT-SUPERUSER");
| if ( s != null )
| {
| log.info("Subscriber info: \n" +
| "Username : " + s.getUsername() + "\n" +
| "First name: " + s.getFirstname() + "\n" +
| "Last name : " + s.getLastname() + "\n" +
| "Email : " + s.getEmailAddress()
| );
| }
| else
| log.info("Injection still not working - *sigh*.");
| }
| }
|
| }
This, in turn, calls an EJB that looks like this:
package com.cei.crunch.ejb;
|
| import javax.ejb.*;
|
| import com.cei.crunch.ejb.Subscriber;
| import com.cei.crunch.ejb.EJBUtil;
| import com.cei.crunch.ejb.EJBUtil.EJBInit;
|
|
| @Stateless
| public class SubscriberBean implements SubscriberRemote {
|
| /* Default Constructor */
| public SubscriberBean() {}
|
| public Subscriber findSubscriber(String guid)
| {
| Subscriber s = null;
| EJBInit ei = null;
| try {
| EJBUtil eu = new EJBUtil();
| ei = eu.ejbSetup();
| }
| catch (EJBException ee) {
| System.out.println("findSubscriber(): " + ee.getMessage());
| ee.printStackTrace();
| return null;
| }
|
| if ( ei.em == null )
| {
| System.out.println("SubscriberBean: em is null; can't find subscriber.");
| }
| else
| {
| try {
| ei.utx.begin();
| s = ei.em.find(Subscriber.class, guid);
| ei.utx.commit();
| }
| catch (Exception e) {
| System.out.println("SubscriberBean: exception in transaction: " + e.getMessage());
| e.printStackTrace();
| }
| }
| return s;
| }
| }
whose interface looks like this:
package com.cei.crunch.ejb;
|
| import javax.ejb.Remote;
| import com.cei.crunch.ejb.Subscriber;
|
| @Remote
| public interface SubscriberRemote {
| public Subscriber findSubscriber(String guid);
| }
The EJB also calls an initialization class (that lives in the same package as the EJB) that gets the InitialContext, EntityManager and UserTransaction. This is where the switch from java:/comp/UserTransaction to UserTransction occurs, in the ctx.lookup() call.
package com.cei.crunch.ejb;
|
| import javax.ejb.*;
| import javax.persistence.*;
| import javax.naming.InitialContext;
| import javax.transaction.UserTransaction;
|
| /**
| * .Crunch server side utilities
| */
| public class EJBUtil {
|
| public class EJBInit {
| public InitialContext ctx;
| public EntityManager em;
| public UserTransaction utx;
| }
|
| /**
| * Default constructor.
| */
| public EJBUtil() {}
|
| /**
| * Initialization for Web Services.
| */
| public EJBInit ejbSetup() throws EJBException
| {
| InitialContext ctx = null;
| EntityManager em = null;
| UserTransaction utx;
| try {
| ctx = new InitialContext();
| em = (EntityManager) ctx.lookup("java:/CrunchPersistence");
| utx = (UserTransaction) ctx.lookup("UserTransaction");
| }
| catch (Exception e)
| {
| EJBException ee = new EJBException(e);
| ee.setMessage("Context setup failed.");
| throw ee;
| }
| if ( em == null )
| {
| EJBException ee = new EJBException("Failed to initialize entity manager.");
| throw ee;
| }
| else
| {
| EJBInit ei = new EJBInit();
| ei.ctx = ctx;
| ei.em = em;
| ei.utx = utx;
| return (ei);
| }
| }
|
| }
The EJBException class is a simple exception class I wrote and is included in the same com.cei.crunch.ejb package.
While it doesn't use injection, it does appear to grab the correct row from the database, and that's about all I can ask for at the moment. Actually making changes to the database hasn't been tested. Hopefully, this helps someone else getting started with Schedulables and also can't get injection to work.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119812#4119812
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119812
18 years, 3 months
[JBoss Tools (users)] - Re: Step away from the tool and nobody gets hurt
by bostroff
"max.andersen(a)jboss.com" wrote : "bostroff" wrote : I guess I'm working too hard to make this work...
| |
| | I have successfully created a seam project in the past (say a month ago) from an existing database schema using seam-gen from the command line. Pretty much just ran the tool, built it (as an ear), deployed it in JBoss, and CRUD just worked. I was using seam 2.0 with JBoss AS 4.2.2.
| |
| | Now, I'm trying to get effectively the same thing working using the seam tools in Eclipse (Europa 3.3.1.1) and I ran into a number of problems:
| |
|
| ok.
| so using the seam-gen command line tool give you different results than running it via the tooling ?
|
|
| anonymous wrote :
| | 1. Missing serialVersionUID everywhere - added it.
| |
|
| That is not a bug, that is fully intentional. See http://opensource.atlassian.com/projects/hibernate/browse/HBX-964
|
| anonymous wrote :
| | 2. The loginout.xhtml apparently missing the ui:composition tag - modified it
| |
|
| not sure what you are referring to...things works for me...please more details.
|
So, the loginout.xhtml file was generated as:
|
| <div class="loginout"
| xmlns="..."
| ...
| >
| ...
| </div>
|
Eclipse whined about the xmlns attribute and I assumed that maybe it should read:
| <ui:composition
| xmlns="..."
| ...
| >
| <div class="loginout">
| ...
| </div>
| </ui:composition>
|
"max.andersen(a)jboss.com" wrote : "bostroff" wrote :
| | 3. Some generated xhtml pages not recognizing the messages bundle - added bundle to faces-config.xml - doesn't seem to help - warnings still exist.
| |
|
| this is a limitaiton of the validations of the tools. Is anything actually failing when you run the app?
|
| anonymous wrote :
| | 4. Try a deploy anyway - complains about missing MethodBinding among others.
| |
|
| details please...War and Ear works for me out of box so need more details to reproduce.
|
|
So, the log reveals a number of these:
| 11:30:08,495 INFO [Initialization] two components with same name, higher precedence wins: org.jboss.seam.core.locale
| 11:30:08,499 INFO [Initialization] two components with same name, higher precedence wins: org.jboss.seam.core.manager
|
followed later by this warning:
| 11:30:08,549 WARN [Initialization] Did not install PojoCache due to NoClassDefFoundError: org/jgroups/MembershipListener
|
and ultimately by this:
| 11:30:09,625 ERROR [StandardContext] Error listenerStart
| 11:30:09,625 ERROR [StandardContext] Context [/cehc] startup failed due to previous errors
| 11:30:09,720 WARN [ServiceController] Problem starting service jboss.web.deployment:war=cehc.war,id=558207986
| org.jboss.deployment.DeploymentException: URL file:/Users/bostroff/Downloads/jboss-4.2.2.GA/server/default/deploy/cehc.ear/cehc.war/ deployment failed
|
It almost looks like I have two different versions of the seam jar on the runtime classpath?
"max.andersen(a)jboss.com" wrote : "bostroff" wrote :
| | So, did I answer some of the wizard questions incorrectly (like should I have NOT picked seam 2.0 technology preview)? Is there a blindingly simple tutorial where I could create a small seam 2.0 application from scratch inside Eclipse (Europa) and have it successfully deploy and execute?
| |
|
| Yes, its in the Getting Started Guide.
|
| The only explanation I can come up with is that you have something specfic in your db that creates bad seamgen output....just weird you are not seeing that when using seamgen commandline.
|
|
Also, now I DO vaguely remember having to drop a jar into my JBoss server default lib directory. This allowed the command line generated version to work (this was done on the vague advice gleaned from another thread somewhere on the net) .
"max.andersen(a)jboss.com" wrote :
|
| /max
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119811#4119811
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119811
18 years, 3 months
[JBoss Seam] - seam-gen generate-entities broken
by nathandennis
grabbed seam from the cvs today 011408 to get around a few other bug in older revision.
wouldnt run generate entities on my existing db.
jboss 4.2.1
postgres 8.1.5
postgresql-8.1-411.jdbc3.jar (current as of today) also tried with 410
| [hibernate] INFO: Hibernate Annotations 3.3.0.GA
| [hibernate] Jan 14, 2008 3:11:43 PM org.hibernate.ejb.Version <clinit>
| [hibernate] INFO: Hibernate EntityManager 3.3.1.GA
| [hibernate] An exception occurred while running exporter #2:generic exportertemplate: view/list.xhtml.ftl
| [hibernate] To get the full stack trace run ant with -verbose
| [hibernate] Problems in creating a configuration for JPA. Have you remembered to add hibernate EntityManager jars to the classpath ?
| [hibernate] java.lang.reflect.InvocationTargetException
| [hibernate] javax.persistence.PersistenceException: [PersistenceUnit: mysite] class or package not found
| [hibernate] java.lang.ClassNotFoundException: com.mysite.model.UserAccount
| [hibernate] A class were not found in the classpath of the Ant task.
|
it appears to be looking for a class com.mysite.model.UserAccount. the question is, "why is it looking for it?" its looking for a table in my db that doesnt exist.
any clue as to what is happening here?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119808#4119808
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119808
18 years, 3 months
[JBoss Tools (users)] - Re: Step away from the tool and nobody gets hurt
by max.andersen@jboss.com
"bostroff" wrote : I guess I'm working too hard to make this work...
|
| I have successfully created a seam project in the past (say a month ago) from an existing database schema using seam-gen from the command line. Pretty much just ran the tool, built it (as an ear), deployed it in JBoss, and CRUD just worked. I was using seam 2.0 with JBoss AS 4.2.2.
|
| Now, I'm trying to get effectively the same thing working using the seam tools in Eclipse (Europa 3.3.1.1) and I ran into a number of problems:
|
ok.
so using the seam-gen command line tool give you different results than running it via the tooling ?
anonymous wrote :
| 1. Missing serialVersionUID everywhere - added it.
|
That is not a bug, that is fully intentional. See http://opensource.atlassian.com/projects/hibernate/browse/HBX-964
anonymous wrote :
| 2. The loginout.xhtml apparently missing the ui:composition tag - modified it
|
not sure what you are referring to...things works for me...please more details.
anonymous wrote :
| 3. Some generated xhtml pages not recognizing the messages bundle - added bundle to faces-config.xml - doesn't seem to help - warnings still exist.
|
this is a limitaiton of the validations of the tools. Is anything actually failing when you run the app?
anonymous wrote :
| 4. Try a deploy anyway - complains about missing MethodBinding among others.
|
details please...War and Ear works for me out of box so need more details to reproduce.
anonymous wrote :
| So, did I answer some of the wizard questions incorrectly (like should I have NOT picked seam 2.0 technology preview)? Is there a blindingly simple tutorial where I could create a small seam 2.0 application from scratch inside Eclipse (Europa) and have it successfully deploy and execute?
|
Yes, its in the Getting Started Guide.
The only explanation I can come up with is that you have something specfic in your db that creates bad seamgen output....just weird you are not seeing that when using seamgen commandline.
/max
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4119794#4119794
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4119794
18 years, 3 months