Solved

IE4 behind a proxy server

Posted on 1998-05-22
10
357 Views
Last Modified: 2010-08-05
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
Comment
Question by:gerry99
  • 5
  • 5
10 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 1221370
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
 
LVL 1

Author Comment

by:gerry99
ID: 1221371
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
 
LVL 32

Accepted Solution

by:
jhance earned 200 total points
ID: 1221372
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
 
LVL 1

Author Comment

by:gerry99
ID: 1221373
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
 
LVL 32

Expert Comment

by:jhance
ID: 1221374
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:gerry99
ID: 1221375
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
 
LVL 32

Expert Comment

by:jhance
ID: 1221376
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
 
LVL 1

Author Comment

by:gerry99
ID: 1221377
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
 
LVL 1

Author Comment

by:gerry99
ID: 1221378
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
 
LVL 32

Expert Comment

by:jhance
ID: 1221379
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now