We help IT Professionals succeed at work.

remote vs local ejb

gudii9
gudii9 asked
on
337 Views
Last Modified: 2017-10-02
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
Comment
Watch Question

Author

Commented:
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

Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
please advise

Author

Commented:
please advise