Re: Error on client lookup
jaidan <[email protected]> Mon, 28 Apr 2008 09:48:47 -0700
| Newsgroups | gmane.comp.java.sun.jini |
|---|---|
| Message-ID | <[email protected]> |
Gregg Wonderly-2 wrote:
>
>
> Based on this message, it sounds like you have not setup a codebase, or
> provided
> a properly configured codebase server. But to be sure, we need to know
> more
> about your service. Is the HelloWorldServiceProxy a class you wrote?
> What
> command line are you using to start the service with? What exporter are
> you
> using for your service? etc...
>
> Gregg Wonderly
>
>
Gregg Wonderly-2 wrote:
> Based on this message, it sounds like you have not setup a codebase, or
> provided
> a properly configured codebase server. But to be sure, we need to know
> more
> about your service. Is the HelloWorldServiceProxy a class you wrote?
> What
> command line are you using to start the service with? What exporter are
> you
> using for your service? etc...
>
> Gregg Wonderly
Hi Gregg, I'll try tell you exactly what Im doing.
This is my clinet
// A simple Client to exercise the HelloWorldService
import net.jini.discovery.DiscoveryListener;
import net.jini.discovery.DiscoveryEvent;
import net.jini.discovery.LookupDiscovery;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceTemplate;
import java.util.Vector;
import java.io.IOException;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
public class HelloWorldClient implements Runnable {
protected ServiceTemplate template;
protected LookupDiscovery disco;
// An inner class to implement DiscoveryListener
class Listener implements DiscoveryListener {
public void discovered(DiscoveryEvent ev) {
ServiceRegistrar[] newregs = ev.getRegistrars();
for (int i=0 ; i<newregs.length ; i++) {
lookForService(newregs[i]);
}
}
public void discarded(DiscoveryEvent ev) {
}
}
public HelloWorldClient() throws IOException {
Class[] types = { HelloWorldServiceInterface.class };
template = new ServiceTemplate(null, types, null);
// Set a security manager
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
// Only search the public group
disco = new LookupDiscovery(new String[] { "" });
// Install a listener
disco.addDiscoveryListener(new Listener());
}
// Once we've found a new lookup service, search
// for proxies that implement
// HelloWorldServiceInterface
protected Object lookForService(ServiceRegistrar lusvc) {
Object o = null;
try {
o = lusvc.lookup(template);
} catch (RemoteException ex) {
System.err.println("Error doing lookup: " + ex.getMessage());
return null;
}
if (o == null) {
System.err.println("No matching service.");
return null;
}
System.out.println("Got a matching service.");
System.out.println("It's message is: " +
((HelloWorldServiceInterface) o).getMessage());
return o;
}
// This thread does nothing--it simply keeps the
// VM from exiting while we do discovery.
public void run() {
while (true) {
try {
Thread.sleep(1000000);
} catch (InterruptedException ex) {
}
}
}
// Create a HelloWorldClient and start its thread
public static void main(String args[]) {
try {
HelloWorldClient hwc = new HelloWorldClient();
new Thread(hwc).start();
} catch (IOException ex) {
System.out.println("Couldn't create client: " +
ex.getMessage());
}
}
}
----------------------------------------------------------------------
This is my interface
// This is the interface that the service's proxy
// implements
public interface HelloWorldServiceInterface {
public String getMessage();
}
--------------------------------------------------------------------
This is my server
// This is the first iteration of a Hello, World
// service--it publishes a proxy that returns
// a string when asked by clients.
import net.jini.discovery.DiscoveryListener;
import net.jini.discovery.DiscoveryEvent;
import net.jini.discovery.LookupDiscovery;
import net.jini.core.lookup.ServiceItem;
import net.jini.core.lookup.ServiceRegistrar;
import net.jini.core.lookup.ServiceRegistration;
import java.util.Hashtable;
import java.io.IOException;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.rmi.RMISecurityManager;
// This is the proxy object that will be downloaded
// by clients. It's serializable and implements
// our well-known HelloWorldServiceInterface.
class HelloWorldServiceProxy implements Serializable,
HelloWorldServiceInterface {
public HelloWorldServiceProxy() {
}
public String getMessage() {
return "Hello, world!";
}
}
// HelloWorldService is the "wrapper" class that
// handles publishing the service item.
public class HelloWorldService implements Runnable {
// 10 minute leases
protected final int LEASE_TIME = 10 * 60 * 1000;
protected Hashtable registrations = new Hashtable();
protected ServiceItem item;
protected LookupDiscovery disco;
// Inner class to listen for discovery events
class Listener implements DiscoveryListener {
// Called when we find a new lookup service.
public void discovered(DiscoveryEvent ev) {
System.out.println("discovered a lookup service!");
ServiceRegistrar[] newregs = ev.getRegistrars();
for (int i=0 ; i<newregs.length ; i++) {
if (!registrations.containsKey(newregs[i])) {
registerWithLookup(newregs[i]);
}
}
}
// Called ONLY when we explicitly discard a
// lookup service, not "automatically" when a
// lookup service goes down. Once discovered,
// there is NO ongoing communication with a
// lookup service.
public void discarded(DiscoveryEvent ev) {
ServiceRegistrar[] deadregs = ev.getRegistrars();
for (int i=0 ; i<deadregs.length ; i++) {
registrations.remove(deadregs[i]);
}
}
}
public HelloWorldService() throws IOException {
item = new ServiceItem(null, createProxy(), null);
// Set a security manager
if (System.getSecurityManager() == null) {
System.setSecurityManager(new RMISecurityManager());
}
// Search for the "public" group, which by
// convention is named by the empty string
disco = new LookupDiscovery(new String[] { "" });
// Install a listener.
disco.addDiscoveryListener(new Listener());
}
protected HelloWorldServiceInterface createProxy() {
return new HelloWorldServiceProxy();
}
// This work involves remote calls, and may take a
// while to complete. Thus, since it's called from
// discovered(), it will prevent us from responding
// in a timely fashion to new discovery events. An
// improvement would be to spin off a separate short-
// lived thread to do the work.
protected synchronized void registerWithLookup(ServiceRegistrar
registrar) {
ServiceRegistration registration = null;
try {
registration = registrar.register(item, LEASE_TIME);
} catch (RemoteException ex) {
System.out.println("Couldn't register: " + ex.getMessage());
return;
}
// If this is our first registration, use the
// service ID returned to us. Ideally, we should
// save this ID so that it can be used after
// restarts of the service
if (item.serviceID == null) {
item.serviceID = registration.getServiceID();
System.out.println("Set serviceID to " + item.serviceID);
}
registrations.put(registrar, registration);
}
// This thread does nothing but sleep, but it
// makes sure the VM doesn't exit.
public void run() {
while (true) {
try {
Thread.sleep(1000000);
} catch (InterruptedException ex) {
}
}
}
// Create a new HelloWorldService and start
// its thread.
public static void main(String args[]) {
try {
HelloWorldService hws = new HelloWorldService();
new Thread(hws).start();
} catch (IOException ex) {
System.out.println("Couldn't create service: " +
ex.getMessage());
}
}
}
-------------------------------------------------------------------
These are the first commands I run to compile the client and service
//compile client
javac -classpath
c:\jini\jini-core.jar;c:\jini\jini-ext.jar;c:\jini\sun-util.jar;c:\jinicode\client
-d c:\jinicode\client HelloWorldServiceInterface.java HelloWorldClient.java
//compile server
javac -classpath
C:\jini\jini-core.jar;C:\jini\jini-ext.jar;C:\jini\sun-util.jar;C:\jinicode\service
-d C:\jinicode\service HelloWorldServiceInterface.java
HelloWorldService.java
copy HelloWorldServiceProxy.class ..\service-dl\
The copy command makes a copy of the world proxy in a folder called
service-dl
then next
// Step 3 run rmi activation daeman
rmid -J-Dsun.rmi.activation.execPolicy=none &
//step 4 running Http server for reggie
(new window)
java -jar c:\jini\tools.jar -port 8080 -dir c:\jini -verbose &
all fine so far
i then go to run the following command
//step 5 running running lookup service
(new window)
java -Djava.security.policy=c:\jini\lookup\policy.all -jar
c:\jini\reggie.jar http://localhost:8080/reggie-dl.jar
c:\jini\lookup\policy.all c:\jini\reggie9_log public
I get an error saying reggie9_log already exists, when i try to delete it ,
it wont let me as it says file in use , so i then have to kill the command
windows that I opened for step 3 and 4.
Then when I run step 5 again it says RMI activation daemon needs to be
running (which is step 3 i think)
I also reggie9_log public to reggie_log
This was okay as I was able to run the following codes
//step 6 running HTTP server for server
(new window)
java -jar c:/jini/tools.jar -port 8085 -dir c:/jinicode/server-dl -verbose &
//step 7 Running Service
(new window)
java -cp
.;c:\jini\jini-core.jar;c:\jini\jini-ext.jar;c:\jini\sun-util.jar;c:\jinicode\service
-Djava.rmi.server.codebase=http://localhost:8085/
-Djava.security.policy=c:\jini\lookup\policy.all HelloWorldService &
//step 8 run Client
(new window)
java -classpath
c:\jini\jini-core.jar;c:\jini\jini-ext.jar;c:\jini\sun-util.jar;c:\jinicode\client
-Djava.security.policy=c:\jini\lookup\policy.all HelloWorldClient
This time the server runs correctly, it prints out a service id, but the
client gets the error saying
Error doing lookup: error marshalling return; nested exception is
Java.lang.classnotfoundException: HelloWorldServiceProxy
Sorry about the long winded nature of the post but i hope this will explain
it better as I am completely lost
My folder set up looks is that I have all the jars from jini 1.2.1_002 in a
folder called jini along with my policy in a lookup folder contained in the
jini folder.
My code is in a folder called jinicode which contains folders for
service,client and service-dl
Any help would be much appreciated
Thanks
--
View this message in context: http://www.nabble.com/Error-on-client-lookup-tp16930323p16943113.html
Sent from the Sun - Jini-Users mailing list archive at Nabble.com.
--------------------------------------------------------------------------
Getting Started: http://www.jini.org/wiki/Category:Getting_Started
Community Web Site: http://jini.org
jini-users Archive: http://archives.java.sun.com/archives/jini-users.html
Unsubscribing: email "signoff JINI-USERS" to [email protected]