3
votes

I use WebLogic Server 10.3.5.0 and I experienced no problems using EJB 2.x on it, but I want to deploy EJB3 and it does not work. I'm new to java ee , but I read a lot of information, I didn't find the answer. What I try: 1. Create my simple Calculator application

package test;

import javax.ejb.Remote;
import java.lang.annotation.*;


@Remote
public interface Calculator {


    public int add(int x, int y);
}


package test;


import javax.ejb.Stateless;
import javax.ejb.Remote; 



@Stateless(name="CalculatorBean", mappedName="EJBCalculatorBean")
@Remote(Calculator.class)
public class CalculatorBean {

    public int add(int x, int y){
        return x + y;
    }

}

Here's my ejb-jar.xml:

<?xml version="1.0"?>


<ejb-jar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/j2ee/ejb-jar_3_0.xsd"
version="3.0" xmlns="http://java.sun.com/xml/ns/javaee">


  <enterprise-beans>


    <session>
      <ejb-name>Calculator</ejb-name>
      <remote>test.Calculator</remote>
      <ejb-class>test.CalculatorBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
  </enterprise-beans>

  <assembly-descriptor>


    <container-transaction>
        <method>
            <ejb-name>Calculator</ejb-name>
            <method-name>*</method-name>
        </method>
        <trans-attribute>NotSupported</trans-attribute>
    </container-transaction>
  </assembly-descriptor>

</ejb-jar>

and my weblogic-ejb-jar.xml:

<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC
'-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN'
'http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd'>

<weblogic-ejb-jar>


    <weblogic-enterprise-bean>
        <ejb-name>Calculator</ejb-name>
        <jndi-name>EJBCalculatorBean</jndi-name>
    </weblogic-enterprise-bean>



</weblogic-ejb-jar>

I also have a very simple application.xml. I packed it into an exploded EAR folder, then I installed it from the weblogic console. When I tried to "activate changes" it failed with the message that the server is missing the home interface.

  1. As far as I know EJB3 does not require home interface.
  2. In EJB3 I don't have to specify any ejb information into my descriptors. Annotation have to provide the information for the server.

Am I right? And what can be the problem?

I also tried to use appc tool but it also missed the home interface.

Thx in advance!

I cleaned up all EJB entries from my ejb-jar.xml and weblogic-ejb-jar.xml and finnaly it worked. The problem is that I cannot access my bean from client running on different JVM. Here's my client code:

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import test.Calculator;

public class Test {

    ;

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

        {
            try

            {
            Hashtable<String, String> env = new Hashtable<String, String>();
            env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
            env.put(Context.SECURITY_PRINCIPAL,"myuser");
            env.put(Context.SECURITY_CREDENTIALS, "mypassword");
            env.put(Context.PROVIDER_URL,"t3://myweblogic:7001");
            InitialContext ctx = new InitialContext(env);

            System.out.println("Initial Context created");

            Calculator calculator  = (Calculator)ctx.lookup("EJBCalculatorBean#test.Calculator");

            System.out.println("lookup successful");
            System.out.println("Calling EJB method . . .");
            System.out.println(calculator.add(3, 6));
            System.out.println("Output will be in Managed server console");
            }

            catch (Exception e)
            {
            e.printStackTrace();
            }

    }
    }
}

A have the wlclient.jar;javax.ejb.jar;calculator.jar on my classpath. calculator.jar is the one I deployed to the server(it contains the Calculator.class and theCalculatorBean.class) This client works fine when I run in the same JVM the weblogic uses, but in different JVM this error comes:

Caused by: java.lang.ClassNotFoundException
        ... 24 more
javax.naming.NamingException: Unhandled exception in lookup [Root exception is org.omg.CORBA.MARSHAL:   vmcid: SUN  minor code: 257 completed: Maybe]
        at weblogic.corba.j2ee.naming.Utils.wrapNamingException(Utils.java:83)
        at weblogic.corba.j2ee.naming.ContextImpl.lookup(ContextImpl.java:291)
        at weblogic.corba.j2ee.naming.ContextImpl.lookup(ContextImpl.java:227)
        at javax.naming.InitialContext.lookup(InitialContext.java:392)
        at Test.main(Test.java:37)

What can be the problem?

1
Have you tried CalculatorBean implement CalculatorNayan Wadekar
Thx Nayan, it was part of the solution.Mike82
@Mike82: When you say you "cleaned up all EJB entries" from ejb-jar.xml and weblogic-ejb-jar.xml, what exactly do you mean? Did you remove the bean declarations? Please give more detail – I am experiencing a similiar problem.Stephan B

1 Answers

1
votes

Weblogic 10.3.5 does support EJB3.

Did you try to call your SimpleCalculator bean from the Test window in the Console? This way you can verify that it works correctly.

W.r.t. deployment, just place the .ear file into the DOMAIN_HOMES/applications/my_domain/ folder and it will get deployed automatically, you do not have to go through the Console deployment every time.

After you test the SimpleCalculator bean in the console, you can then try the lookup, does it work this time?