[Red5devs] [PATCH 02 of 15] check response code

mabrek mabrek at gmail.com
Tue Aug 26 11:03:08 PDT 2008


diff -r 3194e68769da -r fea37acdcd8c src/org/red5/server/net/rtmpt/RTMPTClientConnector.java
--- a/src/org/red5/server/net/rtmpt/RTMPTClientConnector.java	Mon Jul 14 19:35:43 2008 +0400
+++ b/src/org/red5/server/net/rtmpt/RTMPTClientConnector.java	Tue Jul 15 13:16:58 2008 +0400
@@ -24,6 +24,8 @@
 
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.HttpVersion;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.params.HttpClientParams;
 import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
 import org.apache.commons.httpclient.methods.PostMethod;
@@ -102,6 +104,9 @@
 					post.setRequestEntity(ZERO_REQUEST_ENTITY);
 				}
 				httpClient.executeMethod(post);
+				
+				checkResponseCode(post);
+				
 				byte[] received = post.getResponseBody();
 
 				ByteBuffer data = ByteBuffer.allocate(received.length);
@@ -150,6 +155,8 @@
 
 		httpClient.executeMethod(openPost);
 
+		checkResponseCode(openPost);
+		
 		String response = openPost.getResponseBodyAsString();
 		clientId = Integer.parseInt(response
 				.substring(0, response.length() - 1));
@@ -198,6 +205,12 @@
 		post.setRequestHeader("Connection", "Keep-Alive");
 		post.setRequestHeader("Cache-Control", "no-cache");
 	}
+	
+	private void checkResponseCode(HttpMethod method) {
+		if (method.getStatusCode() != HttpStatus.SC_OK) {
+			throw new RuntimeException("Bad HTTP status returned: " + method.getStatusLine());
+		}
+	}
 
 	public void setStopRequested(boolean stopRequested) {
 		this.stopRequested = stopRequested;





More information about the Red5devs mailing list