Javaspaces Applet Help

From: Joe (zief_at_yahoo.com)
Date: 04/12/04


Date: 12 Apr 2004 11:26:34 -0700

Hi,

I don't know if there are any JavaSpaces experts on this group, but if
there are I'd be gratefully for any help on the following problem:

I am trying to get applets working in web browsers, at least IE if
possible, which can then access JavaSpaces on the server, download an
object, compute the result, then post it back.
However, I am having a bit of a nightmare with all this. I have
searched these postings, and on Google/Groups and can't find a simple
guide to achieving it.

I have started as simple as possible, with the HelloWorldTwo example
from the JavaSpaces Principles, Patterns and Practice book. I can get
this working perfectly fine on my computer and over my local network
at the command line. So I then converted the client into a very simple
applet.
This can also be run on any machine on the LAN through appletviewer
with the following command:
java -Djava.security.policy=applet\policy\policy.all
-Doutrigger.spacename=JavaSpaces -Dcom.sun.jini.lookup.groups=public
-Djava.rmi.server.codebase=http://192.168.0.1:8081/space-examples-dl.jar
sun.applet.AppletViewer runjs.jsp

Where runjs.jsp simply contains the appropriate applet tag and the
class to load.

However, when I came to try and get this working through a browser
(which is essential to get working for my dissertation university
project), I am having a lot of problems.
I am using Tomcat webserver for my Jsp pages, but I have decided to
still use the server program in tools.jar (In the running
Javaspaces1_2_1 example), I don't know if this will effect things, it
is on port 8081 while tomcat is on 8080?
Reluctantly (I'd rather not change default permissions for Java
runtime, so it will work on any computer automatically), I added some
permissions to the java.policy file in the J2RE folder. These
permissions were:
permission java.util.PropertyPermission "com.sun.jini.lookup.locator",
"read";
permission java.util.PropertyPermission "com.sun.jini.lookup.groups",
"read";
permission java.net.NetPermission
"net.jini.discovery.DiscoveryPermission";
permission java.util.PropertyPermission
"net.jini.discovery.DiscoveryPermission", "read, write";

This has got rid of several of the errors, but I am now getting a

LookupLocator: find: access denied
(net.jini.discovery.DiscoveryPermission )

java.security.AccessControlException: access denied
(net.jini.discovery.DiscoveryPermission ) at
java.security.AccessControlContext.checkPermission(Unknown
Source)......

which I can't seem to sort out by adding permissions to the policy
file.
As I say, I'd rather not change these permissions, so if anyone can
tell me if there is an easier way I'd be extremely grateful, if not,
any help with this error will also be great.
Also if I can get this eventually working, I am hoping to include all
files required, both my project and the needed jini files, in one JAR
file, so anyone running the applet need not install jini and
classpaths. I think I have identified most of the files I need, but
any further information on this will be excellent.

Thankyou very much for your time in advance,
Joe

ps.. files which I am using to try and get this working are below:

The server in effect, HelloWorld.java

import net.jini.core.lease.Lease;
import net.jini.space.JavaSpace;

public class HelloWorld {
    public static void main(String[] args) {
        try {
            Message msg = new Message("Hello World", 0);

            JavaSpace space = SpaceAccessor.getSpace();
            space.write(msg, null, Lease.FOREVER);

            Message template = new Message();
            for (;;) {
                Message result = (Message)
                    space.read(template, null, Long.MAX_VALUE);
                System.out.println(result);
                Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

The client applet HelloWorldClient.java

import net.jini.core.lease.Lease;
import net.jini.space.JavaSpace;
import java.applet.Applet;
import java.io.IOException;
import java.net.InetAddress;

public class HelloWorldClient extends Applet
{
        public void init()
  {
          super.init();

                // find out who I am
    InetAddress myAddr = null;
    String myHost;
    try
    {
            myAddr = InetAddress.getLocalHost();
      myHost = myAddr.getHostName();
    }
    catch (java.net.UnknownHostException e)
    {
            if (myAddr != null)
              myHost = myAddr.toString();
        else
      myHost = "localhost";
    }
    System.out.println("I am running on " + myHost);
    try
    {
            JavaSpace space = SpaceAccessor.getSpace("JavaSpaces");
            
      Message template = new Message();
      for (;;)
      {
                                System.out.println("Getting object");
        Message result = (Message)space.take(template, null,
Long.MAX_VALUE);
                                System.out.println("Got object");
        result.increment();
        space.write(result, null, Lease.FOREVER);
                                System.out.println("Wrote object back");
        Thread.sleep(1000);
      }
    }
    catch (Exception e)
    {
            e.printStackTrace();
    }
  }
}

Message.java

import net.jini.core.entry.Entry;

public class Message implements Entry {
    public String content;
    public Integer counter;

    public Message() {
    }

    public Message(String content, int initVal) {
        this.content = content;
        counter = new Integer(initVal);
    }

    public String toString() {
        return content + " read " + counter + " times.";
    }

    public void increment() {
        counter = new Integer(counter.intValue() + 1);
    }
}

SpaceAccessor.java

import java.rmi.*;

import net.jini.space.JavaSpace;

import com.sun.jini.mahout.Locator;
import com.sun.jini.outrigger.Finder;

public class SpaceAccessor
{
        public static JavaSpace getSpace(String name)
  {
          try
          {
            if (System.getSecurityManager() == null)
            {
        System.out.println("Getting security manager");
        System.setSecurityManager(new RMISecurityManager());
            }
              
            Locator locator = new com.sun.jini.outrigger.DiscoveryLocator();
            Finder finder = new com.sun.jini.outrigger.LookupFinder();
            return (JavaSpace)finder.find(locator, name);
                }
                catch (Exception e)
                {
            System.err.println(e.getMessage());
                }
    return null;
  }
    
  public static JavaSpace getSpace()
  {
          return getSpace("JavaSpaces");
  }
}



Relevant Pages

  • Re: Security restrictions in signed applets
    ... prompted to grant extra permissions? ... When I load the applet in a web browser I get a security warning pop-up ...
    (comp.lang.java.programmer)
  • SQL Error 229.
    ... What security permissions has the sp. ... The applet is being started by an Server administrator ... >the fresh SQL 7 installations? ...
    (microsoft.public.sqlserver.server)
  • Re: .NET Applet
    ... the first thing I would do is check to see if the framework is ... configured on each of the machines with the appropriate permissions to run ... You have to go to the Framework Configuration utility ... given that the applet runs. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Permission for Tabs in Active Directory
    ... Once you delegate those permissions to your trustee group you ... There is an applet that has a UI that basically looks like the "Terminal ... Services Profile" tab in ADUC. ... I'm looking to Delegate permission for my Active Directory domain down to ...
    (microsoft.public.windows.server.active_directory)