Solved

http tunneling: URLConnection.getOutputStream() Problem

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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
going to wrong jsp page 2 33
Html Table Looping (part 2) 5 27
Java basic valueOf question 1 29
Setup GlassFish 4 21
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…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

839 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