|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Nov 2004
Messaggi: 409
|
[Java]: Client che richiama EJB
Ciao a tutti.
Sto cercando di imparare gli Enterprise Java Bean. Ho deployato un'applicazione con un ejb su Bea Weblogic. L'applicazione è composta dai seguenti file: Adder.java Codice:
package it.ejb.session; import java.rmi.RemoteException; import javax.ejb.EJBLocalObject; public interface Adder extends EJBLocalObject { public int add(int a, int b ); } Codice:
package it.ejb.session; import java.rmi.RemoteException; import javax.ejb.*; public interface AdderHome extends EJBLocalHome { Adder create() throws CreateException; } Codice:
package it.ejb.session; import java.rmi.RemoteException; import javax.ejb.EJBException; import javax.ejb.SessionBean; import javax.ejb.SessionContext; public class AdderBean implements SessionBean{ public void ejbActivate() throws EJBException, RemoteException { // TODO Auto-generated method stub } public void ejbCreate(){ } public void ejbPassivate() throws EJBException, RemoteException { // TODO Auto-generated method stub } public void ejbRemove() throws EJBException, RemoteException { // TODO Auto-generated method stub } public void setSessionContext(SessionContext arg0) throws EJBException, RemoteException { // TODO Auto-generated method stub } public int add ( int a, int b){ System.out.println("from AdderBean"); return a+b; } } ejb-jar.xml Codice:
<?xml version="1.0" encoding="UTF-8"?> <ejb-jar id="ejb-jar_1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" version="2.1"> <description>Example of a session bean</description> <display-name>Adder Bean</display-name> <enterprise-beans> <session> <description>Adder bean</description> <display-name>MyTimeBeanName</display-name> <ejb-name>AdderBean</ejb-name> <local-home>it.ejb.session.AdderHome</local-home> <local>it.ejb.session.Adder</local> <ejb-class>it.ejb.session.AdderBean</ejb-class> <session-type>Stateless</session-type> <transaction-type>Bean</transaction-type> </session> </enterprise-beans> </ejb-jar> Codice:
<!DOCTYPE weblogic-ejb-jar PUBLIC '-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN' 'http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd'> <weblogic-ejb-jar> <description>EJB che fa un addizione</description> <weblogic-enterprise-bean> <ejb-name>AdderBean</ejb-name> <stateless-session-descriptor> <pool> <max-beans-in-free-pool>10</max-beans-in-free-pool> </pool> </stateless-session-descriptor> <local-jndi-name>AdderBean</local-jndi-name> </weblogic-enterprise-bean> </weblogic-ejb-jar> A questo punto quando provo a richiamare un Ejb da un'applcazione Java standard ho questo errore: Codice:
javax.naming.CommunicationException [Root exception is java.rmi.UnmarshalException: failed to unmarshal class weblogic.security.acl.internal.AuthenticatedUser; nested exception is: java.io.StreamCorruptedException: invalid type code: 31] at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:74) at weblogic.jndi.internal.ExceptionTranslator.toNamingException(ExceptionTranslator.java:32) at weblogic.jndi.WLInitialContextFactoryDelegate.toNamingException(WLInitialContextFactoryDelegate.java:773) at weblogic.jndi.WLInitialContextFactoryDelegate.pushSubject(WLInitialContextFactoryDelegate.java:673) at weblogic.jndi.WLInitialContextFactoryDelegate.newContext(WLInitialContextFactoryDelegate.java:466) at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:373) at weblogic.jndi.Environment.getContext(Environment.java:307) at weblogic.jndi.Environment.getContext(Environment.java:277) at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:117) at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.init(Unknown Source) at javax.naming.InitialContext.<init>(Unknown Source) at it.ejb.session.PorvaEjb.main(PorvaEjb.java:30) Caused by: java.rmi.UnmarshalException: failed to unmarshal class weblogic.security.acl.internal.AuthenticatedUser; nested exception is: java.io.StreamCorruptedException: invalid type code: 31 at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:229) at weblogic.rmi.internal.BasicRemoteRef.invoke(BasicRemoteRef.java:224) at weblogic.common.internal.RMIBootServiceImpl_1001_WLStub.authenticate(Unknown Source) at weblogic.security.acl.internal.Security$1.run(Security.java:185) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363) at weblogic.security.service.SecurityManager.runAs(Unknown Source) at weblogic.security.acl.internal.Security.authenticate(Security.java:181) at weblogic.jndi.WLInitialContextFactoryDelegate.authenticateRemotely(WLInitialContextFactoryDelegate.java:734) at weblogic.jndi.WLInitialContextFactoryDelegate.pushSubject(WLInitialContextFactoryDelegate.java:667) ... 10 more Caused by: java.io.StreamCorruptedException: invalid type code: 31 at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:195) at weblogic.rjvm.MsgAbbrevInputStream.readObject(MsgAbbrevInputStream.java:565) at weblogic.utils.io.ChunkedObjectInputStream.readObject(ChunkedObjectInputStream.java:191) at weblogic.rmi.internal.ObjectIO.readObject(ObjectIO.java:62) at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:227) ProvaEjb.java Codice:
package it.ejb.session; import java.io.StreamCorruptedException; import java.util.Hashtable; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.rmi.PortableRemoteObject; public class PorvaEjb { public static void main(String[] args) { InitialContext ctx = null; try { Hashtable env = new Hashtable(); env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); env.put(Context.PROVIDER_URL, "t3://localhost:7001"); env.put(Context.SECURITY_PRINCIPAL, "giuseppe"); env.put(Context.SECURITY_CREDENTIALS, "giuseppe"); //ctx = new InitialContext(); //ctx. ctx = new InitialContext(env); }catch (NamingException e) { e.printStackTrace(); } try { Object obj = ctx.lookup("AdderBean"); if ( obj != null ){ AdderHome home = (AdderHome)PortableRemoteObject.narrow(obj, AdderHome.class); Adder adder = home.create(); System.out.println(adder.add(2, 5)); } }catch (Exception e) { e.printStackTrace(); } } } grazie, ciao
__________________
HU Queen Member Ultima modifica di mercury841 : 12-06-2008 alle 09:15. |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Nov 2004
Messaggi: 409
|
nessuno può aiutarmi?
__________________
HU Queen Member |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Nov 2004
Messaggi: 409
|
up
__________________
HU Queen Member |
![]() |
![]() |
![]() |
#4 |
Senior Member
Iscritto dal: Nov 2004
Messaggi: 409
|
up
__________________
HU Queen Member |
![]() |
![]() |
![]() |
#5 |
Senior Member
Iscritto dal: Nov 2004
Messaggi: 409
|
up
__________________
HU Queen Member |
![]() |
![]() |
![]() |
#6 |
Senior Member
Iscritto dal: Nov 2004
Messaggi: 409
|
ho risolto l'errore, il problema era nel client. L'ho modificato in questo modo
ProvaEjb.java Codice:
public class ProvaEjb { public static void main(String[] args) { InitialContext ctx = null; try { // Hashtable env = new Hashtable(); // env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); // env.put(Context.PROVIDER_URL, "t3://localhost:7001"); // env.put(Context.SECURITY_PRINCIPAL, "giuseppe"); // env.put(Context.SECURITY_CREDENTIALS, "giuseppe"); //ctx = new InitialContext(); //ctx. //ctx = new InitialContext(env); ctx = new InitialContext(); ctx.addToEnvironment(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); ctx.addToEnvironment(Context.PROVIDER_URL, "t3://localhost:7001"); ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, "giuseppe"); ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, "giuseppe"); }catch (NamingException e) { e.printStackTrace(); } try { Object obj = ctx.lookup("AdderBean"); if ( obj != null ){ AdderHome home = (AdderHome)PortableRemoteObject.narrow(obj, AdderHome.class); Adder adder = home.create(); System.out.println(adder.add(2, 5)); } }catch (Exception e) { e.printStackTrace(); } } } Codice:
javax.naming.NameNotFoundException: Unable to resolve 'AdderBean'. Resolved '' [Root exception is javax.naming.NameNotFoundException: Unable to resolve 'AdderBean'. Resolved '']; remaining name 'AdderBean' at weblogic.rjvm.ResponseImpl.unmarshalReturn(ResponseImpl.java:221) at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:338) at weblogic.rmi.cluster.ClusterableRemoteRef.invoke(ClusterableRemoteRef.java:252) at weblogic.jndi.internal.ServerNamingNode_1001_WLStub.lookup(Unknown Source) at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:379) at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:367) at javax.naming.InitialContext.lookup(Unknown Source) at it.ejb.session.ProvaEjb.main(ProvaEjb.java:46) Caused by: javax.naming.NameNotFoundException: Unable to resolve 'AdderBean'. Resolved '' at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1138) at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:251) at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:171) at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:205) at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source) at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589) at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:224) at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:479) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363) at weblogic.security.service.SecurityManager.runAs(Unknown Source) at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:475) at weblogic.rmi.internal.BasicServerRef.access$300(BasicServerRef.java:59) at weblogic.rmi.internal.BasicServerRef$BasicExecuteRequest.run(BasicServerRef.java:1016) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:200) at weblogic.work.ExecuteThread.run(ExecuteThread.java:172) da cosa dipende secondo voi? I file di configurazione dovrebbero essere giusti. ciao
__________________
HU Queen Member |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 10:01.