snichol 2002/09/06 10:02:59 Modified: java/src/org/apache/soap/transport TransportMessage.java java/src/org/apache/soap/util/net HTTPUtils.java Log: Clean up exception declarations. Throw SOAPExceptions rather than arbitrarily choosing IllegalArgumentException. Specify initial sizes for StringBuffer and ByteArrayOutputStream to decrease the number of buffer re-allocations. Revision Changes Path 1.16 +9 -12 xml-soap/java/src/org/apache/soap/transport/TransportMessage.java Index: TransportMessage.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/transport/TransportMessage.java,v retrieving revision 1.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- TransportMessage.java 5 Sep 2002 16:50:52 -0000 1.15 +++ TransportMessage.java 6 Sep 2002 17:02:58 -0000 1.16 @@ -102,9 +102,7 @@ * Call save() to generate the byte array. */ public TransportMessage(String envelope, SOAPContext ctx, - Hashtable headers) - throws IllegalArgumentException, MessagingException, - IOException, SOAPException { + Hashtable headers) { this.envelope = envelope; this.ctx = ctx; if (headers != null) @@ -122,8 +120,7 @@ public TransportMessage(InputStream is, int contentLength, String contentType, SOAPContext ctx, Hashtable headers) - throws IllegalArgumentException, MessagingException, - IOException, SOAPException { + throws IOException, SOAPException { if (headers != null) this.headers = headers; else @@ -200,7 +197,7 @@ * it is up to the invoker to check the root part's Content-Type */ public String read() - throws IllegalArgumentException, MessagingException, + throws MessagingException, IOException, SOAPException { // Parse and validate content type. @@ -325,7 +322,7 @@ * transport types that encode in a non-standard way. */ public void save() - throws IllegalArgumentException, MessagingException, IOException { + throws MessagingException, IOException { /* If an envelope was provided as a string, set it as the root part. * Otherwise, assume that the SOAPContext already has a root part. * If there was already a root part, preserve its content-type. @@ -347,7 +344,7 @@ // Print the whole response to a byte array. ByteArrayOutputStream payload = - new ByteArrayOutputStream(); + new ByteArrayOutputStream(1024); ctx.writeTo(payload); bytes = payload.toByteArray(); @@ -355,8 +352,8 @@ // for MIME support). Just intercept the Content-Type // header. We don't want any of the MIME headers, and we know the // overall Content-Length anyway. - StringBuffer namebuf = new StringBuffer(); - StringBuffer valuebuf = new StringBuffer(); + StringBuffer namebuf = new StringBuffer(64); + StringBuffer valuebuf = new StringBuffer(64); boolean parsingName = true; for (offset = 0; offset < bytes.length; offset++) { if (bytes[offset] == '\n') { @@ -389,8 +386,8 @@ + "\"; start=\"" + rootCID + '"'; } } - namebuf = new StringBuffer(); - valuebuf = new StringBuffer(); + namebuf = new StringBuffer(64); + valuebuf = new StringBuffer(64); parsingName = true; } else if (bytes[offset] != '\r') { 1.31 +19 -17 xml-soap/java/src/org/apache/soap/util/net/HTTPUtils.java Index: HTTPUtils.java =================================================================== RCS file: /home/cvs/xml-soap/java/src/org/apache/soap/util/net/HTTPUtils.java,v retrieving revision 1.30 retrieving revision 1.31 diff -u -r1.30 -r1.31 --- HTTPUtils.java 6 Sep 2002 06:07:03 -0000 1.30 +++ HTTPUtils.java 6 Sep 2002 17:02:59 -0000 1.31 @@ -98,7 +98,7 @@ private static Socket buildSocket(URL url, int targetPort, String httpProxyHost, int httpProxyPort, Boolean tcpNoDelay) - throws Exception { + throws Exception { Socket s = null; String host = null; int port = targetPort; @@ -157,11 +157,12 @@ */ private static int getPort(URL url) throws IOException { int port = url.getPort(); - if (port < 0) // No port given, use HTTP or HTTPS default + if (port < 0) { // No port given, use HTTP or HTTPS default if (url.getProtocol().equalsIgnoreCase("HTTPS")) port = HTTPS_DEFAULT_PORT; else port = HTTP_DEFAULT_PORT; + } return port; } @@ -180,7 +181,7 @@ public static TransportMessage post(URL url, TransportMessage request, int timeout, String httpProxyHost, int httpProxyPort) - throws IllegalArgumentException, IOException, SOAPException { + throws IOException, SOAPException { return post(url, request, timeout, @@ -207,7 +208,7 @@ int timeout, String httpProxyHost, int httpProxyPort, int outputBufferSize) - throws IllegalArgumentException, IOException, SOAPException { + throws IOException, SOAPException { return post(url, request, timeout, @@ -236,7 +237,7 @@ String httpProxyHost, int httpProxyPort, int outputBufferSize, Boolean tcpNoDelay) - throws IllegalArgumentException, IOException, SOAPException { + throws IOException, SOAPException { return post(url, request, timeout, httpProxyHost, httpProxyPort, outputBufferSize, tcpNoDelay, null, null); @@ -274,7 +275,7 @@ Boolean tcpNoDelay, StringBuffer requestCopy, StringBuffer responseCopy) - throws IllegalArgumentException, IOException, SOAPException { + throws IOException, SOAPException { /* Open the connection */ OutputStream outStream = null; InputStream inStream = null; @@ -303,7 +304,8 @@ t = ((InvocationTargetException)t).getTargetException(); } - throw new IllegalArgumentException("Error opening socket: " + t); + throw new SOAPException(Constants.FAULT_CODE_CLIENT, + "Error opening socket: " + t, t); } /* Compute the Request URI */ @@ -349,7 +351,7 @@ /* Read the response status line. */ int statusCode = 0; String statusString = null; - StringBuffer linebuf = new StringBuffer(); + StringBuffer linebuf = new StringBuffer(128); int b = 0; while (b != '\n' && b != -1) { b = bInStream.read(); @@ -361,7 +363,7 @@ StringTokenizer st = new StringTokenizer(line); st.nextToken(); // ignore version part statusCode = Integer.parseInt (st.nextToken()); - StringBuffer sb = new StringBuffer(); + StringBuffer sb = new StringBuffer(128); while (st.hasMoreTokens()) { sb.append (st.nextToken()); if (st.hasMoreTokens()) { @@ -371,8 +373,8 @@ statusString = sb.toString(); } catch (Exception e) { - throw new IllegalArgumentException( - "Error parsing HTTP status line \"" + line + "\": " + e); + throw new SOAPException(Constants.FAULT_CODE_CLIENT, + "Error parsing HTTP status line \"" + line + "\": " + e, e); } /* Read the entire response (following the status line) @@ -380,14 +382,13 @@ ByteArrayDataSource ds = new ByteArrayDataSource(bInStream, Constants.HEADERVAL_DEFAULT_CHARSET); - /* Extract the headers, content type and content length. */ byte[] bytes = ds.toByteArray(); Hashtable respHeaders = new Hashtable(); int respContentLength = -1; String respContentType = null; - StringBuffer namebuf = new StringBuffer(); - StringBuffer valuebuf = new StringBuffer(); + StringBuffer namebuf = new StringBuffer(64); + StringBuffer valuebuf = new StringBuffer(64); boolean parsingName = true; int offset; for (offset = 0; offset < bytes.length; offset++) { @@ -419,8 +420,8 @@ } } } - namebuf = new StringBuffer(); - valuebuf = new StringBuffer(); + namebuf = new StringBuffer(64); + valuebuf = new StringBuffer(64); parsingName = true; } else if (bytes[offset] != '\r') { @@ -465,7 +466,8 @@ // Extract envelope and SOAPContext response.read(); } catch (MessagingException me) { - throw new IllegalArgumentException("Error parsing response: " + me); + throw new SOAPException(Constants.FAULT_CODE_CLIENT, + "Error parsing response: " + me, me); } /* All done here! */
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>