Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 365
  • Last Modified:

IE4 behind a proxy server

I have an applet that uses http to communicate to a process running on its host.  This applet works fine when not behind a  firewall, and I know how to configure Navigator 4 so that it does not prevent the applet from communicating when run behind a firewall.

How can I convince IE 4 to allow the http connection?

The proxy forces a DNS lookup which violates an applet security requirment.  Netscape has a technique for avoiding this, does Microsoft?
0
gerry99
Asked:
gerry99
  • 5
  • 5
1 Solution
 
jhanceCommented:
How is your APPLET accessing the remote host?  Is it using "raw" java.net.Socket calls or java.net.URLConnection?  If using Socket, then you must determine if a proxy is present and talk to the proxy yourself.  If using URLConnection, the library will detect your proxy setting by itself and talk through the proxy as needed.
0
 
gerry99Author Commented:
I'm currently using Socket, because I want to use the CGI Post format.

Some code:

      // get name of html data page
      String sQuery = "POST " + m_source + " HTTP/1.0\r\n"
            + "Content-type: application/x-www-form-urlencoded\r\n"
            + "Content-length: " + m_content.length() + "\r\n\r\n"
            + m_content;
              try       
      {
            // open a socket - m_host set to documentBase, port = 80
            sock = new Socket( m_host, m_port );
            // get data streams
            outStrm = new DataOutputStream( sock.getOutputStream() );
            inStrm = new DataInputStream( sock.getInputStream() );
            // send the request
            outStrm.writeBytes( sQuery );
            // read the page
            while( (line = inStrm.readLine()) != null )
                     // do something with response


0
 
jhanceCommented:
If you're using Socket, you have to use some type of setting to tell your applet to talk to/through the HTTP proxy instead of directly to the remote system.  Basically everything is the same except the following:

1) Instead of opening a Socket to the remote server, you open a Socket to the proxy server and it's port.

2) The HTTP is the same except that you put the full URL (i.e. http://www.remote.com/page.html) where you would normally put just /page.html.

The proxy will do what you ask for you and you will get a response back from the proxy as though you were talking directly to the remote server.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gerry99Author Commented:
Do I need to determine the url of the proxy? and its port?
How would I do that?

In your point 2)
My socket is opened using the full URL of the applet's originating host.  I'm not using
partial URLs here.
0
 
jhanceCommented:
You need to ask your firewall/proxy administrator what the address and port of the proxy are.  If your web browser works, it seems to me that you must already know it.

Your m_source is normally just the page or script you want at the host.  Something like /page.html.  When talking to a proxy, you give the proxy the full URL of what you want.  So in your example, m_source would be something like:

http://www.remote.com/page.html:80

0
 
gerry99Author Commented:
jhance,

I'm going to take some time, to see if I can implement my
http based query using a URLConnection.  I'll get back to you.

The applet in question is available on the public internet, and
can be accessed by people behind firewalls and proxies that I've
never heard of, and that I can't encode into my applet.  I suppose I could prompt for proxy information, but that is too technical for the audience I'm targetting.

The root of my frustration is that connecting back the the host, is well within the sandbox requirements, and yet it can fail based on external networking considerations, and browser type.
0
 
jhanceCommented:
Again, that's the purpose of the URLConnection.  It uses the browser's setup to connect either directly or via a proxy if that's what is configured.  If the browser isn't setup right, then it's a mute point as the user won't ever get to your applet to begin with.  The Socket class is a lower level class that gives you (the programmer) more control over the connection.
0
 
gerry99Author Commented:
I've created some code that uses the URLConnection.  I'm still waiting to find out if this fixes the proxy problem.

During testing I've noticed that the connection.getOutputStream" throws an exception with Netscape 4.05 (JDK 1.5 preview version).

This is my code:

url = new URL( "http", m_host, m_port, m_source );
connection = url.openConnection();
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Content-length", Integer.toString(m_content.length()) );
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches( false );
connection.connect();

outStrm = new DataOutputStream( connection.getOutputStream() );
outStrm.writeBytes( m_content );
outStrm.flush();
outStrm.close();

inStrm = new DataInputStream( connection.getInputStream() );
// read the response                  String line;
while( (line = inStrm.readLine()) != null )
{
     // do something
}

This is the exception:
# Applet exception: Already connected
java.lang.IllegalAccessError: Already connected
  at java.lang.Throwable.<init>(Compiled Code)
  at java.lang.Error.<init>(Compiled Code)
  at java.lang.LinkageError.<init>(Compiled Code)
  at java.lang.IncompatibleClassChangeError.<init>(Compiled Code)
  at java.lang.IllegalAccessError.<init>(Compiled Code)
  at netscape.net.URLConnection.getOutputStream(Compiled Code)
* at sw.common.data.Preferences.MakeQuery(Compiled Code)
  at sw.common.data.Preferences.run(Compiled Code)
  at java.lang.Thread.run(Compiled Code)
java.io.IOException: CreateProcess: vcafe -netscape error=2
  at java.lang.Win32Process.<init>(Compiled Code)
  at java.lang.Runtime.exec(Compiled Code)
* at java.lang.Runtime.exec(Compiled Code)
  at netscape.debug.Debugger.launchDebugger(Compiled Code)
  at netscape.debug.Debugger.uncaughtException(Compiled Code)
  at netscape.applet.AppletThreadGroup.uncaughtException(Compiled Code)

IllegalAccessError is normally thrown if the runtime libary has
changed method or variables in an incompatible way.

From my documentation:
"Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to.

Normally, this error is caught by the compiler; this error can only occur at run-time if the definition of a class has incompatibably changed. "

The code above works fine with IE 4.

Any suggestions?
0
 
gerry99Author Commented:
Jhance,

I've had a client test my new code using URLConnection instead of
Socket, with IE4, behind a firewall/proxy and apparently it still fails.  I'm not sure of the exact nature of the failure.

I'm prepared to accept your answer if you can clarify the following.  A URLConnection will use whatever proxy setup the user has encoded in their browser.  Is this correct?  If so then by definition any applet loaded from the internet that uses URLConnection should be able to communicate back to its host using a fully specified URL (http://myhost.com/myCGI) and the URLConnection.

BTW, with the last exception, I discovered the Netscape and MS both work fine if you remove the "connection.connect();" line.
0
 
jhanceCommented:
I don't find the connect() method as one listed in the URLConnection class.  I'm looking at the JDK 1.02 docs but I don't see it.

A URLConnection when run in a applet within IE or Navigator will use the proxy settings of the host browser environment. This is the exception to the Java applet security rule where the only network connections an applet can make are back to the server which served up the applet.


0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now