Author: veithen
Date: Sat Sep 20 13:10:06 2008
New Revision: 697416
URL: http://svn.apache.org/viewvc?rev=697416&view=rev
Log:
HTTP transport tests: Monitor the TCP connections and dump data to log files.
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/util/tcpmon/
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/util/tcpmon/Relay.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/util/tcpmon/Tunnel.java
Modified:
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/base/datagram/Utils.java
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/http/HttpChannel.java
Modified:
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/base/datagram/Utils.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/base/datagram/Utils.java?rev=697416&r1=697415&r2=697416&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/base/datagram/Utils.java
(original)
+++
synapse/trunk/java/modules/transports/src/main/java/org/apache/synapse/transport/base/datagram/Utils.java
Sat Sep 20 13:10:06 2008
@@ -29,7 +29,7 @@
for (int i=0; i<16; i++) {
int index = start+i;
if (index < length) {
- String hex = Integer.toHexString(data[start+i]);
+ String hex = Integer.toHexString(data[start+i] & 0xFF);
if (hex.length() < 2) {
buffer.append('0');
}
Modified:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/http/HttpChannel.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/http/HttpChannel.java?rev=697416&r1=697415&r2=697416&view=diff
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/http/HttpChannel.java
(original)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/http/HttpChannel.java
Sat Sep 20 13:10:06 2008
@@ -19,18 +19,28 @@
package org.apache.synapse.transport.testkit.http;
+import java.net.InetSocketAddress;
import java.util.UUID;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.synapse.transport.testkit.listener.AsyncChannel;
import org.apache.synapse.transport.testkit.listener.RequestResponseChannel;
+import org.apache.synapse.transport.testkit.util.tcpmon.Tunnel;
public class HttpChannel implements AsyncChannel, RequestResponseChannel {
private String serviceName;
+ private Tunnel tunnel;
@SuppressWarnings("unused")
- private void setUp() {
+ private void setUp() throws Exception {
serviceName = "TestService-" + UUID.randomUUID();
+ tunnel = new Tunnel(new InetSocketAddress("127.0.0.1", 8280));
+ new Thread(tunnel).start();
+ }
+
+ @SuppressWarnings("unused")
+ private void tearDown() throws Exception {
+ tunnel.stop();
}
public String getServiceName() {
@@ -38,6 +48,6 @@
}
public EndpointReference getEndpointReference() throws Exception {
- return new EndpointReference("http://localhost:8280" + CONTEXT_PATH +
"/" + serviceName);
+ return new EndpointReference("http://localhost:" + tunnel.getPort() +
CONTEXT_PATH + "/" + serviceName);
}
}
\ No newline at end of file
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/util/tcpmon/Relay.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/util/tcpmon/Relay.java?rev=697416&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/util/tcpmon/Relay.java
(added)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/util/tcpmon/Relay.java
Sat Sep 20 13:10:06 2008
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.synapse.transport.testkit.util.tcpmon;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.transport.base.datagram.Utils;
+
+public class Relay implements Runnable {
+ private static final Log log = LogFactory.getLog(Relay.class);
+
+ private final String tag;
+ private final InputStream in;
+ private final OutputStream out;
+
+ public Relay(String tag, InputStream in, OutputStream out) {
+ this.tag = tag;
+ this.in = in;
+ this.out = out;
+ }
+
+ public void run() {
+ byte buf[] = new byte[4096];
+ try {
+ int n;
+ while ((n = in.read(buf)) > 0) {
+ StringBuilder dump = new StringBuilder(tag);
+ dump.append('\n');
+ Utils.hexDump(dump, buf, n);
+ log.debug(dump);
+ out.write(buf, 0, n);
+ out.flush();
+ }
+ } catch (IOException ex) {
+ log.error(ex);
+ } finally {
+ IOUtils.closeQuietly(in);
+ IOUtils.closeQuietly(out);
+ }
+ }
+}
Added:
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/util/tcpmon/Tunnel.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/util/tcpmon/Tunnel.java?rev=697416&view=auto
==============================================================================
---
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/util/tcpmon/Tunnel.java
(added)
+++
synapse/trunk/java/modules/transports/src/test/java/org/apache/synapse/transport/testkit/util/tcpmon/Tunnel.java
Sat Sep 20 13:10:06 2008
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.synapse.transport.testkit.util.tcpmon;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class Tunnel implements Runnable {
+ private static final Log log = LogFactory.getLog(Tunnel.class);
+
+ private final ServerSocket serverSocket;
+ private final InetSocketAddress target;
+
+ public Tunnel(InetSocketAddress target) throws IOException {
+ serverSocket = new ServerSocket(0);
+ this.target = target;
+ }
+
+ public int getPort() {
+ return serverSocket.getLocalPort();
+ }
+
+ public void run() {
+ while (true) {
+ Socket socket;
+ try {
+ socket = serverSocket.accept();
+ } catch (IOException ex) {
+ break;
+ }
+ try {
+ Socket targetSocket = new Socket(target.getAddress(),
target.getPort());
+ new Thread(new Relay("SENT", socket.getInputStream(),
targetSocket.getOutputStream())).start();
+ new Thread(new Relay("RECEIVED",
targetSocket.getInputStream(), socket.getOutputStream())).start();
+ } catch (IOException ex) {
+ log.error(ex);
+ }
+ }
+ }
+
+ public void stop() throws IOException {
+ serverSocket.close();
+ }
+}