axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r289655 [2/2] - in /webservices/axis2/trunk/java/modules: core/src/org/apache/axis2/util/ tool/src/org/apache/axis2/tool/tracer/
Date Fri, 16 Sep 2005 21:30:35 GMT
Added: webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/SocketRR.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/SocketRR.java?rev=289655&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/SocketRR.java
(added)
+++ webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/SocketRR.java
Fri Sep 16 14:30:29 2005
@@ -0,0 +1,352 @@
+/*
+ * 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.axis2.tool.tracer;
+
+import javax.swing.JTextArea;
+import javax.swing.table.TableModel;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+
+/**
+ * this class handles the pumping of data from the incoming socket to the
+ * outgoing socket
+ */
+class SocketRR extends Thread {
+
+	/**
+     * Field inSocket
+     */
+    Socket inSocket = null;
+
+    /**
+     * Field outSocket
+     */
+    Socket outSocket = null;
+
+    /**
+     * Field textArea
+     */
+    JTextArea 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
+     */
+    TableModel 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, JTextArea _textArea,
+                    boolean format, TableModel 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;
+            if (tmodel != null) {
+                String tmpStr = (String) tmodel.getValueAt(tableIndex,
+                		HTTPTracer.REQ_COLUMN);
+                if (!"".equals(tmpStr)) {
+                    reqSaved = tmpStr.length();
+                }
+            }
+            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);
+                }
+                
+                if ((tmodel != null) && (reqSaved < 50)) {
+                    String old = (String) tmodel.getValueAt(tableIndex,
+                    		HTTPTracer.REQ_COLUMN);
+                    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;
+                    }
+                    tmodel.setValueAt(old, tableIndex, HTTPTracer.REQ_COLUMN);
+                }
+                
+                
+               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];
+                        }
+                    }
+                    textArea.append(new String(tmpbuffer, 0, i2));
+
+                    // Shift saved bytes to the beginning
+                    for (i = 0; i < saved; i++) {
+                        buffer[i] = buffer[bufferLen - saved + i];
+                    }
+                } else {
+                    textArea.append(new String(buffer, 0, len));
+                }
+            }
+
+        } 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/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/SocketWaiter.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/SocketWaiter.java?rev=289655&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/SocketWaiter.java
(added)
+++ webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/SocketWaiter.java
Fri Sep 16 14:30:29 2005
@@ -0,0 +1,106 @@
+/*
+ * 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.axis2.tool.tracer;
+
+import javax.swing.JLabel;
+import java.awt.Color;
+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 {
+           listener.setLeft(
+                   new JLabel(
+                		   HTTPTracer.getMessage("wait00",
+                                   " Waiting for Connection...")));
+           listener.repaint();
+           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())) {
+               JLabel tmp = new JLabel(exp.toString());
+               tmp.setForeground(Color.red);
+               listener.setLeft(tmp);
+               listener.setRight(new JLabel(""));
+               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/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/httptracer.properties
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/httptracer.properties?rev=289655&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/httptracer.properties
(added)
+++ webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/httptracer.properties
Fri Sep 16 14:30:29 2005
@@ -0,0 +1,59 @@
+# Translation instructions.
+# 1.  Each message line is of the form key=value.  Translate the value, DO NOT translate
the key.
+# 2.  The messages may contain arguments that will be filled in by the runtime.  These are
of the form:  {0}, {1}, etc.  These must appear as is in the message, though the order may
be changed to support proper language syntax.
+# 3.  If a single quote character is to appear in the resulting message, it must appear in
this file as two consecutive single quote characters.
+# 4.  Lines beginning with "#" (like this one) are comment lines and may contain translation
instructions.  They need not be translated unless your translated file, rather than this file,
will serve as a base for other translators.
+
+actAs00=Act as a...
+active00=Active
+add00=Add
+admin00=Admin
+close00=Close
+done00=Done
+resp00=Resp
+req00=Req
+error00=Error
+host00=Host:
+hostname00=Hostname
+listener00=Listener
+listenPort00=Listen Port #
+listenPort01=Listen Port:
+mostRecent00=Most Recent
+newTCP00=Create a new HTTP Tracer...
+options00=Options
+port00=Port #
+port01=Port
+port02=Port:
+proxy00=Proxy
+proxySupport00=HTTP Proxy Support
+removeAll00=Remove All
+removeSelected00=Remove Selected
+request00=Request...
+request01=Request
+requestHost00=Request Host
+resend00=Resend
+response00=Response
+save00=Save
+start00=Start
+state00=State
+stop00=Stop
+switch00=Switch Layout
+targetHost00=Target Host
+targetHost01=Target Host:
+targetHostname00=Target Hostname
+targetPort00=Target Port #
+targetPort01=Target Port:
+time00=Time
+usage00=Usage:
+wait00=Waiting for Connection...
+wait01=Waiting for Connection
+
+# NOTE:  in xmlFormat00, do not translate "XML"
+xmlFormat00=XML Format
+
+#NOTE: this is a SimpleDateFormat format string to declare the layout of date
+#and time in the message log. It does need i18n, but not 'translation', per se.
+dateformat00=yyyy-MM-dd HH:mm:ss
+delay00=Simulate Slow Connection
+delay01=Bytes per Pause
+delay02=Delay in Milliseconds
\ No newline at end of file



Mime
View raw message