Solved

http tunneling: URLConnection.getOutputStream() Problem

Posted on 1997-06-23
3
334 Views
Last Modified: 2011-10-03
hi

within an apllet/application written in JDK112, we have the following problem:

the getOutputStream() method failed with the following message (Exception.getMessage()) :

can't reset method : already connected

here is the code of our method write:

   protected void write(byte b[])
   {
         URLConnection connection;
         URL u=new URL("http://www.tratech.be:8080");
 
         try
         {  connection=u.openConnection();
         }
         catch(Exception e)
         {
            System.out.println("write: Could not open URL connection.");
            return;
         }
 
         connection.setDoOutput(true);

         try
         {  connection.connect();
         }
         catch (IOException e)
         {  System.out.println("Connect failed");
            return;
         }
 
>>       try
>>       {  output=connection.getOutputStream();
>>       }
>>       catch (Exception e)
>>       {  System.out.println("getOutputStream failed : " + e.getMessage());
>>          return;
>>       }
 
         output.write(b);
         output.flush();
         output.close();
   }

We tried with the connect() method, without. there was no difference.

Any idea?

thank you,

jerome Gonze
Tradeware Technology S.A.

jg@tratech.be

http://www.tratech.be
0
Comment
Question by:tv062397
  • 2
3 Comments
 

Author Comment

by:tv062397
ID: 1221939
Edited text of question
0
 
LVL 6

Accepted Solution

by:
jpk041897 earned 100 total points
ID: 1221940
URLConnection is defined as an abstract class and is therfore unable to create an instance of itself. You can make the calls but since the object does not exist in memory, it will be unable to store values in its member variables.

Furthermore, abstract classes do not necesarily implement the methods they define, leaving this to lower level classses.

Think of abstract classes as a kind of template for lower level classes that might, or might not contain implementation details.

Suggestions:

1.- Use a lower level class, derrived from URLConnection (like URL).

2.- Create your own class that extends URLConnection and use that one instead and make sure that and implementation exists for the methods you plan to use via the source files. Otherwise you would have to write te implementations yourself.
0
 

Author Comment

by:tv062397
ID: 1221941


There is a GNU solution for this problem:

HTTPClient

this is a good documented package.
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
Unable to start eclipse ? 17 128
Requested array size exceeds VM limit 3 84
eclipse shortcuts 9 45
difference of if loops 23 37
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

929 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

11 Experts available now in Live!

Get 1:1 Help Now