• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to check whether urlconnection is active?

 
subha neithilath
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am calling a servlet residing in a domino server from a java program.I am passing a cookie value but servlet is not getting invoked.I would like to know how i can test whether the connection is active or not(can you suggest any programs that i can use for testing the same)
I am providing here few lines of code which i am using to get urlconnection and set cookie.
HttpURLConnection urlconnection = null;
URL serverURL = new URL("http://192.168.10.55:8001/servlet/testing");
urlconnection= (HttpURLConnection)serverURL.openConnection();
urlconnection.setRequestProperty("cookie",cookie);
urlconnection.setRequestMethod("GET");
urlconnection.setFollowRedirects(true);
urlconnection.setDoOutput(true);
urlconnection.setDoInput(true);
Please go through and give suggestion/sample programs
Thanks and Regards
Subha
 
Mohamed Yousuff
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code is fine to some extent. I dont really understand what you really mean by 'connection is active or not'. If the openConnection method is successfull (without exception), it definitely means that the connection to the server is established. If the servlet does not get invoked, it indicates invalid usage of HTTP Protocol. If you use setdooutput(true) and setdoinput(true), you need to get the outputstream of the httpurlconnection and write whatever you want to write to it. Then u need to get the inputstream.
Also when you use setdooutput(true), setrequestmethod("GET") does not make sense because setdooutput(true) implicitly means you want POST method.

Originally posted by subha neithilath:
Hi,
I am calling a servlet residing in a domino server from a java program.I am passing a cookie value but servlet is not getting invoked.I would like to know how i can test whether the connection is active or not(can you suggest any programs that i can use for testing the same)
I am providing here few lines of code which i am using to get urlconnection and set cookie.
HttpURLConnection urlconnection = null;
URL serverURL = new URL("http://192.168.10.55:8001/servlet/testing");
urlconnection= (HttpURLConnection)serverURL.openConnection();
urlconnection.setRequestProperty("cookie",cookie);
urlconnection.setRequestMethod("GET");
urlconnection.setFollowRedirects(true);
urlconnection.setDoOutput(true);
urlconnection.setDoInput(true);
Please go through and give suggestion/sample programs
Thanks and Regards
Subha

[ November 11, 2002: Message edited by: Mohamed Yousuff ]
[ November 11, 2002: Message edited by: Mohamed Yousuff ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic