Solved

http tunneling: URLConnection.getOutputStream() Problem

Posted on 1997-06-23
3
335 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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse argument 14 61
map related example 6 49
HashTable highest marks enumeration alternative 9 39
Detect Closed Loops (circles, figure-8s, etc) in PNG Images 6 34
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

831 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