axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: r379334 - in /webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer: Relay.java TcpTunnel.java
Date Tue, 21 Feb 2006 04:41:07 GMT
Author: dims
Date: Mon Feb 20 20:41:05 2006
New Revision: 379334

URL: http://svn.apache.org/viewcvs?rev=379334&view=rev
Log:
am trying to evoke fond memories for some people :)

PS: Seriously, i needed a command line tool to capture the messages for addressing interop
testing.


Added:
    webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/Relay.java
    webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/TcpTunnel.java

Added: webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/Relay.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/Relay.java?rev=379334&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/Relay.java
(added)
+++ webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/Relay.java
Mon Feb 20 20:41:05 2006
@@ -0,0 +1,70 @@
+/**
+ *
+ * Copyright 2000-2004 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 java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * A <code>Relay</code> object is used by <code>TcpTunnel</code>
+ * and <code>TcpTunnelGui</code> to relay bytes from an
+ * <code>InputStream</code> to a <code>OutputStream</code>.
+ *
+ * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
+ * @author Scott Nichol (snichol@computer.org)
+ */
+public class Relay extends Thread {
+    final static int BUFSIZ = 1000;
+    InputStream in;
+    OutputStream out;
+    byte buf[] = new byte[BUFSIZ];
+    OutputStream os;
+    String enc = "8859_1";
+    Relay(InputStream in, OutputStream out, OutputStream os, String enc) {
+        this.in = in;
+        this.out = out;
+        this.os = os;
+        this.enc = enc;
+    }
+    public String getEncoding() {
+        return enc;
+    }
+    public void run() {
+        int n;
+        try {
+            while ((n = in.read(buf)) > 0) {
+                out.write(buf, 0, n);
+                out.flush();
+                if (os != null) {
+                    os.write(buf, 0, n);
+                    os.flush();
+                }
+            }
+        } catch (IOException e) {
+        } finally {
+            try {
+                in.close();
+                out.close();
+            } catch (IOException e) {
+            }
+        }
+    }
+    public void setEncoding(String enc) {
+        this.enc = enc;
+    }
+}

Added: webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/TcpTunnel.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/TcpTunnel.java?rev=379334&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/TcpTunnel.java
(added)
+++ webservices/axis2/trunk/java/modules/tool/src/org/apache/axis2/tool/tracer/TcpTunnel.java
Mon Feb 20 20:41:05 2006
@@ -0,0 +1,61 @@
+/**
+ *
+ * Copyright 2000-2004 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 java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+/**
+ * A <code>TcpTunnel</code> object listens on the given port,
+ * and once <code>Start</code> is pressed, will forward all bytes
+ * to the given host and port.
+ *
+ * @author Sanjiva Weerawarana (sanjiva@watson.ibm.com)
+ */
+public class TcpTunnel {
+    public static void main(String args[]) throws IOException {
+        if (args.length != 3 && args.length != 4) {
+            System.err.println("Usage: java TcpTunnel listenport tunnelhost tunnelport [encoding]");
+            System.exit(1);
+        }
+        int listenport = Integer.parseInt(args[0]);
+        String tunnelhost = args[1];
+        int tunnelport = Integer.parseInt(args[2]);
+        String enc;
+        if (args.length == 4) {
+            enc = args[3];
+        } else {
+            enc = "8859_1";
+        }
+        System.out.println("TcpTunnel: ready to rock and roll on port " + listenport);
+        ServerSocket ss = new ServerSocket(listenport);
+        while (true) {
+            // accept the connection from my client
+            Socket sc = ss.accept();
+
+            // connect to the thing I'm tunnelling for
+            Socket st = new Socket(tunnelhost, tunnelport);
+            System.out.println("TcpTunnel: tunnelling port " + listenport + " to port " +
tunnelport + " on host " + tunnelhost);
+
+            // relay the stuff thru
+            new Relay(sc.getInputStream(), st.getOutputStream(), System.out, enc).start();
+            new Relay(st.getInputStream(), sc.getOutputStream(), System.out, enc).start();
+            // that's it .. they're off; now I go back to my stuff.
+        }
+    }
+}



Mime
View raw message