Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is the "fix it" for getting to the net?

0 views
Skip to first unread message

bher...@hotmail.com

unread,
Nov 15, 2005, 9:49:30 AM11/15/05
to
Hi All,

Given that I have recently acquired BlueJ 2.0.5, that I have Win2k with
NT and Internet Explorer as my browser.

I have an applet that I several years ago made that uses "Bookmark" as
a reserved word. I can compile it with my copy of JB5 (jre 1.3). And
it still runs on successfully my computer by fetching several websites
from the net with a click of the buttons that are on the applet.

Obviously BlueJ 2.0.5, balks at compiling this which uses jdk1.5.0_05,
because Bookmark as a "word" has been depreciated and other issues?.


So as a restart to study the program design I copied from:


The Java Developers Almanac 1.4 e553. Making the Browser Visit a URL
// See also e551 The Quintessential Applet

try {
URL url = new URL(getDocumentBase(),
"http://hostname.com/page.html");
applet.getAppletContext().showDocument(url);
} catch (MalformedURLException e) {
}

And BlueJ will allow me to use my desktop version of "WebServer.exe"
to get a localhost address but will not allow me access to the net
because of security isues.

Again what is the "fix" for getting to the net ?

Bob

Andrew Thompson

unread,
Nov 15, 2005, 10:34:21 AM11/15/05
to
bher...@hotmail.com wrote:
...

> The Java Developers Almanac 1.4 e553. Making the Browser Visit a URL

LOL! It starts wrong, presuming you can
*make* a browser do *anything*.

> // See also e551 The Quintessential Applet
>
> try {
> URL url = new URL(getDocumentBase(),
> "http://hostname.com/page.html");

That will not result in a logical URL. Did you try printing
the document base, to look at it?

> applet.getAppletContext().showDocument(url);
> } catch (MalformedURLException e) {

// always! [1]
e.printStackTrace*();

> }

[1] <http://www.physci.org/codes/javafaq.jsp#stacktrace>

> And BlueJ will allow me to use my desktop version of "WebServer.exe"
> to get a localhost address but will not allow me access to the net
> because of security isues.

Really? It throws a SecurityIssuesException, does it?
Iy is best to quote any error output precisely,
copy/pasting error and exception messages is best.
<http://www.physci.org/codes/javafaq.jsp#exact>

> Again what is the "fix" for getting to the net ?

Let's sort what the real problem is, first.

bher...@hotmail.com

unread,
Nov 16, 2005, 1:16:56 AM11/16/05
to
Andrew,

Responding to your remark that I did not show you the list of errors,
here is the

discussion and error list.
Here is the java program mentioned earlier from Java Developers
Almanac.....
Quintessential Applet adapted for net and localhost sources.


import java.awt.*;
import java.awt.image.*;
import java.applet.*;
import java.net.URL;
import java.net.MalformedURLException;


public class withUrlGetHTMLJpg extends java.applet.Applet {
Image image;
public void init() {
// Load image
image =

getImage(getDocumentBase(),"http://image.weather.com/images/maps/current/c

urwx_720x486.jpg");
//image = getImage(getDocumentBase(),

"http://localhost/bherbst/jgarner_alias_150x200.jpg");
}
public void paint(Graphics g) {
// Draw image
g.drawImage(image, 0, 0, this);
}
}

Class compiled - no syntax errors.

upon running the browser option of BlueJ
these errors are noted in the java console:

