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 aj...@apache.org on 2006/12/25 20:38:15 UTC

svn commit: r490162 [1/2] - in /webservices/commons/trunk/modules/tcpmon: resources/eclipse/ resources/idea/ src/org/apache/ws/commons/tcpmon/ src/org/apache/ws/commons/tcpmon/eclipse/ src/org/apache/ws/commons/tcpmon/eclipse/plugin/ src/org/apache/ws/...

Author: ajith
Date: Mon Dec 25 11:38:14 2006
New Revision: 490162

URL: http://svn.apache.org/viewvc?view=rev&rev=490162
Log:
1. Added the code from Saliya for the Eclipse TCPMon port (WS-Commons Jira 137 [http://issues.apache.org/jira/browse/WSCOMMONS-137]). The classes have been refactored to fit the apache packaging and there is still some work to do to get it right since there are a number of classes that can be reused from the existing ones.
2. Refactored the IDEA components to reflect the same structure as the eclipse one.
3. Fixed a very minor issue in the original TCPMon window - the tab that should have focus at startup is tab 0 rather than tab 1.

Added:
    webservices/commons/trunk/modules/tcpmon/resources/eclipse/
    webservices/commons/trunk/modules/tcpmon/resources/eclipse/plugin.xml
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/TcpmonitorPlugin.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/
    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
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketWaiter.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TableEnhancer.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/IdeaPlugin.java
      - copied, changed from r490160, webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaPlugin.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/ComponentHandler.java
      - copied, changed from r490160, webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ComponentHandler.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/IdeaTCPMonToolWindow.java
      - copied, changed from r490160, webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaTCPMonToolWindow.java
Removed:
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ComponentHandler.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaPlugin.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaTCPMonToolWindow.java
Modified:
    webservices/commons/trunk/modules/tcpmon/resources/idea/plugin.xml
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/TCPMon.java
    webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/tcpmon.properties

Added: webservices/commons/trunk/modules/tcpmon/resources/eclipse/plugin.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/resources/eclipse/plugin.xml?view=auto&rev=490162
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/resources/eclipse/plugin.xml (added)
+++ webservices/commons/trunk/modules/tcpmon/resources/eclipse/plugin.xml Mon Dec 25 11:38:14 2006
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+
+   <extension
+         point="org.eclipse.ui.views">
+      <category
+            name="TCP Monitor"
+            id="tcpmonitor">
+      </category>
+      <view
+            name="TCP Monitor"
+            icon="icons/monitor.gif"
+            category="tcpmonitor"
+            class="tcpmonitor.views.MainView"
+            id="tcpmonitor.views.MainView">
+      </view>
+   </extension>
+   <extension
+         point="org.eclipse.ui.perspectiveExtensions">
+      <perspectiveExtension
+            targetID="org.eclipse.ui.resourcePerspective">
+         <view
+               ratio="0.5"
+               relative="org.eclipse.ui.views.TaskList"
+               relationship="right"
+               id="tcpmonitor.views.MainView">
+         </view>
+      </perspectiveExtension>
+   </extension>
+
+</plugin>

Modified: webservices/commons/trunk/modules/tcpmon/resources/idea/plugin.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/resources/idea/plugin.xml?view=diff&rev=490162&r1=490161&r2=490162
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/resources/idea/plugin.xml (original)
+++ webservices/commons/trunk/modules/tcpmon/resources/idea/plugin.xml Mon Dec 25 11:38:14 2006
@@ -8,8 +8,8 @@
   <idea-version since-build="3000"/>
    <project-components>
        <component>
-           <interface-class>org.apache.ws.commons.tcpmon.idea.IdeaPlugin</interface-class>
-           <implementation-class>org.apache.ws.commons.tcpmon.idea.IdeaPlugin</implementation-class>
+           <interface-class>org.apache.ws.commons.tcpmon.idea.plugin.IdeaPlugin</interface-class>
+           <implementation-class>org.apache.ws.commons.tcpmon.idea.plugin.IdeaPlugin</implementation-class>
        </component>
    </project-components>
 </idea-plugin>

Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/TCPMon.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/TCPMon.java?view=diff&rev=490162&r1=490161&r2=490162
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/TCPMon.java (original)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/TCPMon.java Mon Dec 25 11:38:14 2006
@@ -83,7 +83,7 @@
             } else {
                 l = new Listener(notebook, null, listenPort, targetHost, targetPort, false, null);
             }
-            notebook.setSelectedIndex(1);
+            notebook.setSelectedIndex(0);
             l.HTTPProxyHost = System.getProperty("http.proxyHost");
             if ((l.HTTPProxyHost != null) && l.HTTPProxyHost.equals("")) {
                 l.HTTPProxyHost = null;

Added: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/TcpmonitorPlugin.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/TcpmonitorPlugin.java?view=auto&rev=490162
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/TcpmonitorPlugin.java (added)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/TcpmonitorPlugin.java Mon Dec 25 11:38:14 2006
@@ -0,0 +1,69 @@
+/*
+ * 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.plugin;
+
+import org.eclipse.ui.plugin.*;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class TcpmonitorPlugin extends AbstractUIPlugin {
+
+	//The shared instance.
+	private static TcpmonitorPlugin plugin;
+	
+	/**
+	 * The constructor.
+	 */
+	public TcpmonitorPlugin() {
+		plugin = this;
+	}
+
+	/**
+	 * This method is called upon plug-in activation
+	 */
+	public void start(BundleContext context) throws Exception {
+		super.start(context);
+	}
+
+	/**
+	 * This method is called when the plug-in is stopped
+	 */
+	public void stop(BundleContext context) throws Exception {
+		super.stop(context);
+		plugin = null;
+	}
+
+	/**
+	 * Returns the shared instance.
+	 */
+	public static TcpmonitorPlugin getDefault() {
+		return plugin;
+	}
+
+	/**
+	 * Returns an image descriptor for the image file at the given
+	 * plug-in relative path.
+	 *
+	 * @param path the path
+	 * @return the image descriptor
+	 */
+	public static ImageDescriptor getImageDescriptor(String path) {
+		return AbstractUIPlugin.imageDescriptorFromPlugin("tcpmonitor", path);
+	}
+}

Added: 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?view=auto&rev=490162
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java (added)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java Mon Dec 25 11:38:14 2006
@@ -0,0 +1,602 @@
+/*
+ * 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.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;
+
+/**
+ * a connection listens to a single current connection
+ */
+class Connection extends Thread {
+    private int inputInt;
+    private String inputString;
+    private ArrayList outValues = new ArrayList();
+    public TableItem item;
+
+
+    /**
+     * Field listener
+     */
+    Listener listener;
+
+    /**
+     * Field active
+     */
+    boolean active;
+
+    /**
+     * Field fromHost
+     */
+    String fromHost;
+
+    /**
+     * Field time
+     */
+    String time;
+
+    /**
+     * Field elapsed time
+     */
+    long elapsedTime;
+
+    /**
+     * Field inputText
+     */
+    Text inputText = null;
+
+    /**
+     * Field outputText
+     */
+    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;
+        start();
+    }
+
+    /**
+     * Constructor Connection
+     *
+     * @param l
+     * @param in
+     */
+    public Connection(Listener l, InputStream in) {
+        this(l);
+        inputStream = in;
+        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 = MainView.getMessage("dateformat00", "yyyy-MM-dd HH:mm:ss");
+            DateFormat df = new SimpleDateFormat(dateformat);
+            time = df.format(new Date());
+            int count = listener.connections.size();
+
+            inputInt = count;
+            MainView.display.syncExec(new Runnable() {
+                public void run() {
+                    item = new TableItem(listener.connectionTable, SWT.BORDER, inputInt + 1);
+                    item.setText(new String[]{MainView.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);
+                    }
+                });
+
+            }
+
+            MainView.display.syncExec(new Runnable() {
+                public void run() {
+                    outValues.clear();
+                    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));
+
+
+            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);
+
+            MainView.display.syncExec(new Runnable() {
+                public void run() {
+                    outValues.clear();
+                    outValues.add(listener.isProxyBox.getSelection() ? "true" : "false");
+                    outValues.add((HTTPProxyHost != null) ? "true" : "false");
+                }
+            });
+
+            if ("true".equals(outValues.get(0)) || "true".equals(outValues.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();
+                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);
+                    }
+
+                    MainView.display.syncExec(new Runnable() {
+                        public void run() {
+                            outValues.clear();
+                            outValues.add((listener.isProxyBox.getSelection()) ? "true" : "false");
+                        }
+                    });
+
+                    if ("true".equals(outValues.get(0))) {
+                        url = new URL(urlString);
+                        targetHost = url.getHost();
+                        targetPort = url.getPort();
+                        if (targetPort == -1) {
+                            targetPort = 80;
+                        }
+
+                        inputInt = index;
+                        inputString = targetHost;
+                        MainView.display.syncExec(new Runnable() {
+                            public void run() {
+                                listener.tableEnhancer.setValueAt(inputString,
+                                        inputInt + 1,
+                                        MainView.OUTHOST_COLUMN);
+                            }
+                        });
+
+                        bufferedData = bufferedData.substring(0, start)
+                                + url.getFile()
+                                + bufferedData.substring(end);
+                    } else {
+                        url = new URL("http://" + targetHost + ":"
+                                + targetPort + "/" + urlString);
+
+                        inputInt = index;
+                        inputString = targetHost;
+                        MainView.display.syncExec(new Runnable() {
+                            public void run() {
+                                listener.tableEnhancer.setValueAt(inputString,
+                                        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) {
+
+                    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);
+
+                    inputInt = index;
+                    inputString = s1;
+                    MainView.display.syncExec(new Runnable() {
+                        public void run() {
+                            listener.tableEnhancer.setValueAt(inputString,
+                                    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);
+            }
+
+            MainView.display.syncExec(new Runnable() {
+                public void run() {
+                    outValues.clear();
+                    outValues.add((listener.xmlFormatBox.getSelection()) ? "true" : "false");
+                }
+            });
+            boolean format = ("true".equals(outValues.get(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) {
+                    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)) {
+                        inputInt = index;
+                        MainView.display.syncExec(new Runnable() {
+                            public void run() {
+                                listener.tableEnhancer.setValueAt(
+                                        MainView.getMessage("resp00", "Resp"), 1 + inputInt,
+                                        MainView.STATE_COLUMN);
+                            }
+                        });
+                    }
+                    rr1 = null;
+                }
+
+                if ((null != rr2) && rr2.isDone()) {
+                    if ((index >= 0) && (rr1 != null)) {
+                        inputInt = index;
+                        MainView.display.syncExec(new Runnable() {
+                            public void run() {
+                                listener.tableEnhancer.setValueAt(
+                                        MainView.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.
+                }
+            }
+
+
+            active = false;
+
+            if (index >= 0) {
+                inputInt = index;
+                MainView.display.syncExec(new Runnable() {
+                    public void run() {
+                        listener.tableEnhancer.setValueAt(
+                                MainView.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) {
+                inputInt = index;
+                MainView.display.syncExec(new Runnable() {
+                    public void run() {
+                        listener.tableEnhancer.setValueAt(
+                                MainView.getMessage("error00", "Error"), 1 + inputInt,
+                                MainView.STATE_COLUMN);
+
+                    }
+                });
+            }
+            e.printStackTrace(wr);
+            wr.close();
+
+            inputString = st.toString();
+            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);
+                    }
+
+                }
+            });
+
+            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();
+        }
+    }
+}

Added: 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?view=auto&rev=490162
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java (added)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java Mon Dec 25 11:38:14 2006
@@ -0,0 +1,664 @@
+/*
+ * 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 org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+import org.apache.ws.commons.tcpmon.eclipse.ui.Connection;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.Iterator;
+import java.util.Vector;
+
+/**
+ * This is similar to the main swing listener but includes SWT components instead of Swing ones
+ *
+ */
+class Listener {
+    public Socket inputSocket = null;
+    public Socket outputSocket = null;
+    public ServerSocket sSocket = null;
+
+    public Composite leftPanel = null;
+    public Composite rightPanel = null;
+    public Composite textComposite = null;
+    public Text portField = null;
+    public Text hostField = null;
+    public Text tPortField = null;
+    public Button isProxyBox = null;
+    public Button stopButton = null;
+    public Button removeButton = null;
+    public Button removeAllButton = null;
+    public Button xmlFormatBox = null;
+    public Button saveButton = null;
+    public Button resendButton = null;
+    public Button switchButton = null;
+    public Button closeButton = null;
+    public Table connectionTable = null;
+    public TableEnhancer tableEnhancer = null;
+
+    private TabFolder tabFolder;
+    private TabItem portTabItem;
+
+    public SocketWaiter sw = null;
+    public SlowLinkSimulator slowLink;
+
+    public final Vector connections = new Vector();
+
+    public String HTTPProxyHost = null;
+    public int HTTPProxyPort = 80;
+    public int delayBytes = 0;
+    public int delayTime = 0;
+
+    public Listener(TabFolder tabFolder, String name, int listenPort,
+                    String host, int targetPort, boolean isProxy,
+                    SlowLinkSimulator slowLink) {
+        if (name == null) {
+            name = MainView.getMessage("port01", "Port") + " " + listenPort;
+        }
+        // set the slow link to the passed down link
+        if (slowLink != null) {
+            this.slowLink = slowLink;
+        } else {
+            // or make up a no-op one.
+            this.slowLink = new SlowLinkSimulator(0, 0);
+        }
+
+        this.tabFolder = tabFolder;
+        createPortTab(isProxy, listenPort, host, targetPort);
+
+    }
+
+    public void createPortTab(boolean isProxy, int listenPort, String host, int targetPort) {
+        portTabItem = new TabItem(tabFolder, SWT.NONE);
+
+        final Composite composite = new Composite(tabFolder, SWT.NONE);
+        GridLayout gl = new GridLayout();
+        gl.numColumns = 8;
+        composite.setLayout(gl);
+        portTabItem.setControl(composite);
+
+        stopButton = new Button(composite, SWT.NONE);
+        GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+        gd.widthHint = 71;
+        stopButton.setLayoutData(gd);
+        final String start = MainView.getMessage("start00", "Start");
+        stopButton.setText(start);
+
+        final Label listenPortLabel = new Label(composite, SWT.NONE);
+        gd = new GridData();
+        gd.horizontalIndent = 5;
+        listenPortLabel.setLayoutData(gd);
+        listenPortLabel.setText(MainView.getMessage("listenPort01", "Listen Port:"));
+
+        portField = new Text(composite, SWT.BORDER);
+        portField.setText("" + listenPort);
+        portField.setTextLimit(4);
+        gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+        gd.widthHint = 40;
+        portField.setLayoutData(gd);
+
+        (new Label(composite, SWT.NONE)).setText(MainView.getMessage("host00", "Host:"));
+
+        hostField = new Text(composite, SWT.BORDER);
+        hostField.setText(host);
+        hostField.setTextLimit(30);
+        gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+        gd.widthHint = 202;
+        hostField.setLayoutData(gd);
+
+        (new Label(composite, SWT.NONE)).setText(MainView.getMessage("port02", "Port:"));
+
+        tPortField = new Text(composite, SWT.BORDER);
+        tPortField.setText("" + targetPort);
+        tPortField.setTextLimit(4);
+        gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+        gd.widthHint = 40;
+        tPortField.setLayoutData(gd);
+
+        isProxyBox = new Button(composite, SWT.LEFT | SWT.CHECK);
+        isProxyBox.setAlignment(SWT.LEFT);
+        gd = new GridData(64, SWT.DEFAULT);
+        gd.verticalIndent = 2;
+        gd.horizontalIndent = 10;
+        isProxyBox.setLayoutData(gd);
+        isProxyBox.setText(MainView.getMessage("proxy00", "Proxy"));
+        isProxyBox.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                boolean state = ((Button) e.getSource()).getSelection();
+                tPortField.setEnabled(!state);
+                hostField.setEnabled(!state);
+            }
+        });
+        isProxyBox.setSelection(isProxy);
+        portField.setEditable(false);
+        hostField.setEditable(false);
+        tPortField.setEditable(false);
+        stopButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (stopButton.getText().equals(MainView.getMessage("stop00", "Stop"))) {
+                    stop();
+                } else {
+                    start();
+                }
+            }
+        });
+
+        connectionTable = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.MULTI);
+        connectionTable.setHeaderVisible(true);
+        gd = new GridData(SWT.LEFT, SWT.FILL, true, false, 8, 1);
+        gd.heightHint = 102;
+        connectionTable.setLayoutData(gd);
+
+        final TableColumn stateColumn = new TableColumn(connectionTable, SWT.CENTER);
+        stateColumn.setWidth(47);
+        stateColumn.setText(MainView.getMessage("state00", "State"));
+
+        final TableColumn timeColumn = new TableColumn(connectionTable, SWT.CENTER);
+        timeColumn.setWidth(100);
+        timeColumn.setText(MainView.getMessage("time00", "Time"));
+
+        final TableColumn reqHostColumn = new TableColumn(connectionTable, SWT.CENTER);
+        reqHostColumn.setWidth(100);
+        reqHostColumn.setText(MainView.getMessage("requestHost00", "Request Host"));
+
+        final TableColumn targetHostColumn = new TableColumn(connectionTable, SWT.CENTER);
+        targetHostColumn.setWidth(100);
+        targetHostColumn.setText(MainView.getMessage("targetHost", "Target Host"));
+
+        final TableColumn requestColumn = new TableColumn(connectionTable, SWT.CENTER);
+        requestColumn.setWidth(100);
+        requestColumn.setText(MainView.getMessage("request00", "Request..."));
+
+        final TableColumn elapsedTimeColumn = new TableColumn(connectionTable, SWT.CENTER);
+        elapsedTimeColumn.setWidth(140);
+        elapsedTimeColumn.setText(MainView.getMessage("elapsed00", "Elapsed Time"));
+
+        final TableItem headerItem = new TableItem(connectionTable, SWT.BORDER);
+        headerItem.setText(new String[]{"--", "Most Recent", "--", "--", "--", "--"});
+        tableEnhancer = new TableEnhancer(connectionTable);
+
+//		SelectionListener part goes here - I THINK IT'S DONE
+
+        connectionTable.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                handleSelection();
+            }
+        });
+
+
+        final Composite buttonComposite = new Composite(composite, SWT.NONE);
+        buttonComposite.setLayout(new RowLayout());
+        gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1);
+        gd.heightHint = 32;
+        gd.widthHint = 59;
+        buttonComposite.setLayoutData(gd);
+
+        removeButton = new Button(buttonComposite, SWT.NONE);
+        RowData rd = new RowData();
+        rd.width = 100;
+        removeButton.setLayoutData(rd);
+        final String removeSelected = MainView.getMessage("removeSelected00", "Remove Selected");
+        removeButton.setText(removeSelected);
+        removeButton.setEnabled(false);
+        removeButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (removeSelected.equals(((Button) e.getSource()).getText())) {
+                    remove();
+                }
+            }
+        });
+
+        removeAllButton = new Button(buttonComposite, SWT.NONE);
+        rd = new RowData();
+        rd.width = 100;
+        removeAllButton.setLayoutData(rd);
+        final String removeAll = MainView.getMessage("removeAll00", "Remove All");
+        removeAllButton.setText(removeAll);
+        removeAllButton.setEnabled(false);
+        removeAllButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (removeAll.equals(((Button) e.getSource()).getText())) {
+                    removeAll();
+                }
+            }
+        });
+
+        textComposite = new Composite(composite, SWT.NONE);
+        textComposite.setLayout(new FillLayout(SWT.VERTICAL));
+        gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 8, 1);
+        gd.widthHint = 589;
+        gd.heightHint = 230;
+        textComposite.setLayoutData(gd);
+
+        leftPanel = new Composite(textComposite, SWT.BORDER);
+        leftPanel.setLayout(new GridLayout(8, true));
+
+        rightPanel = new Composite(textComposite, SWT.BORDER);
+        rightPanel.setLayout(new GridLayout(8, true));
+
+        xmlFormatBox = new Button(composite, SWT.CHECK);
+        xmlFormatBox.setText(MainView.getMessage("xmlFormat00", "XML Format"));
+
+        final Composite buttonComposite2 = new Composite(composite, SWT.NONE);
+        buttonComposite2.setLayout(new RowLayout());
+        gd = new GridData(SWT.FILL, SWT.FILL, false, false, 4, 1);
+        gd.heightHint = 27;
+        gd.widthHint = 27;
+        buttonComposite2.setLayoutData(gd);
+
+        saveButton = new Button(buttonComposite2, SWT.NONE);
+        rd = new RowData();
+        rd.width = 100;
+        saveButton.setLayoutData(rd);
+        final String save = MainView.getMessage("save00", "Save");
+        saveButton.setText(save);
+        saveButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (save.equals(((Button) e.getSource()).getText())) {
+                    save();
+                }
+            }
+        });
+
+        resendButton = new Button(buttonComposite2, SWT.NONE);
+        rd = new RowData();
+        rd.width = 100;
+        resendButton.setLayoutData(rd);
+        final String resend = MainView.getMessage("resend00", "Resend");
+        resendButton.setText(resend);
+        resendButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (resend.equals(((Button) e.getSource()).getText())) {
+                    resend();
+                }
+            }
+        });
+
+        switchButton = new Button(buttonComposite2, SWT.NONE);
+        rd = new RowData();
+        rd.width = 100;
+        switchButton.setLayoutData(rd);
+        final String switchStr = MainView.getMessage("switch00", "Switch Layout");
+        switchButton.setText(switchStr);
+        switchButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (switchStr.equals(((Button) e.getSource()).getText())) {
+                    if (((FillLayout) textComposite.getLayout()).type == SWT.HORIZONTAL) {
+                        ((FillLayout) textComposite.getLayout()).type = SWT.VERTICAL;
+                    } else {
+                        ((FillLayout) textComposite.getLayout()).type = SWT.HORIZONTAL;
+                    }
+                    leftPanel.layout();
+                    rightPanel.layout();
+                    textComposite.layout();
+                }
+            }
+        });
+
+        final Composite buttonComposite3 = new Composite(composite, SWT.NONE);
+        buttonComposite3.setLayout(new RowLayout());
+        gd = new GridData(SWT.FILL, SWT.FILL, false, false, 3, 1);
+        gd.horizontalIndent = 95;
+        gd.heightHint = 27;
+        gd.widthHint = 27;
+        buttonComposite3.setLayoutData(gd);
+
+        closeButton = new Button(buttonComposite3, SWT.None);
+        rd = new RowData();
+        rd.width = 60;
+        closeButton.setLayoutData(rd);
+        final String close = MainView.getMessage("close00", "Close");
+        closeButton.setText(close);
+        closeButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (close.equals(((Button) e.getSource()).getText())) {
+                    close();
+                }
+            }
+        });
+        tableEnhancer.setSelectionInterval(0, 0);
+        start();
+    }
+
+    public void handleSelection() {
+        if (tableEnhancer.isSelectionEmpty()) {
+            setLeft(MainView.SWT_LABEL, " " + MainView.getMessage("wait00",
+                    "Waiting for Connection..."));
+            setRight(MainView.SWT_LABEL, "");
+            removeButton.setEnabled(false);
+            removeAllButton.setEnabled(false);
+            saveButton.setEnabled(false);
+            resendButton.setEnabled(false);
+            leftPanel.layout();
+            rightPanel.layout();
+            textComposite.layout();
+        } else {
+            int row = tableEnhancer.getLeadSelectionIndex();
+            if (row != tableEnhancer.getMaxSelectionIndex()) {
+                row = tableEnhancer.getMaxSelectionIndex();
+            }
+            if (row == 0) {
+                if (connections.size() == 0) {
+                    setLeft(MainView.SWT_LABEL, " " + MainView.getMessage("wait00",
+                            "Waiting for connection..."));
+                    setRight(MainView.SWT_LABEL, "");
+                    removeButton.setEnabled(false);
+                    removeAllButton.setEnabled(false);
+                    saveButton.setEnabled(false);
+                    resendButton.setEnabled(false);
+                    leftPanel.layout();
+                    rightPanel.layout();
+                    textComposite.layout();
+                } else {
+                    Connection conn = (Connection) connections.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);
+                    removeButton.setEnabled(false);
+                    removeAllButton.setEnabled(true);
+                    saveButton.setEnabled(true);
+                    resendButton.setEnabled(true);
+                    leftPanel.layout();
+                    rightPanel.layout();
+                    textComposite.layout();
+                }
+            } else {
+                Connection conn = (Connection) connections.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);
+                removeButton.setEnabled(true);
+                removeAllButton.setEnabled(true);
+                saveButton.setEnabled(true);
+                resendButton.setEnabled(true);
+                leftPanel.layout();
+                rightPanel.layout();
+                textComposite.layout();
+            }
+        }
+    }
+
+    public void stop() {
+        try {
+            for (int i = 0; i < connections.size(); i++) {
+                Connection conn = (Connection) connections.get(i);
+                conn.halt();
+            }
+            sw.halt();
+            stopButton.setText(MainView.getMessage("start00", "Start"));
+            portField.setEditable(true);
+            hostField.setEditable(true);
+            tPortField.setEditable(true);
+            isProxyBox.setEnabled(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void start() {
+        int port = Integer.parseInt(portField.getText());
+        portField.setText("" + port);
+        portTabItem.setText(MainView.getMessage("port01", "Port") + " " + port);
+        int tmp = Integer.parseInt(tPortField.getText());
+        tPortField.setText("" + tmp);
+        sw = new SocketWaiter(this, port);
+        stopButton.setText(MainView.getMessage("stop00", "Stop"));
+        portField.setEditable(false);
+        hostField.setEditable(false);
+        tPortField.setEditable(false);
+        isProxyBox.setEnabled(false);
+    }
+
+
+    public void remove() {
+        int index;
+        Connection con;
+        int[] selectionIndices = tableEnhancer.getSelectionIndicesWithoutZero();
+        for (int i = 0; i < selectionIndices.length; i++) {
+            index = selectionIndices[i];
+            con = (Connection) connections.get(index - 1 - i);
+            if (con.active) {
+                MessageBox mb = new MessageBox(MainView.display.getActiveShell(), SWT.ICON_INFORMATION | SWT.OK);
+                mb.setMessage(MainView.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);
+            tableEnhancer.remove(index - i);
+            tableEnhancer.setSelectionInterval(0, 0);
+        }
+    }
+
+
+    public void removeAll() {
+        tableEnhancer.selectAll();
+        remove();
+    }
+
+
+    public void close() {
+        MessageBox mb = new MessageBox(MainView.display.getActiveShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO);
+        mb.setMessage(MainView.getMessage("quit00", "Do you want to remove monitoring") + " " + portTabItem.getText());
+        mb.setText("Remove Monitor");
+        int response = mb.open();
+        if (response == SWT.YES) {
+            if (stopButton.getText().equals(MainView.getMessage("stop00", "Stop"))) {
+                stop();
+            }
+            portTabItem.dispose();
+        }
+    }
+
+
+    public void save() {
+        FileDialog fd = new FileDialog(MainView.display.getActiveShell(), SWT.SAVE);
+        fd.setText("Save");
+        fd.setFilterPath(".");
+        String path = fd.open();
+        if (path == null) {
+            return;
+        }
+        try {
+            File file = new File(path);
+            FileOutputStream out = new FileOutputStream(file);
+            int rc = tableEnhancer.getLeadSelectionIndex();
+            int n = 0;
+            for (Iterator i = connections.iterator(); i.hasNext();
+                 n++) {
+                Connection conn = (Connection) i.next();
+                if (tableEnhancer.isSelectedIndex(n + 1)
+                        || (!(i.hasNext())
+                        && (tableEnhancer.getLeadSelectionIndex() == 0))) {
+                    rc = Integer.parseInt(portField.getText());
+                    out.write("\n==============\n".getBytes());
+                    out.write(((MainView.getMessage("listenPort01",
+                            "Listen Port:")
+                            + " " + rc + "\n")).getBytes());
+                    out.write((MainView.getMessage("targetHost01",
+                            "Target Host:")
+                            + " " + hostField.getText()
+                            + "\n").getBytes());
+                    rc = Integer.parseInt(tPortField.getText());
+                    out.write(((MainView.getMessage("targetPort01",
+                            "Target Port:")
+                            + " " + rc + "\n")).getBytes());
+                    out.write((("==== "
+                            + MainView.getMessage("request01", "Request")
+                            + " ====\n")).getBytes());
+                    out.write(conn.inputText.getText().getBytes());
+                    out.write((("==== "
+                            + MainView.getMessage("response00", "Response")
+                            + " ====\n")).getBytes());
+                    out.write(conn.outputText.getText().getBytes());
+                    out.write("\n==============\n".getBytes());
+                }
+            }
+            out.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void resend() {
+        try {
+            int rc;
+            Connection conn;
+            rc = tableEnhancer.getMaxSelectionIndex();
+            if (rc == 0) {
+                conn = (Connection) connections.lastElement();
+            } else {
+                conn = (Connection) connections.get(rc - 1);
+            }
+
+            if (rc > 0) {
+                tableEnhancer.clearSelection();
+                tableEnhancer.setSelectionInterval(0, 0);
+            }
+            InputStream in = null;
+            String text = conn.inputText.getText();
+
+            // Fix Content-Length HTTP headers
+            if (text.startsWith("POST ") || text.startsWith("GET ")) {
+
+                int pos1, pos2, pos3;
+                String headers;
+                pos3 = text.indexOf("\n\n");
+                if (pos3 == -1) {
+                    pos3 = text.indexOf("\r\n\r\n");
+                    if (pos3 != -1) {
+                        pos3 = pos3 + 4;
+                    }
+                } else {
+                    pos3 += 2;
+                }
+                headers = text.substring(0, pos3);
+                pos1 = headers.indexOf("Content-Length:");
+
+                if (pos1 != -1) {
+                    int newLen = text.length() - pos3;
+                    pos2 = headers.indexOf("\n", pos1);
+                    System.err.println("CL: " + newLen);
+                    System.err.println("Hdrs: '" + headers + "'");
+                    System.err.println("subTEXT: '"
+                            + text.substring(pos3, pos3 + newLen)
+                            + "'");
+                    text = headers.substring(0, pos1) + "Content-Length: "
+                            + newLen + "\n" + headers.substring(pos2 + 1)
+                            + text.substring(pos3);
+                    System.err.println("\nTEXT: '" + text + "'");
+                }
+            }
+            in = new ByteArrayInputStream(text.getBytes());
+            new Connection(this, in);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
+    public Object setLeft(int type, String text) {
+        Control[] children = leftPanel.getChildren();
+        removeChildren(children);
+        switch (type) {
+            case 0:
+                Label label = new Label(leftPanel, SWT.NONE);
+                GridData gd = new GridData(GridData.FILL_BOTH);
+                gd.grabExcessHorizontalSpace = true;
+                gd.horizontalSpan = 8;
+                gd.exclude = false;
+                label.setLayoutData(gd);
+                label.setText(text);
+                leftPanel.layout();
+                textComposite.layout();
+                return label;
+            case 1:
+                Text leftText = new Text(leftPanel, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+                GridData gd1 = new GridData(GridData.FILL_BOTH);
+                gd1.grabExcessHorizontalSpace = true;
+                gd1.horizontalSpan = 8;
+                gd1.exclude = false;
+                leftText.setLayoutData(gd1);
+                leftText.setText(text);
+                leftPanel.layout();
+                textComposite.layout();
+                return leftText;
+        }
+        return null;
+    }
+
+    public void layout() {
+        leftPanel.layout();
+        rightPanel.layout();
+    }
+
+
+    public Object setRight(int type, String text) {
+        Control[] children = rightPanel.getChildren();
+        removeChildren(children);
+        switch (type) {
+            case 0:
+                Label label = new Label(rightPanel, SWT.NONE);
+                GridData gd = new GridData(GridData.FILL_BOTH);
+                gd.grabExcessHorizontalSpace = true;
+                gd.horizontalSpan = 8;
+                gd.exclude = false;
+                label.setLayoutData(gd);
+                label.setText(text);
+                rightPanel.layout();
+                textComposite.layout();
+                return label;
+            case 1:
+                Text rightText = new Text(rightPanel, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+                GridData gd1 = new GridData(GridData.FILL_BOTH);
+                gd1.grabExcessHorizontalSpace = true;
+                gd1.horizontalSpan = 8;
+                rightText.setLayoutData(gd1);
+                rightText.setText(text);
+                rightPanel.layout();
+                textComposite.layout();
+                return rightText;
+        }
+        return null;
+    }
+
+    private void removeChildren(Control[] children) {
+        for (int i = 0; i < children.length; i++) {
+            ((GridData) children[i].getLayoutData()).exclude = true;
+            children[i].setVisible(false);
+            children[i].getShell().layout(true);
+        }
+    }
+
+}

Added: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java?view=auto&rev=490162
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java (added)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java Mon Dec 25 11:38:14 2006
@@ -0,0 +1,356 @@
+/*
+ * 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.util.ResourceBundle;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.part.ViewPart;
+import org.apache.ws.commons.tcpmon.eclipse.ui.Listener;
+
+/**
+ * 
+ * Main view to be mounted into Eclipse
+ *
+ */
+public class MainView extends ViewPart{
+    public static final int SWT_LABEL = 0;
+    public static final int SWT_TEXT = 1;
+    public static final int STATE_COLUMN = 0;
+    public static final int OUTHOST_COLUMN = 3;
+    public static final int REQ_COLUMN = 4;
+    public static final int ELAPSED_COLUMN = 5;
+
+    public static Display display;
+
+    public Button addButton = null;
+    public Button listenerButton = null;
+    public Button proxyButton = null;
+    public Button hTTPProxyBox = null;
+    public Button delayBox = null;
+    public Text port = null;
+    public Text host = null;
+    public Text tport = null;
+    public Text hTTPProxyHost = null;
+    public Text hTTPProxyPort = null;
+    public Text delayBytes = null;
+    public Text delayTime = null;
+
+    public MainView() {
+    }
+
+    public void createPartControl(Composite parent) {
+        display = parent.getDisplay();
+        TabFolder tabFolder = new TabFolder(parent, SWT.TOP);
+        createConfigurationTab(tabFolder);
+        new Sender(tabFolder).createSenderTab();
+    }
+
+    private void createConfigurationTab(final TabFolder tabFolder) {
+        TabItem configTab = new TabItem(tabFolder, SWT.NONE);
+        configTab.setText("Configuration");
+
+        Composite composite = new Composite(tabFolder, SWT.NONE);
+        composite.setLayout(new GridLayout(3, false));
+
+
+        GridData gd = new GridData();
+        gd.horizontalSpan = 3;
+        gd.verticalIndent = 10;
+        Label label = new Label(composite, SWT.NONE);
+        label.setText(MainView.getMessage("newTCP00", "Create a new TCPMon..."));
+        label.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.horizontalAlignment = SWT.BEGINNING;
+        gd.verticalIndent = 15;
+        label = new Label(composite, SWT.NONE);
+        label.setText(MainView.getMessage("listenPort00", "Listen Port #"));
+        label.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.verticalIndent = 15;
+        gd.widthHint = 30;
+        port = new Text(composite, SWT.BORDER);
+        port.setTextLimit(4);
+        port.setLayoutData(gd);
+
+        addActAsOptions(composite);
+        addOptions(composite);
+
+        gd = new GridData(SWT.FILL, SWT.FILL, false, false);
+        gd.verticalIndent = 10;
+        gd.heightHint = 30;
+        addButton = new Button(composite, SWT.PUSH);
+        final String add = MainView.getMessage("add00", "Add");
+        addButton.setText(add);
+        addButton.setLayoutData(gd);
+        addButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(final SelectionEvent e) {
+                if (add.equals(((Button) e.getSource()).getText())) {
+                    String text;
+                    Listener l = null;
+                    int lPort;
+                    lPort = getValue(0, port.getText());
+                    if (lPort == 0) {
+                        return;
+                    }
+                    String tHost = host.getText();
+                    int tPort;
+                    tPort = getValue(0, tport.getText());
+                    SlowLinkSimulator slowLink = null;
+                    if (delayBox.getSelection()) {
+                        int bytes = getValue(0, delayBytes.getText());
+                        int time = getValue(0, delayTime.getText());
+                        slowLink = new SlowLinkSimulator(bytes, time);
+                    }
+                    try {
+                        l = new Listener(tabFolder, null, lPort, tHost, tPort,
+                                proxyButton.getSelection(),
+                                slowLink);
+                    } catch (Exception exp) {
+                        exp.printStackTrace();
+                    }
+
+                    text = hTTPProxyHost.getText();
+                    if ("".equals(text)) {
+                        text = null;
+                    }
+
+                    l.HTTPProxyHost = text;
+                    text = hTTPProxyPort.getText();
+                    int proxyPort = getValue(-1, hTTPProxyPort.getText());
+                    if (proxyPort != -1) {
+                        l.HTTPProxyPort = Integer.parseInt(text);
+                    }
+                    port.setText("");
+                }
+            }
+        });
+        configTab.setControl(composite);
+    }
+
+
+    private void addActAsOptions(Composite composite) {
+        GridData gd = new GridData();
+        gd.horizontalSpan = 3;
+        gd.verticalIndent = 5;
+        Label label = new Label(composite, SWT.NONE);
+        label.setText(MainView.getMessage("actAs00", "Act as a..."));
+        label.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.horizontalSpan = 3;
+        gd.verticalIndent = 5;
+        listenerButton = new Button(composite, SWT.RADIO);
+        listenerButton.setText(MainView.getMessage("listener00", "Listener"));
+        listenerButton.setSelection(true);
+        listenerButton.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.horizontalSpan = 2;
+        gd.verticalIndent = 5;
+        gd.horizontalIndent = 25;
+        final Label hostLabel = new Label(composite, SWT.NONE);
+        hostLabel.setText(MainView.getMessage("targetHostname00", "Target Hostname"));
+        hostLabel.setLayoutData(gd);
+
+        gd = new GridData(SWT.FILL, SWT.NONE, true, false);
+        gd.verticalIndent = 5;
+        host = new Text(composite, SWT.BORDER);
+        host.setText("127.0.0.1");
+        host.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.horizontalSpan = 2;
+        gd.verticalIndent = 2;
+        gd.horizontalIndent = 25;
+        final Label tportLabel = new Label(composite, SWT.NONE);
+        tportLabel.setText(MainView.getMessage("targetPort00", "Target Port #"));
+        tportLabel.setLayoutData(gd);
+
+        gd = new GridData(SWT.NONE, SWT.NONE, false, false);
+        gd.verticalIndent = 2;
+        gd.widthHint = 30;
+        tport = new Text(composite, SWT.BORDER);
+        tport.setTextLimit(4);
+        tport.setText("8080");
+        tport.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.horizontalSpan = 3;
+        gd.verticalIndent = 5;
+        proxyButton = new Button(composite, SWT.RADIO);
+        proxyButton.setText(MainView.getMessage("proxy00", "Proxy"));
+        proxyButton.setLayoutData(gd);
+
+        listenerButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                boolean state = ((Button) e.getSource()).getSelection();
+                hostLabel.setEnabled(state);
+                host.setEnabled(state);
+                tportLabel.setEnabled(state);
+                tport.setEnabled(state);
+            }
+        });
+    }
+
+    private void addOptions(Composite composite) {
+        GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false);
+        gd.horizontalSpan = 3;
+        gd.verticalIndent = 5;
+        final Group optGroup = new Group(composite, SWT.SHADOW_ETCHED_IN);
+        optGroup.setText(MainView.getMessage("options00", "Options"));
+        optGroup.setLayoutData(gd);
+
+        hTTPProxyBox = new Button(optGroup, SWT.CHECK);
+        hTTPProxyBox.setBounds(10, 20, 200, 20);
+        hTTPProxyBox.setText(MainView.getMessage("proxySupport00", "HTTP Proxy Support"));
+
+        final Label hTTPProxyHostLabel = new Label(optGroup, SWT.NONE);
+        hTTPProxyHostLabel.setEnabled(false);
+        hTTPProxyHostLabel.setText(MainView.getMessage("hostname00", "Hostname"));
+        hTTPProxyHostLabel.setBounds(30, 50, 50, 20);
+
+        hTTPProxyHost = new Text(optGroup, SWT.BORDER);
+        hTTPProxyHost.setEnabled(false);
+        hTTPProxyHost.setBounds(90, 50, 150, 20);
+
+        final Label hTTPProxyPortLabel = new Label(optGroup, SWT.NONE);
+        hTTPProxyPortLabel.setEnabled(false);
+        hTTPProxyPortLabel.setText(MainView.getMessage("port00", "Port #"));
+        hTTPProxyPortLabel.setBounds(30, 75, 50, 20);
+
+        hTTPProxyPort = new Text(optGroup, SWT.BORDER);
+        hTTPProxyPort.setTextLimit(4);
+        hTTPProxyPort.setEnabled(false);
+        hTTPProxyPort.setBounds(90, 75, 40, 20);
+
+        // Set default proxy values...
+        String tmp = System.getProperty("http.proxyHost");
+        if ((tmp != null) && tmp.equals("")) {
+            tmp = null;
+        }
+
+        hTTPProxyBox.setSelection(tmp != null);
+        hTTPProxyHost.setEnabled(tmp != null);
+        hTTPProxyPort.setEnabled(tmp != null);
+        hTTPProxyHostLabel.setEnabled(tmp != null);
+        hTTPProxyPortLabel.setEnabled(tmp != null);
+        if (tmp != null) {
+            hTTPProxyBox.setSelection(true);
+            hTTPProxyHost.setText(tmp);
+            tmp = System.getProperty("http.proxyPort");
+            if ((tmp != null) && tmp.equals("")) {
+                tmp = null;
+            }
+            if (tmp == null) {
+                tmp = "80";
+            }
+            hTTPProxyPort.setText(tmp);
+        }
+
+        delayBox = new Button(optGroup, SWT.CHECK);
+        delayBox.setBounds(10, 110, 200, 20);
+        final String delaySupport = MainView.getMessage("delay00", "Simulate Slow Connection");
+        delayBox.setText(delaySupport);
+
+        final Label delayBytesLabel = new Label(optGroup, SWT.NONE);
+        delayBytesLabel.setEnabled(false);
+        delayBytesLabel.setText(MainView.getMessage("delay01", "Bytes per Pause"));
+        delayBytesLabel.setBounds(30, 140, 100, 20);
+
+        delayBytes = new Text(optGroup, SWT.BORDER);
+        delayBytes.setEnabled(false);
+        delayBytes.setBounds(140, 140, 40, 20);
+
+        final Label delayTimeLabel = new Label(optGroup, SWT.NONE);
+        delayTimeLabel.setEnabled(false);
+        delayTimeLabel.setText(MainView.getMessage("delay02", "Delay in Milliseconds"));
+        delayTimeLabel.setBounds(30, 165, 100, 20);
+
+        delayTime = new Text(optGroup, SWT.BORDER);
+        delayTime.setEnabled(false);
+        delayTime.setBounds(140, 165, 40, 20);
+
+
+        hTTPProxyBox.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                boolean state = ((Button) e.getSource()).getSelection();
+                hTTPProxyHostLabel.setEnabled(state);
+                hTTPProxyPortLabel.setEnabled(state);
+                hTTPProxyHost.setEnabled(state);
+                hTTPProxyPort.setEnabled(state);
+            }
+        });
+
+        delayBox.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                boolean state = ((Button) e.getSource()).getSelection();
+                delayBytesLabel.setEnabled(state);
+                delayTimeLabel.setEnabled(state);
+                delayBytes.setEnabled(state);
+                delayTime.setEnabled(state);
+            }
+        });
+
+    }
+
+    public void setFocus() {
+    }
+
+    private static ResourceBundle messages = null;
+
+    public static String getMessage(String key, String defaultMsg) {
+        try {
+            if (messages == null) {
+                initializeMessages();
+            }
+            return messages.getString(key);
+        } catch (Throwable t) {
+            return defaultMsg;
+        }
+    }
+
+    private static void initializeMessages() {
+        messages = ResourceBundle.getBundle("org.apache.ws.commons.tcpmon.tcpmon");
+    }
+
+    public int getValue(int def, String text) {
+        int result = def;
+        if ((text != null) && (text.length() != 0)) {
+            try {
+                result = Integer.parseInt(text);
+            } catch (NumberFormatException e) {
+                return (result = def);
+            }
+        }
+        return result;
+    }
+}
\ No newline at end of file

