Caros,
duvida referente a chamada metodo via Local pois não estou conseguindo chamar
e fiz conforme abaixo mas acho que está errado …
Alguém poderia me dar uma ajuda da forma correta …
abs
public void imprimeLocal() throws ClassNotFoundException, InstantiationException, IllegalAccessException, CreateException, NamingException, RemoteException {
CalculadoraBean cal = new CalculadoraBean();
System.out.println(cal.soma(2000, 2000));
}
--main
public class TesteCalculadora {
private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();
props.put(InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
InitialContext initialContext = new InitialContext(props);
return initialContext;
}
private CalculadoraLocalHome getHome1() throws NamingException, ClassNotFoundException, InstantiationException, IllegalAccessException {
CalculadoraLocalHome result;
Hashtable props = new Hashtable();
props.put(InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
InitialContext initialContext = new InitialContext(props);
result = (CalculadoraLocalHome)initialContext.lookup("CalculadoraLocal");
return result;
}
public void imprimeRemoto() throws ClassNotFoundException, InstantiationException, IllegalAccessException, CreateException, NamingException, RemoteException {
Calculadora cal = getHome().create();
System.out.println(cal.soma( 2008 , -1968));
}
public void imprimeLocal() throws ClassNotFoundException, InstantiationException, IllegalAccessException, CreateException, NamingException, RemoteException {
CalculadoraBean cal = new CalculadoraBean();
System.out.println(cal.soma(2000, 2000));
}
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, RemoteException, CreateException, NamingException {
TesteCalculadora teste = new TesteCalculadora();
teste.imprimeLocal();
}
}
--
package aplicacao;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
public interface Calculadora extends EJBObject {
public Integer soma(Integer v1, Integer v2) throws RemoteException;
}
--
public class CalculadoraBean implements SessionBean {
public CalculadoraBean() {
// TODO Auto-generated constructor stub
}
@Override
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
@Override
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
@Override
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
@Override
public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
// TODO Auto-generated method stub
}
public void ejbCreate() throws CreateException{}
public Integer soma(Integer v1, Integer v2 ){
return v1+v2;
}
}
--
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface CalculadoraHome extends EJBHome {
public Calculadora create() throws CreateException, RemoteException;
}
--
public interface CalculadoraLocal extends EJBLocalObject {
public Integer soma(Integer v1, Integer v2) ;
}
--
public interface CalculadoraLocalHome extends EJBLocalHome {
public CalculadoraLocal create() throws CreateException ;
}
--ejb-jar.xml
<ejb-jar >
<description><![CDATA[Sem Descricao.]]></description>
<display-name>Gerado pelo XDoclet</display-name>
<enterprise-beans>
<!-- Session Beans -->
<session >
<description><![CDATA[]]></description>
<ejb-name>Calculadora</ejb-name>
<home>aplicacao.CalculadoraHome</home>
<remote>aplicacao.Calculadora</remote>
<local-home>aplicacao.CalculadoraLocalHome</local-home>
<local>aplicacao.CalculadoraLocal</local>
<ejb-class>aplicacao.CalculadoraBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor > </assembly-descriptor>
</ejb-jar>
--jboss.jar
<jboss>
<unauthenticated-principal>nobody</unauthenticated-principal>
<enterprise-beans>
<session>
<ejb-name>Calculadora</ejb-name>
<jndi-name>Calculadora</jndi-name>
<local-jndi-name>CalculadoraLocal</local-jndi-name>
</session>
</enterprise-beans>
<resource-managers> </resource-managers>
</jboss>
--main
public class TesteCalculadora {
private InitialContext getContext() throws NamingException {
Hashtable props = new Hashtable();
props.put(InitialContext.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
InitialContext initialContext = new InitialContext(props);
return initialContext;
}
private CalculadoraLocalHome getHome1() throws NamingException, ClassNotFoundException, InstantiationException, IllegalAccessException {
CalculadoraLocalHome result;
result = (CalculadoraLocalHome) getContext().lookup("CalculadoraLocal");
return result;
}
public void imprime() throws ClassNotFoundException, InstantiationException, IllegalAccessException, CreateException, NamingException, RemoteException {
Calculadora cal = (Calculadora) getHome1().create();
System.out.println(cal.soma( 2008 , -1968));
}
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, RemoteException, CreateException, NamingException {
TesteCalculadora teste = new TesteCalculadora();
teste.imprime();
}
}
--
package aplicacao;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
public interface Calculadora extends EJBObject {
public Integer soma(Integer v1, Integer v2) throws RemoteException;
}
--
public class CalculadoraBean implements SessionBean {
public CalculadoraBean() {
// TODO Auto-generated constructor stub
}
@Override
public void ejbActivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
@Override
public void ejbPassivate() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
@Override
public void ejbRemove() throws EJBException, RemoteException {
// TODO Auto-generated method stub
}
@Override
public void setSessionContext(SessionContext arg0) throws EJBException,
RemoteException {
// TODO Auto-generated method stub
}
public void ejbCreate() throws CreateException{}
public Integer soma(Integer v1, Integer v2 ){
return v1+v2;
}
}
--
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface CalculadoraHome extends EJBHome {
public Calculadora create() throws CreateException, RemoteException;
}
--
public interface CalculadoraLocal extends EJBLocalObject {
public Integer soma(Integer v1, Integer v2) ;
}
--
public interface CalculadoraLocalHome extends EJBLocalHome {
public CalculadoraLocal create() throws CreateException ;
}
--ejb-jar.xml
<ejb-jar >
<description><![CDATA[Sem Descricao.]]></description>
<display-name>Gerado pelo XDoclet</display-name>
<enterprise-beans>
<!-- Session Beans -->
<session >
<description><![CDATA[]]></description>
<ejb-name>Calculadora</ejb-name>
<home>aplicacao.CalculadoraHome</home>
<remote>aplicacao.Calculadora</remote>
<local-home>aplicacao.CalculadoraLocalHome</local-home>
<local>aplicacao.CalculadoraLocal</local>
<ejb-class>aplicacao.CalculadoraBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor > </assembly-descriptor>
</ejb-jar>
--jboss.jar
<jboss>
<unauthenticated-principal>nobody</unauthenticated-principal>
<enterprise-beans>
<session>
<ejb-name>Calculadora</ejb-name>
<jndi-name>Calculadora</jndi-name>
<local-jndi-name>CalculadoraLocal</local-jndi-name>
</session>
</enterprise-beans>
<resource-managers> </resource-managers>
</jboss>