Skip to main content

Attempt to invoke when Ejb container is in Initializing

5 replies [Last post]
e3133d3
Offline
Joined: 2008-09-16
Points: 0

My application has 2 components - the Ejb and a Resource adapter.
When I start glassfish, once the resource adapter is initialized it invokes an Ejb method.
Sometimes I'm getting the javax.ejb.EJBException: Attempt to invoke when container is in Initializing.

Is there a way to retrieve the Ejb container state?

Here is the exception:

javax.ejb.EJBException: Attempt to invoke when container is in Initializing
at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1193)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:202)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:120)
at $Proxy23.updatePeerState(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)

Thanks,

Edo

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tsmets
Offline
Joined: 2005-05-04
Points: 0

Any news on this ... ?
I seem to have hit the same issue : https://www.java.net//forum/topic/glassfish/glassfish/oracle-glassfish-s...

Also the embedded server API's are nowhere to be found (for version 3.1.2).
I modified my example into :

package myApp.server;

import java.io.File;

import org.glassfish.embeddable.Deployer;
import org.glassfish.embeddable.GlassFish;
import org.glassfish.embeddable.GlassFishProperties;
import org.glassfish.embeddable.GlassFishRuntime;

/**
*
*
*/
public class StartServerMain {

/**
* @param args
*/
public static void main(String[] args) throws Exception {

    System.out.println("Starting");
    File configFile = new File ("/Applications/servers/glassfish3.1/glassfishv3/glassfish/glassfishv3/glassfish/domains/domain1/config/domain.xml");
        File war = new File("./target/myApp.war");
        GlassFishRuntime glassfishRuntime = GlassFishRuntime.bootstrap();
       
        GlassFishProperties glassfishProperties = new GlassFishProperties();
        System.out.println("URI : '" + configFile.toURI().toString() + "'");
        glassfishProperties.setConfigFileURI(configFile.toURI().toString());    //setConfigFileURI(configFile.toURI());
       
        glassfishProperties.setConfigFileReadOnly(true);  // was false
       
        GlassFish gf = glassfishRuntime.newGlassFish(glassfishProperties);
        gf.start();
       
        Deployer deployer = gf.getDeployer();
        deployer.deploy(war, "--force=true");
       
        int i = 0;
        do
        {
        System.out.println(i++ +  " : Status : '" + gf.getStatus() + "'.");
        Thread.sleep(2000);
        } while (i<20);

        gf.dispose();
        gf.stop();
        glassfishRuntime.shutdown();
}
}

I get from the first iteration of the loop :

0 : Status : 'STARTED'.
1 : Status : 'STARTED'.
2 : Status : 'STARTED'.

So I believe I should see something like INIT instead (tx to code suggestion).

\T,

tsmets
Offline
Joined: 2005-05-04
Points: 0

Using the code sample from docs.oracle.com/cd/E18930_01/html/821-2424/gjlde.html#scrolltoc, I managed to use the Standart API for my UT.

public class InitActionWithEmbeddedContainerTest {
   
    public static EJBContainer ejbContainer;
    public static Context ctx;
    public InitAction action;
   
   
    public InitActionWithEmbeddedContainerTest()
    {
       
    }
   
   
    @Test
    public void callExecute() throws Exception {
       action.setLang("EN");
       action.setRequest("aa");
       action.validate();
       action.execute();
    }
   
    @BeforeClass
    public static void setUpClass() throws Exception {
    Properties props = new Properties();
    props.load(InitActionTest.class.getClassLoader().getResourceAsStream("EJBContainer.properties"));
    System.out.println("Properties :\n" + props);
        ejbContainer = EJBContainer.createEJBContainer(props);
        System.out.println("Starting the container");
        ctx = ejbContainer.getContext();
    }
   
    @AfterClass
    public static void tearDownClass() {
        ejbContainer.close();
         System.out.println("Closing the container");
    }
   
    @Before
    public void setUp() throws Exception {
        action = new InitAction();
        action.prepare();
    }
   
    @After
    public void tearDown() {
    }
}

The file EJBContainer.properties contains the keys as specified in the Oracle documentation. but it seems that my datasource is not created correctly :
SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
java.lang.RuntimeException: Invalid resource : jdbc/myDS__pm
at com.sun.enterprise.connectors.ConnectorRuntime.lookupDataSourceInDAS(ConnectorRuntime.java:539)
at com.sun.enterprise.connectors.ConnectorRuntime.lookupPMResource(ConnectorRuntime.java:468)
at...

...


Jul 18, 2013 01:30:28 AM org.glassfish.deployment.admin.DeployCommand execute
SEVERE: Exception while preparing the app : Invalid resource : jdbc/myDS__pm
com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : jdbc/myDS__pm
at com.sun.enterprise.connectors.service.ConnectorResourceAdminServiceImpl$MyDataSource.validateResource(ConnectorResourceAdminServiceImpl.java:272)
at com.sun.enterprise...

...

PlainTextActionReporterFAILUREDescription: deploy AdminCommandError occurred during deployment: Exception while preparing the app : Invalid resource : jdbc/myApp__pm. Please see server.log for more details.
    [name=classes
Jul 18, 2013 01:30:34 AM org.glassfish.ejb.embedded.EJBContainerProviderImpl createEJBContainer
INFO: [EJBContainerProviderImpl] Cleaning up on failure ...
...

Now one of the reason, I can imagine is that the hsqldb.jar may not be available in the classpath ... ? ? ?
Thought present in the ${instance.root}/lib, as I successfully use the instance for my full size testing

Incidently ...
Where is the server.log written ... ?

\T,

mvatkina
Offline
Joined: 2005-04-04
Points: 0

Embedded container is a Java SE application, so it needs all extra dependencies on the classpath. All GlassFish modules are added to the classpath by the gf-client.jar manifest.

A temporary instance is created either in the java.io.temp dir or in the local dir.

HTH,
-marina

tsmets
Offline
Joined: 2005-05-04
Points: 0

So this means that the following dependency

        <dependency>
            <groupId>org.glassfish.extras</groupId>
            <artifactId>glassfish-embedded-all</artifactId>
            <version>${glassfish-embedded-all.version}</version>
            <scope>test</scope>
        </dependency>

(as indicated in http://mvnrepository.com/artifact/org.glassfish.extras/glassfish-embedde...)

should be replaced by

  <dependency>
            <groupId>org.glassfish.appclient</groupId>
            <artifactId>gf-client</artifactId>
            <version>${glassfish-embedded-all.version}</version>
            <scope>test</scope>         
        </dependency>

?

Property : glassfish-embedded-all.version = 3.1 or glassfish-embedded-all.version = 3.2-b06

I don't know to whom I should report that it raises issue on JDK 1.7 (I believe) ?

[ERROR] Failed to execute goal on project MyProject: Could not resolve dependencies for project com.myCompany:MyProject:war:1.0-SNAPSHOT: Could not find artifact com.sun:tools:jar:1.6.0 at specified path /Library/Java/JavaVirtualMachines/jdk1.7.0_21.jdk/Contents/Home/jre/../Classes/classes.jar -> [Help 1]

(I am running on Mac ... if you did not noticed :) )

\T,

mvatkina
Offline
Joined: 2005-04-04
Points: 0

I meant your regular classpath. Maven dependencies are different. See if http://docs.oracle.com/cd/E26576_01/doc.312/e24932/toc.htm helps.