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/19 00:03:52 UTC

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

Author: veithen
Date: Sun Jan 18 15:03:51 2009
New Revision: 735572

URL: http://svn.apache.org/viewvc?rev=735572&view=rev
Log:
Some slight refactorings to better see the duplicate code in the two Listener implementations.

Modified:
    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/Listener.java

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=735572&r1=735571&r2=735572&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 Sun Jan 18 15:03:51 2009
@@ -399,6 +399,20 @@
         }
     }
 
+    public void start() {
+        int port = Integer.parseInt(portField.getText());
+        portField.setText("" + port);
+        portTabItem.setText(TCPMonBundle.getMessage("port01", "Port") + " " + port);
+        int tmp = Integer.parseInt(tPortField.getText());
+        tPortField.setText("" + tmp);
+        sw = new SocketWaiter(this, port);
+        stopButton.setText(TCPMonBundle.getMessage("stop00", "Stop"));
+        portField.setEditable(false);
+        hostField.setEditable(false);
+        tPortField.setEditable(false);
+        isProxyBox.setEnabled(false);
+    }
+
     public void stop() {
         try {
             for (int i = 0; i < connections.size(); i++) {
@@ -416,21 +430,6 @@
         }
     }
 
-    public void start() {
-        int port = Integer.parseInt(portField.getText());
-        portField.setText("" + port);
-        portTabItem.setText(TCPMonBundle.getMessage("port01", "Port") + " " + port);
-        int tmp = Integer.parseInt(tPortField.getText());
-        tPortField.setText("" + tmp);
-        sw = new SocketWaiter(this, port);
-        stopButton.setText(TCPMonBundle.getMessage("stop00", "Stop"));
-        portField.setEditable(false);
-        hostField.setEditable(false);
-        tPortField.setEditable(false);
-        isProxyBox.setEnabled(false);
-    }
-
-
     public void remove() {
         int index;
         Connection con;
@@ -480,47 +479,46 @@
         fd.setText("Save");
         fd.setFilterPath(".");
         String path = fd.open();
-        if (path == null) {
-            return;
-        }
-        try {
-            File file = new File(path);
-            FileOutputStream out = new FileOutputStream(file);
-            int rc = tableEnhancer.getLeadSelectionIndex();
-            int n = 0;
-            for (Iterator i = connections.iterator(); i.hasNext();
-                 n++) {
-                Connection conn = (Connection) i.next();
-                if (tableEnhancer.isSelectedIndex(n + 1)
-                        || (!(i.hasNext())
-                        && (tableEnhancer.getLeadSelectionIndex() == 0))) {
-                    rc = Integer.parseInt(portField.getText());
-                    out.write("\n==============\n".getBytes());
-                    out.write(((TCPMonBundle.getMessage("listenPort01",
-                            "Listen Port:")
-                            + " " + rc + "\n")).getBytes());
-                    out.write((TCPMonBundle.getMessage("targetHost01",
-                            "Target Host:")
-                            + " " + hostField.getText()
-                            + "\n").getBytes());
-                    rc = Integer.parseInt(tPortField.getText());
-                    out.write(((TCPMonBundle.getMessage("targetPort01",
-                            "Target Port:")
-                            + " " + rc + "\n")).getBytes());
-                    out.write((("==== "
-                            + TCPMonBundle.getMessage("request01", "Request")
-                            + " ====\n")).getBytes());
-                    out.write(conn.inputText.getText().getBytes());
-                    out.write((("==== "
-                            + TCPMonBundle.getMessage("response00", "Response")
-                            + " ====\n")).getBytes());
-                    out.write(conn.outputText.getText().getBytes());
-                    out.write("\n==============\n".getBytes());
+        if (path != null) {
+            try {
+                File file = new File(path);
+                FileOutputStream out = new FileOutputStream(file);
+                int rc = tableEnhancer.getLeadSelectionIndex();
+                int n = 0;
+                for (Iterator i = connections.iterator(); i.hasNext();
+                     n++) {
+                    Connection conn = (Connection) i.next();
+                    if (tableEnhancer.isSelectedIndex(n + 1)
+                            || (!(i.hasNext())
+                            && (tableEnhancer.getLeadSelectionIndex() == 0))) {
+                        rc = Integer.parseInt(portField.getText());
+                        out.write("\n==============\n".getBytes());
+                        out.write(((TCPMonBundle.getMessage("listenPort01",
+                                "Listen Port:")
+                                + " " + rc + "\n")).getBytes());
+                        out.write((TCPMonBundle.getMessage("targetHost01",
+                                "Target Host:")
+                                + " " + hostField.getText()
+                                + "\n").getBytes());
+                        rc = Integer.parseInt(tPortField.getText());
+                        out.write(((TCPMonBundle.getMessage("targetPort01",
+                                "Target Port:")
+                                + " " + rc + "\n")).getBytes());
+                        out.write((("==== "
+                                + TCPMonBundle.getMessage("request01", "Request")
+                                + " ====\n")).getBytes());
+                        out.write(conn.inputText.getText().getBytes());
+                        out.write((("==== "
+                                + TCPMonBundle.getMessage("response00", "Response")
+                                + " ====\n")).getBytes());
+                        out.write(conn.outputText.getText().getBytes());
+                        out.write("\n==============\n".getBytes());
+                    }
                 }
+                out.close();
+            } catch (Exception e) {
+                e.printStackTrace();
             }
-            out.close();
-        } catch (Exception e) {
-            e.printStackTrace();
         }
     }
 

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=735572&r1=735571&r2=735572&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 Sun Jan 18 15:03:51 2009
@@ -498,14 +498,6 @@
     }
 
     /**
-     * Method close
-     */
-    public void close() {
-        stop();
-        notebook.remove(panel);
-    }
-
-    /**
      * Method stop
      */
     public void stop() {
@@ -554,6 +546,14 @@
     }
 
     /**
+     * Method close
+     */
+    public void close() {
+        stop();
+        notebook.remove(panel);
+    }
+
+    /**
      * Method save
      */
     public void save() {
@@ -608,8 +608,8 @@
      * Method resend
      */
     public void resend() {
-        int rc;
         try {
+            int rc;
             ListSelectionModel lsm = connectionTable.getSelectionModel();
             rc = lsm.getLeadSelectionIndex();
             if (rc == 0) {
@@ -626,7 +626,6 @@
             // Fix Content-Length HTTP headers
             if (text.startsWith("POST ") || text.startsWith("GET ")) {
 
-                // System.err.println("IN CL" );
                 int pos1, pos2, pos3;
                 String headers;
                 pos3 = text.indexOf("\n\n");
@@ -641,8 +640,6 @@
                 headers = text.substring(0, pos3);
                 pos1 = headers.indexOf("Content-Length:");
 
-                // System.err.println("pos1: " + pos1 );
-                // System.err.println("pos3: " + pos3 );
                 if (pos1 != -1) {
                     int newLen = text.length() - pos3;
                     pos2 = headers.indexOf("\n", pos1);