Added: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java?view=auto&rev=490162
==============================================================================
--- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java (added)
+++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java Mon Dec 25 11:38:14 2006
@@ -0,0 +1,200 @@
+/*
+ * 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.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+import org.apache.ws.commons.tcpmon.eclipse.ui.MainView;
+
+/**
+ *   This is similar to the main swing sender but includes SWT components instead of Swing ones
+ */
+ class Sender {
+    private TabFolder tabFolder = null;
+
+    public Text endpointField;
+    public Text actionField;
+    public Text inputText;
+    public Text outputText;
+    public Button xmlFormatBox;
+    public Button sendButton;
+    public Button switchButton;
+
+    public Sender(TabFolder tabFolder) {
+        this.tabFolder = tabFolder;
+    }
+
+    public void createSenderTab() {
+        final TabItem senderTabItem = new TabItem(tabFolder, SWT.NONE);
+        senderTabItem.setText("Sender");
+
+        final Composite tabComposite = new Composite(tabFolder, SWT.NONE);
+        final GridLayout gridLayout = new GridLayout();
+        gridLayout.numColumns = 4;
+        tabComposite.setLayout(gridLayout);
+        senderTabItem.setControl(tabComposite);
+
+        (new Label(tabComposite, SWT.NONE)).setText("Connection Endpoint");
+
+        endpointField = new Text(tabComposite, SWT.BORDER);
+        endpointField.setText("http://localhost:8080/axis2/services/XYZ");
+        endpointField.setLayoutData(new GridData(312, SWT.DEFAULT));
+
+        (new Label(tabComposite, SWT.NONE)).setText("SOAP Action");
+        ;
+
+        actionField = new Text(tabComposite, SWT.BORDER);
+
+        final Composite textComposite = new Composite(tabComposite, SWT.NONE);
+        textComposite.setLayout(new FillLayout(SWT.VERTICAL));
+        final GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1);
+        gd.heightHint = 384;
+        gd.widthHint = 611;
+        textComposite.setLayoutData(gd);
+
+        inputText = new Text(textComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
+
+        outputText = new Text(textComposite, SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER);
+
+        xmlFormatBox = new Button(tabComposite, SWT.CHECK);
+        xmlFormatBox.setText(MainView.getMessage("xmlFormat00", "XML Format"));
+
+        final Composite buttonComposite = new Composite(tabComposite, SWT.NONE);
+        buttonComposite.setLayout(new RowLayout());
+        final GridData buttonGd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+        buttonGd.heightHint = 30;
+        buttonGd.widthHint = 166;
+        buttonComposite.setLayoutData(buttonGd);
+
+        sendButton = new Button(buttonComposite, SWT.NONE);
+        final RowData rowData = new RowData();
+        rowData.width = 100;
+        sendButton.setLayoutData(rowData);
+        sendButton.setText("Send");
+        sendButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(final SelectionEvent e) {
+                send();
+            }
+
+        });
+
+        switchButton = new Button(buttonComposite, SWT.NONE);
+        final RowData rd = new RowData();
+        rd.width = 100;
+        switchButton.setLayoutData(rd);
+        switchButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(final SelectionEvent e) {
+                if (((FillLayout) textComposite.getLayout()).type == SWT.HORIZONTAL) {
+                    ((FillLayout) textComposite.getLayout()).type = SWT.VERTICAL;
+                } else {
+                    ((FillLayout) textComposite.getLayout()).type = SWT.HORIZONTAL;
+                }
+                textComposite.layout();
+            }
+        });
+
+        switchButton.setText(MainView.getMessage("switch00", "Switch Layout"));
+    }
+
+    public void send() {
+        try {
+            URL u = new URL(endpointField.getText());
+            URLConnection uc = u.openConnection();
+            HttpURLConnection connection = (HttpURLConnection) uc;
+            connection.setDoOutput(true);
+            connection.setDoInput(true);
+            connection.setRequestMethod("POST");
+            String action = "\"" + (actionField.getText() == null ? "" : actionField.getText()) + "\"";
+            connection.setRequestProperty("SOAPAction", action);
+            connection.setRequestProperty("Content-Type", "text/xml");
+            connection.setRequestProperty("User-Agent", "Axis/2.0");
+            OutputStream out = connection.getOutputStream();
+            Writer writer = new OutputStreamWriter(out);
+            writer.write(inputText.getText());
+            writer.flush();
+            writer.close();
+            String line;
+            InputStream inputStream = null;
+            try {
+                inputStream = connection.getInputStream();
+            } catch (IOException e) {
+                inputStream = connection.getErrorStream();
+            }
+            outputText.setText("");
+            BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream));
+            while ((line = rd.readLine()) != null) {
+                outputText.append(line);
+            }
+            if (xmlFormatBox.getSelection()) {
+                outputText.setText(prettyXML(outputText.getText()));
+            }
+        } catch (Exception e) {
+            StringWriter w = new StringWriter();
+            e.printStackTrace(new PrintWriter(w));
+            outputText.setText(w.toString());
+        }
+    }
+
+    public String prettyXML(String input) throws Exception {
+        TransformerFactory transformerFactory = TransformerFactory.newInstance();
+        try {
+            transformerFactory.setAttribute("indent-number", new Integer(2));
+        } catch (Exception e) {
+        }
+        Transformer transformer = transformerFactory.newTransformer();
+        try {
+            transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", "2");
+        } catch (Exception e) {
+        }
+        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+        StringWriter writer = new StringWriter();
+        transformer.transform(new StreamSource(new StringReader(input)), new StreamResult(writer));
+        return writer.toString();
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org


Re: svn commit: r490162 [1/2] - in /webservices/commons/trunk/modules/tcpmon: resources/eclipse/ resources/idea/ src/org/apache/ws/commons/tcpmon/ src/org/apache/ws/commons/tcpmon/eclipse/ src/org/apache/ws/commons/tcpmon/eclipse/plugin/ src/org/apache/ws/...

Posted by Lawrence Mandel <lm...@ca.ibm.com>.
I'm curious what the value is to reinventing the wheel here seeing as the 
Eclipse Web Tools Platform (WTP) project already includes a TCP/IP monitor 
(as I said in my comment to this Jira). I'd rather see cooperation among 
projects from Apache and Eclipse rather than have both communities spend 
the same amount of energy maintaining very similar code.

Lawrence 




ajith@apache.org 
12/25/2006 02:38 PM
Please respond to
commons-dev@ws.apache.org


To
commons-dev@ws.apache.org
cc

Subject
svn commit: r490162 [1/2] - in /webservices/commons/trunk/modules/tcpmon: 
resources/eclipse/ resources/idea/ src/org/apache/ws/commons/tcpmon/ 
src/org/apache/ws/commons/tcpmon/eclipse/ 
src/org/apache/ws/commons/tcpmon/eclipse/plugin/ src/org/apache/ws/...






Author: ajith
Date: Mon Dec 25 11:38:14 2006
New Revision: 490162

URL: http://svn.apache.org/viewvc?view=rev&rev=490162
Log:
1. Added the code from Saliya for the Eclipse TCPMon port (WS-Commons Jira 
137 [http://issues.apache.org/jira/browse/WSCOMMONS-137]). The classes 
have been refactored to fit the apache packaging and there is still some 
work to do to get it right since there are a number of classes that can be 
reused from the existing ones.
2. Refactored the IDEA components to reflect the same structure as the 
eclipse one.
3. Fixed a very minor issue in the original TCPMon window - the tab that 
should have focus at startup is tab 0 rather than tab 1.

Added:
    webservices/commons/trunk/modules/tcpmon/resources/eclipse/
    webservices/commons/trunk/modules/tcpmon/resources/eclipse/plugin.xml
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/TcpmonitorPlugin.java
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/
 
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
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketWaiter.java
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TableEnhancer.java
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/IdeaPlugin.java
      - copied, changed from r490160, 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaPlugin.java
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/ComponentHandler.java
      - copied, changed from r490160, 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ComponentHandler.java
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/IdeaTCPMonToolWindow.java
      - copied, changed from r490160, 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaTCPMonToolWindow.java
Removed:
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ComponentHandler.java
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaPlugin.java
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaTCPMonToolWindow.java
Modified:
    webservices/commons/trunk/modules/tcpmon/resources/idea/plugin.xml
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/TCPMon.java
 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/tcpmon.properties

Added: 
webservices/commons/trunk/modules/tcpmon/resources/eclipse/plugin.xml
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/resources/eclipse/plugin.xml?view=auto&rev=490162

==============================================================================
--- webservices/commons/trunk/modules/tcpmon/resources/eclipse/plugin.xml 
(added)
+++ webservices/commons/trunk/modules/tcpmon/resources/eclipse/plugin.xml 
Mon Dec 25 11:38:14 2006
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.0"?>
+<plugin>
+
+   <extension
+         point="org.eclipse.ui.views">
+      <category
+            name="TCP Monitor"
+            id="tcpmonitor">
+      </category>
+      <view
+            name="TCP Monitor"
+            icon="icons/monitor.gif"
+            category="tcpmonitor"
+            class="tcpmonitor.views.MainView"
+            id="tcpmonitor.views.MainView">
+      </view>
+   </extension>
+   <extension
+         point="org.eclipse.ui.perspectiveExtensions">
+      <perspectiveExtension
+            targetID="org.eclipse.ui.resourcePerspective">
+         <view
+               ratio="0.5"
+               relative="org.eclipse.ui.views.TaskList"
+               relationship="right"
+               id="tcpmonitor.views.MainView">
+         </view>
+      </perspectiveExtension>
+   </extension>
+
+</plugin>

Modified: 
webservices/commons/trunk/modules/tcpmon/resources/idea/plugin.xml
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/resources/idea/plugin.xml?view=diff&rev=490162&r1=490161&r2=490162

==============================================================================
--- webservices/commons/trunk/modules/tcpmon/resources/idea/plugin.xml 
(original)
+++ webservices/commons/trunk/modules/tcpmon/resources/idea/plugin.xml Mon 
Dec 25 11:38:14 2006
@@ -8,8 +8,8 @@
   <idea-version since-build="3000"/>
    <project-components>
        <component>
- 
<interface-class>org.apache.ws.commons.tcpmon.idea.IdeaPlugin</interface-class>
- 
<implementation-class>org.apache.ws.commons.tcpmon.idea.IdeaPlugin</implementation-class>
+ 
<interface-class>org.apache.ws.commons.tcpmon.idea.plugin.IdeaPlugin</interface-class>
+ 
<implementation-class>org.apache.ws.commons.tcpmon.idea.plugin.IdeaPlugin</implementation-class>
        </component>
    </project-components>
 </idea-plugin>

Modified: 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/TCPMon.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/TCPMon.java?view=diff&rev=490162&r1=490161&r2=490162

==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/TCPMon.java 
(original)
+++ 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/TCPMon.java 
Mon Dec 25 11:38:14 2006
@@ -83,7 +83,7 @@
             } else {
                 l = new Listener(notebook, null, listenPort, targetHost, 
targetPort, false, null);
             }
-            notebook.setSelectedIndex(1);
+            notebook.setSelectedIndex(0);
             l.HTTPProxyHost = System.getProperty("http.proxyHost");
             if ((l.HTTPProxyHost != null) && l.HTTPProxyHost.equals("")) 
{
                 l.HTTPProxyHost = null;

Added: 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/TcpmonitorPlugin.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/TcpmonitorPlugin.java?view=auto&rev=490162

==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/TcpmonitorPlugin.java 
(added)
+++ 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/plugin/TcpmonitorPlugin.java 
Mon Dec 25 11:38:14 2006
@@ -0,0 +1,69 @@
+/*
+ * 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.plugin;
+
+import org.eclipse.ui.plugin.*;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The main plugin class to be used in the desktop.
+ */
+public class TcpmonitorPlugin extends AbstractUIPlugin {
+
+                //The shared instance.
+                private static TcpmonitorPlugin plugin;
+ 
+                /**
+                 * The constructor.
+                 */
+                public TcpmonitorPlugin() {
+                                plugin = this;
+                }
+
+                /**
+                 * This method is called upon plug-in activation
+                 */
+                public void start(BundleContext context) throws Exception 
{
+                                super.start(context);
+                }
+
+                /**
+                 * This method is called when the plug-in is stopped
+                 */
+                public void stop(BundleContext context) throws Exception 
{
+                                super.stop(context);
+                                plugin = null;
+                }
+
+                /**
+                 * Returns the shared instance.
+                 */
+                public static TcpmonitorPlugin getDefault() {
+                                return plugin;
+                }
+
+                /**
+                 * Returns an image descriptor for the image file at the 
given
+                 * plug-in relative path.
+                 *
+                 * @param path the path
+                 * @return the image descriptor
+                 */
+                public static ImageDescriptor getImageDescriptor(String 
path) {
+                                return 
AbstractUIPlugin.imageDescriptorFromPlugin("tcpmonitor", path);
+                }
+}

Added: 
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?view=auto&rev=490162

==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java 
(added)
+++ 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Connection.java 
Mon Dec 25 11:38:14 2006
@@ -0,0 +1,602 @@
+/*
+ * 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.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;
+
+/**
+ * a connection listens to a single current connection
+ */
+class Connection extends Thread {
+    private int inputInt;
+    private String inputString;
+    private ArrayList outValues = new ArrayList();
+    public TableItem item;
+
+
+    /**
+     * Field listener
+     */
+    Listener listener;
+
+    /**
+     * Field active
+     */
+    boolean active;
+
+    /**
+     * Field fromHost
+     */
+    String fromHost;
+
+    /**
+     * Field time
+     */
+    String time;
+
+    /**
+     * Field elapsed time
+     */
+    long elapsedTime;
+
+    /**
+     * Field inputText
+     */
+    Text inputText = null;
+
+    /**
+     * Field outputText
+     */
+    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;
+        start();
+    }
+
+    /**
+     * Constructor Connection
+     *
+     * @param l
+     * @param in
+     */
+    public Connection(Listener l, InputStream in) {
+        this(l);
+        inputStream = in;
+        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 = MainView.getMessage("dateformat00", 
"yyyy-MM-dd HH:mm:ss");
+            DateFormat df = new SimpleDateFormat(dateformat);
+            time = df.format(new Date());
+            int count = listener.connections.size();
+
+            inputInt = count;
+            MainView.display.syncExec(new Runnable() {
+                public void run() {
+                    item = new TableItem(listener.connectionTable, 
SWT.BORDER, inputInt + 1);
+                    item.setText(new 
String[]{MainView.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);
+                    }
+                });
+
+            }
+
+            MainView.display.syncExec(new Runnable() {
+                public void run() {
+                    outValues.clear();
+                    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));
+
+
+            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);
+
+            MainView.display.syncExec(new Runnable() {
+                public void run() {
+                    outValues.clear();
+                    outValues.add(listener.isProxyBox.getSelection() ? 
"true" : "false");
+                    outValues.add((HTTPProxyHost != null) ? "true" : 
"false");
+                }
+            });
+
+            if ("true".equals(outValues.get(0)) || 
"true".equals(outValues.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();
+                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);
+                    }
+
+                    MainView.display.syncExec(new Runnable() {
+                        public void run() {
+                            outValues.clear();
+ outValues.add((listener.isProxyBox.getSelection()) ? "true" : "false");
+                        }
+                    });
+
+                    if ("true".equals(outValues.get(0))) {
+                        url = new URL(urlString);
+                        targetHost = url.getHost();
+                        targetPort = url.getPort();
+                        if (targetPort == -1) {
+                            targetPort = 80;
+                        }
+
+                        inputInt = index;
+                        inputString = targetHost;
+                        MainView.display.syncExec(new Runnable() {
+                            public void run() {
+ listener.tableEnhancer.setValueAt(inputString,
+                                        inputInt + 1,
+                                        MainView.OUTHOST_COLUMN);
+                            }
+                        });
+
+                        bufferedData = bufferedData.substring(0, start)
+                                + url.getFile()
+                                + bufferedData.substring(end);
+                    } else {
+                        url = new URL("http://" + targetHost + ":"
+                                + targetPort + "/" + urlString);
+
+                        inputInt = index;
+                        inputString = targetHost;
+                        MainView.display.syncExec(new Runnable() {
+                            public void run() {
+ listener.tableEnhancer.setValueAt(inputString,
+                                        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) {
+
+                    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);
+
+                    inputInt = index;
+                    inputString = s1;
+                    MainView.display.syncExec(new Runnable() {
+                        public void run() {
+ listener.tableEnhancer.setValueAt(inputString,
+                                    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);
+            }
+
+            MainView.display.syncExec(new Runnable() {
+                public void run() {
+                    outValues.clear();
+                    outValues.add((listener.xmlFormatBox.getSelection()) 
? "true" : "false");
+                }
+            });
+            boolean format = ("true".equals(outValues.get(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) {
+                    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)) {
+                        inputInt = index;
+                        MainView.display.syncExec(new Runnable() {
+                            public void run() {
+                                listener.tableEnhancer.setValueAt(
+                                        MainView.getMessage("resp00", 
"Resp"), 1 + inputInt,
+                                        MainView.STATE_COLUMN);
+                            }
+                        });
+                    }
+                    rr1 = null;
+                }
+
+                if ((null != rr2) && rr2.isDone()) {
+                    if ((index >= 0) && (rr1 != null)) {
+                        inputInt = index;
+                        MainView.display.syncExec(new Runnable() {
+                            public void run() {
+                                listener.tableEnhancer.setValueAt(
+                                        MainView.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.
+                }
+            }
+
+
+            active = false;
+
+            if (index >= 0) {
+                inputInt = index;
+                MainView.display.syncExec(new Runnable() {
+                    public void run() {
+                        listener.tableEnhancer.setValueAt(
+                                MainView.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) {
+                inputInt = index;
+                MainView.display.syncExec(new Runnable() {
+                    public void run() {
+                        listener.tableEnhancer.setValueAt(
+                                MainView.getMessage("error00", "Error"), 
1 + inputInt,
+                                MainView.STATE_COLUMN);
+
+                    }
+                });
+            }
+            e.printStackTrace(wr);
+            wr.close();
+
+            inputString = st.toString();
+            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);
+                    }
+
+                }
+            });
+
+            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();
+        }
+    }
+}

Added: 
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?view=auto&rev=490162

==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java 
(added)
+++ 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Listener.java 
Mon Dec 25 11:38:14 2006
@@ -0,0 +1,664 @@
+/*
+ * 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 org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.*;
+import org.eclipse.swt.widgets.*;
+import org.apache.ws.commons.tcpmon.eclipse.ui.Connection;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.Iterator;
+import java.util.Vector;
+
+/**
+ * This is similar to the main swing listener but includes SWT components 
instead of Swing ones
+ *
+ */
+class Listener {
+    public Socket inputSocket = null;
+    public Socket outputSocket = null;
+    public ServerSocket sSocket = null;
+
+    public Composite leftPanel = null;
+    public Composite rightPanel = null;
+    public Composite textComposite = null;
+    public Text portField = null;
+    public Text hostField = null;
+    public Text tPortField = null;
+    public Button isProxyBox = null;
+    public Button stopButton = null;
+    public Button removeButton = null;
+    public Button removeAllButton = null;
+    public Button xmlFormatBox = null;
+    public Button saveButton = null;
+    public Button resendButton = null;
+    public Button switchButton = null;
+    public Button closeButton = null;
+    public Table connectionTable = null;
+    public TableEnhancer tableEnhancer = null;
+
+    private TabFolder tabFolder;
+    private TabItem portTabItem;
+
+    public SocketWaiter sw = null;
+    public SlowLinkSimulator slowLink;
+
+    public final Vector connections = new Vector();
+
+    public String HTTPProxyHost = null;
+    public int HTTPProxyPort = 80;
+    public int delayBytes = 0;
+    public int delayTime = 0;
+
+    public Listener(TabFolder tabFolder, String name, int listenPort,
+                    String host, int targetPort, boolean isProxy,
+                    SlowLinkSimulator slowLink) {
+        if (name == null) {
+            name = MainView.getMessage("port01", "Port") + " " + 
listenPort;
+        }
+        // set the slow link to the passed down link
+        if (slowLink != null) {
+            this.slowLink = slowLink;
+        } else {
+            // or make up a no-op one.
+            this.slowLink = new SlowLinkSimulator(0, 0);
+        }
+
+        this.tabFolder = tabFolder;
+        createPortTab(isProxy, listenPort, host, targetPort);
+
+    }
+
+    public void createPortTab(boolean isProxy, int listenPort, String 
host, int targetPort) {
+        portTabItem = new TabItem(tabFolder, SWT.NONE);
+
+        final Composite composite = new Composite(tabFolder, SWT.NONE);
+        GridLayout gl = new GridLayout();
+        gl.numColumns = 8;
+        composite.setLayout(gl);
+        portTabItem.setControl(composite);
+
+        stopButton = new Button(composite, SWT.NONE);
+        GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+        gd.widthHint = 71;
+        stopButton.setLayoutData(gd);
+        final String start = MainView.getMessage("start00", "Start");
+        stopButton.setText(start);
+
+        final Label listenPortLabel = new Label(composite, SWT.NONE);
+        gd = new GridData();
+        gd.horizontalIndent = 5;
+        listenPortLabel.setLayoutData(gd);
+        listenPortLabel.setText(MainView.getMessage("listenPort01", 
"Listen Port:"));
+
+        portField = new Text(composite, SWT.BORDER);
+        portField.setText("" + listenPort);
+        portField.setTextLimit(4);
+        gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+        gd.widthHint = 40;
+        portField.setLayoutData(gd);
+
+        (new Label(composite, 
SWT.NONE)).setText(MainView.getMessage("host00", "Host:"));
+
+        hostField = new Text(composite, SWT.BORDER);
+        hostField.setText(host);
+        hostField.setTextLimit(30);
+        gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+        gd.widthHint = 202;
+        hostField.setLayoutData(gd);
+
+        (new Label(composite, 
SWT.NONE)).setText(MainView.getMessage("port02", "Port:"));
+
+        tPortField = new Text(composite, SWT.BORDER);
+        tPortField.setText("" + targetPort);
+        tPortField.setTextLimit(4);
+        gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
+        gd.widthHint = 40;
+        tPortField.setLayoutData(gd);
+
+        isProxyBox = new Button(composite, SWT.LEFT | SWT.CHECK);
+        isProxyBox.setAlignment(SWT.LEFT);
+        gd = new GridData(64, SWT.DEFAULT);
+        gd.verticalIndent = 2;
+        gd.horizontalIndent = 10;
+        isProxyBox.setLayoutData(gd);
+        isProxyBox.setText(MainView.getMessage("proxy00", "Proxy"));
+        isProxyBox.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                boolean state = ((Button) e.getSource()).getSelection();
+                tPortField.setEnabled(!state);
+                hostField.setEnabled(!state);
+            }
+        });
+        isProxyBox.setSelection(isProxy);
+        portField.setEditable(false);
+        hostField.setEditable(false);
+        tPortField.setEditable(false);
+        stopButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if 
(stopButton.getText().equals(MainView.getMessage("stop00", "Stop"))) {
+                    stop();
+                } else {
+                    start();
+                }
+            }
+        });
+
+        connectionTable = new Table(composite, SWT.BORDER | 
SWT.FULL_SELECTION | SWT.MULTI);
+        connectionTable.setHeaderVisible(true);
+        gd = new GridData(SWT.LEFT, SWT.FILL, true, false, 8, 1);
+        gd.heightHint = 102;
+        connectionTable.setLayoutData(gd);
+
+        final TableColumn stateColumn = new TableColumn(connectionTable, 
SWT.CENTER);
+        stateColumn.setWidth(47);
+        stateColumn.setText(MainView.getMessage("state00", "State"));
+
+        final TableColumn timeColumn = new TableColumn(connectionTable, 
SWT.CENTER);
+        timeColumn.setWidth(100);
+        timeColumn.setText(MainView.getMessage("time00", "Time"));
+
+        final TableColumn reqHostColumn = new 
TableColumn(connectionTable, SWT.CENTER);
+        reqHostColumn.setWidth(100);
+        reqHostColumn.setText(MainView.getMessage("requestHost00", 
"Request Host"));
+
+        final TableColumn targetHostColumn = new 
TableColumn(connectionTable, SWT.CENTER);
+        targetHostColumn.setWidth(100);
+        targetHostColumn.setText(MainView.getMessage("targetHost", 
"Target Host"));
+
+        final TableColumn requestColumn = new 
TableColumn(connectionTable, SWT.CENTER);
+        requestColumn.setWidth(100);
+        requestColumn.setText(MainView.getMessage("request00", 
"Request..."));
+
+        final TableColumn elapsedTimeColumn = new 
TableColumn(connectionTable, SWT.CENTER);
+        elapsedTimeColumn.setWidth(140);
+        elapsedTimeColumn.setText(MainView.getMessage("elapsed00", 
"Elapsed Time"));
+
+        final TableItem headerItem = new TableItem(connectionTable, 
SWT.BORDER);
+        headerItem.setText(new String[]{"--", "Most Recent", "--", "--", 
"--", "--"});
+        tableEnhancer = new TableEnhancer(connectionTable);
+
+//                              SelectionListener part goes here - I 
THINK IT'S DONE
+
+        connectionTable.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                handleSelection();
+            }
+        });
+
+
+        final Composite buttonComposite = new Composite(composite, 
SWT.NONE);
+        buttonComposite.setLayout(new RowLayout());
+        gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 4, 1);
+        gd.heightHint = 32;
+        gd.widthHint = 59;
+        buttonComposite.setLayoutData(gd);
+
+        removeButton = new Button(buttonComposite, SWT.NONE);
+        RowData rd = new RowData();
+        rd.width = 100;
+        removeButton.setLayoutData(rd);
+        final String removeSelected = 
MainView.getMessage("removeSelected00", "Remove Selected");
+        removeButton.setText(removeSelected);
+        removeButton.setEnabled(false);
+        removeButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (removeSelected.equals(((Button) 
e.getSource()).getText())) {
+                    remove();
+                }
+            }
+        });
+
+        removeAllButton = new Button(buttonComposite, SWT.NONE);
+        rd = new RowData();
+        rd.width = 100;
+        removeAllButton.setLayoutData(rd);
+        final String removeAll = MainView.getMessage("removeAll00", 
"Remove All");
+        removeAllButton.setText(removeAll);
+        removeAllButton.setEnabled(false);
+        removeAllButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (removeAll.equals(((Button) e.getSource()).getText())) 
{
+                    removeAll();
+                }
+            }
+        });
+
+        textComposite = new Composite(composite, SWT.NONE);
+        textComposite.setLayout(new FillLayout(SWT.VERTICAL));
+        gd = new GridData(SWT.FILL, SWT.CENTER, false, false, 8, 1);
+        gd.widthHint = 589;
+        gd.heightHint = 230;
+        textComposite.setLayoutData(gd);
+
+        leftPanel = new Composite(textComposite, SWT.BORDER);
+        leftPanel.setLayout(new GridLayout(8, true));
+
+        rightPanel = new Composite(textComposite, SWT.BORDER);
+        rightPanel.setLayout(new GridLayout(8, true));
+
+        xmlFormatBox = new Button(composite, SWT.CHECK);
+        xmlFormatBox.setText(MainView.getMessage("xmlFormat00", "XML 
Format"));
+
+        final Composite buttonComposite2 = new Composite(composite, 
SWT.NONE);
+        buttonComposite2.setLayout(new RowLayout());
+        gd = new GridData(SWT.FILL, SWT.FILL, false, false, 4, 1);
+        gd.heightHint = 27;
+        gd.widthHint = 27;
+        buttonComposite2.setLayoutData(gd);
+
+        saveButton = new Button(buttonComposite2, SWT.NONE);
+        rd = new RowData();
+        rd.width = 100;
+        saveButton.setLayoutData(rd);
+        final String save = MainView.getMessage("save00", "Save");
+        saveButton.setText(save);
+        saveButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (save.equals(((Button) e.getSource()).getText())) {
+                    save();
+                }
+            }
+        });
+
+        resendButton = new Button(buttonComposite2, SWT.NONE);
+        rd = new RowData();
+        rd.width = 100;
+        resendButton.setLayoutData(rd);
+        final String resend = MainView.getMessage("resend00", "Resend");
+        resendButton.setText(resend);
+        resendButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (resend.equals(((Button) e.getSource()).getText())) {
+                    resend();
+                }
+            }
+        });
+
+        switchButton = new Button(buttonComposite2, SWT.NONE);
+        rd = new RowData();
+        rd.width = 100;
+        switchButton.setLayoutData(rd);
+        final String switchStr = MainView.getMessage("switch00", "Switch 
Layout");
+        switchButton.setText(switchStr);
+        switchButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (switchStr.equals(((Button) e.getSource()).getText())) 
{
+                    if (((FillLayout) textComposite.getLayout()).type == 
SWT.HORIZONTAL) {
+                        ((FillLayout) textComposite.getLayout()).type = 
SWT.VERTICAL;
+                    } else {
+                        ((FillLayout) textComposite.getLayout()).type = 
SWT.HORIZONTAL;
+                    }
+                    leftPanel.layout();
+                    rightPanel.layout();
+                    textComposite.layout();
+                }
+            }
+        });
+
+        final Composite buttonComposite3 = new Composite(composite, 
SWT.NONE);
+        buttonComposite3.setLayout(new RowLayout());
+        gd = new GridData(SWT.FILL, SWT.FILL, false, false, 3, 1);
+        gd.horizontalIndent = 95;
+        gd.heightHint = 27;
+        gd.widthHint = 27;
+        buttonComposite3.setLayoutData(gd);
+
+        closeButton = new Button(buttonComposite3, SWT.None);
+        rd = new RowData();
+        rd.width = 60;
+        closeButton.setLayoutData(rd);
+        final String close = MainView.getMessage("close00", "Close");
+        closeButton.setText(close);
+        closeButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                if (close.equals(((Button) e.getSource()).getText())) {
+                    close();
+                }
+            }
+        });
+        tableEnhancer.setSelectionInterval(0, 0);
+        start();
+    }
+
+    public void handleSelection() {
+        if (tableEnhancer.isSelectionEmpty()) {
+            setLeft(MainView.SWT_LABEL, " " + 
MainView.getMessage("wait00",
+                    "Waiting for Connection..."));
+            setRight(MainView.SWT_LABEL, "");
+            removeButton.setEnabled(false);
+            removeAllButton.setEnabled(false);
+            saveButton.setEnabled(false);
+            resendButton.setEnabled(false);
+            leftPanel.layout();
+            rightPanel.layout();
+            textComposite.layout();
+        } else {
+            int row = tableEnhancer.getLeadSelectionIndex();
+            if (row != tableEnhancer.getMaxSelectionIndex()) {
+                row = tableEnhancer.getMaxSelectionIndex();
+            }
+            if (row == 0) {
+                if (connections.size() == 0) {
+                    setLeft(MainView.SWT_LABEL, " " + 
MainView.getMessage("wait00",
+                            "Waiting for connection..."));
+                    setRight(MainView.SWT_LABEL, "");
+                    removeButton.setEnabled(false);
+                    removeAllButton.setEnabled(false);
+                    saveButton.setEnabled(false);
+                    resendButton.setEnabled(false);
+                    leftPanel.layout();
+                    rightPanel.layout();
+                    textComposite.layout();
+                } else {
+                    Connection conn = (Connection) 
connections.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);
+                    removeButton.setEnabled(false);
+                    removeAllButton.setEnabled(true);
+                    saveButton.setEnabled(true);
+                    resendButton.setEnabled(true);
+                    leftPanel.layout();
+                    rightPanel.layout();
+                    textComposite.layout();
+                }
+            } else {
+                Connection conn = (Connection) connections.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);
+                removeButton.setEnabled(true);
+                removeAllButton.setEnabled(true);
+                saveButton.setEnabled(true);
+                resendButton.setEnabled(true);
+                leftPanel.layout();
+                rightPanel.layout();
+                textComposite.layout();
+            }
+        }
+    }
+
+    public void stop() {
+        try {
+            for (int i = 0; i < connections.size(); i++) {
+                Connection conn = (Connection) connections.get(i);
+                conn.halt();
+            }
+            sw.halt();
+            stopButton.setText(MainView.getMessage("start00", "Start"));
+            portField.setEditable(true);
+            hostField.setEditable(true);
+            tPortField.setEditable(true);
+            isProxyBox.setEnabled(true);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void start() {
+        int port = Integer.parseInt(portField.getText());
+        portField.setText("" + port);
+        portTabItem.setText(MainView.getMessage("port01", "Port") + " " + 
port);
+        int tmp = Integer.parseInt(tPortField.getText());
+        tPortField.setText("" + tmp);
+        sw = new SocketWaiter(this, port);
+        stopButton.setText(MainView.getMessage("stop00", "Stop"));
+        portField.setEditable(false);
+        hostField.setEditable(false);
+        tPortField.setEditable(false);
+        isProxyBox.setEnabled(false);
+    }
+
+
+    public void remove() {
+        int index;
+        Connection con;
+        int[] selectionIndices = 
tableEnhancer.getSelectionIndicesWithoutZero();
+        for (int i = 0; i < selectionIndices.length; i++) {
+            index = selectionIndices[i];
+            con = (Connection) connections.get(index - 1 - i);
+            if (con.active) {
+                MessageBox mb = new 
MessageBox(MainView.display.getActiveShell(), SWT.ICON_INFORMATION | 
SWT.OK);
+                mb.setMessage(MainView.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);
+            tableEnhancer.remove(index - i);
+            tableEnhancer.setSelectionInterval(0, 0);
+        }
+    }
+
+
+    public void removeAll() {
+        tableEnhancer.selectAll();
+        remove();
+    }
+
+
+    public void close() {
+        MessageBox mb = new MessageBox(MainView.display.getActiveShell(), 
SWT.ICON_QUESTION | SWT.YES | SWT.NO);
+        mb.setMessage(MainView.getMessage("quit00", "Do you want to 
remove monitoring") + " " + portTabItem.getText());
+        mb.setText("Remove Monitor");
+        int response = mb.open();
+        if (response == SWT.YES) {
+            if (stopButton.getText().equals(MainView.getMessage("stop00", 
"Stop"))) {
+                stop();
+            }
+            portTabItem.dispose();
+        }
+    }
+
+
+    public void save() {
+        FileDialog fd = new FileDialog(MainView.display.getActiveShell(), 
SWT.SAVE);
+        fd.setText("Save");
+        fd.setFilterPath(".");
+        String path = fd.open();
+        if (path == null) {
+            return;
+        }
+        try {
+            File file = new File(path);
+            FileOutputStream out = new FileOutputStream(file);
+            int rc = tableEnhancer.getLeadSelectionIndex();
+            int n = 0;
+            for (Iterator i = connections.iterator(); i.hasNext();
+                 n++) {
+                Connection conn = (Connection) i.next();
+                if (tableEnhancer.isSelectedIndex(n + 1)
+                        || (!(i.hasNext())
+                        && (tableEnhancer.getLeadSelectionIndex() == 0))) 
{
+                    rc = Integer.parseInt(portField.getText());
+                    out.write("\n==============\n".getBytes());
+                    out.write(((MainView.getMessage("listenPort01",
+                            "Listen Port:")
+                            + " " + rc + "\n")).getBytes());
+                    out.write((MainView.getMessage("targetHost01",
+                            "Target Host:")
+                            + " " + hostField.getText()
+                            + "\n").getBytes());
+                    rc = Integer.parseInt(tPortField.getText());
+                    out.write(((MainView.getMessage("targetPort01",
+                            "Target Port:")
+                            + " " + rc + "\n")).getBytes());
+                    out.write((("==== "
+                            + MainView.getMessage("request01", "Request")
+                            + " ====\n")).getBytes());
+                    out.write(conn.inputText.getText().getBytes());
+                    out.write((("==== "
+                            + MainView.getMessage("response00", 
"Response")
+                            + " ====\n")).getBytes());
+                    out.write(conn.outputText.getText().getBytes());
+                    out.write("\n==============\n".getBytes());
+                }
+            }
+            out.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    public void resend() {
+        try {
+            int rc;
+            Connection conn;
+            rc = tableEnhancer.getMaxSelectionIndex();
+            if (rc == 0) {
+                conn = (Connection) connections.lastElement();
+            } else {
+                conn = (Connection) connections.get(rc - 1);
+            }
+
+            if (rc > 0) {
+                tableEnhancer.clearSelection();
+                tableEnhancer.setSelectionInterval(0, 0);
+            }
+            InputStream in = null;
+            String text = conn.inputText.getText();
+
+            // Fix Content-Length HTTP headers
+            if (text.startsWith("POST ") || text.startsWith("GET ")) {
+
+                int pos1, pos2, pos3;
+                String headers;
+                pos3 = text.indexOf("\n\n");
+                if (pos3 == -1) {
+                    pos3 = text.indexOf("\r\n\r\n");
+                    if (pos3 != -1) {
+                        pos3 = pos3 + 4;
+                    }
+                } else {
+                    pos3 += 2;
+                }
+                headers = text.substring(0, pos3);
+                pos1 = headers.indexOf("Content-Length:");
+
+                if (pos1 != -1) {
+                    int newLen = text.length() - pos3;
+                    pos2 = headers.indexOf("\n", pos1);
+                    System.err.println("CL: " + newLen);
+                    System.err.println("Hdrs: '" + headers + "'");
+                    System.err.println("subTEXT: '"
+                            + text.substring(pos3, pos3 + newLen)
+                            + "'");
+                    text = headers.substring(0, pos1) + "Content-Length: 
"
+                            + newLen + "\n" + headers.substring(pos2 + 1)
+                            + text.substring(pos3);
+                    System.err.println("\nTEXT: '" + text + "'");
+                }
+            }
+            in = new ByteArrayInputStream(text.getBytes());
+            new Connection(this, in);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+
+    public Object setLeft(int type, String text) {
+        Control[] children = leftPanel.getChildren();
+        removeChildren(children);
+        switch (type) {
+            case 0:
+                Label label = new Label(leftPanel, SWT.NONE);
+                GridData gd = new GridData(GridData.FILL_BOTH);
+                gd.grabExcessHorizontalSpace = true;
+                gd.horizontalSpan = 8;
+                gd.exclude = false;
+                label.setLayoutData(gd);
+                label.setText(text);
+                leftPanel.layout();
+                textComposite.layout();
+                return label;
+            case 1:
+                Text leftText = new Text(leftPanel, SWT.MULTI | 
SWT.H_SCROLL | SWT.V_SCROLL);
+                GridData gd1 = new GridData(GridData.FILL_BOTH);
+                gd1.grabExcessHorizontalSpace = true;
+                gd1.horizontalSpan = 8;
+                gd1.exclude = false;
+                leftText.setLayoutData(gd1);
+                leftText.setText(text);
+                leftPanel.layout();
+                textComposite.layout();
+                return leftText;
+        }
+        return null;
+    }
+
+    public void layout() {
+        leftPanel.layout();
+        rightPanel.layout();
+    }
+
+
+    public Object setRight(int type, String text) {
+        Control[] children = rightPanel.getChildren();
+        removeChildren(children);
+        switch (type) {
+            case 0:
+                Label label = new Label(rightPanel, SWT.NONE);
+                GridData gd = new GridData(GridData.FILL_BOTH);
+                gd.grabExcessHorizontalSpace = true;
+                gd.horizontalSpan = 8;
+                gd.exclude = false;
+                label.setLayoutData(gd);
+                label.setText(text);
+                rightPanel.layout();
+                textComposite.layout();
+                return label;
+            case 1:
+                Text rightText = new Text(rightPanel, SWT.MULTI | 
SWT.H_SCROLL | SWT.V_SCROLL);
+                GridData gd1 = new GridData(GridData.FILL_BOTH);
+                gd1.grabExcessHorizontalSpace = true;
+                gd1.horizontalSpan = 8;
+                rightText.setLayoutData(gd1);
+                rightText.setText(text);
+                rightPanel.layout();
+                textComposite.layout();
+                return rightText;
+        }
+        return null;
+    }
+
+    private void removeChildren(Control[] children) {
+        for (int i = 0; i < children.length; i++) {
+            ((GridData) children[i].getLayoutData()).exclude = true;
+            children[i].setVisible(false);
+            children[i].getShell().layout(true);
+        }
+    }
+
+}

Added: 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java?view=auto&rev=490162

==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java 
(added)
+++ 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/MainView.java 
Mon Dec 25 11:38:14 2006
@@ -0,0 +1,356 @@
+/*
+ * 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.util.ResourceBundle;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.part.ViewPart;
+import org.apache.ws.commons.tcpmon.eclipse.ui.Listener;
+
+/**
+ * 
+ * Main view to be mounted into Eclipse
+ *
+ */
+public class MainView extends ViewPart{
+    public static final int SWT_LABEL = 0;
+    public static final int SWT_TEXT = 1;
+    public static final int STATE_COLUMN = 0;
+    public static final int OUTHOST_COLUMN = 3;
+    public static final int REQ_COLUMN = 4;
+    public static final int ELAPSED_COLUMN = 5;
+
+    public static Display display;
+
+    public Button addButton = null;
+    public Button listenerButton = null;
+    public Button proxyButton = null;
+    public Button hTTPProxyBox = null;
+    public Button delayBox = null;
+    public Text port = null;
+    public Text host = null;
+    public Text tport = null;
+    public Text hTTPProxyHost = null;
+    public Text hTTPProxyPort = null;
+    public Text delayBytes = null;
+    public Text delayTime = null;
+
+    public MainView() {
+    }
+
+    public void createPartControl(Composite parent) {
+        display = parent.getDisplay();
+        TabFolder tabFolder = new TabFolder(parent, SWT.TOP);
+        createConfigurationTab(tabFolder);
+        new Sender(tabFolder).createSenderTab();
+    }
+
+    private void createConfigurationTab(final TabFolder tabFolder) {
+        TabItem configTab = new TabItem(tabFolder, SWT.NONE);
+        configTab.setText("Configuration");
+
+        Composite composite = new Composite(tabFolder, SWT.NONE);
+        composite.setLayout(new GridLayout(3, false));
+
+
+        GridData gd = new GridData();
+        gd.horizontalSpan = 3;
+        gd.verticalIndent = 10;
+        Label label = new Label(composite, SWT.NONE);
+        label.setText(MainView.getMessage("newTCP00", "Create a new 
TCPMon..."));
+        label.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.horizontalAlignment = SWT.BEGINNING;
+        gd.verticalIndent = 15;
+        label = new Label(composite, SWT.NONE);
+        label.setText(MainView.getMessage("listenPort00", "Listen Port 
#"));
+        label.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.verticalIndent = 15;
+        gd.widthHint = 30;
+        port = new Text(composite, SWT.BORDER);
+        port.setTextLimit(4);
+        port.setLayoutData(gd);
+
+        addActAsOptions(composite);
+        addOptions(composite);
+
+        gd = new GridData(SWT.FILL, SWT.FILL, false, false);
+        gd.verticalIndent = 10;
+        gd.heightHint = 30;
+        addButton = new Button(composite, SWT.PUSH);
+        final String add = MainView.getMessage("add00", "Add");
+        addButton.setText(add);
+        addButton.setLayoutData(gd);
+        addButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(final SelectionEvent e) {
+                if (add.equals(((Button) e.getSource()).getText())) {
+                    String text;
+                    Listener l = null;
+                    int lPort;
+                    lPort = getValue(0, port.getText());
+                    if (lPort == 0) {
+                        return;
+                    }
+                    String tHost = host.getText();
+                    int tPort;
+                    tPort = getValue(0, tport.getText());
+                    SlowLinkSimulator slowLink = null;
+                    if (delayBox.getSelection()) {
+                        int bytes = getValue(0, delayBytes.getText());
+                        int time = getValue(0, delayTime.getText());
+                        slowLink = new SlowLinkSimulator(bytes, time);
+                    }
+                    try {
+                        l = new Listener(tabFolder, null, lPort, tHost, 
tPort,
+                                proxyButton.getSelection(),
+                                slowLink);
+                    } catch (Exception exp) {
+                        exp.printStackTrace();
+                    }
+
+                    text = hTTPProxyHost.getText();
+                    if ("".equals(text)) {
+                        text = null;
+                    }
+
+                    l.HTTPProxyHost = text;
+                    text = hTTPProxyPort.getText();
+                    int proxyPort = getValue(-1, 
hTTPProxyPort.getText());
+                    if (proxyPort != -1) {
+                        l.HTTPProxyPort = Integer.parseInt(text);
+                    }
+                    port.setText("");
+                }
+            }
+        });
+        configTab.setControl(composite);
+    }
+
+
+    private void addActAsOptions(Composite composite) {
+        GridData gd = new GridData();
+        gd.horizontalSpan = 3;
+        gd.verticalIndent = 5;
+        Label label = new Label(composite, SWT.NONE);
+        label.setText(MainView.getMessage("actAs00", "Act as a..."));
+        label.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.horizontalSpan = 3;
+        gd.verticalIndent = 5;
+        listenerButton = new Button(composite, SWT.RADIO);
+        listenerButton.setText(MainView.getMessage("listener00", 
"Listener"));
+        listenerButton.setSelection(true);
+        listenerButton.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.horizontalSpan = 2;
+        gd.verticalIndent = 5;
+        gd.horizontalIndent = 25;
+        final Label hostLabel = new Label(composite, SWT.NONE);
+        hostLabel.setText(MainView.getMessage("targetHostname00", "Target 
Hostname"));
+        hostLabel.setLayoutData(gd);
+
+        gd = new GridData(SWT.FILL, SWT.NONE, true, false);
+        gd.verticalIndent = 5;
+        host = new Text(composite, SWT.BORDER);
+        host.setText("127.0.0.1");
+        host.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.horizontalSpan = 2;
+        gd.verticalIndent = 2;
+        gd.horizontalIndent = 25;
+        final Label tportLabel = new Label(composite, SWT.NONE);
+        tportLabel.setText(MainView.getMessage("targetPort00", "Target 
Port #"));
+        tportLabel.setLayoutData(gd);
+
+        gd = new GridData(SWT.NONE, SWT.NONE, false, false);
+        gd.verticalIndent = 2;
+        gd.widthHint = 30;
+        tport = new Text(composite, SWT.BORDER);
+        tport.setTextLimit(4);
+        tport.setText("8080");
+        tport.setLayoutData(gd);
+
+        gd = new GridData();
+        gd.horizontalSpan = 3;
+        gd.verticalIndent = 5;
+        proxyButton = new Button(composite, SWT.RADIO);
+        proxyButton.setText(MainView.getMessage("proxy00", "Proxy"));
+        proxyButton.setLayoutData(gd);
+
+        listenerButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                boolean state = ((Button) e.getSource()).getSelection();
+                hostLabel.setEnabled(state);
+                host.setEnabled(state);
+                tportLabel.setEnabled(state);
+                tport.setEnabled(state);
+            }
+        });
+    }
+
+    private void addOptions(Composite composite) {
+        GridData gd = new GridData(SWT.FILL, SWT.NONE, true, false);
+        gd.horizontalSpan = 3;
+        gd.verticalIndent = 5;
+        final Group optGroup = new Group(composite, 
SWT.SHADOW_ETCHED_IN);
+        optGroup.setText(MainView.getMessage("options00", "Options"));
+        optGroup.setLayoutData(gd);
+
+        hTTPProxyBox = new Button(optGroup, SWT.CHECK);
+        hTTPProxyBox.setBounds(10, 20, 200, 20);
+        hTTPProxyBox.setText(MainView.getMessage("proxySupport00", "HTTP 
Proxy Support"));
+
+        final Label hTTPProxyHostLabel = new Label(optGroup, SWT.NONE);
+        hTTPProxyHostLabel.setEnabled(false);
+        hTTPProxyHostLabel.setText(MainView.getMessage("hostname00", 
"Hostname"));
+        hTTPProxyHostLabel.setBounds(30, 50, 50, 20);
+
+        hTTPProxyHost = new Text(optGroup, SWT.BORDER);
+        hTTPProxyHost.setEnabled(false);
+        hTTPProxyHost.setBounds(90, 50, 150, 20);
+
+        final Label hTTPProxyPortLabel = new Label(optGroup, SWT.NONE);
+        hTTPProxyPortLabel.setEnabled(false);
+        hTTPProxyPortLabel.setText(MainView.getMessage("port00", "Port 
#"));
+        hTTPProxyPortLabel.setBounds(30, 75, 50, 20);
+
+        hTTPProxyPort = new Text(optGroup, SWT.BORDER);
+        hTTPProxyPort.setTextLimit(4);
+        hTTPProxyPort.setEnabled(false);
+        hTTPProxyPort.setBounds(90, 75, 40, 20);
+
+        // Set default proxy values...
+        String tmp = System.getProperty("http.proxyHost");
+        if ((tmp != null) && tmp.equals("")) {
+            tmp = null;
+        }
+
+        hTTPProxyBox.setSelection(tmp != null);
+        hTTPProxyHost.setEnabled(tmp != null);
+        hTTPProxyPort.setEnabled(tmp != null);
+        hTTPProxyHostLabel.setEnabled(tmp != null);
+        hTTPProxyPortLabel.setEnabled(tmp != null);
+        if (tmp != null) {
+            hTTPProxyBox.setSelection(true);
+            hTTPProxyHost.setText(tmp);
+            tmp = System.getProperty("http.proxyPort");
+            if ((tmp != null) && tmp.equals("")) {
+                tmp = null;
+            }
+            if (tmp == null) {
+                tmp = "80";
+            }
+            hTTPProxyPort.setText(tmp);
+        }
+
+        delayBox = new Button(optGroup, SWT.CHECK);
+        delayBox.setBounds(10, 110, 200, 20);
+        final String delaySupport = MainView.getMessage("delay00", 
"Simulate Slow Connection");
+        delayBox.setText(delaySupport);
+
+        final Label delayBytesLabel = new Label(optGroup, SWT.NONE);
+        delayBytesLabel.setEnabled(false);
+        delayBytesLabel.setText(MainView.getMessage("delay01", "Bytes per 
Pause"));
+        delayBytesLabel.setBounds(30, 140, 100, 20);
+
+        delayBytes = new Text(optGroup, SWT.BORDER);
+        delayBytes.setEnabled(false);
+        delayBytes.setBounds(140, 140, 40, 20);
+
+        final Label delayTimeLabel = new Label(optGroup, SWT.NONE);
+        delayTimeLabel.setEnabled(false);
+        delayTimeLabel.setText(MainView.getMessage("delay02", "Delay in 
Milliseconds"));
+        delayTimeLabel.setBounds(30, 165, 100, 20);
+
+        delayTime = new Text(optGroup, SWT.BORDER);
+        delayTime.setEnabled(false);
+        delayTime.setBounds(140, 165, 40, 20);
+
+
+        hTTPProxyBox.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                boolean state = ((Button) e.getSource()).getSelection();
+                hTTPProxyHostLabel.setEnabled(state);
+                hTTPProxyPortLabel.setEnabled(state);
+                hTTPProxyHost.setEnabled(state);
+                hTTPProxyPort.setEnabled(state);
+            }
+        });
+
+        delayBox.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(SelectionEvent e) {
+                boolean state = ((Button) e.getSource()).getSelection();
+                delayBytesLabel.setEnabled(state);
+                delayTimeLabel.setEnabled(state);
+                delayBytes.setEnabled(state);
+                delayTime.setEnabled(state);
+            }
+        });
+
+    }
+
+    public void setFocus() {
+    }
+
+    private static ResourceBundle messages = null;
+
+    public static String getMessage(String key, String defaultMsg) {
+        try {
+            if (messages == null) {
+                initializeMessages();
+            }
+            return messages.getString(key);
+        } catch (Throwable t) {
+            return defaultMsg;
+        }
+    }
+
+    private static void initializeMessages() {
+        messages = 
ResourceBundle.getBundle("org.apache.ws.commons.tcpmon.tcpmon");
+    }
+
+    public int getValue(int def, String text) {
+        int result = def;
+        if ((text != null) && (text.length() != 0)) {
+            try {
+                result = Integer.parseInt(text);
+            } catch (NumberFormatException e) {
+                return (result = def);
+            }
+        }
+        return result;
+    }
+}
\ No newline at end of file

Added: 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java
URL: 
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java?view=auto&rev=490162

==============================================================================
--- 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java 
(added)
+++ 
webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/Sender.java 
Mon Dec 25 11:38:14 2006
@@ -0,0 +1,200 @@
+/*
+ * 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.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.layout.RowData;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.TabFolder;
+import org.eclipse.swt.widgets.TabItem;
+import org.eclipse.swt.widgets.Text;
+import org.apache.ws.commons.tcpmon.eclipse.ui.MainView;
+
+/**
+ *   This is similar to the main swing sender but includes SWT components 
instead of Swing ones
+ */
+ class Sender {
+    private TabFolder tabFolder = null;
+
+    public Text endpointField;
+    public Text actionField;
+    public Text inputText;
+    public Text outputText;
+    public Button xmlFormatBox;
+    public Button sendButton;
+    public Button switchButton;
+
+    public Sender(TabFolder tabFolder) {
+        this.tabFolder = tabFolder;
+    }
+
+    public void createSenderTab() {
+        final TabItem senderTabItem = new TabItem(tabFolder, SWT.NONE);
+        senderTabItem.setText("Sender");
+
+        final Composite tabComposite = new Composite(tabFolder, 
SWT.NONE);
+        final GridLayout gridLayout = new GridLayout();
+        gridLayout.numColumns = 4;
+        tabComposite.setLayout(gridLayout);
+        senderTabItem.setControl(tabComposite);
+
+        (new Label(tabComposite, SWT.NONE)).setText("Connection 
Endpoint");
+
+        endpointField = new Text(tabComposite, SWT.BORDER);
+        endpointField.setText("http://localhost:8080/axis2/services/XYZ
");
+        endpointField.setLayoutData(new GridData(312, SWT.DEFAULT));
+
+        (new Label(tabComposite, SWT.NONE)).setText("SOAP Action");
+        ;
+
+        actionField = new Text(tabComposite, SWT.BORDER);
+
+        final Composite textComposite = new Composite(tabComposite, 
SWT.NONE);
+        textComposite.setLayout(new FillLayout(SWT.VERTICAL));
+        final GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, 
false, 4, 1);
+        gd.heightHint = 384;
+        gd.widthHint = 611;
+        textComposite.setLayoutData(gd);
+
+        inputText = new Text(textComposite, SWT.V_SCROLL | SWT.H_SCROLL | 
SWT.BORDER);
+
+        outputText = new Text(textComposite, SWT.V_SCROLL | SWT.H_SCROLL 
| SWT.BORDER);
+
+        xmlFormatBox = new Button(tabComposite, SWT.CHECK);
+        xmlFormatBox.setText(MainView.getMessage("xmlFormat00", "XML 
Format"));
+
+        final Composite buttonComposite = new Composite(tabComposite, 
SWT.NONE);
+        buttonComposite.setLayout(new RowLayout());
+        final GridData buttonGd = new GridData(SWT.FILL, SWT.CENTER, 
false, false);
+        buttonGd.heightHint = 30;
+        buttonGd.widthHint = 166;
+        buttonComposite.setLayoutData(buttonGd);
+
+        sendButton = new Button(buttonComposite, SWT.NONE);
+        final RowData rowData = new RowData();
+        rowData.width = 100;
+        sendButton.setLayoutData(rowData);
+        sendButton.setText("Send");
+        sendButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(final SelectionEvent e) {
+                send();
+            }
+
+        });
+
+        switchButton = new Button(buttonComposite, SWT.NONE);
+        final RowData rd = new RowData();
+        rd.width = 100;
+        switchButton.setLayoutData(rd);
+        switchButton.addSelectionListener(new SelectionAdapter() {
+            public void widgetSelected(final SelectionEvent e) {
+                if (((FillLayout) textComposite.getLayout()).type == 
SWT.HORIZONTAL) {
+                    ((FillLayout) textComposite.getLayout()).type = 
SWT.VERTICAL;
+                } else {
+                    ((FillLayout) textComposite.getLayout()).type = 
SWT.HORIZONTAL;
+                }
+                textComposite.layout();
+            }
+        });
+
+        switchButton.setText(MainView.getMessage("switch00", "Switch 
Layout"));
+    }
+
+    public void send() {
+        try {
+            URL u = new URL(endpointField.getText());
+            URLConnection uc = u.openConnection();
+            HttpURLConnection connection = (HttpURLConnection) uc;
+            connection.setDoOutput(true);
+            connection.setDoInput(true);
+            connection.setRequestMethod("POST");
+            String action = "\"" + (actionField.getText() == null ? "" : 
actionField.getText()) + "\"";
+            connection.setRequestProperty("SOAPAction", action);
+            connection.setRequestProperty("Content-Type", "text/xml");
+            connection.setRequestProperty("User-Agent", "Axis/2.0");
+            OutputStream out = connection.getOutputStream();
+            Writer writer = new OutputStreamWriter(out);
+            writer.write(inputText.getText());
+            writer.flush();
+            writer.close();
+            String line;
+            InputStream inputStream = null;
+            try {
+                inputStream = connection.getInputStream();
+            } catch (IOException e) {
+                inputStream = connection.getErrorStream();
+            }
+            outputText.setText("");
+            BufferedReader rd = new BufferedReader(new 
InputStreamReader(inputStream));
+            while ((line = rd.readLine()) != null) {
+                outputText.append(line);
+            }
+            if (xmlFormatBox.getSelection()) {
+                outputText.setText(prettyXML(outputText.getText()));
+            }
+        } catch (Exception e) {
+            StringWriter w = new StringWriter();
+            e.printStackTrace(new PrintWriter(w));
+            outputText.setText(w.toString());
+        }
+    }
+
+    public String prettyXML(String input) throws Exception {
+        TransformerFactory transformerFactory = 
TransformerFactory.newInstance();
+        try {
+            transformerFactory.setAttribute("indent-number", new 
Integer(2));
+        } catch (Exception e) {
+        }
+        Transformer transformer = transformerFactory.newTransformer();
+        try {
+ 
transformer.setOutputProperty("{http://xml.apache.org/xalan}indent-amount", 
"2");
+        } catch (Exception e) {
+        }
+        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+        StringWriter writer = new StringWriter();
+        transformer.transform(new StreamSource(new StringReader(input)), 
new StreamResult(writer));
+        return writer.toString();
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org