Set Timeout on HTTPUtils.HTTPRequestToByteArray

Hi there. We have a setup where whenever someone begins streaming to Wowza, it checks the stream name with our webserver. This request is set up so that if the webserver is down, Wowza will let them stream.

The problem is that if the webserver handles the request very slowly, the encoder (FMLE) gives up before Wowza gives up trying to connect to the webserver, and FMLE stops trying to connect to Wowza, failing with an error message. I added in a 30 second delay to my webserver to test this.

How can I set a timeout setting on HTTPUtils.HTTPRequestToByteArray?

Here is the code that connects to the webserver:

	public static Boolean requestPublish( String pingParams )
	{
		Boolean streamAllowed = false;
		try
		{
			// Send the request to the website to make sure that the password part of the stream is correct.
			byte[] resp = HTTPUtils.HTTPRequestToByteArray("http://www." + baseDomain + "/webserver/url", "POST", pingParams, null);
			String response = new String(resp, "UTF-8");
			if ( response.indexOf("true") >= 0 ) streamAllowed = true;
		}
		catch(Exception e)
		{
			log.error("HscFunc: Failed to check password.");
			log.error(e.getMessage());
			streamAllowed = true;
		}
		return streamAllowed;
	}

Thanks,

Micah

Hi

Granted this isn’t perfect either but you’re better off trying to get it like this

 
URL myUrl = new URL( url );
    URLConnection conn = myUrl.openConnection();
    conn.setConnectTimeout(2000);
    conn.setReadTimeout(2000);
     
    InputStreamReader isr = new InputStreamReader( conn.getInputStream() );
     
      InputSource is = new InputSource( isr );

From here you should be able to take the input and do what you want with it.

Jason

Thanks for the help, this was very useful.

Here’s what I ended up with:

	public static Boolean requestPublish( String pingParams )
	{
		Boolean streamAllowed = false;
		try
		{
		    URL url = new URL("http://www." + baseDomain + "/webserver/url");
		    URLConnection conn = url.openConnection();
		    conn.setDoOutput(true);
		    conn.setConnectTimeout(3000);
		    conn.setReadTimeout(3000);
		    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
		    wr.write(pingParams);
		    wr.flush();
		    // Get the response
		    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
		    String line;
		    while ((line = rd.readLine()) != null) {
		    	if ( line.indexOf("true") >= 0 ) streamAllowed = true;
		    }
		    wr.close();
		    rd.close();
		}
		catch(Exception e)
		{
			log.error("HscFunc: Failed to check password.");
			log.error(e.getMessage());
			streamAllowed = true;
		}
		return streamAllowed;
	}