Procrastinator
Procrastinator

Reputation: 89

EJB 3.0 lookup in Weblogic 10.3.0

1: Our application runs on Weblogic Application Server,version 10.3.0

2: In our system,we need to deploy an EJB conforming to the EJB 3.0 specification.

Please find the sample code for our UAT environment as below :

/*The remote interface*/

package com.serverside.ejb.session;
import javax.ejb.Remote;

@Remote
public interface ASimpleSessionBeanRemote { 

 public void printThis(String print);

}


/*The bean class*/

package com.serverside.ejb.session;

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

/**
 * Session Bean implementation class ASimpleSessionBean
 */
@Stateless(name="ASimpleSessionBean", **mappedName = "ASimpleSessionEJB"**)
@Remote(ASimpleSessionBeanRemote.class)
public class ASimpleSessionBean implements ASimpleSessionBeanRemote {

    /**
     * Default constructor. 
     */
    public ASimpleSessionBean() {
        // TODO Auto-generated constructor stub
    }

 @Override
 public void printThis(String print) {
  // TODO Auto-generated method stub
  System.out.println("ASimpleSessionBean : "+print); 
 }

}

3: The above files when packaged in jar get deployed on the server successfully.

4: As per EJB 3.0 specification,the deployement descriptors are not mandatory.Hence,the jar doesn't include ejb-jar.xml and weblogic-ejb-jar.xml

5: Please find below,the EJB3.0 annotations reference as per the Weblogic Application Server Documentation :

Annotation : @Stateless

Package: javax.ejb.Stateless

Attribute : mappedName

Description : 

Specifies the product-specific name to which the stateless session bean should be mapped.
You can also use this attribute to specify the JNDI name of this stateless session bean. WebLogic Server uses the value of the mappedName attribute when creating the bean’s global JNDI name. In particular, the JNDI name will be:
mappedName#name_of_businessInterface
where name_of_businessInterface is the fully qualified name of the business interface of this session bean.
For example, if you specify mappedName="bank" and the fully qualified name of the business interface is com.CheckingAccount, then the JNDI of the business interface is bank#com.CheckingAccount.

6: Conforming to the above specification, the sample EJB deployed on our application server has the binding name(as reflected in the jndi tree) as follows :

ASimpleSessionEJB#com.serverside.ejb.session.ASimpleSessionBeanRemote

A jndi lookup using this name succeeds :

InitialContext.doLookup("ASimpleSessionEJB#com.serverside.ejb.session.ASimpleSesionBeanRemote");

7: Now,we want the binding name to be a simple string i.e the lookup must be something like :

InitialContext.doLookup("ASimpleSessionEJB");

8: To implement point-7,we tried using the ejb-jar.xml and weblogic-ejb-jar.xml as follows(Sorry,couldn't figure out how to attach/render xml files):

9: Inspite of the point-8,the binding name remains as follows :

ASimpleSessionEJB#com.serverside.ejb.session.ASimpleSessionBeanRemote

10: Please guide us about the solution and implementation to attend point-7.

Thanks !

Upvotes: 1

Views: 11914

Answers (3)

Vahid Sadeghi
Vahid Sadeghi

Reputation: 115

This is a sample configuration of weblogic-ejb-jar.xml

<wls:weblogic-enterprise-bean>      
     <wls:ejb-name>BasketBean</wls:ejb-name>            
     <wls:jndi-name>BasketBean</wls:jndi-name>
</wls:weblogic-enterprise-bean>

Then you can make jndi lookup like this : InitialContext.doLookup("BasketBean");

Upvotes: 1

mezmo
mezmo

Reputation: 2480

In the weblogic-ejb-jar.xml you should be able to add the weblogic-enterprise-bean section with a jndi-name section. This worked perfectly for me on Weblogic versions 10.3.1, 10.3.3, and 10.3.4. I'm running into an issue on 10.3.0. The ejb seems to deploy fine, and the jndi entry is there, but when I try to call it I'm getting that it can't find the bean class. Not sure what is causing that, but hopefully the jndi-name section will do if for you.

Good Luck.

Upvotes: 0

JSS
JSS

Reputation: 2201

Can you somehow paste your weblogic-ejb.xml? Atleast name element.

Can you also specify where you running this lookup code? I hope it's running inside the web container else you won't see the weblogic-ejb.xml. :)

If nothing helps why don't you just create a properties file where you can specify your key and a long remote name and then just use that key to lookup?

Cheers.

JS

Upvotes: 0

Related Questions