Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / September 2005

Tip: Looking for answers? Try searching our database.

problem getting a db4o file from a server with an Applet

Thread view: 
Johan Kütt - 03 Sep 2005 09:59 GMT
Hi

When I start my Applet I need to retrieve a db4o database file from a
server. I tried reading the file with an InputStream and then writing it
to a FileOutputStream, but this doesn't work, because when trying to
write a File, I get some kind of SecurityException (don't remember
exactly). Tried right now again and now I get a AccessControlException
(access denied) when trying to open an InputStream. Yesturday I was able
to open an InputStream.

Any suggestions on how could I get the requested file? And later, if the
database is modified, write it back to the server? (Servlets can't be
used on this server for some reason)

code:
============================================
public class AppletTest extends JApplet {

  URL url;
  URLConnection conn;

  public void paint( Graphics g ) {
    try {
      url = new URL( http://www.tac.ee/~johan/java/AppletTest/test.db4o" );
      conn = url.openConnection();

      InputStream input = conn.getInputStream();
      byte[] buffer = new byte[512];
      int read = -1;

      FileOutputStream fileOut = new FileOutputStream("temp.db4o");
      while ((read = input.read(buffer, 0, buffer.length)) != -1)
        fileOut.write(buffer, 0, read);

      fileOut.close();
      input.close();
    }
    catch( allkindsofexceptions ){}
  }
}
=============================================

I use the server in this example only for testing, because I don't
currently have access to the final server where the completed
application will reside.

johan
Andrew Thompson - 03 Sep 2005 10:12 GMT
> When I start my Applet

URL?

> ..I need to retrieve a db4o database file from a
> server.

Which server?  The same one that hosts the applet?

>..I tried reading the file with an InputStream and then writing it
> to a FileOutputStream, but this doesn't work,

Maybe it's just lazy.   [ ;-) ]

>..because when trying to write a File, I get some kind of
> SecurityException (don't remember exactly).

Perhaps you should write it down, or copy/paste it..
<http://www.physci.org/codes/javafaq.jsp#exact>

>..Tried right now again and now I get a AccessControlException
> (access denied) when trying to open an InputStream.

Applet security sandbox.  You're in it.
<http://www.physci.org/codes/javafaq.jsp#security>

To break out of that sandbox, you need to sign your
applet and convince the user to accept your signed code.

> public class AppletTest extends JApplet {

Why a JApplet?

>    URL url;
>    URLConnection conn;
>
>    public void paint( Graphics g ) {

..and why override paint (rather than paintComponent)

>      try {
>        url = new URL( http://www.tac.ee/~johan/java/AppletTest/test.db4o" );
>        conn = url.openConnection();

What?!?  You are trying to open a new connection every
time the applet is painted?

>      }
>      catch( allkindsofexceptions ){}

Bad, bad, bad!  Never swallow exceptions in code that is failing!
<http://www.physci.org/codes/javafaq.jsp#stacktrace>

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"Sing out Hare Hare, dance the Hoochie Koo."
Led Zeppelin 'The Song Remains The Same'

Johan Kütt - 03 Sep 2005 10:54 GMT
note: when anyone answers my help request, please send a copy of your
reply also to my private e-mail address (remove underscores) because I
always don't receive all news messages (don't know why)

johan

> Hi
>
[quoted text clipped - 43 lines]
>
> johan
Andrew Thompson - 03 Sep 2005 11:04 GMT
> note: when anyone answers my help request, please send a copy of your
> reply also to my private e-mail address (remove underscores) because I
> always don't receive all news messages (don't know why)

Whereas I don't care.  I suggest you find yourself a decent ISP
or use one of the web based interfaces to usenet.  Such as..
<http://groups.google.com.au/group/comp.lang.java.help/browse_frm/thread/5b507584
1231edb7/2386a2766372e0de#2386a2766372e0de
>
<http://www.javakb.com/Uwe/Forum.aspx/java-setup/6575/problem-getting-a-db4o-file
-from-a-server-with-an-Applet
>

As an aside, my news-reader client is not set-up to send
email, and I have no intention of changing that.

Signature

Andrew Thompson
physci.org 1point1c.org javasaver.com lensescapes.com athompson.info
"If you don't love me baby, you better act like you do.."
Screamin' Jay Hawkins 'I Need You'



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.