Added: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java?view=auto&rev=490162 ============================================================================== --- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java (added) +++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketRR.java Mon Dec 25 11:38:14 2006 @@ -0,0 +1,398 @@ +/* + * 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.net.Socket; + +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Text; +import org.apache.ws.commons.tcpmon.eclipse.ui.Connection; +import org.apache.ws.commons.tcpmon.eclipse.ui.MainView; +import org.apache.ws.commons.tcpmon.eclipse.ui.SlowLinkSimulator; + +/** + * this class handles the pumping of data from the incoming socket to the + * outgoing socket Same as the swing one except for the use of SWT components + */ +class SocketRR extends Thread { + + private int inputInt; + private String inputString; + private boolean outBool; + private String outString; + + /** + * Field inSocket + */ + Socket inSocket = null; + + /** + * Field outSocket + */ + Socket outSocket = null; + + /** + * Field textArea + */ + Text textArea; + + /** + * Field in + */ + InputStream in = null; + + /** + * Field out + */ + OutputStream out = null; + + /** + * Field xmlFormat + */ + boolean xmlFormat; + + /** + * Field done + */ + volatile boolean done = false; + + /** + * Field tmodel + */ + volatile long elapsed = 0; + + /** + * Field tmodel + */ + Table tmodel = null; + + /** + * Field tableIndex + */ + int tableIndex = 0; + + /** + * Field type + */ + String type = null; + + /** + * Field myConnection + */ + Connection myConnection = null; + + /** + * Field slowLink + */ + SlowLinkSimulator slowLink; + + /** + * Constructor SocketRR + * + * @param c + * @param inputSocket + * @param inputStream + * @param outputSocket + * @param outputStream + * @param _textArea + * @param format + * @param tModel + * @param index + * @param type + * @param slowLink + */ + public SocketRR(Connection c, Socket inputSocket, + InputStream inputStream, Socket outputSocket, + OutputStream outputStream, Text _textArea, + boolean format, Table tModel, int index, + final String type, SlowLinkSimulator slowLink) { + inSocket = inputSocket; + in = inputStream; + outSocket = outputSocket; + out = outputStream; + textArea = _textArea; + xmlFormat = format; + tmodel = tModel; + tableIndex = index; + this.type = type; + myConnection = c; + this.slowLink = slowLink; + start(); + } + + /** + * Method isDone + * + * @return boolean + */ + public boolean isDone() { + return done; + } + + public String getElapsed() { + return String.valueOf(elapsed); + } + + /** + * Method run + */ + public void run() { + try { + byte[] buffer = new byte[4096]; + byte[] tmpbuffer = new byte[8192]; + int saved = 0; + int len; + int i1, i2; + int i; + int reqSaved = 0; + int tabWidth = 3; + boolean atMargin = true; + int thisIndent = -1, nextIndent = -1, previousIndent = -1; + + inputInt = reqSaved; + MainView.display.syncExec(new Runnable() { + public void run() { + if (tmodel != null) { + String tmpStr = tmodel.getItem(tableIndex).getText(MainView.REQ_COLUMN); + if (!"".equals(tmpStr)) { + inputInt = tmpStr.length(); + } + } + } + }); + reqSaved = inputInt; + + long start = System.currentTimeMillis(); + a: + for (; ;) { + + elapsed = System.currentTimeMillis() - start; + + if (done) { + break; + } + + // try{ + // len = in.available(); + // }catch(Exception e){len=0;} + len = buffer.length; + + // Used to be 1, but if we block it doesn't matter + // however 1 will break with some servers, including apache + if (len == 0) { + len = buffer.length; + } + if (saved + len > buffer.length) { + len = buffer.length - saved; + } + int len1 = 0; + while (len1 == 0) { + try { + len1 = in.read(buffer, saved, len); + } catch (Exception ex) { + if (done && (saved == 0)) { + break a; + } + len1 = -1; + break; + } + } + len = len1; + if ((len == -1) && (saved == 0)) { + break; + } + if (len == -1) { + done = true; + } + + // No matter how we may (or may not) format it, send it + // on unformatted - we don't want to mess with how its + // sent to the other side, just how its displayed + if ((out != null) && (len > 0)) { + slowLink.pump(len); + out.write(buffer, saved, len); + } + + MainView.display.syncExec(new Runnable() { + public void run() { + outBool = (tmodel != null); + } + }); + + + if (outBool && (reqSaved < 50)) { + MainView.display.syncExec(new Runnable() { + public void run() { + outString = tmodel.getItem(tableIndex).getText(MainView.REQ_COLUMN); + } + }); + + String old = outString; + old = old + new String(buffer, saved, len); + if (old.length() > 50) { + old = old.substring(0, 50); + } + reqSaved = old.length(); + if ((i = old.indexOf('\n')) > 0) { + old = old.substring(0, i - 1); + reqSaved = 50; + } + + inputString = old; + MainView.display.syncExec(new Runnable() { + public void run() { + tmodel.getItem(tableIndex).setText(MainView.REQ_COLUMN, inputString); + } + }); + } + + + if (xmlFormat) { + + // Do XML Formatting + boolean inXML = false; + int bufferLen = saved; + if (len != -1) { + bufferLen += len; + } + i1 = 0; + i2 = 0; + saved = 0; + for (; i1 < bufferLen; i1++) { + + // Except when we're at EOF, saved last char + if ((len != -1) && (i1 + 1 == bufferLen)) { + saved = 1; + break; + } + thisIndent = -1; + if ((buffer[i1] == '<') + && (buffer[i1 + 1] != '/')) { + previousIndent = nextIndent++; + thisIndent = nextIndent; + inXML = true; + } + if ((buffer[i1] == '<') + && (buffer[i1 + 1] == '/')) { + if (previousIndent > nextIndent) { + thisIndent = nextIndent; + } + previousIndent = nextIndent--; + inXML = true; + } + if ((buffer[i1] == '/') + && (buffer[i1 + 1] == '>')) { + previousIndent = nextIndent--; + inXML = true; + } + if (thisIndent != -1) { + if (thisIndent > 0) { + tmpbuffer[i2++] = (byte) '\n'; + } + for (i = tabWidth * thisIndent; i > 0; i--) { + tmpbuffer[i2++] = (byte) ' '; + } + } + atMargin = ((buffer[i1] == '\n') + || (buffer[i1] == '\r')); + if (!inXML || !atMargin) { + tmpbuffer[i2++] = buffer[i1]; + } + } + + inputString = new String(tmpbuffer, 0, i2); + MainView.display.syncExec(new Runnable() { + public void run() { + textArea.append(inputString); + } + }); + + // Shift saved bytes to the beginning + for (i = 0; i < saved; i++) { + buffer[i] = buffer[bufferLen - saved + i]; + } + } else { + + inputString = new String(buffer, 0, len); + MainView.display.syncExec(new Runnable() { + public void run() { + textArea.append(inputString); + } + }); + } + } + + } catch (Exception e) { + e.printStackTrace(); + } finally { + done = true; + try { + if (out != null) { + out.flush(); + if (null != outSocket) { + outSocket.shutdownOutput(); + } else { + out.close(); + } + out = null; + } + } catch (Exception e) { + } + try { + if (in != null) { + if (inSocket != null) { + inSocket.shutdownInput(); + } else { + in.close(); + } + in = null; + } + } catch (Exception e) { + } + myConnection.wakeUp(); + } + } + + /** + * Method halt + */ + public void halt() { + try { + if (inSocket != null) { + inSocket.close(); + } + if (outSocket != null) { + outSocket.close(); + } + inSocket = null; + outSocket = null; + if (in != null) { + in.close(); + } + if (out != null) { + out.close(); + } + in = null; + out = null; + done = true; + } catch (Exception e) { + e.printStackTrace(); + } + } +}
Added: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketWaiter.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketWaiter.java?view=auto&rev=490162 ============================================================================== --- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketWaiter.java (added) +++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/SocketWaiter.java Mon Dec 25 11:38:14 2006 @@ -0,0 +1,114 @@ +/* + * 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.apache.ws.commons.tcpmon.eclipse.ui.Connection; +import org.apache.ws.commons.tcpmon.eclipse.ui.Listener; +import org.apache.ws.commons.tcpmon.eclipse.ui.MainView; + +import java.net.ServerSocket; +import java.net.Socket; + +/** + * wait for incoming connections, spawn a connection thread when + * stuff comes in. + */ +class SocketWaiter extends Thread { + + /** + * Field sSocket + */ + ServerSocket sSocket = null; + + /** + * Field listener + */ + Listener listener; + + /** + * Field port + */ + int port; + + /** + * Field pleaseStop + */ + boolean pleaseStop = false; + + /** + * Constructor SocketWaiter + * + * @param l + * @param p + */ + public SocketWaiter(Listener l, int p) { + listener = l; + port = p; + start(); + } + + /** + * Method run + */ + public void run() { + + try { + MainView.display.syncExec(new Runnable() { + public void run() { + listener.setLeft(MainView.SWT_LABEL, MainView.getMessage("wait00", " Waiting for Connection...")); + } + }); + + sSocket = new ServerSocket(port); + for (; ;) { + + Socket inSocket = sSocket.accept(); + if (pleaseStop) { + break; + } + new Connection(listener, inSocket); + inSocket = null; + } + } catch (Exception exp) { + if (!"socket closed".equals(exp.getMessage())) { + final String inputString = exp.toString(); + MainView.display.syncExec(new Runnable() { + public void run() { + listener.setLeft(MainView.SWT_LABEL, inputString); + listener.setRight(MainView.SWT_LABEL, ""); + listener.stop(); + } + }); + } + } + } + + /** + * force a halt by connecting to self and then closing the server socket + */ + public void halt() { + try { + pleaseStop = true; + new Socket("127.0.0.1", port); + if (sSocket != null) { + sSocket.close(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} Added: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TableEnhancer.java URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TableEnhancer.java?view=auto&rev=490162 ============================================================================== --- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TableEnhancer.java (added) +++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/eclipse/ui/TableEnhancer.java Mon Dec 25 11:38:14 2006 @@ -0,0 +1,164 @@ +/* + * 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.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.SWT; + +/** + * + * A table enhancer class that wraps a table - A 'decorator' :) + * + */ +public class TableEnhancer { + private Table table; + private int secondArgument; + + public TableEnhancer(Table table) { + this.table = table; + } + + public void setValueAt(String value, int row, int column) { + TableItem item = table.getItem(row); + item.setText(column, value); + } + + public int getLeadSelectionIndex() { + return secondArgument; + } + + public int getMaxSelectionIndex() { + int[] selectionIndices = table.getSelectionIndices(); + if (selectionIndices.length != 0) { + int temp = selectionIndices[0]; + for (int i = 1; i < selectionIndices.length; i++) { + if (temp < selectionIndices[i]) { + temp = selectionIndices[i]; + } + } + return temp; + } + return -1; + } + + public int getNearestSelectionToZero() { + int[] selectionIndices = sortArray(table.getSelectionIndices()); + if (selectionIndices[0] == 0) { + return selectionIndices[1]; + } else { + return selectionIndices[0]; + } + } + + public int[] getSelectionIndicesWithoutZero() { + int[] selectionIndices = sortArray(table.getSelectionIndices()); + if (selectionIndices[0] == 0) { + int[] tempArray = new int[selectionIndices.length - 1]; + for (int i = 1; i < selectionIndices.length; i++) { + tempArray[i - 1] = selectionIndices[i]; + } + return tempArray; + } + return selectionIndices; + } + + private int[] sortArray(int[] selectionIndices) { + if (selectionIndices.length != 0) { + for (int i = 0; i < selectionIndices.length; i++) { + int temp = selectionIndices[i]; + int index = i; + for (int j = i; j < selectionIndices.length; j++) { + if (temp > selectionIndices[j]) { + temp = selectionIndices[j]; + index = j; + } + } + int element = selectionIndices[i]; + selectionIndices[i] = selectionIndices[index]; + selectionIndices[index] = element; + } + return selectionIndices; + } + return null; + } + + public int getMinSelectionIndex() { + int[] selectionIndices = table.getSelectionIndices(); + if (selectionIndices.length != 0) { + int temp = selectionIndices[0]; + for (int i = 1; i < selectionIndices.length; i++) { + if (temp > selectionIndices[i]) { + temp = selectionIndices[i]; + } + } + return temp; + } + return -1; + } + + /** + * @param index0 + * @param index1 Similar to setSelectionInterval(int index0, int index1) in DefaultListSelectionModel of SWING + * but index0 should be less than index1 + */ + public void setSelectionInterval(int index0, int index1) { + secondArgument = index1; + table.setSelection(index0, index1); + notifyListeners(SWT.Selection, new Event()); + } + + + public boolean isSelectionEmpty() { + return (table.getSelectionIndices().length == 0); + } + + public void selectAll() { + table.selectAll(); + } + + public void clearSelection() { + if (table.getSelectionCount() != 0) { + notifyListeners(SWT.Selection, new Event()); + } + table.deselectAll(); + } + + public int indexOf(TableItem item) { + return (table.indexOf(item)); + } + + public void remove(int index) { + table.remove(index); + } + + + public void notifyListeners(int type, Event e) { + table.notifyListeners(type, e); + } + + public boolean isSelectedIndex(int index) { + int arr[] = table.getSelectionIndices(); + for (int i = 0; i < arr.length; i++) { + if (index == arr[i]) { + return true; + } + } + return false; + } +} Copied: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/IdeaPlugin.java (from r490160, webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaPlugin.java) URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/IdeaPlugin.java?view=diff&rev=490162&p1=webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaPlugin.java&r1=490160&p2=webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/IdeaPlugin.java&r2=490162 ============================================================================== --- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaPlugin.java (original) +++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/plugin/IdeaPlugin.java Mon Dec 25 11:38:14 2006 @@ -1,4 +1,4 @@ -package org.apache.ws.commons.tcpmon.idea; +package org.apache.ws.commons.tcpmon.idea.plugin; import com.intellij.openapi.components.ProjectComponent; import com.intellij.openapi.project.Project; @@ -6,8 +6,7 @@ import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.openapi.wm.ToolWindowAnchor; -import javax.swing.*; -import java.net.URL; +import org.apache.ws.commons.tcpmon.idea.ui.ComponentHandler; /* * Copyright 2004,2005 The Apache Software Foundation. * Copied: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/ComponentHandler.java (from r490160, webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ComponentHandler.java) URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/ComponentHandler.java?view=diff&rev=490162&p1=webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ComponentHandler.java&r1=490160&p2=webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/ComponentHandler.java&r2=490162 ============================================================================== --- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ComponentHandler.java (original) +++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/ComponentHandler.java Mon Dec 25 11:38:14 2006 @@ -1,4 +1,4 @@ -package org.apache.ws.commons.tcpmon.idea; +package org.apache.ws.commons.tcpmon.idea.ui; import javax.swing.*; /* Copied: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/IdeaTCPMonToolWindow.java (from r490160, webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaTCPMonToolWindow.java) URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/IdeaTCPMonToolWindow.java?view=diff&rev=490162&p1=webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaTCPMonToolWindow.java&r1=490160&p2=webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/IdeaTCPMonToolWindow.java&r2=490162 ============================================================================== --- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/IdeaTCPMonToolWindow.java (original) +++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/idea/ui/IdeaTCPMonToolWindow.java Mon Dec 25 11:38:14 2006 @@ -1,4 +1,4 @@ -package org.apache.ws.commons.tcpmon.idea; +package org.apache.ws.commons.tcpmon.idea.ui; import org.apache.ws.commons.tcpmon.TCPMon; import org.apache.ws.commons.tcpmon.AdminPane; Modified: webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/tcpmon.properties URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/tcpmon.properties?view=diff&rev=490162&r1=490161&r2=490162 ============================================================================== --- webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/tcpmon.properties (original) +++ webservices/commons/trunk/modules/tcpmon/src/org/apache/ws/commons/tcpmon/tcpmon.properties Mon Dec 25 11:38:14 2006 @@ -15,6 +15,7 @@ error00=Error host00=Host: hostname00=Hostname +inform00=Connection can be removed only when its status indicates Done listener00=Listener listenPort00=Listen Port # listenPort01=Listen Port: @@ -26,6 +27,7 @@ port02=Port: proxy00=Proxy proxySupport00=HTTP Proxy Support +quit00=Do you want to remove monitoring removeAll00=Remove All removeSelected00=Remove Selected request00=Request... --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
