Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4411836

java plugin 1.3.0_01 client authentication dialog returns NullPointerException

XMLWordPrintable

    • 008
    • generic, x86
    • generic, windows_nt
    • Verified

        The problem occurs when attempting to access a URL from an applet running
        under the plug-in (1.3.0_01) when the file associated with the URL has been
        specified as requiring client authentication.

        In previous versions (1.3.0-C) of the plug-in, the user was correctly
        prompted
        with a dialog requesting a username and password. Once the user had entered
        in the correct username and password, access to the URL proceeded as normal.

        Under the 1.3.0_01 version of the plug-in, however, once the user has
        entered
        in the username and password and clicks "OK", a NullPointerException occurs.
        I get the same behavior on both IE 5.5 and Netscape 4.0 browsers running on
        NT 4.0 sp5.

        Included is a sample applet that can be used to help reproduce the problem.
        It attempts to retrieve the contents of an html file from the URL typed into
        the text field. The contents of the text file are displayed in the text
        area
        below the url text field.

        To test, setup an html file as requiring client authentication on a web
        server
        (instructions to do this are server specific), and then bring up the
        attached
        ClientAuthTest.html page to load the test applet. Then type in the URL of
        the
        html file requiring client authentication and hit return. The contents of
        the
        file should appear in the text area.

        The output that I get in the Java Console window when I encounter the error
        is given below.


        =========================================================================

        Java(TM) Plug-in: Version 1.3.0_01
        Using JRE version 1.3.0_01 Java HotSpot(TM) Client VM
        User home directory = C:\WINNT\Profiles\MGOMEZ Proxy Configuration: no proxy
        ----------------------------------------------------
        c: clear console window
        f: finalize objects on finalization queue
        g: garbage collect
        h: display this help message
        l: dump classloader list
        m: print memory usage
        q: hide console
        s: dump system properties
        t: dump thread list
        x: clear classloader cache
        0-5: set trace level to <n>
        ----------------------------------------------------
        Exception occurred during event dispatching: java.lang.NullPointerException
            at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
        Source)
            at
        sun.plugin.protocol.jdk12.http.HttpURLConnection.getInputStream(Unknown
        Source)
            at sun.net.www.protocol.http.HttpURLConnection.getHeaderField(Unknown
        Source)
            at
        sun.plugin.protocol.jdk12.http.HttpURLConnection.checkCookieHeader(Unknown
        Source)
            at
        sun.plugin.protocol.jdk12.http.HttpURLConnection.getInputStream(Unknown
        Source)
            at ClientAuthTest.performTest(ClientAuthTest.java:108)
            at ClientAuthTest.actionPerformed(ClientAuthTest.java:87)
            at javax.swing.JTextField.fireActionPerformed(Unknown Source)
            at javax.swing.JTextField.postActionEvent(Unknown Source)
            at javax.swing.JTextField$NotifyAction.actionPerformed(Unknown Source)
            at javax.swing.SwingUtilities.notifyAction(Unknown Source)
            at javax.swing.JComponent.processKeyBinding(Unknown Source)
            at javax.swing.JComponent.processKeyBindings(Unknown Source
            at javax.swing.JComponent.processKeyEvent(Unknown Source)
            at java.awt.Component.processEvent(Unknown Source)
            at java.awt.Container.processEvent(Unknown Source)
            at java.awt.Component.dispatchEventImpl(Unknown Source)
            at java.awt.Container.dispatchEventImpl(Unknown Source)
            at java.awt.Component.dispatchEvent(Unknown Source)
            at java.awt.LightweightDispatcher.processKeyEvent(Unknown Source)
            at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
            at java.awt.Container.dispatchEventImpl(Unknown Source)
            at java.awt.Component.dispatchEvent(Unknown Source)
            at java.awt.EventQueue.dispatchEvent(Unknown Source)
            at java.awt.EventDispatchThread.pumpOneEvent(Unknown Source)
            at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
            at java.awt.EventDispatchThread.run(Unknown Source)

        ********************************************************************************
        ClientAuthTest.java:

        /*
         * Applet to test client authentication in Java Plug-in
         *
         * Type a URL into the text field and hit return to retrieve the
         * associated file and display its contents in the text area.
         *
         * To test client authentication, attempt to retrieve a html (or
         * other text file) that has been designated as requiring client
         * authentication by the server.
         */

        import java.awt.*;
        import java.awt.event.*;
        import javax.swing.*;

        import java.io.*;
        import java.net.*;

        public class ClientAuthTest extends JApplet implements ActionListener
        {
            // Method to initialize applet.

            public void init()
            {

                // Set up a panel containing a text field with a text area below it.

                _urlTextField = new JTextField(25);
                _urlTextField.addActionListener(this);

                _textArea = new JTextArea(5, 20);
                _textArea.setEditable(false);

                JScrollPane scrollPane = new JScrollPane(_textArea,
                                               JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                                               JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

                // Add components to the applet.

                GridBagLayout gridBag = new GridBagLayout();

                Container contentPane = getContentPane();
                contentPane.setLayout( gridBag );

                GridBagConstraints c = new GridBagConstraints();
                c.gridwidth = GridBagConstraints.REMAINDER;

                c.fill = GridBagConstraints.HORIZONTAL;
                gridBag.setConstraints( _urlTextField, c );

                contentPane.add( _urlTextField );

                c.fill = GridBagConstraints.BOTH;
                c.weightx = 1.0;
                c.weighty = 1.0;
                gridBag.setConstraints(scrollPane, c);
                contentPane.add(scrollPane);

                // Init the url text field so save on typing.

                String urlText = this.getDocumentBase().toString();

                int index = urlText.indexOf( "//" );

                if ( index != -1 )
                {
                    index = urlText.indexOf( '/', index + 2 );

                    if ( index != -1 )
                        _urlTextField.setText( urlText.substring(0, index + 1) );
                }
            }

            // Method to handle event from URL text field.

            public void actionPerformed( ActionEvent event )
            {
                String urlText = _urlTextField.getText();
                Object source = event.getSource();

                if ( (urlText == null) || (urlText.length() == 0) )
                    return;

                try
                {
                    if ( source == _urlTextField )
                        performTest( new URL(urlText), _textArea );
                }

                catch (MalformedURLException e)
                {
                    System.out.println( "ERROR: couldn't open URL" );
                }
            }

            // Method to perform test. Retrieves the associated text file from
            // the server and displays its contents in the text area.

            private void performTest( URL url, JTextArea textArea )
            {
                try
                {
                    // Open a connection and get an input stream to the file.

                    URLConnection connection = url.openConnection();
                    connection.setUseCaches( false );

                    BufferedReader in = new BufferedReader(
                    new InputStreamReader( connection.getInputStream()) );

                    // First display the header fields for the response.

                    textArea.setText("");
                    textArea.append( connection.getHeaderField(0) + "\n");

                    int fieldIndex = 1;
                    String fieldName = connection.getHeaderFieldKey( fieldIndex );

                    while ( fieldName != null )
                    {
                        textArea.append( fieldName + ": " + connection.getHeaderField( fieldIndex ) + "\n");
                        fieldName = connection.getHeaderFieldKey( ++fieldIndex );
                    }

                    textArea.append( "-------------------------------------\n" );

                    // Now get the actual text retrieved from the specified URL

                    String line;

                    while ( (line = in.readLine()) != null )
                        textArea.append( line + "\n" );

                    in.close();
                }

                // Catch any I/O exceptions

                catch (IOException e)
                {
                    System.out.println( "ERROR: IO problem" );
                }
           }

            // Declare attributes

            private JTextField _urlTextField;
            private JTextArea _textArea;

        }

        ********************************************************************************

        ClientAuthTest.html:


        <html>
        <title>Plug-in Client Authentication Tester</title>
        <body>
        <!--"CONVERTED_APPLET"-->
        <!-- CONVERTER VERSION 1.3 -->
        <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
        WIDTH = 100% HEIGHT = 100% codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-win32.cab#Version=1,3,0,0">
        <PARAM NAME = CODE VALUE = "ClientAuthTest.class">
        <PARAM NAME = "type" VALUE="application/x-java-applet;version=1.3">
        <PARAM NAME = "scriptable" VALUE="false">

        <COMMENT>
        <EMBED type="application/x-java-applet;version=1.3"
           CODE = "ClientAuthTest.class"
           WIDTH = 100% HEIGHT = 100%
           scriptable = false
           pluginspage = "http://java.sun.com/products/plugin/1.3/plugin-install.html">
        <NOEMBED>
        </COMMENT>

        </NOEMBED></EMBED>
        </OBJECT>

              stanleyh Stanley Ho (Inactive)
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: