Problemi s PortableRemoteObject.narrow()
7 отговора
279 прегледа
Problemi s PortableRemoteObject.narrow()
Zna4i imam Server koyto go puskam s:
java -Djava.naming.factory.initial=com.sun.jndi.
cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:900 Server
Servera si syzdava obect ot tip CountryRemote i si go registrirva v naming service pod imeto "CountryRemote". Do tuk vsi4ko e ok 100%. Ot servera moga da napravia lookup za CountryRemote i da izvikvam metodite mu.
Problema e kogato klientskoto prilojenie e web application, t.e. ot servlet pravia lookup, narrow i izvikam metod.
Servleta mi namira registrirania obect, t.e. Object obj = context.lookup("CountryRemote"); minava. obj.toString() v Server i
v servleta mi vryshta edno i sashto, koeto shte re4e 4e lookup namira obekta koyto iskam. Kogato izvikam oba4e narrow, neshtata umirat:
CountryRemote countryRemote = (CountryRemote) PortableRemoteObject.narrow(
obj, CountryRemote.class);
mi izkarva syobshtenie:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet CountryServlet threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:536)
root cause
java.lang.NoClassDefFoundError
com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:276)
javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
com.pm.web.servlets.country.CountryServlet.init(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:536)
CountryRemote.class i syotvetnite stubove sa si v jar file v lib direktoriata na web prilojenieto.
Prilojenieto se deployva 4rez war file i servera e Tomcat 5.0.
Eto kak mi izglejda 4ast ot init metoda na servleta:
public void init(ServletConfig config) throws ServletException {
try {
Hashtable env = new Hashtable();
// select a service provider factory
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");
//url
env.put(Context.PROVIDER_URL, "iiop://localhost:900");
// create the initial context
Context context = new InitialContext(env);
obj = context.lookup("CountryRemote");
if (obj != null) {
System.out.println("Obj is not null.");
countryRemote = (CountryRemote) PortableRemoteObject.narrow(
obj, CountryRemote.class);
} else {
System.out.println("Obj is null.");
}
......
Drugo neshto koeto bih iskal da popitam e moje li da ukaja environment settings za web prilojenieto v web.xml, t.e.
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://localhost:900");
moje li da se zameniat s neshto vyv web.xml?
Probvah slednoto neshto, no to ne proraboti:
<env-entry>
<description>Initial context</description>
<env-entry-name>java.naming.factory.initial</env-entry-name>
<env-entry-value>
com.sun.jndi.cosnaming.CNCtxFactory
</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<description>URL</description>
<env-entry-name>java.naming.provider.url</env-entry-name>
<env-entry-value>iiop://localhost:900</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
Mersi predvaritelno.
Pozdravi
java -Djava.naming.factory.initial=com.sun.jndi.
cosnaming.CNCtxFactory -Djava.naming.provider.url=iiop://localhost:900 Server
Servera si syzdava obect ot tip CountryRemote i si go registrirva v naming service pod imeto "CountryRemote". Do tuk vsi4ko e ok 100%. Ot servera moga da napravia lookup za CountryRemote i da izvikvam metodite mu.
Problema e kogato klientskoto prilojenie e web application, t.e. ot servlet pravia lookup, narrow i izvikam metod.
Servleta mi namira registrirania obect, t.e. Object obj = context.lookup("CountryRemote"); minava. obj.toString() v Server i
v servleta mi vryshta edno i sashto, koeto shte re4e 4e lookup namira obekta koyto iskam. Kogato izvikam oba4e narrow, neshtata umirat:
CountryRemote countryRemote = (CountryRemote) PortableRemoteObject.narrow(
obj, CountryRemote.class);
mi izkarva syobshtenie:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet CountryServlet threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:536)
root cause
java.lang.NoClassDefFoundError
com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:276)
javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
com.pm.web.servlets.country.CountryServlet.init(Unknown Source)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
java.lang.Thread.run(Thread.java:536)
CountryRemote.class i syotvetnite stubove sa si v jar file v lib direktoriata na web prilojenieto.
Prilojenieto se deployva 4rez war file i servera e Tomcat 5.0.
Eto kak mi izglejda 4ast ot init metoda na servleta:
public void init(ServletConfig config) throws ServletException {
try {
Hashtable env = new Hashtable();
// select a service provider factory
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");
//url
env.put(Context.PROVIDER_URL, "iiop://localhost:900");
// create the initial context
Context context = new InitialContext(env);
obj = context.lookup("CountryRemote");
if (obj != null) {
System.out.println("Obj is not null.");
countryRemote = (CountryRemote) PortableRemoteObject.narrow(
obj, CountryRemote.class);
} else {
System.out.println("Obj is null.");
}
......
Drugo neshto koeto bih iskal da popitam e moje li da ukaja environment settings za web prilojenieto v web.xml, t.e.
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://localhost:900");
moje li da se zameniat s neshto vyv web.xml?
Probvah slednoto neshto, no to ne proraboti:
<env-entry>
<description>Initial context</description>
<env-entry-name>java.naming.factory.initial</env-entry-name>
<env-entry-value>
com.sun.jndi.cosnaming.CNCtxFactory
</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<description>URL</description>
<env-entry-name>java.naming.provider.url</env-entry-name>
<env-entry-value>iiop://localhost:900</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
Mersi predvaritelno.
Pozdravi
Re: Problemi s PortableRemoteObject.narrow()
missing stubs (for IIOP) -> gen with "idl"?
Re: Problemi s PortableRemoteObject.narrow()
Stubs sa generirani s iiop i nishto ne lipsva. Ima si pyt do tiah. Probvah go pod JBoss i vsi4ko si vyrvi kakto triabva, no pod Tomcat 5.0.28 ne iska i ne iska
.
Re: Problemi s PortableRemoteObject.narrow()
Instalirah si Tomcat 5.5. i vsi4ko e OK. Moje li da ukaja environment settings za web prilojenieto v web.xml, t.e.
Hashtable env = new Hashtable();
// select a service provider factory
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");
//url
env.put(Context.PROVIDER_URL, "iiop://localhost:900");
// create the initial context
Context context = new InitialContext(env);
obj = context.lookup("CountryRemote");
moje li da se zameni s neshto vyv web.xml? V momenta INITIAL_CONTEXT_FACTORY i PROVIDER_URL sa mi hard coded. Ima li na4in tezi neshta da se konfigurirat ot web.xml, t.e. da imam samo Context context = new InitialContext(); vmesto gornoto?
Pozdravi.
Hashtable env = new Hashtable();
// select a service provider factory
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");
//url
env.put(Context.PROVIDER_URL, "iiop://localhost:900");
// create the initial context
Context context = new InitialContext(env);
obj = context.lookup("CountryRemote");
moje li da se zameni s neshto vyv web.xml? V momenta INITIAL_CONTEXT_FACTORY i PROVIDER_URL sa mi hard coded. Ima li na4in tezi neshta da se konfigurirat ot web.xml, t.e. da imam samo Context context = new InitialContext(); vmesto gornoto?
Pozdravi.
Re: Problemi s PortableRemoteObject.narrow()
За подробности виж J2EE 1.4 specification Chapter 5:
Context initCtx = new InitialContext();
Context myEnv = (Context)initCtx.lookup(“java:comp/env”);
// Obtain the maximum number of tax exemptions
// configured by the Deployer.
Integer max = (Integer)myEnv.lookup(“maxExemptions”);
If the Application Component Provider provides a value for an environment
entry using the env-entry-value element, the value can be changed later by the
Application Assembler or Deployer. The value must be a string that is valid for the
constructor of the specified type that takes a single String parameter, or in the
case of Character, a single character.
The following example is the declaration of environment entries used by the
application component whose code was illustrated in the previous subsection.
...
<env-entry>
<description>
The maximum number of tax exemptions
allowed to be set.
</description>
<env-entry-name>maxExemptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>15</env-entry-value>
</env-entry>
<env-entry>
<description>
The minimum number of tax exemptions
allowed to be set.
</description>
<env-entry-name>minExemptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>1</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>foo/name1</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>value1</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>foo/bar/name2</env-entry-name>
<env-entry-type>java.lang.Boolean</env-entry-type>
<env-entry-value>true</env-entry-value>
</env-entry>
<env-entry>
<description>Some description.</description>
<env-entry-name>name3</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>
<env-entry>
<env-entry-name>foo/name4</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>10</env-entry-value>
</env-entry>
Context initCtx = new InitialContext();
Context myEnv = (Context)initCtx.lookup(“java:comp/env”);
// Obtain the maximum number of tax exemptions
// configured by the Deployer.
Integer max = (Integer)myEnv.lookup(“maxExemptions”);
If the Application Component Provider provides a value for an environment
entry using the env-entry-value element, the value can be changed later by the
Application Assembler or Deployer. The value must be a string that is valid for the
constructor of the specified type that takes a single String parameter, or in the
case of Character, a single character.
The following example is the declaration of environment entries used by the
application component whose code was illustrated in the previous subsection.
...
<env-entry>
<description>
The maximum number of tax exemptions
allowed to be set.
</description>
<env-entry-name>maxExemptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>15</env-entry-value>
</env-entry>
<env-entry>
<description>
The minimum number of tax exemptions
allowed to be set.
</description>
<env-entry-name>minExemptions</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>1</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>foo/name1</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>value1</env-entry-value>
</env-entry>
<env-entry>
<env-entry-name>foo/bar/name2</env-entry-name>
<env-entry-type>java.lang.Boolean</env-entry-type>
<env-entry-value>true</env-entry-value>
</env-entry>
<env-entry>
<description>Some description.</description>
<env-entry-name>name3</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>
<env-entry>
<env-entry-name>foo/name4</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>10</env-entry-value>
</env-entry>
Re: Problemi s PortableRemoteObject.narrow()
Probvah slednoto neshto no ne proraboti:
public void init(ServletConfig config) throws ServletException {
try {
Context initCtx = new InitialContext();
Context myEnv = (Context)initCtx.lookup("java:comp/env");
obj = myEnv.lookup("CountryRemote");
....
Vyv web.xml imam:
<env-entry-name>java.naming.factory.initial</env-entry-name>
<env-entry-value>
com.sun.jndi.cosnaming.CNCtxFactory
</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<description>URL provider</description>
<env-entry-name>java.naming.provider.url</env-entry-name>
<env-entry-value>iiop://localhost:900</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
Slednoto neshto raboti bez da sym ukazal kakvoto i da e vyv web.xml, no na men tova ne mi haresva poneje e hard coded:
public void init(ServletConfig config) throws ServletException {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://localhost:900");
// create the initial context
Context context = new InitialContext(env);
obj = context.lookup("CountryRemote");
...
Probvah i s jndi.properties file koeto go slagam vyv WEB-INF/classes, no i s nego ne stane. Sydyrjanieto na tozi file e slednoto:
java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory
java.naming.provider.url=iiop://localhost:900
Neznam drugo kakvo da probvam
Pozdravi
public void init(ServletConfig config) throws ServletException {
try {
Context initCtx = new InitialContext();
Context myEnv = (Context)initCtx.lookup("java:comp/env");
obj = myEnv.lookup("CountryRemote");
....
Vyv web.xml imam:
<env-entry-name>java.naming.factory.initial</env-entry-name>
<env-entry-value>
com.sun.jndi.cosnaming.CNCtxFactory
</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<description>URL provider</description>
<env-entry-name>java.naming.provider.url</env-entry-name>
<env-entry-value>iiop://localhost:900</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
Slednoto neshto raboti bez da sym ukazal kakvoto i da e vyv web.xml, no na men tova ne mi haresva poneje e hard coded:
public void init(ServletConfig config) throws ServletException {
try {
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.cosnaming.CNCtxFactory");
env.put(Context.PROVIDER_URL, "iiop://localhost:900");
// create the initial context
Context context = new InitialContext(env);
obj = context.lookup("CountryRemote");
...
Probvah i s jndi.properties file koeto go slagam vyv WEB-INF/classes, no i s nego ne stane. Sydyrjanieto na tozi file e slednoto:
java.naming.factory.initial=com.sun.jndi.cosnaming.CNCtxFactory
java.naming.provider.url=iiop://localhost:900
Neznam drugo kakvo da probvam
Pozdravi
Re: Problemi s PortableRemoteObject.narrow()
Според мен малко ги бъркаш нещата: имаме environment entries и EJB references. Това, което разбирам, че правиш и искаш да направиш е да запишеш стринговете "iiop://localhost:900" и " com.sun.jndi.cosnaming.CNCtxFactory" в web.xml за да не са ти хардкодед. После чрез lookup си ги намираш в web приложението и си правиш вече EJB lookup. До тук никакво използване на EJB references. т.е.
в web.xml
<env-entry-name>java.naming.factory.initial</env-entry-name>
<env-entry-value>
com.sun.jndi.cosnaming.CNCtxFactory
</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<description>URL provider</description>
<env-entry-name>java.naming.provider.url</env-entry-name>
<env-entry-value>iiop://localhost:900</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
в кода
public void init(ServletConfig config) throws ServletException {
try {
Context initCtx = new InitialContext();
Context myEnv = (Context)initCtx.lookup("java:comp/env");
String urlFromWebXml = (String) myEnv.lookup("java.naming.provider.url");
...
същото за factory-то
и после
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,factoryFromWebXml);
env.put(Context.PROVIDER_URL, urlFromWebXml);
// create the initial context
Context context = new InitialContext(env);
obj = context.lookup("CountryRemote");
...
Вече obj ти е EJB-то, което търсиш.
Пак да отбележа, че това най-добре е описано в J2EE (JavaEE) спецификацията.
Cheers,
Toshe
в web.xml
<env-entry-name>java.naming.factory.initial</env-entry-name>
<env-entry-value>
com.sun.jndi.cosnaming.CNCtxFactory
</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
<env-entry>
<description>URL provider</description>
<env-entry-name>java.naming.provider.url</env-entry-name>
<env-entry-value>iiop://localhost:900</env-entry-value>
<env-entry-type>java.lang.String</env-entry-type>
</env-entry>
в кода
public void init(ServletConfig config) throws ServletException {
try {
Context initCtx = new InitialContext();
Context myEnv = (Context)initCtx.lookup("java:comp/env");
String urlFromWebXml = (String) myEnv.lookup("java.naming.provider.url");
...
същото за factory-то
и после
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,factoryFromWebXml);
env.put(Context.PROVIDER_URL, urlFromWebXml);
// create the initial context
Context context = new InitialContext(env);
obj = context.lookup("CountryRemote");
...
Вече obj ти е EJB-то, което търсиш.
Пак да отбележа, че това най-добре е описано в J2EE (JavaEE) спецификацията.
Cheers,
Toshe
Re: Problemi s PortableRemoteObject.narrow()
Хм не знаех че ЙБос ползва ииоп за ремоте цаллс, това е голяма глупост?
Или вие нещо сте се объркали и единия пич говори за Цорба а другия за ЙНДИ+РМИ?
В смисъл че като че прочетох постингите останах с впечатление че говорите за различни неща.
Или вие нещо сте се объркали и единия пич говори за Цорба а другия за ЙНДИ+РМИ?
В смисъл че като че прочетох постингите останах с впечатление че говорите за различни неща.