Please find a patch proposed for converting HTTP headers using own
conversion instead of using JVM byte to char converter, as it happens not
to be efficient
Also I have concatenated several const Strings in StringBuffer.append
Thanks,
Pavel
Index: HTTPUtils.java
===================================================================
RCS file: /home/cvspublic/xml-soap/java/src/org/apache/soap/util/net/HTTPUtils.java,v
retrieving revision 1.39
diff -u -r1.39 HTTPUtils.java
--- HTTPUtils.java 20 Nov 2002 06:33:57 -0000 1.39
+++ HTTPUtils.java 22 Nov 2002 12:17:12 -0000
@@ -461,14 +461,13 @@
/* Construct the HTTP header. */
StringBuffer headerbuf = new StringBuffer(512);
- headerbuf.append(Constants.HEADER_POST).append(' ').append(URI)
- .append(" HTTP/").append(HTTP_VERSION).append("\r\n")
- .append(Constants.HEADER_HOST).append(": ").append(host)
- .append(':').append(port)
- .append("\r\n")
- .append(Constants.HEADER_CONTENT_TYPE).append(": ")
- .append(request.getContentType()).append("\r\n")
- .append(Constants.HEADER_CONTENT_LENGTH).append(": ")
+ headerbuf.append(Constants.HEADER_POST + ' ').append(URI)
+ .append(" HTTP/"+ HTTP_VERSION + "\r\n" +
+ Constants.HEADER_HOST + ": ").append(host)
+ .append(':').append(port).append("\r\n" +
+ Constants.HEADER_CONTENT_TYPE + ": ")
+ .append(request.getContentType()).append("\r\n" +
+ Constants.HEADER_CONTENT_LENGTH + ": ")
.append(request.getContentLength()).append("\r\n");
for (Enumeration e = request.getHeaderNames(); e.hasMoreElements(); ) {
Object key = e.nextElement();
@@ -493,6 +492,7 @@
BufferedInputStream bInStream = new BufferedInputStream(inStream);
byte[] linebuf = new byte[1024];
+ char[] cbuf = new char[128];
int count = 0;
int b;
@@ -506,7 +506,7 @@
int codeStart = -1;
int codeEnd = -1;
int stringStart = -1;
-
+
for (count = 0, b = bInStream.read(); b != '\n' && b != -1; b =
bInStream.read()) {
if (b != '\r') {
if (b == ' ') {
@@ -534,12 +534,12 @@
throw new Exception("Reached end of stream while reading HTTP response
status");
if (codeStart == -1)
throw new Exception("HTTP response status not present");
- versionString = new String(linebuf, 0, versionEnd, ISO_8859_1);
+ versionString = getStringISO8859_1(linebuf, 0, versionEnd, cbuf);
if (codeEnd == -1)
codeEnd = count + 1;
- statusCode = Integer.parseInt(new String(linebuf, codeStart, codeEnd -
codeStart, ISO_8859_1));
+ statusCode = Integer.parseInt( getStringISO8859_1(linebuf, codeStart,
+codeEnd - codeStart, cbuf));
if (stringStart != -1)
- statusString = new String(linebuf, stringStart, 1 + count -
stringStart, ISO_8859_1);
+ statusString = getStringISO8859_1(linebuf, stringStart, 1 + count -
+stringStart, cbuf);
else
statusString = "";
} catch (Exception e) {
@@ -580,13 +580,13 @@
if (nameEnd == -1)
throw new Exception("Incorrectly formed HTTP response header");
- String name = new String(linebuf, 0, nameEnd, ISO_8859_1);
+ String name = getStringISO8859_1(linebuf, 0, nameEnd, cbuf);
String value = null;
if (valStart != -1) {
// Remove trailing ; to prevent ContentType from throwing
exception
if (linebuf[count - 1] == ';')
--count;
- value = new String(linebuf, valStart, count - valStart,
ISO_8859_1);
+ value = getStringISO8859_1(linebuf, valStart, count - valStart,
+cbuf);
} else
value = "";
@@ -608,7 +608,7 @@
}
} catch (Exception e) {
throw new SOAPException(Constants.FAULT_CODE_CLIENT,
- "Error parsing HTTP header line \"" + new String(linebuf, 0, count,
ISO_8859_1) + "\": " + e, e);
+ "Error parsing HTTP header line \"" + getStringISO8859_1(linebuf, 0,
+count, cbuf) + "\": " + e, e);
}
boolean isOneWay = false;
@@ -689,6 +689,31 @@
}
}
return false;
+ }
+
+ /**
+ * Creates a String from byte array using direct byte to char conversion
+ * (the same as ISO8859_1), using preallocated char array
+ * main purpose is to workaround slow JDK conversion
+ *
+ * @param value array that is the source of characters.
+ * @param offset the initial offset.
+ * @param count the length.
+ * @param cbuf preallocated char array
+ *
+ * @return <code>true</code> when the string matches against the pattern,
+ * <code>false</code> otherwise.
+ */
+ private static String getStringISO8859_1(byte[] value, int offset, int count,
+char[] cbuf)
+ throws UnsupportedEncodingException
+ {
+ if (count > value.length)
+ return new String(value, offset, count, ISO_8859_1);
+
+ // make own transformation
+ for (int i=0; i<count; i++)
+ cbuf[i] = (char)value[i+offset];
+ return new String(cbuf, 0, count);
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>