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/31 19:24:45 UTC

svn commit: r739582 - 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: Sat Jan 31 18:24:44 2009
New Revision: 739582

URL: http://svn.apache.org/viewvc?rev=739582&view=rev
Log:
Refactored the connection handling code to decouple it a bit more from the UI and to make a distinction between connections and request-responses (this will allow us to handle keep-alive connections in the future).  

Added:
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Connection.java
      - copied, changed from r738521, 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/IRequestResponse.java   (with props)
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/RequestResponse.java   (with props)
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/RequestResponse.java   (with props)
Removed:
    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-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/Connection.java
Modified:
    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-core/src/main/java/org/apache/ws/commons/tcpmon/core/SocketRR.java
    webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/SocketWaiter.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/Listener.java

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=739582&r1=739581&r2=739582&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 Sat Jan 31 18:24:44 2009
@@ -18,13 +18,12 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
-import java.net.Socket;
 
 public abstract class AbstractListener {
-    protected void resend(AbstractConnection conn) {
+    protected void resend(IRequestResponse requestResponse) {
         try {
             InputStream in = null;
-            String text = conn.getRequestAsString();
+            String text = requestResponse.getRequestAsString();
 
             // Fix Content-Length HTTP headers
             if (text.startsWith("POST ") || text.startsWith("GET ")) {
@@ -58,14 +57,14 @@
                 }
             }
             in = new ByteArrayInputStream(text.getBytes());
-            createConnection(in);
+            new Connection(this, in).start();
         } catch (Exception e) {
             e.printStackTrace();
         }
     }
     
+    public abstract Configuration getConfiguration();
     public abstract void onServerSocketStart();
     public abstract void onServerSocketError(Throwable ex);
-    public abstract AbstractConnection createConnection(Socket inSocket);
-    public abstract AbstractConnection createConnection(InputStream in);
+    public abstract IRequestResponse createRequestResponse(String time, String fromHost, String targetHost);
 }

