Solved

Making an URLConnection

Posted on 1998-05-18
8
559 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
basic hardware to learn oop advanced design patterns 3 88
simple java question 3 44
Java DateChooser? 3 29
object oriented programming comparison 5 54
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

911 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

22 Experts available now in Live!

Get 1:1 Help Now