Solved

Making an URLConnection

Posted on 1998-05-18
8
575 Views
Last Modified: 2008-02-01
I don't understand why the call to getResponseCode() below gives an UnsatisfiedLinkError.

          URL url = new URL(docName);
          HttpURLConnection checkURL =  (HttpURLConnection)url.openConnection();
          try {
            if (checkURL.getResponseCode() == 404)
            {
              System.err.println("Failed to get doc " + docName);
              return;
            }
          } catch (UnsatisfiedLinkError ule) {
            System.err.println("Unable to resolve docname " + docName);
            return;
          } catch (NullPointerException npe) {
            System.err.println("Can't get doc " + docName);
            return;
          }

If I understand the docs correctly, openConnection() should call connect() for me.
The other weird thing is that this code ran fine under 1.1.2, but fails under 1.1.3 and later.
0
Comment
Question by:wex
  • 4
  • 4
8 Comments
 
LVL 5

Expert Comment

by:msmolyak
ID: 1221165
Is it possible that you have multiple JDK  installations on your machine with environment variables pointing to the more than one at a time. For example your CLASSPATH may point to JDK1.1.2\lib\classes.zip while your PATH may contain JDK1.1.3\bin directory. That may cause the described behaviour. (The DLL on your path does not contain the exact native function the JVM is trying to invoke).
0
 
LVL 1

Author Comment

by:wex
ID: 1221166
Yeah, I think that's the right track, but I'm confused why it's happening.  I'm on a UNIX box
and the only relevant thing on my PATH is /usr/java/bin

My CLASSPATH includes only the directories relevant to my project; I'm depending on
java to add the proper directories for its own .class files.  Is that an error?
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1221167
It's hard for me to speak about UNIX since I do my development on NT. Each JDK come with set of class files and set of executables and dynamic libraries (shared objects in UNIX). When I install subsequent versions of JDK I install them in different directories which causes my to update CLASSPATH and PATH each time I do that. What you are saying is that your path keeps pointing to /usr/java/bin. Does it mean that each new installation overwrites an older one? Is it the only possible way to install JDK?

Anyway, why don't you find out for sure where the classes.zip and the executables (such as java) for the version you want to use are. You can do it by using "which java" command and renaming directories where class libraries are.

Not putting classes.zip on a classpath is not an error as long as you know that it uses the right version. In your case you don't seem to be sure of that.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:wex
ID: 1221168
There's no classes.zip file in there.  I've checked for it.
I've also checked for the possibility of multiple installations and there's only one on each machine.
The executables are clearly in /usr/java/bin
I checked that and it's the standard approach where everything points to one java_wrapper script which (among a zillion other things) sets the CLASSPATH.

What baffles me is why there's only one file which it can't find.  When I get the stack trace from this error, it looks like this:
java.lang.UnsatisfiedLinkError: getInetFamily
        at java.net.InetAddress.<init>(InetAddress.java:63)
        at
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:201)
        at sun.net.www.http.HttpClient.<init>(HttpClient.java:219)
        at sun.net.www.http.HttpClient.New(HttpClient.java:230)
        at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:326)
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:407)
        at Footprints.database.convert.ReadPath.parse(ReadPath.java:329)
        at Footprints.database.convert.ReadPath.main(ReadPath.java:896)

So it only fails on finding something in java.net.InetFamily (InetAddress).  If the other .class files are found, why not this particular one?

I'm still baffled.
0
 
LVL 5

Expert Comment

by:msmolyak
ID: 1221169
What OS are you using?
0
 
LVL 1

Author Comment

by:wex
ID: 1221170
I'm using IRIX 6.1 as it happens, but you were essentially correct.
It's a CLASSPATH problem.  I can't figure out how to go back and give you the points.
I guess if you post a new answer I can accept it and you'll get the points that way?
0
 
LVL 5

Accepted Solution

by:
msmolyak earned 100 total points
ID: 1221171
Thess are the commands I found in the .java_wrapper script in /usr/java/bin on an our IRIX machine:

COMM_CLASSPATH="$JAVA_HOME/lib/rt.jar:$JAVA_HOME/lib/dev.jar:$JAVA_HOME/lib/i18n.jar:$JAVA_HOME/lib/tiny.jar:$JAVA_HOME/classes"
if [ -z "${CLASSPATH}" ] ; then
    CLASSPATH=$COMM_CLASSPATH
else
    CLASSPATH="$CLASSPATH:$COMM_CLASSPATH"
fi

Thus, CLASSPATH is being set to something very concrete.

Did you fix the problem or you are still looking?
0
 
LVL 1

Author Comment

by:wex
ID: 1221172
OK, the problem was indeed with my $CLASSPATH
36 hours of wild-goose chasing later I've finally gotten it working.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
mysql jsp example issue 32 51
ejb mdb examples 1 10
hashmap order 17 37
Eclipse for Java EE development 2 28
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

830 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