Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ejb3 application client can't find session bean. Error: Exception in thread "main" java.lang.Asserti  RSS feed

 
Aruna Bhamidipati
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying a simple EJB client. I developed a simple EJB session bean (CartBean) with remote and local interfaces in Eclipse. I created an EAR project and deployed them to weblogic server.
After deploying to weblogic server I can see the ejb in JNDI tree.

Then I developed an application client CartClient in another project. In the client, after getting the initial context, It's throwing ClassNotFoundException. It seems lookup is successful. But it's giving ClassNotFoundException exception. Please help. Attached the code. Following is the error

Check 1
Check 1.1: Got initial Context
Exception in thread "main" java.lang.AssertionError: java.lang.ClassNotFoundException: com.ejb.CartBeanRemote
at weblogic.ejb.container.internal.RemoteBusinessIntfGenerator.generateRemoteInterface(RemoteBusinessIntfGenerator.java:57)
at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.readObject(RemoteBusinessIntfProxy.java:205)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:197)
at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:564)
at weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:193)
at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:62)
at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:240)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:348)
at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:259)
at weblogic.jndi.internal.ServerNamingNode_1030_WLStub.lookup(Unknown Source)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:392)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:380)
at javax.naming.InitialContext.lookup(Unknown Source)
at cart.client.CartBeanClient.main(CartBeanClient.java:42)
Caused by: java.lang.ClassNotFoundException: com.ejb.CartBeanRemote
at weblogic.ejb.container.deployer.RemoteBizIntfClassLoader.getClassBytes(RemoteBizIntfClassLoader.java:151)
at weblogic.ejb.container.deployer.RemoteBizIntfClassLoader.loadClass(RemoteBizIntfClassLoader.java:96)
at weblogic.ejb.container.internal.RemoteBusinessIntfGenerator.generateRemoteInterface(RemoteBusinessIntfGenerator.java:54)
... 26 more

----------
**************************CartBean.java**************************
package com.ejb;

import javax.ejb.Stateless;
import com.util.BookException;
import com.util.IdVerifier;
import javax.ejb.Remove;
import java.util.List;
import java.util.ArrayList;


/**
* Session Bean implementation class CartBean
*/
@Stateless(mappedName="CartBean")
public class CartBean implements CartBeanRemote, CartBeanLocal {

public String customerName;
public String customerId;
public List<String> contents;

/**
* Default constructor.
*/
public CartBean() {
// TODO Auto-generated constructor stub
}
public void initialize(String person) throws BookException{
if(person == null){
throw new BookException("Person can't be null");
}else {
customerName = person;
}
customerId = "0";

contents = new ArrayList<String>();
}

public void initialize(String person, String Id) throws BookException{
if(person == null){
throw new BookException("Person can't be Null");
}else{
customerName = person;
}

IdVerifier verifier = new IdVerifier();
if( verifier.validate(Id) == false){
throw new BookException("Id can't be Null");
}else{
customerId = Id;
}

contents = new ArrayList<String>();

}

public void addItem(String title){
System.out.println("dummy");
contents.add(title);
}

public void removeItem (String title) throws BookException{
boolean result = contents.remove(title);
if(result == false){
throw new BookException(title + " does not exists in the list") ;
}
}
@Remove
public void remove(){
contents = null;
}
}



**************************CartBeanRemote.java**************************

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

import com.util.BookException;

@Remote
public interface CartBeanRemote {
public void initialize(String person) throws BookException;

public void initialize(String person, String Id) throws BookException;

public void addItem(String title);

public void removeItem (String title) throws BookException;
public void remove();
//This is remote interface.
}



**************************CartBeanLocal.java**************************

package com.ejb;
import javax.ejb.Local;

import com.util.BookException;

@Local
public interface CartBeanLocal {

public void initialize(String person) throws BookException;
public void initialize(String person, String Id) throws BookException;
public void addItem(String title);
public void removeItem (String title) throws BookException;
public void remove();
}




**************************CartBeanClient.java**************************