java.security.AccessControlException: access denied
(java.net.SocketPermission

image.weather.com resolve)
at java.security.AccessControlContext.checkPermission(Unknown

Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at

sun.plugin.viewer.context.DefaultPluginAppletContext.getImage(Unknown
Source)
at java.applet.Applet.getImage(Unknown Source)
at java.applet.Applet.getImage(Unknown Source)
at withUrlGetHTMLJpg.init(withUrlGetHTMLJpg.java:36)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.security.AccessControlException: access denied
(java.net.SocketPermission

image.weather.com resolve)
at java.security.AccessControlContext.checkPermission(Unknown

Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at

sun.plugin.viewer.context.DefaultPluginAppletContext.getImage(Unknown
Source)
at java.applet.Applet.getImage(Unknown Source)
at java.applet.Applet.getImage(Unknown Source)
at withUrlGetHTMLJpg.init(withUrlGetHTMLJpg.java:36)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "thread applet-withUrlGetHTMLJpg.class"

java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.security.AccessControlException: access denied
(java.net.SocketPermission

image.weather.com resolve)
at java.security.AccessControlContext.checkPermission(Unknown

Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at

sun.plugin.viewer.context.DefaultPluginAppletContext.getImage(Unknown
Source)
at java.applet.Applet.getImage(Unknown Source)
at java.applet.Applet.getImage(Unknown Source)
at withUrlGetHTMLJpg.init(withUrlGetHTMLJpg.java:36)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "thread applet-withUrlGetHTMLJpg.class"

java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.security.AccessControlException: access denied
(java.net.SocketPermission

image.weather.com resolve)
at java.security.AccessControlContext.checkPermission(Unknown

Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at

sun.plugin.viewer.context.DefaultPluginAppletContext.getImage(Unknown
Source)
at java.applet.Applet.getImage(Unknown Source)
at java.applet.Applet.getImage(Unknown Source)
at withUrlGetHTMLJpg.init(withUrlGetHTMLJpg.java:36)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception in thread "thread applet-withUrlGetHTMLJpg.class"

java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.security.AccessControlException: access denied
(java.net.SocketPermission

image.weather.com resolve)
at java.security.AccessControlContext.checkPermission(Unknown

Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at

sun.plugin.viewer.context.DefaultPluginAppletContext.getImage(Unknown
Source)
at java.applet.Applet.getImage(Unknown Source)
at java.applet.Applet.getImage(Unknown Source)
at withUrlGetHTMLJpg.init(withUrlGetHTMLJpg.java:36)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
.............. end of error list

Upon running the localhost option as noted in the original above ....
image = getImage(getDocumentBase(),

"http://localhost/bherbst/jgarner_alias_150x200.jpg");
}

Using the option to Run applet in appletviewer and the other option Run
applet in

web browser, each method displayed the image correctly.

Bob

Andrew Thompson

unread,
Nov 16, 2005, 2:48:05 AM11/16/05
to
bher...@hotmail.com wrote:

....


> Here is the java program mentioned earlier from Java Developers
> Almanac.....

Is this 'copy/pasted' from the original?

> Quintessential Applet adapted ..

...hhhmmmm.

>.. for net and localhost sources.

OK. This is not intended as 'an answer', but simply
a piece of code that might help to bring a variety of
things to your attention. Please read all the comments
carefully, and run it and observe the behaviour.

Note that creating an URL and 'showDocument(url)'
casuese no errors but has no effect in the applet
biewer here locally, but that the applet viewer fails
with an AccessControlException when we try to obtain
the image. This behaviour is as I expect it to be*.

What had me a little confused before was that your
call to showDocument was failing, and I could not
immediately understand why.

By separating the creation of the URL to a separate
line (rather than calling it blindly from within a
method call as the original code was doing) the
call to showDocument now 'works'. I can only assume
(left as a problem for the OP to chase up) that your
original call to create the URL used a form that
incurred access restrictions.

The real 'lesson' if any to be learned here is to break
the statements up, to get a clearer idea of exactly wht
is breaking/not permitted/null at the point of failure.

Here is the altered code..

<sscce>


import java.awt.*;
import java.awt.image.*;
import java.applet.*;
import java.net.URL;
import java.net.MalformedURLException;

// the 'ClassName' should have each word start upper
// case, for a class like this I suggest
// TestUrlGetImage


public class withUrlGetHTMLJpg extends java.applet.Applet{
Image image;
public void init() {

try {

// your strings are too long, and break lines
// and compilation.Take note how to build
// up strings over several lines.
URL url = new URL("http://image.weather" +
".com/images/maps/current/curwx_720x486.jpg");

// what happened to 'showDocument()'??
// now you are getting an image?!?
getAppletContext().showDocument(url);
System.out.println("New document should be open!");

// Load image
image = getImage(url);
System.out.println("Image has been 'got'!");

//getImage(getDocumentBase(), "http://image.weather" +
//".com/images/maps/current/curwx_720x486.jpg");
//image = getImage(getDocumentBase(),
// is this supposed to be commented too?
//"http://localhost/bherbst/jgarner_alias_150x200.jpg");

// 'now' (commented out very early) I do not know
// if we are using the same code... :-(
} catch(MalformedURLException murle) {
murle.printStackTrace();
} catch (java.security.AccessControlException ace) {
ace.printStackTrace();
}
}

public void paint(Graphics g) {
// Draw image
g.drawImage(image, 0, 0, this);
}
}

</sscce>

Oh, and now I am clear on how this code is behaving, I
can clarify a few things for you.

- you can create an URL from a string and call
showDocument(url). It might not have any effect
(especially in this day and age) but should not
throw any errors.
- An unsigned applet can not obtain resources such
as images across codebases. In other words, it cannot
'pull content from other sites'
- A signed applet, that the end user has 'OK'd can
get content across domains.
- As a web-master (who hates serving up content for
"other people's sites") I am prompted to ask.
Why exactly are you pulling content from other sites
in this applet? Why not host the (dang) image on
your own site?!?

Roedy Green

unread,
Nov 16, 2005, 4:45:14 AM11/16/05
to
On 15 Nov 2005 06:49:30 -0800, bher...@hotmail.com wrote, quoted or
indirectly quoted someone who said :

>Obviously BlueJ 2.0.5, balks at compiling this which uses jdk1.5.0_05,
>because Bookmark as a "word" has been depreciated and other issues?.

Bookmark is not a reserved word. There may be a name clash, but you
can easily resolve that by putting your code in a package.

see http://mindprod.com/jgloss/package.html
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

bher...@hotmail.com

unread,
Nov 18, 2005, 11:05:42 PM11/18/05
to
Roedy,
What got me moving on this "applet topic" was this posting:

URL connection problem , Dated Nov 14
http://groups.google.com/group/comp.lang.java.programmer/browse_frm/thread/9

d912f4bef6751ec/d11d89f1d3202e4c#d11d89f1d3202e4c

Early on I asked: Is this an application or an applet.
......
I have Win2K, a sample applet with buttons to click the specific
images up and safeguards to report error.

...........you wrote
you can't load images from a server other than Mom with an Applet. It
must be signed. Or use an application.


Roedy, I was downsizing my bookmark [] applet to see if I could rework
the
bookmark program and saw that something was depreciated......
"Warning: [deprecation] action(java.awt.Event,java.lang.Object) in
ava.awt.Component has been deprecated"

Discovered the "fixit" in this recent google posting.
"Replacement requested for depricated coding"
http://groups.google.com/group/comp.lang.java.help/browse_frm/thread/6c8336db75d4dd30/8cf58afcd731ca9a?hl=en#8cf58afcd731ca9a

So at this time the bookmark applet program is updated and is alive and
well.


Andrew,


You wrote:
- As a web-master (who hates serving up content for
"other people's sites") I am prompted to ask.
Why exactly are you pulling content from other sites
in this applet? Why not host the (dang) image on
your own site?!?

..........

I have no website that I am sharing my download. It's just for my
personal use.

With "bookmark" I have java "buttoned" to 6 or 8 sites on the net :
weather.com, this google site, a Borland java news student group site,
my hotmail account, a search page for MSN and accessing "localhost"
with my
WebServer.exe a Delphi ICS tool. I use the latter for testing what I
have
designed. I don't want to see more web popups full of advertising does
nothing for me but use up a "limited" amount of internet time.

Hope that explains it.

Bob

0 new messages