We are connecting to a web service as follows:
URL url = new URL("https://...");
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-length", "" + data.length());
conn.setDoOutput(true);
OutputStreamWriter o = new OutputStreamWriter(conn.getOutputStream());
Sometimes, the connection hangs on this last line, with either a very long or infinite timeout.
How can we get into this and find out what is happening, for sure? (We have plenty of speculation, but little confirmation at this point.) We've instrumented our code with plenty of logging statements (which is how we know where the stopping point is), but can't very well do the same for Java libraries. What additional information can we convince these classes to tell us? If we wanted to set a timeout, how would we do it?
How do we debug this?