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 2008/12/29 20:54:56 UTC

svn commit: r729985 - in /webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon: Connection.java Listener.java core/AbstractConnection.java core/Configuration.java eclipse/ui/Connection.java eclipse/ui/Listener.java

Author: veithen
Date: Mon Dec 29 11:54:55 2008
New Revision: 729985

URL: http://svn.apache.org/viewvc?rev=729985&view=rev
Log:
Refactored the common code in the two Connection implementations into a common base class.

Added:
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractConnection.java   (contents, props changed)
      - copied, changed from r729930, webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/Configuration.java
Modified:
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Listener.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java

Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java?rev=729985&r1=729984&r2=729985&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java Mon Dec 29 11:54:55 2008
@@ -19,47 +19,24 @@
 import javax.swing.JScrollPane;
 import javax.swing.JTextArea;
 import javax.swing.ListSelectionModel;
+
+import org.apache.ws.commons.tcpmon.core.AbstractConnection;
+import org.apache.ws.commons.tcpmon.core.AbstractSocketRR;
+
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.net.Socket;
-import java.net.URL;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Date;
 
 /**
  * a connection listens to a single current connection
  */
-class Connection extends Thread {
-
+class Connection extends AbstractConnection {
     /**
      * Field listener
      */
     Listener listener;
 
     /**
-     * Field active
-     */
-    boolean active;
-
-    /**
-     * Field fromHost
-     */
-    String fromHost;
-
-    /**
-     * Field time
-     */
-    String time;
-
-    /**
-     * Field elapsed time
-     */
-    long elapsedTime;
-    
-    /**
      * Field inputText
      */
     JTextArea inputText = null;
@@ -80,76 +57,14 @@
     JScrollPane outputScroll = null;
 
     /**
-     * Field inSocket
-     */
-    Socket inSocket = null;
-
-    /**
-     * Field outSocket
-     */
-    Socket outSocket = null;
-
-    /**
-     * Field clientThread
-     */
-    Thread clientThread = null;
-
-    /**
-     * Field serverThread
-     */
-    Thread serverThread = null;
-
-    /**
-     * Field rr1
-     */
-    SocketRR rr1 = null;
-
-    /**
-     * Field rr2
-     */
-    SocketRR rr2 = null;
-
-    /**
-     * Field inputStream
-     */
-    InputStream inputStream = null;
-
-    /**
-     * Field HTTPProxyHost
-     */
-    String HTTPProxyHost = null;
-
-    /**
-     * Field HTTPProxyPort
-     */
-    int HTTPProxyPort = 80;
-
-    /**
-     * Field slowLink
-     */
-    private SlowLinkSimulator slowLink;
-
-    /**
-     * Constructor Connection
-     *
-     * @param l
-     */
-    public Connection(Listener l) {
-        listener = l;
-        HTTPProxyHost = l.HTTPProxyHost;
-        HTTPProxyPort = l.HTTPProxyPort;
-        slowLink = l.slowLink;
-    }
-
-    /**
      * Constructor Connection
      *
      * @param l
      * @param s
      */
     public Connection(Listener l, Socket s) {
-        this(l);
-        inSocket = s;
+        super(l.getConfiguration(), s);
+        listener = l;
         start();
     }
 
@@ -160,333 +75,12 @@
      * @param in
      */
     public Connection(Listener l, InputStream in) {
-        this(l);
-        inputStream = in;
+        super(l.getConfiguration(), in);
+        listener = l;
         start();
     }
 
     /**
-     * Method run
-     */
-    public void run() {
-        try {
-            active = true;
-            HTTPProxyHost = System.getProperty("http.proxyHost");
-            if ((HTTPProxyHost != null) && HTTPProxyHost.equals("")) {
-                HTTPProxyHost = null;
-            }
-            if (HTTPProxyHost != null) {
-                String tmp = System.getProperty("http.proxyPort");
-                if ((tmp != null) && tmp.equals("")) {
-                    tmp = null;
-                }
-                if (tmp == null) {
-                    HTTPProxyPort = 80;
-                } else {
-                    HTTPProxyPort = Integer.parseInt(tmp);
-                }
-            }
-            if (inSocket != null) {
-                fromHost = (inSocket.getInetAddress()).getHostName();
-            } else {
-                fromHost = "resend";
-            }
-            String dateformat = TCPMonBundle.getMessage("dateformat00", "yyyy-MM-dd HH:mm:ss");
-            DateFormat df = new SimpleDateFormat(dateformat);
-            time = df.format(new Date());
-            int count = listener.connections.size();
-            listener.tableModel.insertRow(count + 1,
-                    new Object[]{
-                        TCPMonBundle.getMessage("active00","Active"),
-                        time,
-                        fromHost,
-                        listener.hostField.getText(),
-                        ""});
-            listener.connections.add(this);
-            inputText = new JTextArea(null, null, 20, 80);
-            inputScroll = new JScrollPane(inputText);
-            outputText = new JTextArea(null, null, 20, 80);
-            outputScroll = new JScrollPane(outputText);
-            ListSelectionModel lsm = listener.connectionTable.getSelectionModel();
-            if ((count == 0) || (lsm.getLeadSelectionIndex() == 0)) {
-                listener.outPane.setVisible(false);
-                int divLoc = listener.outPane.getDividerLocation();
-                listener.setLeft(inputScroll);
-                listener.setRight(outputScroll);
-                listener.removeButton.setEnabled(false);
-                listener.removeAllButton.setEnabled(true);
-                listener.saveButton.setEnabled(true);
-                listener.resendButton.setEnabled(true);
-                listener.outPane.setDividerLocation(divLoc);
-                listener.outPane.setVisible(true);
-            }
-            String targetHost = listener.hostField.getText();
-            int targetPort = Integer.parseInt(listener.tPortField.getText());
-            int listenPort = Integer.parseInt(listener.portField.getText());
-            InputStream tmpIn1 = inputStream;
-            OutputStream tmpOut1 = null;
-            InputStream tmpIn2 = null;
-            OutputStream tmpOut2 = null;
-            if (tmpIn1 == null) {
-                tmpIn1 = inSocket.getInputStream();
-            }
-            if (inSocket != null) {
-                tmpOut1 = inSocket.getOutputStream();
-            }
-            String bufferedData = null;
-            StringBuffer buf = null;
-            int index = listener.connections.indexOf(this);
-            if (listener.isProxyBox.isSelected() || (HTTPProxyHost != null)) {
-
-                // Check if we're a proxy
-                byte[] b = new byte[1];
-                buf = new StringBuffer();
-                String s;
-                for (; ;) {
-                    int len;
-                    len = tmpIn1.read(b, 0, 1);
-                    if (len == -1) {
-                        break;
-                    }
-                    s = new String(b);
-                    buf.append(s);
-                    if (b[0] != '\n') {
-                        continue;
-                    }
-                    break;
-                }
-                bufferedData = buf.toString();
-                inputText.append(bufferedData);
-                if (bufferedData.startsWith("GET ")
-                        || bufferedData.startsWith("POST ")
-                        || bufferedData.startsWith("PUT ")
-                        || bufferedData.startsWith("DELETE ")) {
-                    int start, end;
-                    URL url;
-                    start = bufferedData.indexOf(' ') + 1;
-                    while (bufferedData.charAt(start) == ' ') {
-                        start++;
-                    }
-                    end = bufferedData.indexOf(' ', start);
-                    String urlString = bufferedData.substring(start, end);
-                    if (urlString.charAt(0) == '/') {
-                        urlString = urlString.substring(1);
-                    }
-                    if (listener.isProxyBox.isSelected()) {
-                        url = new URL(urlString);
-                        targetHost = url.getHost();
-                        targetPort = url.getPort();
-                        if (targetPort == -1) {
-                            targetPort = 80;
-                        }
-                        listener.tableModel.setValueAt(targetHost,
-                                index + 1,
-                                TCPMon.OUTHOST_COLUMN);
-                        bufferedData = bufferedData.substring(0, start)
-                                + url.getFile()
-                                + bufferedData.substring(end);
-                    } else {
-                        url = new URL("http://" + targetHost + ":"
-                                + targetPort + "/" + urlString);
-                        listener.tableModel.setValueAt(targetHost,
-                                index + 1,
-                                TCPMon.OUTHOST_COLUMN);
-                        bufferedData = bufferedData.substring(0, start)
-                                + url.toExternalForm()
-                                + bufferedData.substring(end);
-                        targetHost = HTTPProxyHost;
-                        targetPort = HTTPProxyPort;
-                    }
-                }
-            } else {
-                //
-                // Change Host: header to point to correct host
-                //
-                byte[] b1 = new byte[1];
-                buf = new StringBuffer();
-                String s1;
-                String lastLine = null;
-                for (; ;) {
-                    int len;
-                    len = tmpIn1.read(b1, 0, 1);
-                    if (len == -1) {
-                        break;
-                    }
-                    s1 = new String(b1);
-                    buf.append(s1);
-                    if (b1[0] != '\n') {
-                        continue;
-                    }
-
-                    // we have a complete line
-                    String line = buf.toString();
-                    buf.setLength(0);
-
-                    // check to see if we have found Host: header
-                    if (line.startsWith("Host: ")) {
-
-                        // we need to update the hostname to target host
-                        String newHost = "Host: " + targetHost + ":"
-                                + listenPort + "\r\n";
-                        bufferedData = bufferedData.concat(newHost);
-                        break;
-                    }
-
-                    // add it to our headers so far
-                    if (bufferedData == null) {
-                        bufferedData = line;
-                    } else {
-                        bufferedData = bufferedData.concat(line);
-                    }
-
-                    // failsafe
-                    if (line.equals("\r\n")) {
-                        break;
-                    }
-                    if ("\n".equals(lastLine) && line.equals("\n")) {
-                        break;
-                    }
-                    lastLine = line;
-                }
-                if (bufferedData != null) {
-                    inputText.append(bufferedData);
-                    int idx = (bufferedData.length() < 50)
-                            ? bufferedData.length()
-                            : 50;
-                    s1 = bufferedData.substring(0, idx);
-                    int i = s1.indexOf('\n');
-                    if (i > 0) {
-                        s1 = s1.substring(0, i - 1);
-                    }
-                    s1 = s1 + "                           "
-                            + "                       ";
-                    s1 = s1.substring(0, 51);
-                    listener.tableModel.setValueAt(s1, index + 1,
-                    		TCPMon.REQ_COLUMN);
-                }
-            }
-            if (targetPort == -1) {
-                targetPort = 80;
-            }
-            outSocket = new Socket(targetHost, targetPort);
-            tmpIn2 = outSocket.getInputStream();
-            tmpOut2 = outSocket.getOutputStream();
-            if (bufferedData != null) {
-                byte[] b = bufferedData.getBytes();
-                tmpOut2.write(b);
-                slowLink.pump(b.length);
-            }
-            boolean format = listener.xmlFormatBox.isSelected();
-
-            // this is the channel to the endpoint
-            rr1 = new SocketRR(this, inSocket, tmpIn1, outSocket, tmpOut2,
-                    inputText, format, listener.tableModel,
-                    index + 1, "request:", slowLink);
-
-            // create the response slow link from the inbound slow link
-            SlowLinkSimulator responseLink =
-                    new SlowLinkSimulator(slowLink);
-
-            // this is the channel from the endpoint
-            rr2 = new SocketRR(this, outSocket, tmpIn2, inSocket, tmpOut1,
-                    outputText, format, null, 0, "response:",
-                    responseLink);
-            
-            while ((rr1 != null) || (rr2 != null)) {
-
-                if (rr2 != null) {
-                    listener.tableModel.setValueAt(rr2.getElapsed(), 1 + index, TCPMon.ELAPSED_COLUMN);
-                }
-                
-                // Only loop as long as the connection to the target
-                // machine is available - once that's gone we can stop.
-                // The old way, loop until both are closed, left us
-                // looping forever since no one closed the 1st one.
-                
-                if ((null != rr1) && rr1.isDone()) {
-                    if ((index >= 0) && (rr2 != null)) {
-                        listener.tableModel.setValueAt(
-                                TCPMonBundle.getMessage("resp00", "Resp"), 1 + index,
-                                TCPMon.STATE_COLUMN);
-                    }
-                    rr1 = null;
-                }
-
-                if ((null != rr2) && rr2.isDone()) {
-                    if ((index >= 0) && (rr1 != null)) {
-                        listener.tableModel.setValueAt(
-                                TCPMonBundle.getMessage("req00", "Req"), 1 + index,
-                                TCPMon.STATE_COLUMN);
-                    }
-                    rr2 = null;
-                }
-
-                synchronized (this) {
-                    this.wait(100);    // Safety just incase we're not told to wake up.
-                }
-            }
-
-            active = false;
-
-            if (index >= 0) {
-                listener.tableModel.setValueAt(
-                        TCPMonBundle.getMessage("done00", "Done"),
-                        1 + index, TCPMon.STATE_COLUMN);
-            }
-
-        } catch (Exception e) {
-            StringWriter st = new StringWriter();
-            PrintWriter wr = new PrintWriter(st);
-            int index = listener.connections.indexOf(this);
-            if (index >= 0) {
-                listener.tableModel.setValueAt(
-                        TCPMonBundle.getMessage("error00", "Error"), 1 + index,
-                        TCPMon.STATE_COLUMN);
-            }
-            e.printStackTrace(wr);
-            wr.close();
-            if (outputText != null) {
-                outputText.append(st.toString());
-            } else {
-                // something went wrong before we had the output area
-                System.out.println(st.toString());
-            }
-            halt();
-        }
-    }
-
-    /**
-     * Method wakeUp
-     */
-    synchronized void wakeUp() {
-        this.notifyAll();
-    }
-
-    /**
-     * Method halt
-     */
-    public void halt() {
-        try {
-            if (rr1 != null) {
-                rr1.halt();
-            }
-            if (rr2 != null) {
-                rr2.halt();
-            }
-            if (inSocket != null) {
-                inSocket.close();
-            }
-            inSocket = null;
-            if (outSocket != null) {
-                outSocket.close();
-            }
-            outSocket = null;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    /**
      * Method remove
      */
     public void remove() {
@@ -500,4 +94,85 @@
             e.printStackTrace();
         }
     }
+    
+    protected void init(String time, String fromHost, String targetHost) {
+        int count = listener.connections.size();
+        listener.tableModel.insertRow(count + 1,
+                new Object[]{
+                    TCPMonBundle.getMessage("active00","Active"),
+                    time,
+                    fromHost,
+                    targetHost,
+                    ""});
+        listener.connections.add(this);
+        inputText = new JTextArea(null, null, 20, 80);
+        inputScroll = new JScrollPane(inputText);
+        outputText = new JTextArea(null, null, 20, 80);
+        outputScroll = new JScrollPane(outputText);
+        ListSelectionModel lsm = listener.connectionTable.getSelectionModel();
+        if ((count == 0) || (lsm.getLeadSelectionIndex() == 0)) {
+            listener.outPane.setVisible(false);
+            int divLoc = listener.outPane.getDividerLocation();
+            listener.setLeft(inputScroll);
+            listener.setRight(outputScroll);
+            listener.removeButton.setEnabled(false);
+            listener.removeAllButton.setEnabled(true);
+            listener.saveButton.setEnabled(true);
+            listener.resendButton.setEnabled(true);
+            listener.outPane.setDividerLocation(divLoc);
+            listener.outPane.setVisible(true);
+        }
+    }
+    
+    protected AbstractSocketRR createInputSocketRR(Socket inSocket, InputStream inputStream,
+            Socket outSocket, OutputStream outputStream, boolean format,
+            SlowLinkSimulator slowLink) {
+        return new SocketRR(this, inSocket, inputStream, outSocket, outputStream,
+                inputText, format, listener.tableModel,
+                listener.connections.indexOf(this) + 1, "request:", slowLink);
+    }
+
+    protected AbstractSocketRR createOutputSocketRR(Socket outSocket, InputStream inputStream,
+            Socket inSocket, OutputStream outputStream, boolean format,
+            SlowLinkSimulator slowLink) {
+        return new SocketRR(this, outSocket, inputStream, inSocket, outputStream,
+                outputText, format, null, 0, "response:",
+                slowLink);
+    }
+
+    protected void appendInputText(String data) {
+        inputText.append(data);
+    }
+    
+    protected void appendOutputText(String data) {
+        if (outputText != null) {
+            outputText.append(data);
+        } else {
+            // something went wrong before we had the output area
+            System.out.println(data);
+        }
+    }
+    
+    private void setValue(int column, String value) {
+        int index = listener.connections.indexOf(this);
+        if (index >= 0) {
+            listener.tableModel.setValueAt(value, 1 + index, column);
+        }
+    }
+    
+    protected void setOutHost(String outHost) {
+        setValue(TCPMon.OUTHOST_COLUMN, outHost);
+    }
+    
+    protected void setState(String state) {
+        setValue(TCPMon.STATE_COLUMN, state);
+    }
+    
+    protected void setRequest(String request) {
+        setValue(TCPMon.REQ_COLUMN, request);
+    }
+    
+    protected void setElapsed(String elapsed) {
+        setValue(TCPMon.ELAPSED_COLUMN, elapsed);
+    }
 }

Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Listener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Listener.java?rev=729985&r1=729984&r2=729985&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Listener.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Listener.java Mon Dec 29 11:54:55 2008
@@ -37,6 +37,9 @@
 import javax.swing.plaf.basic.BasicButtonListener;
 import javax.swing.table.DefaultTableModel;
 import javax.swing.table.TableColumn;
+
+import org.apache.ws.commons.tcpmon.core.Configuration;
+
 import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.Dimension;
@@ -689,4 +692,17 @@
             e.printStackTrace();
         }
     }