package cart.client;

import com.ejb.*;
import com.util.*;
import java.util.Hashtable;

import javax.naming.InitialContext;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.ejb.EJB;
//import com.ejb.CartBean;

public class CartBeanClient {

public CartBeanClient() {
// TODO Auto-generated constructor stub
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//CartBeanClient cartBeanClient = new CartBeanClient();
Context ctx = null;
CartBeanRemote cartBeanRemote;
Hashtable ht = new Hashtable();
String msg;


ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://localhost:7001");
ht.put(Context.SECURITY_PRINCIPAL, "weblogic");
ht.put(Context.SECURITY_CREDENTIALS, "weblogic123");

try{
System.out.println("Check 1" );
msg = "Getting the initial context";
ctx = new InitialContext(ht);
System.out.println("Check 1.1: Got initial Context");
msg = "Looking up Cart Bean";
cartBeanRemote = (CartBeanRemote) ctx.lookup("CartBean#com.ejb.CartBeanRemote");
//cartBeanClient.cartBeanRemote.addItem("Arun");
System.out.println("Check 1.2");
msg = "got the Cart Bean";
}catch(NamingException e){
//System.out.println("msg: " + msg);
e.printStackTrace();
}

}

}

******************************BookException.java***************************************
package com.util;

public class BookException extends Exception{

public BookException() {
// TODO Auto-generated constructor stub
}
public BookException(String msg) {
// TODO Auto-generated constructor stub
super(msg);
}
}

******************************IdVerifier.java***************************************
package com.util;

public class IdVerifier {

public IdVerifier() {
// TODO Auto-generated constructor stub
}
public boolean validate(String id){
boolean result = true;
for(int i=0; i < id.length(); i++){
if(Character.isDigit(id.charAt(i) ) == false){
result = false;
return result;
}
}
return result;
}
}


--------
Thanks
 
Andrew Moko
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to check your project structure. Your ejbs are under package com.ejb and your client is under cart.client. Also, CartBeanRemote is not being imported on the client class??

There MUST BE a CartBeanRemote reference (with the exact same declaration) upon which the lookup/ proxied bean will be mapped.

PS: It's end of year and i have all the time to answer all questions on the message board
 
Aruna Bhamidipati
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew ,

Thanks for looking into this.

The classes are in correct packages.

Also client is importing cart.ejb.* which have both remote and bean classes.

I first created an ejb3 project, added local, remote interfaces, and then the session bean.

Then I created a java project for client. In the client project I imported all the interfaces and classes also. In the client I created initial context, and trying to look up the remote interface. If I mis type the remote interace name it gives Name not resolved error as given below.

Check 1
Check 1.1: Got initial Context
javax.naming.NameNotFoundException: Unable to resolve 'CartBean#com.ejb.CartBeanRemot'. Resolved 'CartBean#com.ejb' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'CartBean#com.ejb.CartBeanRemot'. Resolved 'CartBean#com.ejb']; remaining name 'CartBeanRemot'

BUT if I use correct name, then I am getting error which I have posted in my initial question. If you search with second line in the error you can see posts saying it's an known bug
Please google this

at weblogic.ejb.container.internal.RemoteBusinessIntfGenerator.generateRemoteInterface(RemoteBusinessIntfGenerator.java:57)

you would get following links
https://cn.forums.oracle.com/forums/thread.jspa?threadID=939241
https://forums.oracle.com/forums/thread.jspa?threadID=839694

Not sure if it's still problem or not.

Thanks,
Arun
 
Mr sujeet khandelwal
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi,

In EJB3, at client we use only
@EJB
CartBeanRemote CartBean;

That only would be enough to look up EJB.

Cheers.
 
Andrew Moko
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tip:
Login to the weblogic console. Navigate to server -> view jndi tree. Checkout for CartBeanRemote and the corresponding binding name.

Also create a package called com.ejb on your client 'workspace'. Copy the CartBeanRemote interface on the newly created package. As opposed to importing from the com.ejb package.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!