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
LVL 7
gudii9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gudii9Author 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

0
gudii9Author Commented:
http://www.ejbtutorial.com/j2ee/tutorial-of-how-to-call-enterprise-java-beans-ejb-from-a-java-servlet-injecting-ejb-into-servlet

i tried above as well
http://localhost:8180/WebCaculator/doadd?a=1&b=3&bt=Submit

when i gave 1 and 3 as A and B values
 getting error



Error processing request

Context Path:

/WebCaculator


Servlet Path:

/doadd


Path Info:

null


Query String:

a=1&b=3&bt=Submit

Stack Trace
javax.servlet.ServletException: UT010013: Could not instantiate com.logic.doadd
io.undertow.servlet.core.ManagedServlet$DefaultInstanceStrategy.start(ManagedServlet.java:247)
io.undertow.servlet.core.ManagedServlet.getServlet(ManagedServlet.java:171)
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:84)
io.undertow.servlet.handlers.security.ServletSecurityRoleHandler.handleRequest(ServletSecurityRoleHandler.java:62)
io.undertow.servlet.handlers.ServletDispatchingHandler.handleRequest(ServletDispatchingHandler.java:36)
org.wildfly.extension.undertow.security.SecurityContextAssociationHandler.handleRequest(SecurityContextAssociationHandler.java:78)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.security.SSLInformationAssociationHandler.handleRequest(SSLInformationAssociationHandler.java:131)
io.undertow.servlet.handlers.security.ServletAuthenticationCallHandler.handleRequest(ServletAuthenticationCallHandler.java:57)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.security.handlers.AbstractConfidentialityHandler.handleRequest(AbstractConfidentialityHandler.java:46)
io.undertow.servlet.handlers.security.ServletConfidentialityConstraintHandler.handleRequest(ServletConfidentialityConstraintHandler.java:64)
io.undertow.security.handlers.AuthenticationMechanismsHandler.handleRequest(AuthenticationMechanismsHandler.java:60)
io.undertow.servlet.handlers.security.CachedAuthenticatedSessionHandler.handleRequest(CachedAuthenticatedSessionHandler.java:77)
io.undertow.security.handlers.NotificationReceiverHandler.handleRequest(NotificationReceiverHandler.java:50)
io.undertow.security.handlers.AbstractSecurityContextAssociationHandler.handleRequest(AbstractSecurityContextAssociationHandler.java:43)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
org.wildfly.extension.undertow.security.jacc.JACCContextIdHandler.handleRequest(JACCContextIdHandler.java:61)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.server.handlers.PredicateHandler.handleRequest(PredicateHandler.java:43)
io.undertow.servlet.handlers.ServletInitialHandler.handleFirstRequest(ServletInitialHandler.java:292)
io.undertow.servlet.handlers.ServletInitialHandler.access$100(ServletInitialHandler.java:81)
io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:138)
io.undertow.servlet.handlers.ServletInitialHandler$2.call(ServletInitialHandler.java:135)
io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:48)
io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.api.LegacyThreadSetupActionWrapper$1.call(LegacyThreadSetupActionWrapper.java:44)
io.undertow.servlet.handlers.ServletInitialHandler.dispatchRequest(ServletInitialHandler.java:272)
io.undertow.servlet.handlers.ServletInitialHandler.access$000(ServletInitialHandler.java:81)
io.undertow.servlet.handlers.ServletInitialHandler$1.handleRequest(ServletInitialHandler.java:104)
io.undertow.server.Connectors.executeRootHandler(Connectors.java:202)
io.undertow.server.HttpServerExchange$1.run(HttpServerExchange.java:805)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
sum.png
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gudii9Author Commented:
please advise
0
gudii9Author Commented:
please advise
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.