+
+    public Configuration getConfiguration() {
+        Configuration config = new Configuration();
+        config.setListenPort(Integer.parseInt(portField.getText()));
+        config.setTargetHost(hostField.getText());
+        config.setTargetPort(Integer.parseInt(tPortField.getText()));
+        config.setProxy(isProxyBox.isSelected());
+        config.setXmlFormat(xmlFormatBox.isSelected());
+        config.setHttpProxyHost(HTTPProxyHost);
+        config.setHttpProxyPort(HTTPProxyPort);
+        config.setSlowLink(slowLink);
+        return config;
+    }
 }

Copied: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractConnection.java (from r729930, webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java)
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractConnection.java?p2=webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractConnection.java&p1=webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java&r1=729930&r2=729985&rev=729985&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/Connection.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractConnection.java Mon Dec 29 11:54:55 2008
@@ -14,11 +14,11 @@
  * limitations under the License.
  */
 
-package org.apache.ws.commons.tcpmon;
+package org.apache.ws.commons.tcpmon.core;
+
+import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
+import org.apache.ws.commons.tcpmon.TCPMonBundle;
 
-import javax.swing.JScrollPane;
-import javax.swing.JTextArea;
-import javax.swing.ListSelectionModel;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintWriter;
@@ -32,12 +32,8 @@
 /**
  * a connection listens to a single current connection
  */
