Calls to Streaming API are blocking


I’ve set up a client which listens to the Streaming API for specific tweets, but are unable to get any responses from the HttpUrlConnection. Both conn.getResponseCode() and conn.getInputStream() are blocking until the connection times out. However if i change the request so that the OAuth signature provided is invalid conn.getResponseCode() returns 401 and I am able to read an Unauthorized message from the input stream. Any tips on how to get it working?

   URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Accept", "*/*");

Map<String, String> map = getParamMap(consumerKey, nonce, OAUTH_METHOD, timestamp, token, OAUTH_VERSION);
String signature;
try {
  signature = TwitterListenerUtils.getOauthSignature(QUERY_STRING, map, path, METHOD, REQUEST_URL, consumerSecret, secret);
} catch (InvalidKeyException | NoSuchAlgorithmException | DecoderException e) {
  log.warning("Exception when generating oauth signature!");
  log.warning("Class: " + e.getClass().getName());
  log.warning("Message: " + e.getMessage());

String auth = TwitterListenerUtils.generateHeader(consumerKey, nonce, signature, OAUTH_METHOD, timestamp, token, OAUTH_VERSION);"Auth: " + auth);

connection.setRequestProperty("Authorization", auth);"Sat auth");

connection.setDoOutput(true);"Sat doOutput");

PrintWriter writer = new PrintWriter(connection.getOutputStream());"Opened PrintWriter");

writer.write("track=" + TAGS);"Wrote tags");

writer.close();"Closed PrintWriter");


//"Avail: " + connection.getInputStream().available());"Code: " + connection.getResponseCode());"Msg: " + connection.getResponseMessage());


Without any hint what programming language you are using and which HTTP Framework it is hard to help you. The issue is not with the Streaming API but with your Framework and how it handles the HTTP request. It seems it waits until all the body is received, which will never be the case, as it is a long-live connection.


Programming language is Java and the framework used is HttpUrlConnection


I have no experience with Java, but you might want to check out this blogpost.