aspose file tools*
The moose likes Servlets and the fly likes invoking servlet using URLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "invoking servlet using URLConnection" Watch "invoking servlet using URLConnection" New topic
Author

invoking servlet using URLConnection

prasad hagargi
Ranch Hand

Joined: Oct 21, 2002
Posts: 36
hi there,
i am trying to invoke a servlet from one jboss to another servlet on another jboss,using URLConnection.
iam getting
java.lang.IllegalStateException: Already connected
20:57:48,371 ERROR [STDERR] at java.net.URLConnection.setDoInput(URLConnection.java:709)
20:57:48,371 ERROR [STDERR] at com.dpsl.dxdam.util.assettransfer.FTPController.run(Unknown Source)
where as if i run the same code on as standalone application,the servlet on the other jboss gets invoked,below is the code:

URL url = new URL(strPreingestServletUrl);
URLConnection connection = url.openConnection();
connection.connect();
connection.setDoOutput(true);connection.setUseCaches(false);connection.connect();
InputStream is = connection.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String response = in.readLine();System.out.println(response);
while(response!=null){
System.out.println(response);
response = in.readLine();
}
is.close();
in.close();

please explain why this happens,does it have anything to do with the policy file of catalina.
--thanks in advance--Prasad
Jaime Garcia
Ranch Hand

Joined: Jan 07, 2003
Posts: 38
the section url.openConnection(); already opens the connection.
URLConnection connection = url.openConnection();
so, you do not have to:
connection.connect();
Hope this helps
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
I don't think that is entirely correct. The URLConnection.connect() method will open a connection only if there isn't one already established, otherwise the call will be ignored.
I think you are generating the IllegalStateException in the URLConnection.setDoInput(boolean) method. It looks like that you are calling setup parameters after the actual connection has already been established. This should be done prior to calling the URLConnection.connect() method.

Craig
prasad hagargi
Ranch Hand

Joined: Oct 21, 2002
Posts: 36
thanks u were right i was openning the connection before setting the doinput and dooutput fields
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: invoking servlet using URLConnection