Hello again,

I hope I will not offend anyone by repeating myself.

Take 2 of my patch has been created against CVS version of these files.

This change can be seen as change in API. Is voting required?

Kind Regards,
-- 
[newbie]Arek Wnukowski



--- 1.26/HTTPUtils.java Thu May 23 18:20:22 2002
+++ patch/HTTPUtils.java        Tue May 28 12:00:16 2002
@@ -218,6 +218,38 @@
                                       int outputBufferSize,
                                      Boolean tcpNoDelay)
       throws IllegalArgumentException, IOException, SOAPException {
+          
+    return post(url, request, timeout, httpProxyHost, httpProxyPort,
+                 outputBufferSize, tcpNoDelay, null, null);
+  }
+
+  /**
+   * POST something to the given URL. The headers are put in as
+   * HTTP headers, the content length is calculated and the content
+   * byte array is sent as the POST content.
+   *
+   * @param url the url to post to
+   * @param request the message
+   * @param timeout the amount of time, in ms, to block on reading data
+   * @param httpProxyHost the HTTP proxy host or null if no proxy
+   * @param httpProxyPort the HTTP proxy port, if the proxy host is not null
+   * @param outputBufferSize the size of the output buffer on the HTTP stream
+   * @param tcpNoDelay the tcpNoDelay setting for the socket
+   * @param requestCopy the buffer for capturing copy of the request or null
+   *                    if capture is not required.
+   * @param responseCopy the buffer for capturing copy of the response or null
+   *                     if capture is not required.
+   * @param  the tcpNoDelay setting for the socket
+   * @return the response message
+   */
+  public static TransportMessage post(URL url, TransportMessage request,
+                                      int timeout,
+                                      String httpProxyHost, int httpProxyPort,
+                                      int outputBufferSize,
+                                     Boolean tcpNoDelay,
+                                      StringBuffer requestCopy,
+                                      StringBuffer responseCopy)
+      throws IllegalArgumentException, IOException, SOAPException {
       /* Open the connection */
       OutputStream outStream = null;
       InputStream inStream = null;
@@ -276,6 +308,13 @@
       bOutStream.write(
           headerbuf.toString().getBytes(Constants.HEADERVAL_DEFAULT_CHARSET));
       request.writeTo(bOutStream);
+      
+      /* If required, capture a copy of the request. */
+      if (requestCopy != null) {
+        requestCopy.append(headerbuf)
+            .append(new String(request.getBytes()));
+      }
+      
       //bOutStream.write('\r'); bOutStream.write('\n');
       //bOutStream.write('\r'); bOutStream.write('\n');
       bOutStream.flush();
@@ -316,6 +355,7 @@
       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();
@@ -369,6 +409,11 @@
       if (respContentLength < 0)
           respContentLength = ds.getSize() - offset - 1;
 
+      /* If required, capture a copy of the response. */
+      if (responseCopy != null) {
+        responseCopy.append(line).append("\r\n").append(new String(bytes));
+      }
+      
       /* Construct the response object. */
       SOAPContext ctx;
       TransportMessage response;
--- 1.21/SOAPHTTPConnection.java        Thu May 23 18:20:22 2002
+++ patch/SOAPHTTPConnection.java       Tue May 28 12:03:24 2002
@@ -99,6 +99,8 @@
   private String cookieHeader2;
   private int    outputBufferSize = HTTPUtils.DEFAULT_OUTPUT_BUFFER_SIZE;
   private Boolean tcpNoDelay = null;
+  private StringBuffer requestCopy = null;
+  private StringBuffer responseCopy = null;
 
   /**
    * Set HTTP proxy host.
@@ -164,6 +166,40 @@
     this.proxyPassword = password;
   }
 
+  /**
+   * Set buffer for capturing copy of the request.
+   */
+  public void setRequestCopy (StringBuffer requestCopy) {
+    this.requestCopy = requestCopy;
+  }
+  
+  /**
+   * Set buffer for capturing copy of the response.
+   */
+  public void setResponseCopy (StringBuffer responseCopy) {
+    this.responseCopy = responseCopy;
+  }
+
+  /**
+   * Get Buffer containing copy of the request.
+   *
+   * @return the Buffer containing copy of the request.
+   *         Returns null if buffer has not been previously set.
+   */
+  public StringBuffer getRequestCopy () {
+    return requestCopy;
+  }
+
+  /**
+   * Get Buffer containing copy of the response.
+   *
+   * @return the Buffer containing copy of the response.
+   *         Returns null if buffer has not been previously set.
+   */
+  public StringBuffer getResponseCopy () {
+    return responseCopy;
+  }
+  
   private static String encodeAuth(String userName, String password)
     throws SOAPException
   {
@@ -306,9 +342,11 @@
       {
         TransportMessage msg = new TransportMessage(payload, ctx, headers);
         msg.save();
+        
         response = HTTPUtils.post (sendTo, msg,
                                    timeout, httpProxyHost, httpProxyPort,
-                                   outputBufferSize, tcpNoDelay);
+                                   outputBufferSize, tcpNoDelay,
+                                   requestCopy, responseCopy);
       } catch (MessagingException me) {
         throw new IOException ("Failed to encode mime multipart: " + me);
       } catch (UnsupportedEncodingException uee) {


Reply via email to