[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Applet NetworkClassLoader

Posted on 1997-03-10
6
Medium Priority
?
273 Views
Last Modified: 2013-12-29
I'm trying to build a NetworkClassLoader that will load an instance of an object from a .class file located on a Web server on the net.  This will be inside of an applet, and the Web server where i load my object from will change..

Now, to get around the security of an Applet, I'm going to load this applet from my local file system.  I believe this will allow me to load classes from a server other than my Applet's codebase (at least that's what I understand from the documentation from Sun.)

I've tried to follow the example from the ClassLoader example in the API, but it doesn't work... just doesn't complete..

An example NetworkClassLoader would be invaluable to me..

thx, kurt colvin
0
Comment
Question by:colvin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:tatti
ID: 1219034
Not saying anything about ClassLoader, I'll just confirm that locally loaded applets are free from most of the security restrictions, including the restriction on servers they can connect to.
0
 

Expert Comment

by:amarshal
ID: 1219035
the security restriction is dependent on the browser.  I beleive IE maintains the security restriction, unless it is loaded through the local classpath (Windows/java/classes.zip).  Applet classpath, even if froma local file system, are still secure.
0
 

Author Comment

by:colvin
ID: 1219036
Well....
I've pretty much figured out that what I want to do is not possible with the ClassLoader used in a browser.  I guess you can't do much to alter the classloader that the browser uses to load classes... so, i guess i'm going to switch my applet to an application.  

there is some new functionality in the new JDK 1.1 that may allow stuff like this with RMI and "signed" applets, but i'll let the real gurus try this stuff out first...

this service is a great idea... i noticed it was based in SLO, CA... are you guys Mustangs??? i was a few years back...

thx, kurt colvin
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:colvin
ID: 1219037
Still trying to do this... How about a functional NetworkClassLoader that will can actually load a class? This would be for an application.  I've seen several examples on the Web, but i can't get any of them to work.

thx, Kurt Colvin
0
 

Accepted Solution

by:
rickl032797 earned 400 total points
ID: 1219038
This example is from the symantec help file, I have not tried it....

ClassLoader is an abstract Class that can be used to define a policy for loading Java classes into the runtime environment. By default, the runtime system loads classes that originate as files by reading them from the directory defined by the CLASSPATH environment variable (this is platform dependent). The default mechanism does not involve a Class loader.  

However, some classes may not originate from a file; they could be loaded from some other source, e.g., the network. Classes loaded from the network are an array of bytes. A ClassLoader can be used to tell the runtime system to convert an array of bytes into an instance of class Class. This conversion information is passed to the runtime using the defineClass() method.  
Classes that are created through the defineClass() mechanism can reference other classes by name. To resolve those names, the runtime system calls the ClassLoader that originally created the Class. The runtime system calls the abstract method loadClass() to load the referenced classes.  

        ClassLoader loader = new NetworkClassLoader(host, port);
        Object main = loader.loadClass("Main").newInstance();
        ....

The NetworkClassLoader subclass must define the method loadClass() to load a Class from the network. Once it has downloaded the bytes that make up the Class it should use the method defineClass() to create a Class instance. A sample implementation could be:

        class NetworkClassLoader {
            String host;
            int port;
            Hashtable cache = new Hashtable();
            private byte loadClassData(String name)[] {
                // load the class data from the connection
                ...
            }
            public synchronized Class loadClass(String name) {
                Class c = cache.get(name);
                if (c == null) {
                    byte data[] = loadClassData(name);

                    cache.put(name, defineClass(data, 0, data.length));
                }
                return c;
            }
        }

0
 

Author Comment

by:colvin
ID: 1219039
thanks for the reply..
i've tried this example too, but never could get it to work with my requriements..

i've since compromised by downloading the remote class to a file, then creating an instance from the file. not very pretty, but it works from what i'm doing. thx, kc
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question