Closed Bug 86437 Opened 23 years ago Closed 23 years ago

Javascript initiated connection to a URL through a Java applet does not work

Categories

(Core Graveyard :: Java: OJI, defect, P2)

x86
Linux
defect

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: mubashir.a.cheema, Assigned: joe.chou)

Details

(Whiteboard: jpibug)

Attachments

(1 file)

We need to be able to update a data field on a page without submitting a form and reloading the page. So we get Javascript to connect to an embedded Java applet that connects to a URL and fetches data that we are interested in. This works in Netscape 4.7x just fine. However it does not work in any of the recent Mozilla releases or nightly builds, using Sun's jre 1.3.1. Here is a simple test case that makes Mozilla hang every time. Some members of Sun's OJI team have tried it and confirmed the existence of the problem. --------- DrawStringApplet ----------- import java.applet.*; import java.awt.*; import java.net.*; import java.io.*; public class DrawStringApplet extends Applet { Thread myThread; String errTxt = "Initializing"; public void connectToCgi(String txt) { URL url; URLConnection urlConn; String thisLine; String location = "http://localhost/cgi-bin/test.cgi"; try { URL testServlet = new URL( location ); URLConnection servletConnection = testServlet.openConnection(); DataInputStream in = new DataInputStream(servletConnection.getInputStream ()); BufferedReader theHTML = new BufferedReader( new InputStreamReader(in)); while ((thisLine = theHTML.readLine()) != null) { updateDisplay(thisLine); sleep(1000); } } catch (Exception e) { } } public void updateDisplay(String txt) { errTxt = new String(txt); this.showStatus(errTxt); repaint(); } public void repaint(Graphics g) { paint(g); } public void paint (Graphics g) { g.drawString(errTxt,10,10); } public void sleep (int period) { try {Thread.sleep(period);} catch(InterruptedException e) {} } } --------- testjava.html ----------- <html> <head> <title> Test Applet </title> </head> <body> <h1>Test Applet</h1> <applet name=testapp code = "DrawStringApplet2.class" width=300 height=50> </applet><P> <script language="JavaScript"> function ConnectToURL() { document.testapp.connectToCgi("Clicked"); } </script> <a href="#" onClick="ConnectToURL()">Click here to Connect to CGI script</a> </body> </html> ------- test.cgi ----------- #!/bin/sh echo "Content-Type: text/html"; echo; echo "URL Connection successful!";
Assignee: rogerl → edburns
Status: UNCONFIRMED → NEW
Component: Live Connect → OJI
Ever confirmed: true
QA Contact: pschwartau → shrir
Reassigning to OJI component -
A couple of additional comments : - Test case needs a small modification. Line 10 of testjava.html should read: <applet name=testapp code = "DrawStringApplet.class" width=300 and not <applet name=testapp code = "DrawStringApplet2.class" width=300 - You will need to place the script test.cgi behind a web server and test it by pointing a web browser at http://localhost/cgi-bin/test.cgi or wherever you put the test.cgi script at. - Point Netscape 4.7x at testjava.html file. Click on : "Click here to Connect to CGI script" and your applet will show : "URL Connection successful!" Repeat this with a recent Mozilla and if it works for you, please please drop me a line. I'd be very very interested in finding out how you did it.
Re-assigning to Joe Chou, who has already been in contact with the customer. Joe, please accept the bug and place a priority on it right away.
Assignee: edburns → joe.chou
Severity: blocker → critical
Priority: -- → P2
Reproduced the problem, assign the bug to myself for now.
Status: NEW → ASSIGNED
Some more update: 1)If added a button to the test page via the applet (see attachment), then the test case would work by clicking the button. (Would that be a work-around till a fix is available, Cheema?) 2)Also if added init() in the applet, and call connectToCgi() in init(), it would work. 3)Also the testcase worked with waterfall. Stanley, the problem seems to be between applet and cgi when triggered by JavaScript. Can you take a look?
I was actually already aware of the possibility of using Java applet to initiate the connection to CGI. However our product is designed so that we cannot use that. The connection has to be initiated by Javascript. Again, thanks for looking into this.
Through some primitive debugging I discovered that nsCSecurityContext::GetOrigin and nsCSecurityContext::Implies methods get called from what seems like an infinite loop when the user clicks on the "Click here to Connect to CGI script" link of the test case. nsCSecurityContext.cpp belongs to the OJI module and can be found at mozilla/modules/oji/src. This behaviour can be observed by making these methods print a debug line toward the end of each of respective methods. I thought I'd share this information in the hopes that it helps the developers get some idea of where the problem may be.
The problem seems to be with the URLConnection object being returned by protocol handler on the openConnection call (sun.plugin.protocol.jdk12.http.HttpURLConnection). Any call to this object will fail (I know not why). However, if we use the default object (sun.net.www.protocol.http.HttpURLConnection) everything works. So, a workaround is to set: java.protocol.handler.pkgs=sun.net.www.protocol in your .java/properties file.
I tried it (adding a line to java property file), and it seemed working.
This problem seems to be a Java bug. A Sun internal bug (#4473593) has been created, and assigned to the Java plugin group. Till the bug is fixed, use the work around provide by Salomon. It worked for me.
Added "jpibug" to Status Whiteboard (a Java Plugin bug), also filed Sun's bugtraq bug (4473593). Mark invalid (not a browser bug).
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
Whiteboard: jpibug
4473593 has been fixed, and the fix will be available in JRE 1.4.
SPAM: reassigning OJI bugs to new QA, pmac. (227 bugs)
QA Contact: shrir → pmac
QA Contact: pmac → petersen
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: