Author: pferraro
Date: 2008-12-02 16:05:52 -0500 (Tue, 02 Dec 2008)
New Revision: 2089
Modified:
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java
Log:
Cleanup
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-12-02
20:56:39 UTC (rev 2088)
+++
trunk/mod_cluster/src/main/java/org/jboss/modcluster/mcmp/impl/DefaultMCMPHandler.java 2008-12-02
21:05:52 UTC (rev 2089)
@@ -746,25 +746,25 @@
}
}
- private String sendRequest(Writer writer, BufferedReader reader, MCMPURLEncoder
encoder, StringBuilder builder) throws IOException
+ private String sendRequest(Proxy proxy, String request, char[] body, int length)
throws IOException
{
- writer.write(builder.toString());
+ Writer writer = proxy.getConnectionWriter();
+
+ writer.write(request);
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(body, 0, length);
writer.write("\r\n");
writer.flush();
// Read the first response line and skip the rest of the HTTP header
- return reader.readLine();
+ return proxy.getConnectionReader().readLine();
}
-
+
private String sendRequest(MCMPRequest request, Proxy proxy)
{
// If there was an error, do nothing until the next periodic event, where the whole
configuration
@@ -812,9 +812,6 @@
try
{
// Then, connect to the proxy
- Writer writer = proxy.getConnectionWriter();
- BufferedReader reader = proxy.getConnectionReader();
-
// Generate and write request
StringBuilder builder = new StringBuilder();
@@ -839,20 +836,28 @@
builder.append(" HTTP/1.0");
+ String head = builder.toString();
+ int length = encoder.getLength();
+ char[] body = encoder.getBuffer();
+
String line = null;
- try {
- line = sendRequest(writer, reader, encoder, builder);
+ try
+ {
+ line = sendRequest(proxy, head, body, length);
}
- catch (IOException e) {
+ catch (IOException e)
+ {
+ // Ignore first write failure
}
- /* Retry once if it fails */
- if (line == null) {
- // Get a new connection; if it fails this second time, it is an error
+
+ if (line == null)
+ {
+ // Retry failed read/write with fresh connection
proxy.closeConnection();
- writer = proxy.getConnectionWriter();
- reader = proxy.getConnectionReader();
- line = sendRequest(writer, reader, encoder, builder);
+ line = sendRequest(proxy, head, body, length);
}
+
+ BufferedReader reader = proxy.getConnectionReader();
// Parse the line, which is formed like HTTP/1.x YYY Message
int status = 500;
// String version = "0";
@@ -867,14 +872,14 @@
String responseStatus = line.substring(spaceIndex + 1,
line.indexOf(' ', spaceIndex + 1));
status = Integer.parseInt(responseStatus);
line = reader.readLine();
- while (line.length() > 0)
+ while ((line != null) && (line.length() > 0))
{
int colon = line.indexOf(':');
String headerName = line.substring(0, colon).trim();
String headerValue = line.substring(colon + 1).trim();
if ("version".equalsIgnoreCase(headerName))
{
-// version = headerValue;
+// version = headerValue;
}
else if ("type".equalsIgnoreCase(headerName))
{
Show replies by date