Copied: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Connection.java (from r738521, 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/Connection.java?p2=webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/Connection.java&p1=webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/AbstractConnection.java&r1=738521&r2=739582&rev=739582&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/Connection.java Sat Jan 31 18:24:44 2009
@@ -45,9 +45,10 @@
 /**
  * a connection listens to a single current connection
  */
-public abstract class AbstractConnection extends Thread {
+public class Connection extends Thread {
     private static final Charset UTF8 = Charset.forName("utf-8");
     
+    private final AbstractListener listener;
     private final Configuration config;
 
     /**
@@ -79,29 +80,33 @@
      * Field inputStream
      */
     private InputStream inputStream = null;
-
-    protected Writer inputWriter;
-    protected Writer outputWriter;
+    
+    private IRequestResponse requestResponse;
+    
+    private Writer inputWriter;
+    private Writer outputWriter;
 
     /**
      * Constructor Connection
      *
-     * @param config
+     * @param listener
      * @param s
      */
-    public AbstractConnection(Configuration config, Socket s) {
-        this.config = config;
+    public Connection(AbstractListener listener, Socket s) {
+        this.listener = listener;
+        config = listener.getConfiguration();
         inSocket = s;
     }
 
     /**
      * Constructor Connection
      *
-     * @param config
+     * @param listener
      * @param in
      */
-    public AbstractConnection(Configuration config, InputStream in) {
-        this.config = config;
+    public Connection(AbstractListener listener, InputStream in) {
+        this.listener = listener;
+        config = listener.getConfiguration();
         inputStream = in;
     }
 
@@ -139,7 +144,10 @@
             String dateformat = TCPMonBundle.getMessage("dateformat00", "yyyy-MM-dd HH:mm:ss");
             DateFormat df = new SimpleDateFormat(dateformat);
             String targetHost = config.getTargetHost();
-            init(df.format(new Date()), fromHost, targetHost);
+            requestResponse = listener.createRequestResponse(
+                    df.format(new Date()), fromHost, targetHost);
+            inputWriter = requestResponse.getRequestWriter();
+            outputWriter = requestResponse.getResponseWriter();
             int targetPort = config.getTargetPort();
             InputStream tmpIn1 = inputStream;
             OutputStream tmpOut1 = null;
@@ -154,7 +162,7 @@
             Pipeline requestPipeline = new Pipeline();
             requestPipeline.addFilter(new RequestLineExtractor(50) {
                 protected void done(String requestLine) {
-                    setRequest(requestLine);
+                    requestResponse.setRequest(requestLine);
                 }
             });
             HttpRequestFilter requestFilter = new HttpRequestFilter(false);
@@ -219,7 +227,7 @@
             while ((rr1 != null) || (rr2 != null)) {
 
                 if (rr2 != null) {
-                    setElapsed(rr2.getElapsed());
+                    requestResponse.setElapsed(rr2.getElapsed());
                 }
                 
                 // Only loop as long as the connection to the target
@@ -229,14 +237,14 @@
                 
                 if ((null != rr1) && rr1.isDone()) {
                     if (rr2 != null) {
-                        setState(TCPMonBundle.getMessage("resp00", "Resp"));
+                        requestResponse.setState(TCPMonBundle.getMessage("resp00", "Resp"));
                     }
                     rr1 = null;
                 }
 
                 if ((null != rr2) && rr2.isDone()) {
                     if (rr1 != null) {
-                        setState(TCPMonBundle.getMessage("req00", "Req"));
+                        requestResponse.setState(TCPMonBundle.getMessage("req00", "Req"));
                     }
                     rr2 = null;
                 }
@@ -248,12 +256,14 @@
 
             active = false;
 
-            setState(TCPMonBundle.getMessage("done00", "Done"));
+            requestResponse.setState(TCPMonBundle.getMessage("done00", "Done"));
 
         } catch (Exception e) {
             StringWriter st = new StringWriter();
             PrintWriter wr = new PrintWriter(st);
-            setState(TCPMonBundle.getMessage("error00", "Error"));
+            if (requestResponse != null) {
+                requestResponse.setState(TCPMonBundle.getMessage("error00", "Error"));
+            }
             e.printStackTrace(wr);
             wr.close();
             if (outputWriter != null) {
@@ -301,13 +311,4 @@
             e.printStackTrace();
         }
     }
-
-    protected abstract void init(String time, String fromHost, String targetHost);
-    protected abstract void setOutHost(String outHost);
-    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();
 }

Added: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/IRequestResponse.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/IRequestResponse.java?rev=739582&view=auto
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/IRequestResponse.java (added)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/IRequestResponse.java Sat Jan 31 18:24:44 2009
@@ -0,0 +1,33 @@
+/*
+ * 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 java.io.Writer;
+
+/**
+ * Listener receiving information about a given request-response exchange.
+ */
+public interface IRequestResponse {
+    void setOutHost(String outHost);
+    void setState(String state);
+    void setRequest(String request);
+    void setElapsed(String elapsed);
+    Writer getRequestWriter();
+    Writer getResponseWriter();
+    String getRequestAsString();
+    String getResponseAsString();
+}

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

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/SocketRR.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/SocketRR.java?rev=739582&r1=739581&r2=739582&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/SocketRR.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/SocketRR.java Sat Jan 31 18:24:44 2009
@@ -28,7 +28,7 @@
  * outgoing socket
  */
 public class SocketRR extends Thread {
-    private final AbstractConnection connection;
+    private final Connection connection;
 
     /**
      * Field inSocket
@@ -77,7 +77,7 @@
      * @param type
      * @param slowLink
      */
-    public SocketRR(AbstractConnection connection, Socket inputSocket,
+    public SocketRR(Connection connection, Socket inputSocket,
                     InputStream inputStream, Socket outputSocket,
                     OutputStream outputStream, Pipeline pipeline) {
         this.connection = connection;

Modified: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/SocketWaiter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/SocketWaiter.java?rev=739582&r1=739581&r2=739582&view=diff
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/SocketWaiter.java (original)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-core/src/main/java/org/apache/ws/commons/tcpmon/core/SocketWaiter.java Sat Jan 31 18:24:44 2009
@@ -18,6 +18,8 @@
 
 import java.net.ServerSocket;
 import java.net.Socket;
+import java.util.Iterator;
+import java.util.Vector;
 
 /**
  * wait for incoming connections, spawn a connection thread when
@@ -45,6 +47,8 @@
      */
     boolean pleaseStop = false;
 
+    private final Vector connections = new Vector();
+
     /**
      * Constructor SocketWaiter
      *
@@ -69,7 +73,11 @@
                 if (pleaseStop) {
                     break;
                 }
-                listener.createConnection(inSocket);
+                Connection connection = new Connection(listener, inSocket);
+                // TODO: at some point we need to remove closed connections,
+                //       otherwise this will be a memory leak.
+                connections.add(connection);
+                connection.start();
                 inSocket = null;
             }
         } catch (Exception exp) {
@@ -89,6 +97,9 @@
             if (sSocket != null) {
                 sSocket.close();
             }
+            for (Iterator it = connections.iterator(); it.hasNext(); ) {
+                ((Connection)it.next()).halt();
+            }
         } catch (Exception e) {
             e.printStackTrace();
         }

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=739582&r1=739581&r2=739582&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 Sat Jan 31 18:24:44 2009
@@ -17,9 +17,9 @@
 
 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.AbstractListener;
 import org.apache.ws.commons.tcpmon.core.Configuration;
+import org.apache.ws.commons.tcpmon.core.IRequestResponse;
 import org.apache.ws.commons.tcpmon.core.SocketWaiter;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionAdapter;
@@ -29,8 +29,6 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.net.Socket;
 import java.util.Iterator;
 import java.util.Vector;
 
@@ -61,7 +59,7 @@
     private SocketWaiter sw = null;
     private SlowLinkSimulator slowLink;
 
-    public final Vector connections = new Vector();
+    public final Vector requestResponses = new Vector();
 
     public String HTTPProxyHost = null;
     public int HTTPProxyPort = 80;
@@ -352,7 +350,7 @@
                 row = tableEnhancer.getMaxSelectionIndex();
             }
             if (row == 0) {
-                if (connections.size() == 0) {
+                if (requestResponses.size() == 0) {
                     setLeft(MainView.SWT_LABEL, " " + TCPMonBundle.getMessage("wait00",
                             "Waiting for connection..."));
                     setRight(MainView.SWT_LABEL, "");
@@ -364,13 +362,13 @@
                     rightPanel.layout();
                     textComposite.layout();
                 } else {
-                    Connection conn = (Connection) connections.lastElement();
+                    RequestResponse requestResponse = (RequestResponse) requestResponses.lastElement();
                     removeChildren(leftPanel.getChildren());
                     removeChildren(rightPanel.getChildren());
-                    ((GridData) conn.inputText.getLayoutData()).exclude = false;
-                    conn.inputText.setVisible(true);
-                    ((GridData) conn.outputText.getLayoutData()).exclude = false;
-                    conn.outputText.setVisible(true);
+                    ((GridData) requestResponse.inputText.getLayoutData()).exclude = false;
+                    requestResponse.inputText.setVisible(true);
+                    ((GridData) requestResponse.outputText.getLayoutData()).exclude = false;
+                    requestResponse.outputText.setVisible(true);
                     removeButton.setEnabled(false);
                     removeAllButton.setEnabled(true);
                     saveButton.setEnabled(true);
@@ -380,13 +378,13 @@
                     textComposite.layout();
                 }
             } else {
-                Connection conn = (Connection) connections.get(row - 1);
+                RequestResponse requestResponse = (RequestResponse) requestResponses.get(row - 1);
                 removeChildren(leftPanel.getChildren());
                 removeChildren(rightPanel.getChildren());
-                ((GridData) conn.inputText.getLayoutData()).exclude = false;
-                conn.inputText.setVisible(true);
-                ((GridData) conn.outputText.getLayoutData()).exclude = false;
-                conn.outputText.setVisible(true);
+                ((GridData) requestResponse.inputText.getLayoutData()).exclude = false;
+                requestResponse.inputText.setVisible(true);
+                ((GridData) requestResponse.outputText.getLayoutData()).exclude = false;
+                requestResponse.outputText.setVisible(true);
                 removeButton.setEnabled(true);
                 removeAllButton.setEnabled(true);
                 saveButton.setEnabled(true);
@@ -414,10 +412,6 @@
 
     public void stop() {
         try {
-            for (int i = 0; i < connections.size(); i++) {
-                Connection conn = (Connection) connections.get(i);
-                conn.halt();
-            }
             sw.halt();
             stopButton.setText(TCPMonBundle.getMessage("start00", "Start"));
             portField.setEditable(true);
@@ -431,22 +425,22 @@
 
     public void remove() {
         int index;
-        Connection con;
+        RequestResponse requestResponse;
         int[] selectionIndices = tableEnhancer.getSelectionIndicesWithoutZero();
         for (int i = 0; i < selectionIndices.length; i++) {
             index = selectionIndices[i];
-            con = (Connection) connections.get(index - 1 - i);
-            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");
-                mb.open();
-                continue;
-            }
-            con.halt();
-            con.inputText.dispose();
-            con.outputText.dispose();
-            connections.remove(con);
+            requestResponse = (RequestResponse) requestResponses.get(index - 1 - i);
+//            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");
+//                mb.open();
+//                continue;
+//            }
+//            con.halt();
+            requestResponse.inputText.dispose();
+            requestResponse.outputText.dispose();
+            requestResponses.remove(requestResponse);
             tableEnhancer.remove(index - i);
             tableEnhancer.setSelectionInterval(0, 0);
         }
@@ -484,9 +478,9 @@
                 FileOutputStream out = new FileOutputStream(file);
                 int rc = tableEnhancer.getLeadSelectionIndex();
                 int n = 0;
-                for (Iterator i = connections.iterator(); i.hasNext();
+                for (Iterator i = requestResponses.iterator(); i.hasNext();
                      n++) {
-                    Connection conn = (Connection) i.next();
+                    RequestResponse requestResponse = (RequestResponse) i.next();
                     if (tableEnhancer.isSelectedIndex(n + 1)
                             || (!(i.hasNext())
                             && (tableEnhancer.getLeadSelectionIndex() == 0))) {
@@ -506,11 +500,11 @@
                         out.write((("==== "
                                 + TCPMonBundle.getMessage("request01", "Request")
                                 + " ====\n")).getBytes());
-                        out.write(conn.getRequestAsString().getBytes());
+                        out.write(requestResponse.getRequestAsString().getBytes());
                         out.write((("==== "
                                 + TCPMonBundle.getMessage("response00", "Response")
                                 + " ====\n")).getBytes());
-                        out.write(conn.getResponseAsString().getBytes());
+                        out.write(requestResponse.getResponseAsString().getBytes());
                         out.write("\n==============\n".getBytes());
                     }
                 }
@@ -523,19 +517,19 @@
 
     public void resend() {
         int rc;
-        Connection conn;
+        RequestResponse requestResponse;
         rc = tableEnhancer.getMaxSelectionIndex();
         if (rc == 0) {
-            conn = (Connection) connections.lastElement();
+            requestResponse = (RequestResponse) requestResponses.lastElement();
         } else {
-            conn = (Connection) connections.get(rc - 1);
+            requestResponse = (RequestResponse) requestResponses.get(rc - 1);
         }
 
         if (rc > 0) {
             tableEnhancer.clearSelection();
             tableEnhancer.setSelectionInterval(0, 0);
         }
-        resend(conn);
+        resend(requestResponse);
     }
 
 
@@ -647,11 +641,7 @@
         });
     }
 
-    public AbstractConnection createConnection(Socket inSocket) {
-        return new Connection(this, inSocket);
-    }
-
-    public AbstractConnection createConnection(InputStream in) {
-        return new Connection(this, in);
+    public IRequestResponse createRequestResponse(String time, String fromHost, String targetHost) {
+        return new RequestResponse(this, time, fromHost, targetHost);
     }
 }

Added: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/RequestResponse.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/RequestResponse.java?rev=739582&view=auto
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/RequestResponse.java (added)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/RequestResponse.java Sat Jan 31 18:24:44 2009
@@ -0,0 +1,117 @@
+/*
+ * 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.eclipse.ui;
+
+import java.io.Writer;
+
+import org.apache.ws.commons.tcpmon.TCPMonBundle;
+import org.apache.ws.commons.tcpmon.core.IRequestResponse;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.TableItem;
+import org.eclipse.swt.widgets.Text;
+
+public class RequestResponse implements IRequestResponse {
+    private final Listener listener;
+
+    /**
+     * Field inputText
+     */
+    Text inputText = null;
+
+    /**
+     * Field outputText
+     */
+    Text outputText = null;
+
+    public RequestResponse(final Listener listener, final String time, final String fromHost, final String targetHost) {
+        this.listener = listener;
+        final int count = listener.requestResponses.size();
+
+        MainView.display.syncExec(new Runnable() {
+            public void run() {
+                TableItem 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.requestResponses.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);
+                }
+            });
+
+        }
+    }
+
+    private void setValue(final int column, final String value) {
+        final int index = listener.requestResponses.indexOf(this);
+        if (index >= 0) {
+            MainView.display.syncExec(new Runnable() {
+                public void run() {
+                    listener.tableEnhancer.setValueAt(value, 1 + index, column);
+                }
+            });
+        }
+    }
+    
+    public void setOutHost(String outHost) {
+        setValue(MainView.OUTHOST_COLUMN, outHost);
+    }
+    
+    public void setState(String state) {
+        setValue(MainView.STATE_COLUMN, state);
+    }
+
+    public void setRequest(String request) {
+        setValue(MainView.REQ_COLUMN, request);
+    }
+    
+    public void setElapsed(String elapsed) {
+        setValue(MainView.ELAPSED_COLUMN, elapsed);
+    }
+
+    public Writer getRequestWriter() {
+        return new TextWidgetWriter(inputText);
+    }
+
+    public Writer getResponseWriter() {
+        return new TextWidgetWriter(outputText);
+    }
+
+    public String getRequestAsString() {
+        return inputText.getText();
+    }
+
+    public String getResponseAsString() {
+        return outputText.getText();
+    }
+}

Propchange: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-eclipse-plugin/src/main/java/org/apache/ws/commons/tcpmon/eclipse/ui/RequestResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=739582&r1=739581&r2=739582&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 Sat Jan 31 18:24:44 2009
@@ -40,9 +40,9 @@
 import javax.swing.table.DefaultTableModel;
 import javax.swing.table.TableColumn;
 
-import org.apache.ws.commons.tcpmon.core.AbstractConnection;
 import org.apache.ws.commons.tcpmon.core.AbstractListener;
 import org.apache.ws.commons.tcpmon.core.Configuration;
+import org.apache.ws.commons.tcpmon.core.IRequestResponse;
 import org.apache.ws.commons.tcpmon.core.SocketWaiter;
 
 import java.awt.BorderLayout;
@@ -55,8 +55,6 @@
 import java.awt.event.ItemListener;
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.InputStream;
-import java.net.Socket;
 import java.util.Iterator;
 import java.util.Vector;
 
@@ -171,7 +169,7 @@
     /**
      * Field connections
      */
-    public final Vector connections = new Vector();
+    public final Vector requestResponses = new Vector();
 
     /**
      * create a listener
@@ -393,35 +391,35 @@
     public void handleSelection() {
         ListSelectionModel m = connectionTable.getSelectionModel();
         int divLoc = outPane.getDividerLocation();
-        Connection conn;
+        RequestResponse requestResponse;
         if (m.isSelectionEmpty()) {
-            conn = null;
+            requestResponse = null;
             removeButton.setEnabled(false);
         } else {
             int row = m.getLeadSelectionIndex();
             if (row == 0) {
-                if (connections.size() == 0) {
-                    conn = null;
+                if (requestResponses.size() == 0) {
+                    requestResponse = null;
                 } else {
-                    conn = (Connection) connections.lastElement();
+                    requestResponse = (RequestResponse)requestResponses.lastElement();
                 }
                 removeButton.setEnabled(false);
             } else {
-                conn = (Connection) connections.get(row - 1);
+                requestResponse = (RequestResponse)requestResponses.get(row - 1);
                 removeButton.setEnabled(true);
             }
         }
-        if (conn == null) {
+        if (requestResponse == null) {
             setLeft(new JLabel(" " + TCPMonBundle.getMessage("wait00",
                     "Waiting for Connection...")));
             setRight(new JLabel(""));
         } else {
-            setLeft(conn.inputScroll);
-            setRight(conn.outputScroll);
+            setLeft(requestResponse.inputScroll);
+            setRight(requestResponse.outputScroll);
         }
-        saveButton.setEnabled(conn != null);
-        resendButton.setEnabled(conn != null);
-        removeAllButton.setEnabled(!connections.isEmpty());
+        saveButton.setEnabled(requestResponse != null);
+        resendButton.setEnabled(requestResponse != null);
+        removeAllButton.setEnabled(!requestResponses.isEmpty());
         outPane.setDividerLocation(divLoc);
     }
 
@@ -471,10 +469,6 @@
     public void stop() {
         if (sw != null) {
             try {
-                for (int i = 0; i < connections.size(); i++) {
-                    Connection conn = (Connection) connections.get(i);
-                    conn.halt();
-                }
                 sw.halt();
                 sw = null;
                 startButton.setSelected(false);
@@ -496,10 +490,10 @@
         int bot = lsm.getMinSelectionIndex();
         int top = lsm.getMaxSelectionIndex();
         for (int i = top; i >= bot; i--) {
-            ((Connection) connections.get(i - 1)).remove();
+            ((RequestResponse)requestResponses.get(i - 1)).remove();
         }
-        if (bot > connections.size()) {
-            bot = connections.size();
+        if (bot > requestResponses.size()) {
+            bot = requestResponses.size();
         }
         lsm.setSelectionInterval(bot, bot);
     }
@@ -510,8 +504,8 @@
     public void removeAll() {
         ListSelectionModel lsm = connectionTable.getSelectionModel();
         lsm.clearSelection();
-        while (connections.size() > 0) {
-            ((Connection) connections.get(0)).remove();
+        while (requestResponses.size() > 0) {
+            ((RequestResponse)requestResponses.get(0)).remove();
         }
         lsm.setSelectionInterval(0, 0);
     }
@@ -538,9 +532,9 @@
                         connectionTable.getSelectionModel();
                 rc = lsm.getLeadSelectionIndex();
                 int n = 0;
-                for (Iterator i = connections.iterator(); i.hasNext();
+                for (Iterator i = requestResponses.iterator(); i.hasNext();
                      n++) {
-                    Connection conn = (Connection) i.next();
+                    RequestResponse requestResponse = (RequestResponse) i.next();
                     if (lsm.isSelectedIndex(n + 1)
                             || (!(i.hasNext())
                             && (lsm.getLeadSelectionIndex() == 0))) {
@@ -560,11 +554,11 @@
                         out.write((("==== "
                                 + TCPMonBundle.getMessage("request01", "Request")
                                 + " ====\n")).getBytes());
-                        out.write(conn.getRequestAsString().getBytes());
+                        out.write(requestResponse.getRequestAsString().getBytes());
                         out.write((("==== "
                                 + TCPMonBundle.getMessage("response00", "Response")
                                 + " ====\n")).getBytes());
-                        out.write(conn.getResponseAsString().getBytes());
+                        out.write(requestResponse.getResponseAsString().getBytes());
                         out.write("\n==============\n".getBytes());
                     }
                 }
@@ -583,14 +577,14 @@
         ListSelectionModel lsm = connectionTable.getSelectionModel();
         rc = lsm.getLeadSelectionIndex();
         if (rc == 0) {
-            rc = connections.size();
+            rc = requestResponses.size();
         }
-        Connection conn = (Connection) connections.get(rc - 1);
+        RequestResponse requestResponse = (RequestResponse)requestResponses.get(rc - 1);
         if (rc > 0) {
             lsm.clearSelection();
             lsm.setSelectionInterval(0, 0);
         }
-        resend(conn);
+        resend(requestResponse);
     }
 
     public Configuration getConfiguration() {
@@ -621,11 +615,7 @@
         stop();
     }
 
-    public AbstractConnection createConnection(Socket inSocket) {
-        return new Connection(this, inSocket);
-    }
-
-    public AbstractConnection createConnection(InputStream in) {
-        return new Connection(this, in);
+    public IRequestResponse createRequestResponse(String time, String fromHost, String targetHost) {
+        return new RequestResponse(this, time, fromHost, targetHost);
     }
 }

Added: webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/RequestResponse.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/RequestResponse.java?rev=739582&view=auto
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/RequestResponse.java (added)
+++ webservices/commons/trunk/modules/tcpmon/modules/tcpmon-ui/src/main/java/org/apache/ws/commons/tcpmon/RequestResponse.java Sat Jan 31 18:24:44 2009
@@ -0,0 +1,120 @@
+/*
+ * 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;
+
+import java.io.Writer;
+
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+
+import org.apache.ws.commons.tcpmon.core.IRequestResponse;
+
+public class RequestResponse implements IRequestResponse {
+    private final Listener listener;
+    
+    /**
+     * Field inputText
+     */
+    private JTextArea inputText;
+
+    /**
+     * Field inputScroll
+     */
+    JScrollPane inputScroll = null;
+
+    /**
+     * Field outputText
+     */
+    private JTextArea outputText;
+
+    /**
+     * Field outputScroll
+     */
+    JScrollPane outputScroll = null;
+    
+    public RequestResponse(Listener listener, String time, String fromHost,
+            String targetHost) {
+        this.listener = listener;
+        int count = listener.requestResponses.size();
+        listener.tableModel.insertRow(count + 1,
+                new Object[]{
+                    TCPMonBundle.getMessage("active00","Active"),
+                    time,
+                    fromHost,
+                    targetHost,
+                    ""});
+        listener.requestResponses.add(this);
+        inputText = new JTextArea(null, null, 20, 80);
+        inputScroll = new JScrollPane(inputText);
+        outputText = new JTextArea(null, null, 20, 80);
+        outputScroll = new JScrollPane(outputText);
+        listener.handleSelection();
+    }
+
+    /**
+     * Method remove
+     */
+    public void remove() {
+        int index = -1;
+        try {
+            index = listener.requestResponses.indexOf(this);
+            listener.tableModel.removeRow(index + 1);
+            listener.requestResponses.remove(index);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+    
+    private void setValue(int column, String value) {
+        int index = listener.requestResponses.indexOf(this);
+        if (index >= 0) {
+            listener.tableModel.setValueAt(value, 1 + index, column);
+        }
+    }
+    
+    public void setOutHost(String outHost) {
+        setValue(TCPMon.OUTHOST_COLUMN, outHost);
+    }
+    
+    public void setState(String state) {
+        setValue(TCPMon.STATE_COLUMN, state);
+    }
+    
+    public void setRequest(String request) {
+        setValue(TCPMon.REQ_COLUMN, request);
+    }
+    
+    public void setElapsed(String elapsed) {
+        setValue(TCPMon.ELAPSED_COLUMN, elapsed);
+    }
+    
+    public Writer getRequestWriter() {
+        return new JTextAreaWriter(inputText);
+    }
+
+    public Writer getResponseWriter() {
+        return new JTextAreaWriter(outputText);
+    }
+
+    public String getRequestAsString() {
+        return inputText.getText();
+    }
+
+    public String getResponseAsString() {
+        return outputText.getText();
+    }
+}

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