Avatar of gudii9
gudii9
Flag for United States of America asked on

remote vs local ejb

Hi,

what is the difference between remote vs local ejb. When to use which one and advantages, disadvantages, practical uses of each.

I am trying below example and author choose remote here which is not clear
http://www.ejbtutorial.com/j2ee/hello-word-tutorial-for-writing-stateless-session-enterprise-java-bean-ejb
As given below i created java project to access above ejb as jar

i included above ejb jar in build path i still get compilation error while recognizing Addition class and AdditionRemote interface as attached.

please advise on how to fix i9tremoteplease advise
build.png
JavaJava EEJSPXMLWeb Services

Avatar of undefined
Last Comment
gudii9

8/22/2022 - Mon
gudii9

ASKER
when i took import those errors are gone but when i run as java application getting below error

please advise

Hello From Java!
Mar 28, 2017 10:58:45 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.4.0.Final
Mar 28, 2017 10:58:45 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.4.0.Final
Mar 28, 2017 10:58:46 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.21.Final
ejb:/MyAdditionEJB//Addition!com.mylogic.AdditionRemote
Mar 28, 2017 10:58:46 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.1.4.Final
java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:MyAdditionEJB, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@cc285f4
      at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798)
      at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128)
      at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
      at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
      at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
      at com.sun.proxy.$Proxy2.add(Unknown Source)
      at StartCalc.main(StartCalc.java:34)


final error is

Hello From Java!
Mar 28, 2017 11:00:21 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.4.0.Final
Mar 28, 2017 11:00:21 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.4.0.Final
Mar 28, 2017 11:00:21 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.21.Final
ejb:/MyAdditionEJB//Addition!com.mylogic.AdditionRemote
Mar 28, 2017 11:00:21 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.1.4.Final
java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:MyAdditionEJB, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@cc285f4
      at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798)
      at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128)
      at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
      at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
      at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
      at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
      at com.sun.proxy.$Proxy2.add(Unknown Source)
      at StartCalc.main(StartCalc.java:33)



final java file is
import java.util.*;
import javax.naming.*;
import com.mylogic.Addition;
import com.mylogic.AdditionRemote;

import javax.ejb.*;
 
public class StartCalc {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try{
 
			System.out.println("Hello From Java!");
		    Properties props = new Properties();
	        props.put("java.naming.factory.url.pkgs","org.jboss.ejb.client.naming");
	        props.put("java.naming.factory.initial","org.jboss.naming.remote.client.InitialContextFactory");
	        props.put("java.naming.provider.url","remote://127.0.0.1:4447");
	        props.put("jboss.naming.client.ejb.context","true");
	        props.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");
	        InitialContext context = new InitialContext(props);
 
	        String appName = "";        	 
	        String moduleName = "MyAdditionEJB";
	        String distinctName = "";        	 
	        String beanName = Addition.class.getSimpleName();        	 
	        String interfaceName = AdditionRemote.class.getName();
	        String name = "ejb:" + appName + "/" + moduleName + "/" +  distinctName    + "/" + beanName + "!" + interfaceName;
	        System.out.println(name);
	        AdditionRemote bean = (AdditionRemote)context.lookup(name);
	        int result=bean.add(4,6);
	        System.out.println("Result computed by EJB is :"+result); 	        
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}

Open in new window

ASKER CERTIFIED SOLUTION
gudii9

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
gudii9

ASKER
please advise
gudii9

ASKER
please advise
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck