java - invoke RMI method from servlet -


i'm writing servlet make rmi call. i've write rmi server , tested java swing client, , goes fine. have problem using servlet. when user open main web page, servlet automatically call rmi method retrieve information on database, build web page show. when user click link fired servlet invoke rmi method, obtain error:

java.rmi.connectexception: connection refused host: 192.168.1.101; nested exception is:  java.net.connectexception: connection refused @ sun.rmi.transport.tcp.tcpendpoint.newsocket(tcpendpoint.java:619) @ sun.rmi.transport.tcp.tcpchannel.createconnection(tcpchannel.java:216) @ sun.rmi.transport.tcp.tcpchannel.newconnection(tcpchannel.java:202) @ sun.rmi.server.unicastref.newcall(unicastref.java:340) @ sun.rmi.registry.registryimpl_stub.lookup(unknown source) @ project.remoteclass.getengine(remoteclass.java:33) @ project.mainservlet.processrequest(mainservlet.java:57) @ project.mainservlet.doget(mainservlet.java:176) @ javax.servlet.http.httpservlet.service(httpservlet.java:621) @ javax.servlet.http.httpservlet.service(httpservlet.java:728) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:305) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.netbeans.modules.web.monitor.server.monitorfilter.dofilter(monitorfilter.java:393) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:243) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:210) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:222) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:123) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:472) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:171) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:99) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:936) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:118) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:407) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1004) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:589) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:312) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ java.lang.thread.run(thread.java:724) caused by: java.net.connectexception: connection refused @ java.net.plainsocketimpl.socketconnect(native method) @ java.net.abstractplainsocketimpl.doconnect(abstractplainsocketimpl.java:339) @ java.net.abstractplainsocketimpl.connecttoaddress(abstractplainsocketimpl.java:200) @ java.net.abstractplainsocketimpl.connect(abstractplainsocketimpl.java:182) @ java.net.sockssocketimpl.connect(sockssocketimpl.java:392) @ java.net.socket.connect(socket.java:579) @ java.net.socket.connect(socket.java:528) @ java.net.socket.<init>(socket.java:425) @ java.net.socket.<init>(socket.java:208) @ sun.rmi.transport.proxy.rmidirectsocketfactory.createsocket(rmidirectsocketfactory.java:40) @ sun.rmi.transport.proxy.rmimastersocketfactory.createsocket(rmimastersocketfactory.java:146) @ sun.rmi.transport.tcp.tcpendpoint.newsocket(tcpendpoint.java:613) 

i think can caused how lookup registry , pass serlvets. avoid write everytime lookup rmi code inside each servlet, thought class (like connectionmanager used on jdbc clien) class lookup registry , give invoking servlet:

public class remoteclass {     private remoteclass(){}     private static registry registry = null;     private static remoteinterface interface_engine = null;     private static final string rmiaddress = "192.168.1.101";     private static final int rmiport = 22222;     private static final string skeleton = "projrmiskeleton";      public static remoteinterface getengine() throws remoteexception {         registry = locateregistry.getregistry(rmiaddress, rmiport);         try {             interface_engine = (remoteinterface) registry.lookup(skeleton);         } catch (remoteexception ex) {             logger.getlogger(mainservlet.class.getname()).log(level.severe, null, ex);         } catch (notboundexception ex) {             logger.getlogger(mainservlet.class.getname()).log(level.severe, null, ex);         }         return interface_engine;     } } 

and error occours when code execute registry.lookup method. how can solve it?

connection refused host: 192.168.1.101 ... @ sun.rmi.registry.registryimpl_stub.lookup(unknown source)

there no registry running @ 192.168.1.101, in case on port 22222 called locateregistry.getregistry("192.168.1.101", 22222).

maybe registry exits after first call. if create @ server locateregistry.createregistry() , don't store result in static field liable garbage-collected.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -