bobbit31
asked on
access denied (java.lang.RuntimePermission accessClassInPackage
Hello, i'm trying to pass a serialized CachedRowSet (sun.jdbc.rowset.CachedRow Set) to my applet.
Here is the code i use to retrieve it from the servlet:
CachedRowSet crs = null;
ObjectInputStream result = null;
URL myURL = new URL (getDocumentBase(), "MyServlet");
URLConnection con = myURL.openConnection();
InputStream in = con.getInputStream();
result = new ObjectInputStream(in);
// Read the RowSet Object from the stream
Object obj = result.readObject();
crs = (CachedRowSet) obj;
Here is the stacktrace:
java.security.AccessContro lException : access denied (java.lang.RuntimePermissi on accessClassInPackage.sun.j dbc.rowset )
at java.security.AccessContro lContext.c heckPermis sion(Acces sControlCo ntext.java :270)
at java.security.AccessContro ller.check Permission (AccessCon troller.ja va:401)
at java.lang.SecurityManager. checkPermi ssion(Secu rityManage r.java:542 )
at java.lang.SecurityManager. checkPacka geAccess(S ecurityMan ager.java: 1513)
at sun.applet.AppletSecurity. checkPacka geAccess(A ppletSecur ity.java:1 66)
at sun.applet.AppletClassLoad er.loadCla ss(AppletC lassLoader .java:109)
at java.lang.ClassLoader.load Class(Clas sLoader.ja va:262)
at java.lang.ClassLoader.load ClassInter nal(ClassL oader.java :322)
at java.lang.Class.forName0(N ative Method)
at java.lang.Class.forName(Cl ass.java:2 07)
at java.io.ObjectInputStream. resolveCla ss(ObjectI nputStream .java:551)
at java.io.ObjectInputStream. readNonPro xyDesc(Obj ectInputSt ream.java: 1503)
at java.io.ObjectInputStream. readClassD esc(Object InputStrea m.java:142 5)
at java.io.ObjectInputStream. readOrdina ryObject(O bjectInput Stream.jav a:1616)
at java.io.ObjectInputStream. readObject 0(ObjectIn putStream. java:1264)
at java.io.ObjectInputStream. readObject (ObjectInp utStream.j ava:322)
at DatabaseApplet.getCachedRo wSetFromSe rvlet(Data baseApplet .java:139)
at DatabaseApplet.init(Databa seApplet.j ava:29)
at sun.applet.AppletPanel.run (AppletPan el.java:34 1)
at java.lang.Thread.run(Threa d.java:536 )
I know the error is happening b/c of the security manager not letting me access the class in package sun.jdbc.rowset (pretty obvious from the stack trace).
The question is, how do i get this damn thing working?
Here is the code i use to retrieve it from the servlet:
CachedRowSet crs = null;
ObjectInputStream result = null;
URL myURL = new URL (getDocumentBase(), "MyServlet");
URLConnection con = myURL.openConnection();
InputStream in = con.getInputStream();
result = new ObjectInputStream(in);
// Read the RowSet Object from the stream
Object obj = result.readObject();
crs = (CachedRowSet) obj;
Here is the stacktrace:
java.security.AccessContro
at java.security.AccessContro
at java.security.AccessContro
at java.lang.SecurityManager.
at java.lang.SecurityManager.
at sun.applet.AppletSecurity.
at sun.applet.AppletClassLoad
at java.lang.ClassLoader.load
at java.lang.ClassLoader.load
at java.lang.Class.forName0(N
at java.lang.Class.forName(Cl
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at DatabaseApplet.getCachedRo
at DatabaseApplet.init(Databa
at sun.applet.AppletPanel.run
at java.lang.Thread.run(Threa
I know the error is happening b/c of the security manager not letting me access the class in package sun.jdbc.rowset (pretty obvious from the stack trace).
The question is, how do i get this damn thing working?
ASKER
> In your java.policy file add the following
I did that, still no go.
I did that, still no go.
ASKER
i've pretty much scoured the web looking for a solution and though many ppl have had this exact same problem, none of their posts had a working solution...
Did you check that you changed the correct java.policy file? If you have the JDK installed then you probably have two. Change both to be sure. You'll also need to restart your browser as I believe the policy file is only read at startup.
Can you post your java.policy entry pls.
Also what is your environment?
Can you post your java.policy entry pls.
Also what is your environment?
ASKER
// Standard extensions get all permissions by default
grant codeBase "file:${java.home}/lib/ext /*" {
permission java.security.AllPermissio n;
};
// default permissions granted to all domains
grant {
// just grant to everyone for now
permission java.lang.RuntimePermissio n "accessClassInPackage.sun. jdbc.rowse t";
// Allows any thread to stop itself using the java.lang.Thread.stop()
// method that takes no argument.
// Note that this permission is granted by default only to remain
// backwards compatible.
// It is strongly recommended that you either remove this permission
// from this policy file or further restrict it to code sources
// that you specify, because Thread.stop() is potentially unsafe.
// See "http://java.sun.com/notes" for more information.
permission java.lang.RuntimePermissio n "stopThread";
// allows anyone to listen on un-privileged ports
permission java.net.SocketPermission "localhost:1024-", "listen";
// "standard" properies that can be read by anyone
permission java.util.PropertyPermissi on "java.version", "read";
permission java.util.PropertyPermissi on "java.vendor", "read";
permission java.util.PropertyPermissi on "java.vendor.url", "read";
permission java.util.PropertyPermissi on "java.class.version", "read";
permission java.util.PropertyPermissi on "os.name", "read";
permission java.util.PropertyPermissi on "os.version", "read";
permission java.util.PropertyPermissi on "os.arch", "read";
permission java.util.PropertyPermissi on "file.separator", "read";
permission java.util.PropertyPermissi on "path.separator", "read";
permission java.util.PropertyPermissi on "line.separator", "read";
permission java.util.PropertyPermissi on "java.specification.versio n", "read";
permission java.util.PropertyPermissi on "java.specification.vendor ", "read";
permission java.util.PropertyPermissi on "java.specification.name", "read";
permission java.util.PropertyPermissi on "java.vm.specification.ver sion", "read";
permission java.util.PropertyPermissi on "java.vm.specification.ven dor", "read";
permission java.util.PropertyPermissi on "java.vm.specification.nam e", "read";
permission java.util.PropertyPermissi on "java.vm.version", "read";
permission java.util.PropertyPermissi on "java.vm.vendor", "read";
permission java.util.PropertyPermissi on "java.vm.name", "read";
};
JRE:
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
OS:
Linux
btw: i don't want every client to have to change their policy file.
grant codeBase "file:${java.home}/lib/ext
permission java.security.AllPermissio
};
// default permissions granted to all domains
grant {
// just grant to everyone for now
permission java.lang.RuntimePermissio
// Allows any thread to stop itself using the java.lang.Thread.stop()
// method that takes no argument.
// Note that this permission is granted by default only to remain
// backwards compatible.
// It is strongly recommended that you either remove this permission
// from this policy file or further restrict it to code sources
// that you specify, because Thread.stop() is potentially unsafe.
// See "http://java.sun.com/notes" for more information.
permission java.lang.RuntimePermissio
// allows anyone to listen on un-privileged ports
permission java.net.SocketPermission "localhost:1024-", "listen";
// "standard" properies that can be read by anyone
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
permission java.util.PropertyPermissi
};
JRE:
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
OS:
Linux
btw: i don't want every client to have to change their policy file.
> btw: i don't want every client to have to change their policy file.
Then you'll have to sign your applet, and request the user grant the necessary permissions.
Then you'll have to sign your applet, and request the user grant the necessary permissions.
Did your check for the existence of other policy files?
ASKER
ok, then is there a better solution to pass my data from the servlet to the applet?
I don't want to pass a new list (ie. a vector generated from ResultSet).
I was thinking of using RMI.
I don't want to pass a new list (ie. a vector generated from ResultSet).
I was thinking of using RMI.
Another possible solution would be to include the required classes in your jar, though I'm not sure how many that would involve.
ASKER
> Did your check for the existence of other policy files?
yes, i was in the wrong one :(
yes, i was in the wrong one :(
ASKER
> Another possible solution would be to include the required classes in your jar, though I'm not sure
how many that would involve.
i tried that too, but i still get the accessClassInPath Error
how many that would involve.
i tried that too, but i still get the accessClassInPath Error
> I don't want to pass a new list
Can I ask why?
Can I ask why?
ASKER
b/c if i have a lot of records, i have to loop through the resultset and populate the vector. It's an efficiency issue. (though it's not necessarily a problem now, i want this to be scalable)
ASKER
actually, would i be able to populate a JTable from the resultset in the servlet and pass that to the applet?
i think that would work since JTable is serializable.
i think that would work since JTable is serializable.
Then why not make the JDBC call directly from the applet.
Or setup your servlet to return results in chunks.
Or have your servlet 'stream' the results one row at a time.
Or setup your servlet to return results in chunks.
Or have your servlet 'stream' the results one row at a time.
> would i be able to populate a JTable
What is difference between populating a JTable and populating a Vector?
I wouldn't recommend using a JTable for this purpose.
What is difference between populating a JTable and populating a Vector?
I wouldn't recommend using a JTable for this purpose.
ASKER
> Then why not make the JDBC call directly from the applet.
Yeah, i was thinking about doing that, but i like the idea of having the backend do all the work so as to maintain MVC architecture.
> Or setup your servlet to return results in chunks.
I may end up doing that.
> What's wrong w/ RMI?
Yeah, i was thinking about doing that, but i like the idea of having the backend do all the work so as to maintain MVC architecture.
> Or setup your servlet to return results in chunks.
I may end up doing that.
> What's wrong w/ RMI?
ASKER
> What is difference between populating a JTable and populating a Vector?
b/c the applet will show this JTable and i won't have to run through the vector at the applet to populate the JTable
b/c the applet will show this JTable and i won't have to run through the vector at the applet to populate the JTable
> What's wrong w/ RMI?
It seems unnecessary compication for required task.
> b/c the applet will show this JTable and i won't have to
> run through the vector at the applet to populate
> the JTable
Previously you stated you didn't want to loop thru the rs on the servlet to populate the vector. You'd have to do that to populate the table.
And you wouldn't send the JTable you'd simply send the model.
It seems unnecessary compication for required task.
> b/c the applet will show this JTable and i won't have to
> run through the vector at the applet to populate
> the JTable
Previously you stated you didn't want to loop thru the rs on the servlet to populate the vector. You'd have to do that to populate the table.
And you wouldn't send the JTable you'd simply send the model.
Personally it sounds like the best solution would be to try and have your servlet stream the results back as as they are read from the rs.
How big is the size(in KO) of a ResultSet ? You should build a specific string on the servlet and let the aplet to parse'it and rebuild the data. Should be not so time consuming this transfer and I expect not to have more that 20KO at maximum size.
Why construct a String and have the applet parse it?? A lot easier to just return data as an array or Vector.
bobbit31 also stated in an earlier comment that they aren't keen to load the entire result set for scaleability reasons.
bobbit31 also stated in an earlier comment that they aren't keen to load the entire result set for scaleability reasons.
array/Vector = objects colection = RMI transfer/serialized object transfer = inconsistent data over variuos connections = applet crashes = ...
"keep things simple" said someone ...
The parsing should not be a problem since you only need to add special separators between "table rows"&"table cells".
I don't get your point, whats complicated about passing an array/Vector from a servlet to an applet??
And why do u need RMI to do it, when a simple URLConnection will do the job?
And why do u need RMI to do it, when a simple URLConnection will do the job?
Vector = java.util.Vector ?
Vector = java.util.Vector ?
ASKER
ok, looking for a good data structure to use:
let's say i have 20 cols and 2000 rows... i was thinking a hashtable w/ the colname as key and a vector of col data as object. but to populate this vector would be time consuming... unless of course i chunk it into smaller bits.
Do you guys know of a more efficient way to do this?
I'm not too keen on the string idea b/c passing the hashtable would be just as easy and i wouldn't have to parse anything.
let's say i have 20 cols and 2000 rows... i was thinking a hashtable w/ the colname as key and a vector of col data as object. but to populate this vector would be time consuming... unless of course i chunk it into smaller bits.
Do you guys know of a more efficient way to do this?
I'm not too keen on the string idea b/c passing the hashtable would be just as easy and i wouldn't have to parse anything.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm not sure I agree with your efficiency concern. A CachedRowSet and a vector or list is in essence the same thing. When the CachedRowSet is created, it still loops through the entire resultset since it caches all the data. Arguably, a HashMap could actually propose less overhead since it's a simpler class than the CachedRowSet and contains less meta data.
ASKER
thanks everyone, but this is the way i decided to go...
Thanks for the points :)
http://www.objects.com.au
Brainbench MVP for Java 1
http://www.brainbench.com
http://www.objects.com.au
Brainbench MVP for Java 1
http://www.brainbench.com
permission java.lang.RuntimePermissio