Results 1 to 5 of 5
  1. #1
    vietnamusa is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB

    Hello Everyone,

    I'm a new to JavaEE and currently I'm following the The Java EE 6 Tutorial (March 2011).

    System:
    - Windows 7 Professional 32-bit
    - java -version
    java version "1.6.0_24"
    Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
    Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode, sharing)
    - GlassFish Server 3.1 Open Source glassfish-3.1-windows.exe
    - netbeans-6.9.1-ml-windows.exe
    - apache-maven-3.0.2-bin.zip

    After installations are done, I used Update Tool to obtain the Java EE Tutorial and it is now at C:\glassfish3.1\glassfish\docs\javaee-tutorial\ where C:\glassfish3.1\ is the installed_dir of the GlassFish Server 3.1 Open Source.

    Then now I'm following the The Java EE 6 Tutorial that is C:\glassfish3.1\glassfish\docs\javaee-tutorial\doc\javaeetutorial6.pdf.

    Now I'm building, deploying, and running the example async that is one of EJB examples, located at C:\glassfish3.1\glassfish\docs\javaee-tutorial\examples\ejb\async\.

    It was builded OK.
    It was deployed OK.
    At the browser Firefox 3.6.16, I went to http://localhost:8080/async/. I provided an email and then clicked Send email button, I saw an error below:
    javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB

    The server.log (in C:\glassfish3.1\glassfish\domains\domain1\logs\) showed:

    [#|2011-03-30T09:51:39.397-0700|INFO|glassfish3.1|org.hibernate.validator.eng ine.resolver.DefaultTraversableResolver|_ThreadID= 29;_ThreadName=Thread-1;|Instantiated an instance of org.hibernate.validator.engine.resolver.JPATravers ableResolver.|#]

    [#|2011-03-30T09:51:39.464-0700|SEVERE|glassfish3.1|javax.enterprise.system.c ontainer.ejb.com.sun.ejb.containers|_ThreadID=180; _ThreadName=Thread-1;|EJB5070: Exception creating stateless session bean : [MailerBean]|#]

    [#|2011-03-30T09:51:39.466-0700|WARNING|glassfish3.1|javax.enterprise.system. container.ejb.com.sun.ejb.containers|_ThreadID=180 ;_ThreadName=Thread-1;|A system exception occurred during an invocation on EJB MailerBean method public java.util.concurrent.Future async.ejb.MailerBean.sendMessage(java.lang.String)
    javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
    at com.sun.ejb.containers.StatelessSessionContainer._ getContext(StatelessSessionContainer.java:454)
    at com.sun.ejb.containers.BaseContainer.getContext(Ba seContainer.java:2528)
    at com.sun.ejb.containers.BaseContainer.preInvoke(Bas eContainer.java:1895)
    at com.sun.ejb.containers.EjbAsyncTask.call(EjbAsyncT ask.java:99)
    at java.util.concurrent.FutureTask$Sync.innerRun(Futu reTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.jav a:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run Task(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
    Caused by: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
    at com.sun.ejb.containers.StatelessSessionContainer$S essionContextFactory.create(StatelessSessionContai ner.java:726)
    at com.sun.ejb.containers.util.pool.NonBlockingPool.g etObject(NonBlockingPool.java:247)
    at com.sun.ejb.containers.StatelessSessionContainer._ getContext(StatelessSessionContainer.java:449)
    ... 8 more
    Caused by: javax.ejb.CreateException: Could not create stateless EJB
    at com.sun.ejb.containers.StatelessSessionContainer.c reateStatelessEJB(StatelessSessionContainer.java:5 34)
    at com.sun.ejb.containers.StatelessSessionContainer.a ccess$000(StatelessSessionContainer.java:95)
    at com.sun.ejb.containers.StatelessSessionContainer$S essionContextFactory.create(StatelessSessionContai ner.java:724)
    ... 10 more
    Caused by: java.lang.IllegalStateException: Exception attempting to inject Res-Ref-Env-Property: mail/myExampleSession@javax.mail.Session@ resolved as: jndi: mail/myExampleSession@res principal: null@mail: null
    No Runtime properties
    Database Vendor : null
    Create Tables at Deploy : false
    Delete Tables at Undeploy : false into class async.ejb.MailerBean
    at org.glassfish.weld.services.InjectionServicesImpl. aroundInject(InjectionServicesImpl.java:137)
    at org.jboss.weld.injection.InjectionContextImpl.run( InjectionContextImpl.java:50)
    at org.jboss.weld.bean.SessionBean$1.inject(SessionBe an.java:190)
    at org.glassfish.weld.services.JCDIServiceImpl.inject EJBInstance(JCDIServiceImpl.java:198)
    at com.sun.ejb.containers.BaseContainer.injectEjbInst ance(BaseContainer.java:1675)
    at com.sun.ejb.containers.StatelessSessionContainer.c reateStatelessEJB(StatelessSessionContainer.java:4 94)
    ... 12 more
    Caused by: com.sun.enterprise.container.common.spi.util.Injec tionException: Exception attempting to inject Res-Ref-Env-Property: mail/myExampleSession@javax.mail.Session@ resolved as: jndi: mail/myExampleSession@res principal: null@mail: null
    No Runtime properties
    Database Vendor : null
    Create Tables at Deploy : false
    Delete Tables at Undeploy : false into class async.ejb.MailerBean
    at com.sun.enterprise.container.common.impl.util.Inje ctionManagerImpl._inject(InjectionManagerImpl.java :698)
    at com.sun.enterprise.container.common.impl.util.Inje ctionManagerImpl.inject(InjectionManagerImpl.java: 468)
    at com.sun.enterprise.container.common.impl.util.Inje ctionManagerImpl.injectInstance(InjectionManagerIm pl.java:173)
    at org.glassfish.weld.services.InjectionServicesImpl. aroundInject(InjectionServicesImpl.java:130)
    ... 17 more
    Caused by: javax.naming.NamingException: Lookup failed for 'java:comp/env/mail/myExampleSession' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterpr ise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.pr esentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.na ming} [Root exception is javax.naming.NamingException: Lookup failed for 'mail/myExampleSession' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterpr ise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.pr esentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.na ming, com.sun.enterprise.naming.logicalName=java:comp/env/mail/myExampleSession} [Root exception is javax.naming.NameNotFoundException: mail]]
    at com.sun.enterprise.naming.impl.SerialContext.looku p(SerialContext.java:518)
    at com.sun.enterprise.naming.impl.SerialContext.looku p(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext. java:392)
    at javax.naming.InitialContext.lookup(InitialContext. java:392)
    at com.sun.enterprise.container.common.impl.util.Inje ctionManagerImpl._inject(InjectionManagerImpl.java :597)
    ... 20 more
    Caused by: javax.naming.NamingException: Lookup failed for 'mail/myExampleSession' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterpr ise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.pr esentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.na ming, com.sun.enterprise.naming.logicalName=java:comp/env/mail/myExampleSession} [Root exception is javax.naming.NameNotFoundException: mail]
    at com.sun.enterprise.naming.impl.SerialContext.looku p(SerialContext.java:518)
    at com.sun.enterprise.naming.impl.SerialContext.looku p(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext. java:392)
    at javax.naming.InitialContext.lookup(InitialContext. java:392)
    at com.sun.enterprise.naming.util.JndiNamingObjectFac tory.create(JndiNamingObjectFactory.java:90)
    at com.sun.enterprise.naming.impl.GlassfishNamingMana gerImpl.lookup(GlassfishNamingManagerImpl.java:772 )
    at com.sun.enterprise.naming.impl.GlassfishNamingMana gerImpl.lookup(GlassfishNamingManagerImpl.java:740 )
    at com.sun.enterprise.naming.impl.JavaURLContext.look up(JavaURLContext.java:172)
    at com.sun.enterprise.naming.impl.SerialContext.looku p(SerialContext.java:498)
    ... 24 more
    Caused by: javax.naming.NameNotFoundException: mail
    at com.sun.enterprise.naming.impl.TransientContext.re solveContext(TransientContext.java:310)
    at com.sun.enterprise.naming.impl.TransientContext.lo okup(TransientContext.java:218)
    at com.sun.enterprise.naming.impl.SerialContextProvid erImpl.lookup(SerialContextProviderImpl.java:77)
    at com.sun.enterprise.naming.impl.LocalSerialContextP roviderImpl.lookup(LocalSerialContextProviderImpl. java:119)
    at com.sun.enterprise.naming.impl.SerialContext.looku p(SerialContext.java:505)
    ... 32 more
    |#]


    Please let me know what I was missing or it is GlassFish 3.1 Open Source bug.

    Thank you in advance.
    Attached Files Attached Files

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Lookup failed for 'mail/myExampleSession' means you tried to lookup an object that was not bound in the JNDI tree with the name that you provided. Are you sure that resource exists on the server and is bound under that name?

  3. #3
    vietnamusa is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    Hi r035198x,

    I really don't know. I just followed the The async Example Application (page 468 of 908 from the javaeetutorial6.pdf).

    At page 470,
    Running the async Example Application in NetBeans
    IDE
    Follow these instructions for running the async example application inNetBeans IDE.
    Before running this example, you must configure your GlassFish Server instance to access the
    keystore and truststore used by GlassFish Server to create a secure connection to the target
    SMTPS server.
    Fromthe File menu, choose Open Project.
    In the Open Project dialog, navigate to:
    tut-install/examples/ejb/
    Select the async folder and click Open Project.
    Under async in the project pane, expand the Server Resources node and double-click
    glassfish-resources.xml.
    Enter the configuration settings for yourSMTPS server in glassfish-resources.xml.
    The SMTPS server host name is set in the host attribute, email address from which you want
    the message sent is the from attribute, the SMTPS user name is the user attribute. Set the
    mail-smtps-password property value to the password for the SMTPS server user. The
    following code snippet shows an example resource configuration. Lines in bold need to be
    modified.
    <resources>
    <mail-resource debug="false"
    enabled="true"
    from="user@example.com"
    host="smtp.example.com"
    jndi-name="mail/myExampleSession"
    object-type="user" store-protocol="imap"
    store-protocol-class="com.sun.mail.imap.IMAPStore"
    transport-protocol="smtps"
    transport-protocol-class="com.sun.mail.smtp.SMTPSSLTransport"
    user="user@example.com">
    <description/>
    <property name="mail-smtps-auth" value="true"/>
    <property name="mail-smtps-password" value="mypassword"/>
    </mail-resource>
    </resources>
    Right-click async in the project pane and select Run.
    This will compile, assemble, and deploy the application, and start a web browser at the
    following URL: http://localhost:8080/async.

    So I changed the from, host, user, and mail-smtps-password. The zip file that I attached is the entire project. Please unzip it and view it to see if I missed any thing.

    Thank you

  4. #4
    vietnamusa is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    /*
    * Copyright 2011 Oracle and/or its affiliates.
    * All rights reserved. You may not modify, use,
    * reproduce, or distribute this software except in
    * compliance with the terms of the License at:
    * License
    */


    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package async.ejb;

    import java.text.DateFormat;
    import java.util.Date;
    import java.util.concurrent.Future;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.annotation.Resource;
    import javax.ejb.AsyncResult;
    import javax.ejb.Asynchronous;
    import javax.ejb.Stateless;
    import javax.inject.Named;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeMessage;


    /**
    *
    * @author ievans
    */
    @Named
    @Stateless
    public class MailerBean {
    private static final Logger logger = Logger.getLogger("async.ejb.MailerBean");

    @Resource(name = "mail/myExampleSession")
    private Session session;

    @Asynchronous
    public Future<String> sendMessage(String email) {
    String status;

    try {
    Message message = new MimeMessage(session);
    message.setFrom();
    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email, false));
    message.setSubject("Test message from async example");
    message.setHeader("X-Mailer", "JavaMail");

    DateFormat dateFormatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT);
    Date timeStamp = new Date();
    String messageBody = "This is a test message from the async example "
    + "of the Java EE Tutorial. It was sent on "
    + dateFormatter.format(timeStamp) + ".";
    message.setText(messageBody);
    message.setSentDate(timeStamp);
    Transport.send(message);
    status = "Sent";
    logger.log(Level.INFO, "Mail sent to {0}", email);
    } catch (MessagingException ex) {
    logger.severe("Error in sending message.");
    status = "Encountered an error";
    logger.severe(ex.getCause().getMessage());
    }

    return new AsyncResult<String>(status);
    }
    }

  5. #5
    vietnamusa is offline Member
    Join Date
    Dec 2010
    Posts
    8
    Rep Power
    0

    Default

    I got it.

    The async example of the tutorial provides glassfish-resources.xml. I changed it to sun-resources.xml and it works now.

    Thank you

Similar Threads

  1. javax.mail
    By sashaxiv in forum Advanced Java
    Replies: 2
    Last Post: 06-08-2011, 12:37 PM
  2. Javax-ws
    By gold.dudu in forum Advanced Java
    Replies: 1
    Last Post: 09-19-2010, 07:19 PM
  3. javax.microedition.io/ javax.bluetooth
    By ahtiven in forum New To Java
    Replies: 3
    Last Post: 01-13-2009, 03:54 PM
  4. map javax.swing.text.Element to javax.swing.text.View
    By elizabeth in forum New To Java
    Replies: 1
    Last Post: 07-30-2007, 08:02 PM
  5. javax.net.ssl.SSLHandshakeException:
    By bbq in forum Enterprise JavaBeans (EJB)
    Replies: 3
    Last Post: 07-18-2007, 04:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •