Author: jfrederic.clere(a)jboss.com
Date: 2008-11-24 16:10:14 -0500 (Mon, 24 Nov 2008)
New Revision: 2068
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
Arrange the retry logic (readLine() return null but the write() don't fail as
excepted).
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
===================================================================
---
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-11-24
11:07:05 UTC (rev 2067)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-11-24
21:10:14 UTC (rev 2068)
@@ -746,6 +746,25 @@
}
}
+ private String sendRequest(Writer writer, BufferedReader reader, MCMPURLEncoder
encoder, StringBuilder builder) throws IOException
+ {
+ writer.write(builder.toString());
+ writer.write("\r\n");
+
+ int length = encoder.getLength();
+
+ writer.write("Content-Length: " + length + "\r\n");
+ writer.write("User-Agent: ClusterListener/1.0\r\n");
+ writer.write("Connection: Keep-Alive\r\n");
+ writer.write("\r\n");
+ writer.write(encoder.getBuffer(), 0, length);
+ writer.write("\r\n");
+ writer.flush();
+
+ // Read the first response line and skip the rest of the HTTP header
+ return reader.readLine();
+ }
+
private String sendRequest(MCMPRequest request, Proxy proxy)
{
// If there was an error, do nothing until the next periodic event, where the whole
configuration
@@ -794,19 +813,7 @@
{
// Then, connect to the proxy
Writer writer = proxy.getConnectionWriter();
- // Check connection to see if it is still alive (not really allowed,
- // but httpd deals with the extra CRLF)
- try
- {
- writer.write("\r\n");
- writer.flush();
- }
- catch (IOException e)
- {
- // Get a new connection; if it fails this second time, it is an error
- proxy.closeConnection();
- writer = proxy.getConnectionWriter();
- }
+ BufferedReader reader = proxy.getConnectionReader();
// Generate and write request
StringBuilder builder = new StringBuilder();
@@ -832,23 +839,20 @@
builder.append(" HTTP/1.0");
- writer.write(builder.toString());
- writer.write("\r\n");
-
- int length = encoder.getLength();
-
- writer.write("Content-Length: " + length + "\r\n");
- writer.write("User-Agent: ClusterListener/1.0\r\n");
- writer.write("Connection: Keep-Alive\r\n");
- writer.write("\r\n");
- writer.write(encoder.getBuffer(), 0, length);
- writer.write("\r\n");
- writer.flush();
-
- // Read the response to a string
- BufferedReader reader = proxy.getConnectionReader();
- // Read the first response line and skip the rest of the HTTP header
- String line = reader.readLine();
+ String line = null;
+ try {
+ line = sendRequest(writer, reader, encoder, builder);
+ }
+ catch (IOException e) {
+ }
+ /* Retry once if it fails */
+ if (line == null) {
+ // Get a new connection; if it fails this second time, it is an error
+ proxy.closeConnection();
+ writer = proxy.getConnectionWriter();
+ reader = proxy.getConnectionReader();
+ line = sendRequest(writer, reader, encoder, builder);
+ }
// Parse the line, which is formed like HTTP/1.x YYY Message
int status = 500;
// String version = "0";
Show replies by date