You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/01/28 17:07:57 UTC

svn commit: r738521 - in /webservices/commons/trunk/modules/tcpmon/modules: tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/ tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/ tcpmon-ui/src/main/java/org/apache/ws/...

Author: veithen
Date: Wed Jan 28 16:07:56 2009
New Revision: 738521

URL: http://svn.apache.org/viewvc?rev=738521&view=rev
Log:
Improved encapsulation and eliminated some duplicate code.

Modified:
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/AbstractConnection.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/AbstractListener.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Connection.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/AbstractConnection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/AbstractConnection.java?rev=738521&r1=738520&r2=738521&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/AbstractConnection.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/AbstractConnection.java Wed Jan 28 16:07:56 2009
@@ -307,4 +307,7 @@
     protected abstract void setState(String state);
     protected abstract void setRequest(String request);
     protected abstract void setElapsed(String elapsed);
+    
+    public abstract String getRequestAsString();
+    public abstract String getResponseAsString();
 }

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/AbstractListener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/AbstractListener.java?rev=738521&r1=738520&r2=738521&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/AbstractListener.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/AbstractListener.java Wed Jan 28 16:07:56 2009
@@ -16,10 +16,56 @@
 
 package org.apache.ws.commons.tcpmon.core;
 
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
 import java.net.Socket;
 
 public abstract class AbstractListener {
+    protected void resend(AbstractConnection conn) {
+        try {
+            InputStream in = null;
+            String text = conn.getRequestAsString();
+
+            // Fix Content-Length HTTP headers
+            if (text.startsWith("POST ") || text.startsWith("GET ")) {
+
+                int pos1, pos2, pos3;
+                String headers;
+                pos3 = text.indexOf("\n\n");
+                if (pos3 == -1) {
+                    pos3 = text.indexOf("\r\n\r\n");
+                    if (pos3 != -1) {
+                        pos3 = pos3 + 4;
+                    }
+                } else {
+                    pos3 += 2;
+                }
+                headers = text.substring(0, pos3);
+                pos1 = headers.indexOf("Content-Length:");
+
+                if (pos1 != -1) {
+                    int newLen = text.length() - pos3;
+                    pos2 = headers.indexOf("\n", pos1);
+                    System.err.println("CL: " + newLen);
+                    System.err.println("Hdrs: '" + headers + "'");
+                    System.err.println("subTEXT: '"
+                            + text.substring(pos3, pos3 + newLen)
+                            + "'");
+                    text = headers.substring(0, pos1) + "Content-Length: "
+                            + newLen + "\n" + headers.substring(pos2 + 1)
+                            + text.substring(pos3);
+                    System.err.println("\nTEXT: '" + text + "'");
+                }
+            }
+            in = new ByteArrayInputStream(text.getBytes());
+            createConnection(in);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
     public abstract void onServerSocketStart();
     public abstract void onServerSocketError(Throwable ex);
     public abstract AbstractConnection createConnection(Socket inSocket);
+    public abstract AbstractConnection createConnection(InputStream in);
 }

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java?rev=738521&r1=738520&r2=738521&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java Wed Jan 28 16:07:56 2009
@@ -29,12 +29,10 @@
  * a connection listens to a single current connection
  */
 class Connection extends AbstractConnection {
-    public TableItem item;
-
     /**
      * Field listener
      */
-    Listener listener;
+    private final Listener listener;
 
     /**
      * Field inputText
@@ -75,7 +73,7 @@
 
         MainView.display.syncExec(new Runnable() {
             public void run() {
-                item = new TableItem(listener.connectionTable, SWT.BORDER, count + 1);
+                TableItem item = new TableItem(listener.connectionTable, SWT.BORDER, count + 1);
                 item.setText(new String[]{TCPMonBundle.getMessage("active00", "Active"),
                         time,
                         fromHost,
@@ -132,4 +130,12 @@
     protected void setElapsed(String elapsed) {
         setValue(MainView.ELAPSED_COLUMN, elapsed);
     }
+
+    public String getRequestAsString() {
+        return inputText.getText();
+    }
+
+    public String getResponseAsString() {
+        return outputText.getText();
+    }
 }

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java?rev=738521&r1=738520&r2=738521&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java Wed Jan 28 16:07:56 2009
@@ -27,7 +27,6 @@
 import org.eclipse.swt.layout.*;
 import org.eclipse.swt.widgets.*;
 
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
@@ -507,11 +506,11 @@
                         out.write((("==== "
                                 + TCPMonBundle.getMessage("request01", "Request")
                                 + " ====\n")).getBytes());
-                        out.write(conn.inputText.getText().getBytes());
+                        out.write(conn.getRequestAsString().getBytes());
                         out.write((("==== "
                                 + TCPMonBundle.getMessage("response00", "Response")
                                 + " ====\n")).getBytes());
-                        out.write(conn.outputText.getText().getBytes());
+                        out.write(conn.getResponseAsString().getBytes());
                         out.write("\n==============\n".getBytes());
                     }
                 }
@@ -523,59 +522,20 @@
     }
 
     public void resend() {
-        try {
-            int rc;
-            Connection conn;
-            rc = tableEnhancer.getMaxSelectionIndex();
-            if (rc == 0) {
-                conn = (Connection) connections.lastElement();
-            } else {
-                conn = (Connection) connections.get(rc - 1);
-            }
-
-            if (rc > 0) {
-                tableEnhancer.clearSelection();
-                tableEnhancer.setSelectionInterval(0, 0);
-            }
-            InputStream in = null;
-            String text = conn.inputText.getText();
-
-            // Fix Content-Length HTTP headers
-            if (text.startsWith("POST ") || text.startsWith("GET ")) {
-
-                int pos1, pos2, pos3;
-                String headers;
-                pos3 = text.indexOf("\n\n");
-                if (pos3 == -1) {
-                    pos3 = text.indexOf("\r\n\r\n");
-                    if (pos3 != -1) {
-                        pos3 = pos3 + 4;
-                    }
-                } else {
-                    pos3 += 2;
-                }
-                headers = text.substring(0, pos3);
-                pos1 = headers.indexOf("Content-Length:");
+        int rc;
+        Connection conn;
+        rc = tableEnhancer.getMaxSelectionIndex();
+        if (rc == 0) {
+            conn = (Connection) connections.lastElement();
+        } else {
+            conn = (Connection) connections.get(rc - 1);
+        }
 
-                if (pos1 != -1) {
-                    int newLen = text.length() - pos3;
-                    pos2 = headers.indexOf("\n", pos1);
-                    System.err.println("CL: " + newLen);
-                    System.err.println("Hdrs: '" + headers + "'");
-                    System.err.println("subTEXT: '"
-                            + text.substring(pos3, pos3 + newLen)
-                            + "'");
-                    text = headers.substring(0, pos1) + "Content-Length: "
-                            + newLen + "\n" + headers.substring(pos2 + 1)
-                            + text.substring(pos3);
-                    System.err.println("\nTEXT: '" + text + "'");
-                }
-            }
-            in = new ByteArrayInputStream(text.getBytes());
-            new Connection(this, in);
-        } catch (Exception e) {
-            e.printStackTrace();
+        if (rc > 0) {
+            tableEnhancer.clearSelection();
+            tableEnhancer.setSelectionInterval(0, 0);
         }
+        resend(conn);
     }
 
 
@@ -690,4 +650,8 @@
     public AbstractConnection createConnection(Socket inSocket) {
         return new Connection(this, inSocket);
     }
+
+    public AbstractConnection createConnection(InputStream in) {
+        return new Connection(this, in);
+    }
 }

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Connection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Connection.java?rev=738521&r1=738520&r2=738521&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Connection.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Connection.java Wed Jan 28 16:07:56 2009
@@ -31,12 +31,12 @@
     /**
      * Field listener
      */
-    Listener listener;
+    private final Listener listener;
 
     /**
      * Field inputText
      */
-    JTextArea inputText = null;
+    private JTextArea inputText;
 
     /**
      * Field inputScroll
@@ -46,7 +46,7 @@
     /**
      * Field outputText
      */
-    JTextArea outputText = null;
+    private JTextArea outputText;
 
     /**
      * Field outputScroll
@@ -133,4 +133,12 @@
     protected void setElapsed(String elapsed) {
         setValue(TCPMon.ELAPSED_COLUMN, elapsed);
     }
+
+    public String getRequestAsString() {
+        return inputText.getText();
+    }
+
+    public String getResponseAsString() {
+        return outputText.getText();
+    }
 }

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java?rev=738521&r1=738520&r2=738521&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Listener.java Wed Jan 28 16:07:56 2009
@@ -53,7 +53,6 @@
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
-import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.InputStream;
@@ -570,11 +569,11 @@
                         out.write((("==== "
                                 + TCPMonBundle.getMessage("request01", "Request")
                                 + " ====\n")).getBytes());
-                        out.write(conn.inputText.getText().getBytes());
+                        out.write(conn.getRequestAsString().getBytes());
                         out.write((("==== "
                                 + TCPMonBundle.getMessage("response00", "Response")
                                 + " ====\n")).getBytes());
-                        out.write(conn.outputText.getText().getBytes());
+                        out.write(conn.getResponseAsString().getBytes());
                         out.write("\n==============\n".getBytes());
                     }
                 }
@@ -589,57 +588,18 @@
      * Method resend
      */
     public void resend() {
-        try {
-            int rc;
-            ListSelectionModel lsm = connectionTable.getSelectionModel();
-            rc = lsm.getLeadSelectionIndex();
-            if (rc == 0) {
-                rc = connections.size();
-            }
-            Connection conn = (Connection) connections.get(rc - 1);
-            if (rc > 0) {
-                lsm.clearSelection();
-                lsm.setSelectionInterval(0, 0);
-            }
-            InputStream in = null;
-            String text = conn.inputText.getText();
-
-            // Fix Content-Length HTTP headers
-            if (text.startsWith("POST ") || text.startsWith("GET ")) {
-
-                int pos1, pos2, pos3;
-                String headers;
-                pos3 = text.indexOf("\n\n");
-                if (pos3 == -1) {
-                    pos3 = text.indexOf("\r\n\r\n");
-                    if (pos3 != -1) {
-                        pos3 = pos3 + 4;
-                    }
-                } else {
-                    pos3 += 2;
-                }
-                headers = text.substring(0, pos3);
-                pos1 = headers.indexOf("Content-Length:");
-
-                if (pos1 != -1) {
-                    int newLen = text.length() - pos3;
-                    pos2 = headers.indexOf("\n", pos1);
-                    System.err.println("CL: " + newLen);
-                    System.err.println("Hdrs: '" + headers + "'");
-                    System.err.println("subTEXT: '"
-                            + text.substring(pos3, pos3 + newLen)
-                            + "'");
-                    text = headers.substring(0, pos1) + "Content-Length: "
-                            + newLen + "\n" + headers.substring(pos2 + 1)
-                            + text.substring(pos3);
-                    System.err.println("\nTEXT: '" + text + "'");
-                }
-            }
-            in = new ByteArrayInputStream(text.getBytes());
-            new Connection(this, in);
-        } catch (Exception e) {
-            e.printStackTrace();
+        int rc;
+        ListSelectionModel lsm = connectionTable.getSelectionModel();
+        rc = lsm.getLeadSelectionIndex();
+        if (rc == 0) {
+            rc = connections.size();
+        }
+        Connection conn = (Connection) connections.get(rc - 1);
+        if (rc > 0) {
+            lsm.clearSelection();
+            lsm.setSelectionInterval(0, 0);
         }
+        resend(conn);
     }
 
     public Configuration getConfiguration() {
@@ -673,4 +633,8 @@
     public AbstractConnection createConnection(Socket inSocket) {
         return new Connection(this, inSocket);
     }
+
+    public AbstractConnection createConnection(InputStream in) {
+        return new Connection(this, in);
+    }
 }