-class Connection extends Thread {
-
-    /**
-     * Field listener
-     */
-    Listener listener;
+public abstract class AbstractConnection extends Thread {
+    private final Configuration config;
 
     /**
      * Field active
@@ -60,26 +56,6 @@
     long elapsedTime;
     
     /**
-     * Field inputText
-     */
-    JTextArea inputText = null;
-
-    /**
-     * Field inputScroll
-     */
-    JScrollPane inputScroll = null;
-
-    /**
-     * Field outputText
-     */
-    JTextArea outputText = null;
-
-    /**
-     * Field outputScroll
-     */
-    JScrollPane outputScroll = null;
-
-    /**
      * Field inSocket
      */
     Socket inSocket = null;
@@ -102,12 +78,12 @@
     /**
      * Field rr1
      */
-    SocketRR rr1 = null;
+    AbstractSocketRR rr1 = null;
 
     /**
      * Field rr2
      */
-    SocketRR rr2 = null;
+    AbstractSocketRR rr2 = null;
 
     /**
      * Field inputStream
@@ -115,54 +91,25 @@
     InputStream inputStream = null;
 
     /**
-     * Field HTTPProxyHost
-     */
-    String HTTPProxyHost = null;
-
-    /**
-     * Field HTTPProxyPort
-     */
-    int HTTPProxyPort = 80;
-
-    /**
-     * Field slowLink
-     */
-    private SlowLinkSimulator slowLink;
-
-    /**
-     * Constructor Connection
-     *
-     * @param l
-     */
-    public Connection(Listener l) {
-        listener = l;
-        HTTPProxyHost = l.HTTPProxyHost;
-        HTTPProxyPort = l.HTTPProxyPort;
-        slowLink = l.slowLink;
-    }
-
-    /**
      * Constructor Connection
      *
-     * @param l
+     * @param config
      * @param s
      */
-    public Connection(Listener l, Socket s) {
-        this(l);
+    public AbstractConnection(Configuration config, Socket s) {
+        this.config = config;
         inSocket = s;
-        start();
     }
 
     /**
      * Constructor Connection
      *
-     * @param l
+     * @param config
      * @param in
      */
-    public Connection(Listener l, InputStream in) {
-        this(l);
+    public AbstractConnection(Configuration config, InputStream in) {
+        this.config = config;
         inputStream = in;
-        start();
     }
 
     /**
@@ -171,19 +118,23 @@
     public void run() {
         try {
             active = true;
-            HTTPProxyHost = System.getProperty("http.proxyHost");
-            if ((HTTPProxyHost != null) && HTTPProxyHost.equals("")) {
-                HTTPProxyHost = null;
-            }
-            if (HTTPProxyHost != null) {
-                String tmp = System.getProperty("http.proxyPort");
-                if ((tmp != null) && tmp.equals("")) {
-                    tmp = null;
+            String HTTPProxyHost = config.getHttpProxyHost();
+            int HTTPProxyPort = config.getHttpProxyPort();
+            if (HTTPProxyHost == null) {
+                HTTPProxyHost = System.getProperty("http.proxyHost");
+                if ((HTTPProxyHost != null) && HTTPProxyHost.equals("")) {
+                    HTTPProxyHost = null;
                 }
-                if (tmp == null) {
-                    HTTPProxyPort = 80;
-                } else {
-                    HTTPProxyPort = Integer.parseInt(tmp);
+                if (HTTPProxyHost != null) {
+                    String tmp = System.getProperty("http.proxyPort");
+                    if ((tmp != null) && tmp.equals("")) {
+                        tmp = null;
+                    }
+                    if (tmp == null) {
+                        HTTPProxyPort = 80;
+                    } else {
+                        HTTPProxyPort = Integer.parseInt(tmp);
+                    }
                 }
             }
             if (inSocket != null) {
@@ -194,35 +145,10 @@
             String dateformat = TCPMonBundle.getMessage("dateformat00", "yyyy-MM-dd HH:mm:ss");
             DateFormat df = new SimpleDateFormat(dateformat);
             time = df.format(new Date());
-            int count = listener.connections.size();
-            listener.tableModel.insertRow(count + 1,
-                    new Object[]{
-                        TCPMonBundle.getMessage("active00","Active"),
-                        time,
-                        fromHost,
-                        listener.hostField.getText(),
-                        ""});
-            listener.connections.add(this);
-            inputText = new JTextArea(null, null, 20, 80);
-            inputScroll = new JScrollPane(inputText);
-            outputText = new JTextArea(null, null, 20, 80);
-            outputScroll = new JScrollPane(outputText);
-            ListSelectionModel lsm = listener.connectionTable.getSelectionModel();
-            if ((count == 0) || (lsm.getLeadSelectionIndex() == 0)) {
-                listener.outPane.setVisible(false);
-                int divLoc = listener.outPane.getDividerLocation();
-                listener.setLeft(inputScroll);
-                listener.setRight(outputScroll);
-                listener.removeButton.setEnabled(false);
-                listener.removeAllButton.setEnabled(true);
-                listener.saveButton.setEnabled(true);
-                listener.resendButton.setEnabled(true);
-                listener.outPane.setDividerLocation(divLoc);
-                listener.outPane.setVisible(true);
-            }
-            String targetHost = listener.hostField.getText();
-            int targetPort = Integer.parseInt(listener.tPortField.getText());
-            int listenPort = Integer.parseInt(listener.portField.getText());
+            String targetHost = config.getTargetHost();
+            init(time, fromHost, targetHost);
+            int targetPort = config.getTargetPort();
+            int listenPort = config.getListenPort();
             InputStream tmpIn1 = inputStream;
             OutputStream tmpOut1 = null;
             InputStream tmpIn2 = null;
@@ -235,8 +161,7 @@
             }
             String bufferedData = null;
             StringBuffer buf = null;
-            int index = listener.connections.indexOf(this);
-            if (listener.isProxyBox.isSelected() || (HTTPProxyHost != null)) {
+            if (config.isProxy() || (HTTPProxyHost != null)) {
 
                 // Check if we're a proxy
                 byte[] b = new byte[1];
@@ -256,7 +181,7 @@
                     break;
                 }
                 bufferedData = buf.toString();
-                inputText.append(bufferedData);
+                appendInputText(bufferedData);
                 if (bufferedData.startsWith("GET ")
                         || bufferedData.startsWith("POST ")
                         || bufferedData.startsWith("PUT ")
@@ -272,25 +197,21 @@
                     if (urlString.charAt(0) == '/') {
                         urlString = urlString.substring(1);
                     }
-                    if (listener.isProxyBox.isSelected()) {
+                    if (config.isProxy()) {
                         url = new URL(urlString);
                         targetHost = url.getHost();
                         targetPort = url.getPort();
                         if (targetPort == -1) {
                             targetPort = 80;
                         }
-                        listener.tableModel.setValueAt(targetHost,
-                                index + 1,
-                                TCPMon.OUTHOST_COLUMN);
+                        setOutHost(targetHost);
                         bufferedData = bufferedData.substring(0, start)
                                 + url.getFile()
                                 + bufferedData.substring(end);
                     } else {
                         url = new URL("http://" + targetHost + ":"
                                 + targetPort + "/" + urlString);
-                        listener.tableModel.setValueAt(targetHost,
-                                index + 1,
-                                TCPMon.OUTHOST_COLUMN);
+                        setOutHost(targetHost);
                         bufferedData = bufferedData.substring(0, start)
                                 + url.toExternalForm()
                                 + bufferedData.substring(end);
@@ -349,7 +270,7 @@
                     lastLine = line;
                 }
                 if (bufferedData != null) {
-                    inputText.append(bufferedData);
+                    appendInputText(bufferedData);
                     int idx = (bufferedData.length() < 50)
                             ? bufferedData.length()
                             : 50;
@@ -361,8 +282,7 @@
                     s1 = s1 + "                           "
                             + "                       ";
                     s1 = s1.substring(0, 51);
-                    listener.tableModel.setValueAt(s1, index + 1,
-                    		TCPMon.REQ_COLUMN);
+                    setRequest(s1);
                 }
             }
             if (targetPort == -1) {
@@ -371,31 +291,30 @@
             outSocket = new Socket(targetHost, targetPort);
             tmpIn2 = outSocket.getInputStream();
             tmpOut2 = outSocket.getOutputStream();
+            SlowLinkSimulator slowLink = config.getSlowLink();
             if (bufferedData != null) {
                 byte[] b = bufferedData.getBytes();
                 tmpOut2.write(b);
                 slowLink.pump(b.length);
             }
-            boolean format = listener.xmlFormatBox.isSelected();
+            boolean format = config.isXmlFormat();
 
             // this is the channel to the endpoint
-            rr1 = new SocketRR(this, inSocket, tmpIn1, outSocket, tmpOut2,
-                    inputText, format, listener.tableModel,
-                    index + 1, "request:", slowLink);
+            rr1 = createInputSocketRR(inSocket, tmpIn1, outSocket, tmpOut2,
+                    format, slowLink);
 
             // create the response slow link from the inbound slow link
             SlowLinkSimulator responseLink =
                     new SlowLinkSimulator(slowLink);
 
             // this is the channel from the endpoint
-            rr2 = new SocketRR(this, outSocket, tmpIn2, inSocket, tmpOut1,
-                    outputText, format, null, 0, "response:",
-                    responseLink);
+            rr2 = createOutputSocketRR(outSocket, tmpIn2, inSocket, tmpOut1,
+                    format, responseLink);
             
             while ((rr1 != null) || (rr2 != null)) {
 
                 if (rr2 != null) {
-                    listener.tableModel.setValueAt(rr2.getElapsed(), 1 + index, TCPMon.ELAPSED_COLUMN);
+                    setElapsed(rr2.getElapsed());
                 }
                 
                 // Only loop as long as the connection to the target
@@ -404,19 +323,15 @@
                 // looping forever since no one closed the 1st one.
                 
                 if ((null != rr1) && rr1.isDone()) {
-                    if ((index >= 0) && (rr2 != null)) {
-                        listener.tableModel.setValueAt(
-                                TCPMonBundle.getMessage("resp00", "Resp"), 1 + index,
-                                TCPMon.STATE_COLUMN);
+                    if (rr2 != null) {
+                        setState(TCPMonBundle.getMessage("resp00", "Resp"));
                     }
                     rr1 = null;
                 }
 
                 if ((null != rr2) && rr2.isDone()) {
-                    if ((index >= 0) && (rr1 != null)) {
-                        listener.tableModel.setValueAt(
-                                TCPMonBundle.getMessage("req00", "Req"), 1 + index,
-                                TCPMon.STATE_COLUMN);
+                    if (rr1 != null) {
+                        setState(TCPMonBundle.getMessage("req00", "Req"));
                     }
                     rr2 = null;
                 }
@@ -428,37 +343,27 @@
 
             active = false;
 
-            if (index >= 0) {
-                listener.tableModel.setValueAt(
-                        TCPMonBundle.getMessage("done00", "Done"),
-                        1 + index, TCPMon.STATE_COLUMN);
-            }
+            setState(TCPMonBundle.getMessage("done00", "Done"));
 
         } catch (Exception e) {
             StringWriter st = new StringWriter();
             PrintWriter wr = new PrintWriter(st);
-            int index = listener.connections.indexOf(this);
-            if (index >= 0) {
-                listener.tableModel.setValueAt(
-                        TCPMonBundle.getMessage("error00", "Error"), 1 + index,
-                        TCPMon.STATE_COLUMN);
-            }
+            setState(TCPMonBundle.getMessage("error00", "Error"));
             e.printStackTrace(wr);
             wr.close();
-            if (outputText != null) {
-                outputText.append(st.toString());
-            } else {
-                // something went wrong before we had the output area
-                System.out.println(st.toString());
-            }
+            appendOutputText(st.toString());
             halt();
         }
     }
 
+    public boolean isActive() {
+        return active;
+    }
+
     /**
      * Method wakeUp
      */
-    synchronized void wakeUp() {
+    public synchronized void wakeUp() {
         this.notifyAll();
     }
 
@@ -486,18 +391,17 @@
         }
     }
 
-    /**
-     * Method remove
-     */
-    public void remove() {
-        int index = -1;
-        try {
-            halt();
-            index = listener.connections.indexOf(this);
-            listener.tableModel.removeRow(index + 1);
-            listener.connections.remove(index);
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
+    protected abstract void init(String time, String fromHost, String targetHost);
+    protected abstract AbstractSocketRR createInputSocketRR(Socket inSocket,
+            InputStream inputStream, Socket outSocket, OutputStream outputStream, boolean format,
+            SlowLinkSimulator slowLink);
+    protected abstract AbstractSocketRR createOutputSocketRR(Socket outSocket,
+            InputStream inputStream, Socket inSocket, OutputStream outputStream, boolean format,
+            SlowLinkSimulator slowLink);
+    protected abstract void appendInputText(String data);
+    protected abstract void appendOutputText(String data);
+    protected abstract void setOutHost(String outHost);
+    protected abstract void setState(String state);
+    protected abstract void setRequest(String request);
+    protected abstract void setElapsed(String elapsed);
 }

Propchange: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/AbstractConnection.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/Configuration.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/Configuration.java?rev=729985&view=auto
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/Configuration.java (added)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/core/Configuration.java Mon Dec 29 11:54:55 2008
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ws.commons.tcpmon.core;
+
+import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
+
+public class Configuration {
+    private int listenPort;
+    private String targetHost;
+    private int targetPort;
+    private boolean proxy;
+    private boolean xmlFormat;
+    private String httpProxyHost;
+    private int httpProxyPort;
+    private SlowLinkSimulator slowLink;
+    
+    public int getListenPort() {
+        return listenPort;
+    }
+    
+    public void setListenPort(int listenPort) {
+        this.listenPort = listenPort;
+    }
+
+    public String getTargetHost() {
+        return targetHost;
+    }
+    
+    public void setTargetHost(String targetHost) {
+        this.targetHost = targetHost;
+    }
+    
+    public int getTargetPort() {
+        return targetPort;
+    }
+    
+    public void setTargetPort(int targetPort) {
+        this.targetPort = targetPort;
+    }
+
+    public boolean isProxy() {
+        return proxy;
+    }
+
+    public void setProxy(boolean proxy) {
+        this.proxy = proxy;
+    }
+
+    public boolean isXmlFormat() {
+        return xmlFormat;
+    }
+
+    public void setXmlFormat(boolean xmlFormat) {
+        this.xmlFormat = xmlFormat;
+    }
+
+    public String getHttpProxyHost() {
+        return httpProxyHost;
+    }
+
+    public void setHttpProxyHost(String httpProxyHost) {
+        this.httpProxyHost = httpProxyHost;
+    }
+
+    public int getHttpProxyPort() {
+        return httpProxyPort;
+    }
+
+    public void setHttpProxyPort(int httpProxyPort) {
+        this.httpProxyPort = httpProxyPort;
+    }
+
+    public SlowLinkSimulator getSlowLink() {
+        return slowLink;
+    }
+
+    public void setSlowLink(SlowLinkSimulator slowLink) {
+        this.slowLink = slowLink;
+    }
+}

Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java?rev=729985&r1=729984&r2=729985&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java Mon Dec 29 11:54:55 2008
@@ -18,25 +18,20 @@
 
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.net.Socket;
-import java.net.URL;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Date;
 
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.TableItem;
 import org.eclipse.swt.widgets.Text;
 import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
 import org.apache.ws.commons.tcpmon.TCPMonBundle;
+import org.apache.ws.commons.tcpmon.core.AbstractConnection;
+import org.apache.ws.commons.tcpmon.core.AbstractSocketRR;
 
 /**
  * a connection listens to a single current connection
  */
-class Connection extends Thread {
+class Connection extends AbstractConnection {
     public TableItem item;
 
     /**
@@ -45,26 +40,6 @@
     Listener listener;
 
     /**
-     * Field active
-     */
-    boolean active;
-
-    /**
-     * Field fromHost
-     */
-    String fromHost;
-
-    /**
-     * Field time
-     */
-    String time;
-
-    /**
-     * Field elapsed time
-     */
-    long elapsedTime;
-    
-    /**
      * Field inputText
      */
     Text inputText = null;
@@ -75,76 +50,14 @@
     Text outputText = null;
 
     /**
-     * Field inSocket
-     */
-    Socket inSocket = null;
-
-    /**
-     * Field outSocket
-     */
-    Socket outSocket = null;
-
-    /**
-     * Field clientThread
-     */
-    Thread clientThread = null;
-
-    /**
-     * Field serverThread
-     */
-    Thread serverThread = null;
-
-    /**
-     * Field rr1
-     */
-    SocketRR rr1 = null;
-
-    /**
-     * Field rr2
-     */
-    SocketRR rr2 = null;
-
-    /**
-     * Field inputStream
-     */
-    InputStream inputStream = null;
-
-    /**
-     * Field HTTPProxyHost
-     */
-    String HTTPProxyHost = null;
-
-    /**
-     * Field HTTPProxyPort
-     */
-    int HTTPProxyPort = 80;
-
-    /**
-     * Field slowLink
-     */
-    private SlowLinkSimulator slowLink;
-
-    /**
-     * Constructor Connection
-     *
-     * @param l
-     */
-    public Connection(Listener l) {
-        listener = l;
-        HTTPProxyHost = l.HTTPProxyHost;
-        HTTPProxyPort = l.HTTPProxyPort;
-        slowLink = l.slowLink;
-    }
-
-    /**
      * Constructor Connection
      *
      * @param l
      * @param s
      */
     public Connection(Listener l, Socket s) {
-        this(l);
-        inSocket = s;
+        super(l.getConfiguration(), s);
+        listener = l;
         start();
     }
 
@@ -155,439 +68,106 @@
      * @param in
      */
     public Connection(Listener l, InputStream in) {
-        this(l);
-        inputStream = in;
+        super(l.getConfiguration(), in);
+        listener = l;
         start();
     }
 
-    /**
-     * Method run
-     */
-    public void run() {
-        try {
-            active = true;
-            HTTPProxyHost = System.getProperty("http.proxyHost");
-            if ((HTTPProxyHost != null) && HTTPProxyHost.equals("")) {
-                HTTPProxyHost = null;
-            }
-            if (HTTPProxyHost != null) {
-                String tmp = System.getProperty("http.proxyPort");
-                if ((tmp != null) && tmp.equals("")) {
-                    tmp = null;
-                }
-                if (tmp == null) {
-                    HTTPProxyPort = 80;
-                } else {
-                    HTTPProxyPort = Integer.parseInt(tmp);
-                }
-            }
-            if (inSocket != null) {
-                fromHost = (inSocket.getInetAddress()).getHostName();
-            } else {
-                fromHost = "resend";
-            }
-            String dateformat = TCPMonBundle.getMessage("dateformat00", "yyyy-MM-dd HH:mm:ss");
-            DateFormat df = new SimpleDateFormat(dateformat);
-            time = df.format(new Date());
-            final int count = listener.connections.size();
-
-            MainView.display.syncExec(new Runnable() {
-                public void run() {
-                    item = new TableItem(listener.connectionTable, SWT.BORDER, count + 1);
-                    item.setText(new String[]{TCPMonBundle.getMessage("active00", "Active"),
-                            time,
-                            fromHost,
-                            listener.hostField.getText(),
-                            "", ""});
-                    listener.tableEnhancer.setSelectionInterval(0, 0);
-                }
-            });
-
-
-            listener.connections.add(this);
-            TableEnhancer te = listener.tableEnhancer;
-            if ((count == 0) || (te.getLeadSelectionIndex() == 0)) {
-
-                MainView.display.syncExec(new Runnable() {
-                    public void run() {
-                        inputText = (Text) listener.setLeft(MainView.SWT_TEXT, "");
-                        outputText = (Text) listener.setRight(MainView.SWT_TEXT, "");
-                        listener.removeButton.setEnabled(false);
-                        listener.removeAllButton.setEnabled(true);
-                        listener.saveButton.setEnabled(true);
-                        listener.resendButton.setEnabled(true);
-                    }
-                });
-
-            }
-
-            final ArrayList outValues = new ArrayList();
-            MainView.display.syncExec(new Runnable() {
-                public void run() {
-                    outValues.add(listener.hostField.getText());
-                    outValues.add(listener.tPortField.getText());
-                    outValues.add(listener.portField.getText());
-
-                }
-            });
-
-            String targetHost = (String) outValues.get(0);
-            int targetPort = Integer.parseInt((String) outValues.get(1));
-            int listenPort = Integer.parseInt((String) outValues.get(2));
+    protected void init(final String time, final String fromHost, final String targetHost) {
+        final int count = listener.connections.size();
 
+        MainView.display.syncExec(new Runnable() {
+            public void run() {
+                item = new TableItem(listener.connectionTable, SWT.BORDER, count + 1);
+                item.setText(new String[]{TCPMonBundle.getMessage("active00", "Active"),
+                        time,
+                        fromHost,
+                        targetHost,
+                        "", ""});
+                listener.tableEnhancer.setSelectionInterval(0, 0);
+            }
+        });
+
+
+        listener.connections.add(this);
+        TableEnhancer te = listener.tableEnhancer;
+        if ((count == 0) || (te.getLeadSelectionIndex() == 0)) {
 
-            InputStream tmpIn1 = inputStream;
-            OutputStream tmpOut1 = null;
-            InputStream tmpIn2 = null;
-            OutputStream tmpOut2 = null;
-            if (tmpIn1 == null) {
-                tmpIn1 = inSocket.getInputStream();
-            }
-            if (inSocket != null) {
-                tmpOut1 = inSocket.getOutputStream();
-            }
-            String bufferedData = null;
-            StringBuffer buf = null;
-            int index = listener.connections.indexOf(this);
-
-            final ArrayList outValues2 = new ArrayList();
             MainView.display.syncExec(new Runnable() {
                 public void run() {
-                    outValues2.add(listener.isProxyBox.getSelection() ? "true" : "false");
-                    outValues2.add((HTTPProxyHost != null) ? "true" : "false");
+                    inputText = (Text) listener.setLeft(MainView.SWT_TEXT, "");
+                    outputText = (Text) listener.setRight(MainView.SWT_TEXT, "");
+                    listener.removeButton.setEnabled(false);
+                    listener.removeAllButton.setEnabled(true);
+                    listener.saveButton.setEnabled(true);
+                    listener.resendButton.setEnabled(true);
                 }
             });
 
-            if ("true".equals(outValues2.get(0)) || "true".equals(outValues2.get(1))) {
-
-                // Check if we're a proxy
-                byte[] b = new byte[1];
-                buf = new StringBuffer();
-                String s;
-                for (; ;) {
-                    int len;
-                    len = tmpIn1.read(b, 0, 1);
-                    if (len == -1) {
-                        break;
-                    }
-                    s = new String(b);
-                    buf.append(s);
-                    if (b[0] != '\n') {
-                        continue;
-                    }
-                    break;
-                }
-                bufferedData = buf.toString();
-                final String inputString = bufferedData;
-                MainView.display.syncExec(new Runnable() {
-                    public void run() {
-                        inputText.append(inputString);
-                    }
-                });
-                if (bufferedData.startsWith("GET ")
-                        || bufferedData.startsWith("POST ")
-                        || bufferedData.startsWith("PUT ")
-                        || bufferedData.startsWith("DELETE ")) {
-                    int start, end;
-                    URL url;
-                    start = bufferedData.indexOf(' ') + 1;
-                    while (bufferedData.charAt(start) == ' ') {
-                        start++;
-                    }
-                    end = bufferedData.indexOf(' ', start);
-                    String urlString = bufferedData.substring(start, end);
-                    if (urlString.charAt(0) == '/') {
-                        urlString = urlString.substring(1);
-                    }
-
-                    final boolean[] out = new boolean[1];
-                    MainView.display.syncExec(new Runnable() {
-                        public void run() {
-                            out[0] = listener.isProxyBox.getSelection();
-                        }
-                    });
-
-                    if (out[0]) {
-                        url = new URL(urlString);
-                        targetHost = url.getHost();
-                        targetPort = url.getPort();
-                        if (targetPort == -1) {
-                            targetPort = 80;
-                        }
-
-                        final int inputInt = index;
-                        final String inputString2 = targetHost;
-                        MainView.display.syncExec(new Runnable() {
-                            public void run() {
-                                listener.tableEnhancer.setValueAt(inputString2,
-                                        inputInt + 1,
-                                        MainView.OUTHOST_COLUMN);
-                            }
-                        });
-
-                        bufferedData = bufferedData.substring(0, start)
-                                + url.getFile()
-                                + bufferedData.substring(end);
-                    } else {
-                        url = new URL("http://" + targetHost + ":"
-                                + targetPort + "/" + urlString);
-
-                        final int inputInt = index;
-                        final String inputString2 = targetHost;
-                        MainView.display.syncExec(new Runnable() {
-                            public void run() {
-                                listener.tableEnhancer.setValueAt(inputString2,
-                                        inputInt + 1,
-                                        MainView.OUTHOST_COLUMN);
-                            }
-                        });
-                        bufferedData = bufferedData.substring(0, start)
-                                + url.toExternalForm()
-                                + bufferedData.substring(end);
-                        targetHost = HTTPProxyHost;
-                        targetPort = HTTPProxyPort;
-                    }
-                }
-            } else {
-                //
-                // Change Host: header to point to correct host
-                //
-                byte[] b1 = new byte[1];
-                buf = new StringBuffer();
-                String s1;
-                String lastLine = null;
-                for (; ;) {
-                    int len;
-                    len = tmpIn1.read(b1, 0, 1);
-                    if (len == -1) {
-                        break;
-                    }
-                    s1 = new String(b1);
-                    buf.append(s1);
-                    if (b1[0] != '\n') {
-                        continue;
-                    }
-
-                    // we have a complete line
-                    String line = buf.toString();
-                    buf.setLength(0);
-
-                    // check to see if we have found Host: header
-                    if (line.startsWith("Host: ")) {
-
-                        // we need to update the hostname to target host
-                        String newHost = "Host: " + targetHost + ":"
-                                + listenPort + "\r\n";
-                        bufferedData = bufferedData.concat(newHost);
-                        break;
-                    }
-
-                    // add it to our headers so far
-                    if (bufferedData == null) {
-                        bufferedData = line;
-                    } else {
-                        bufferedData = bufferedData.concat(line);
-                    }
-
-                    // failsafe
-                    if (line.equals("\r\n")) {
-                        break;
-                    }
-                    if ("\n".equals(lastLine) && line.equals("\n")) {
-                        break;
-                    }
-                    lastLine = line;
-                }
-                if (bufferedData != null) {
+        }
+    }
 
-                    final String inputString = bufferedData;
-                    MainView.display.syncExec(new Runnable() {
-                        public void run() {
-                            inputText.append(inputString);
-                        }
-                    });
-                    int idx = (bufferedData.length() < 50)
-                            ? bufferedData.length()
-                            : 50;
-                    s1 = bufferedData.substring(0, idx);
-                    int i = s1.indexOf('\n');
-                    if (i > 0) {
-                        s1 = s1.substring(0, i - 1);
-                    }
-                    s1 = s1 + "                           "
-                            + "                       ";
-                    s1 = s1.substring(0, 51);
-
-                    final int inputInt = index;
-                    final String inputString2 = s1;
-                    MainView.display.syncExec(new Runnable() {
-                        public void run() {
-                            listener.tableEnhancer.setValueAt(inputString2,
-                                    inputInt + 1,
-                                    MainView.REQ_COLUMN);
-                        }
-                    });
-                }
-            }
-            if (targetPort == -1) {
-                targetPort = 80;
-            }
-            outSocket = new Socket(targetHost, targetPort);
-            tmpIn2 = outSocket.getInputStream();
-            tmpOut2 = outSocket.getOutputStream();
-            if (bufferedData != null) {
-                byte[] b = bufferedData.getBytes();
-                tmpOut2.write(b);
-                slowLink.pump(b.length);
+    protected AbstractSocketRR createInputSocketRR(Socket inSocket, InputStream inputStream,
+            Socket outSocket, OutputStream outputStream, boolean format,
+            SlowLinkSimulator slowLink) {
+        return new SocketRR(this, inSocket, inputStream, outSocket, outputStream,
+                inputText, format, listener.connectionTable,
+                listener.connections.indexOf(this) + 1, "request:", slowLink);
+    }
+
+    protected AbstractSocketRR createOutputSocketRR(Socket outSocket, InputStream inputStream,
+            Socket inSocket, OutputStream outputStream, boolean format,
+            SlowLinkSimulator slowLink) {
+        return new SocketRR(this, outSocket, inputStream, inSocket, outputStream,
+                outputText, format, null, 0, "response:",
+                slowLink);
+    }
+
+    protected void appendInputText(final String data) {
+        MainView.display.syncExec(new Runnable() {
+            public void run() {
+                inputText.append(data);
             }
-
-            final boolean[] out = new boolean[1];
-            MainView.display.syncExec(new Runnable() {
-                public void run() {
-                    out[0] = listener.xmlFormatBox.getSelection();
-                }
-            });
-            boolean format = out[0];
-
-            // this is the channel to the endpoint
-            rr1 = new SocketRR(this, inSocket, tmpIn1, outSocket, tmpOut2,
-                    inputText, format, listener.connectionTable,
-                    index + 1, "request:", slowLink);
-
-            // create the response slow link from the inbound slow link
-            SlowLinkSimulator responseLink =
-                    new SlowLinkSimulator(slowLink);
-
-            // this is the channel from the endpoint
-            rr2 = new SocketRR(this, outSocket, tmpIn2, inSocket, tmpOut1,
-                    outputText, format, null, 0, "response:",
-                    responseLink);
-            
-            while ((rr1 != null) || (rr2 != null)) {
-
-                if (rr2 != null) {
-                    final int inputInt = index;
-                    MainView.display.syncExec(new Runnable() {
-                        public void run() {
-                            listener.tableEnhancer.setValueAt(rr2.getElapsed(), 1 + inputInt, MainView.ELAPSED_COLUMN);
-                        }
-                    });
-                }
-                
-                // Only loop as long as the connection to the target
-                // machine is available - once that's gone we can stop.
-                // The old way, loop until both are closed, left us
-                // looping forever since no one closed the 1st one.
-                
-                if ((null != rr1) && rr1.isDone()) {
-                    if ((index >= 0) && (rr2 != null)) {
-                        final int inputInt = index;
-                        MainView.display.syncExec(new Runnable() {
-                            public void run() {
-                                listener.tableEnhancer.setValueAt(
-                                        TCPMonBundle.getMessage("resp00", "Resp"), 1 + inputInt,
-                                        MainView.STATE_COLUMN);
-                            }
-                        });
-                    }
-                    rr1 = null;
-                }
-
-                if ((null != rr2) && rr2.isDone()) {
-                    if ((index >= 0) && (rr1 != null)) {
-                        final int inputInt = index;
-                        MainView.display.syncExec(new Runnable() {
-                            public void run() {
-                                listener.tableEnhancer.setValueAt(
-                                        TCPMonBundle.getMessage("req00", "Req"), 1 + inputInt,
-                                        MainView.STATE_COLUMN);
-                            }
-                        });
-                    }
-                    rr2 = null;
-                }
-
-                synchronized (this) {
-                    this.wait(100);    // Safety just incase we're not told to wake up.
+        });
+    }
+    
+    protected void appendOutputText(final String data) {
+        MainView.display.syncExec(new Runnable() {
+            public void run() {
+                if (outputText != null) {
+                    outputText.append(data);
+                } else {
+                    // something went wrong before we had the output area
+                    System.out.println(data);
                 }
             }
-
-            active = false;
-
-            if (index >= 0) {
-                final int inputInt = index;
-                MainView.display.syncExec(new Runnable() {
-                    public void run() {
-                        listener.tableEnhancer.setValueAt(
-                                TCPMonBundle.getMessage("done00", "Done"),
-                                1 + inputInt, MainView.STATE_COLUMN);
-                    }
-                });
-            }
-
-        } catch (Exception e) {
-            StringWriter st = new StringWriter();
-            PrintWriter wr = new PrintWriter(st);
-            int index = listener.connections.indexOf(this);
-            if (index >= 0) {
-                final int inputInt = index;
-                MainView.display.syncExec(new Runnable() {
-                    public void run() {
-                        listener.tableEnhancer.setValueAt(
-                                TCPMonBundle.getMessage("error00", "Error"), 1 + inputInt,
-                                MainView.STATE_COLUMN);
-
-                    }
-                });
-            }
-            e.printStackTrace(wr);
-            wr.close();
-
-            final String inputString = st.toString();
+        });
+    }
+    
+    private void setValue(final int column, final String value) {
+        final int index = listener.connections.indexOf(this);
+        if (index >= 0) {
             MainView.display.syncExec(new Runnable() {
                 public void run() {
-                    if (outputText != null) {
-                        outputText.append(inputString);
-                    } else {
-                        // something went wrong before we had the output area
-                        System.out.println(inputString);
-                    }
-
+                    listener.tableEnhancer.setValueAt(value, 1 + index, column);
                 }
             });
-
-            halt();
         }
     }
-
-    /**
-     * Method wakeUp
-     */
-    synchronized void wakeUp() {
-        this.notifyAll();
+    
+    protected void setOutHost(String outHost) {
+        setValue(MainView.OUTHOST_COLUMN, outHost);
+    }
+    
+    protected void setState(String state) {
+        setValue(MainView.STATE_COLUMN, state);
     }
 
-    /**
-     * Method halt
-     */
-    public void halt() {
-        try {
-            if (rr1 != null) {
-                rr1.halt();
-            }
-            if (rr2 != null) {
-                rr2.halt();
-            }
-            if (inSocket != null) {
-                inSocket.close();
-            }
-            inSocket = null;
-            if (outSocket != null) {
-                outSocket.close();
-            }
-            outSocket = null;
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
+    protected void setRequest(String request) {
+        setValue(MainView.REQ_COLUMN, request);
+    }
+    
+    protected void setElapsed(String elapsed) {
+        setValue(MainView.ELAPSED_COLUMN, elapsed);
     }
 }

Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java?rev=729985&r1=729984&r2=729985&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java Mon Dec 29 11:54:55 2008
@@ -17,6 +17,7 @@
 
 import org.apache.ws.commons.tcpmon.SlowLinkSimulator;
 import org.apache.ws.commons.tcpmon.TCPMonBundle;
+import org.apache.ws.commons.tcpmon.core.Configuration;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
@@ -443,7 +444,7 @@
         for (int i = 0; i < selectionIndices.length; i++) {
             index = selectionIndices[i];
             con = (Connection) connections.get(index - 1 - i);
-            if (con.active) {
+            if (con.isActive()) {
                 MessageBox mb = new MessageBox(MainView.display.getActiveShell(), SWT.ICON_INFORMATION | SWT.OK);
                 mb.setMessage(TCPMonBundle.getMessage("inform00", "Connection can be removed only when its status indicates Done"));
                 mb.setText("Connection Active");
@@ -659,4 +660,20 @@
         }
     }
 
+    public Configuration getConfiguration() {
+        final Configuration config = new Configuration();
+        MainView.display.syncExec(new Runnable() {
+            public void run() {
+                config.setListenPort(Integer.parseInt(portField.getText()));
+                config.setTargetHost(hostField.getText());
+                config.setTargetPort(Integer.parseInt(tPortField.getText()));
+                config.setProxy(isProxyBox.getSelection());
+                config.setXmlFormat(xmlFormatBox.getSelection());
+            }
+        });
+        config.setHttpProxyHost(HTTPProxyHost);
+        config.setHttpProxyPort(HTTPProxyPort);
+        config.setSlowLink(slowLink);
+        return config;
+    }
 }