diff --git a/src/main/java/org/jboss/netty/channel/socket/servlet/ServletClientSocketChannel.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelClientSocketChannel.java similarity index 88% rename from src/main/java/org/jboss/netty/channel/socket/servlet/ServletClientSocketChannel.java rename to src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelClientSocketChannel.java index 4cc68cc2cf..f72b675086 100644 --- a/src/main/java/org/jboss/netty/channel/socket/servlet/ServletClientSocketChannel.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelClientSocketChannel.java @@ -20,7 +20,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.jboss.netty.channel.socket.servlet; +package org.jboss.netty.channel.socket.http; import org.jboss.netty.buffer.ChannelBuffer; import org.jboss.netty.buffer.ChannelBuffers; @@ -36,14 +36,11 @@ import org.jboss.netty.channel.DefaultChannelPipeline; import org.jboss.netty.channel.MessageEvent; import org.jboss.netty.channel.SimpleChannelHandler; import org.jboss.netty.channel.ExceptionEvent; -import org.jboss.netty.channel.ChannelStateEvent; import org.jboss.netty.channel.ChannelPipelineCoverage; import org.jboss.netty.channel.socket.ClientSocketChannelFactory; import org.jboss.netty.channel.socket.SocketChannel; import org.jboss.netty.channel.socket.SocketChannelConfig; -import static org.jboss.netty.channel.socket.servlet.ServletClientSocketPipelineSink.LINE_TERMINATOR; import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; -import org.jboss.netty.handler.codec.frame.Delimiters; import org.jboss.netty.util.LinkedTransferQueue; import java.io.IOException; @@ -58,7 +55,7 @@ import java.util.concurrent.locks.Lock; * @author Andy Taylor (andy.taylor@jboss.org) * @version $Rev$, $Date$ */ -class ServletClientSocketChannel extends AbstractChannel +class HttpTunnelClientSocketChannel extends AbstractChannel implements org.jboss.netty.channel.socket.SocketChannel { private final Lock reconnectLock = new ReentrantLock(); @@ -83,9 +80,9 @@ class ServletClientSocketChannel extends AbstractChannel private DelimiterBasedFrameDecoder handler = new DelimiterBasedFrameDecoder(8092, ChannelBuffers.wrappedBuffer(new byte[] { '\r', '\n' })); - private ServletClientSocketChannel.ServletChannelHandler servletHandler = new ServletChannelHandler(); + private HttpTunnelClientSocketChannel.ServletChannelHandler servletHandler = new ServletChannelHandler(); - ServletClientSocketChannel( + HttpTunnelClientSocketChannel( ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, URL url, ClientSocketChannelFactory clientSocketChannelFactory) { @@ -151,26 +148,26 @@ class ServletClientSocketChannel extends AbstractChannel } channel.connect(remoteAddress); StringBuilder builder = new StringBuilder(); - builder.append("POST ").append(url.toExternalForm()).append(" HTTP/1.1").append(LINE_TERMINATOR). - append("HOST: ").append(url.getHost()).append(":").append(url.getPort()).append(LINE_TERMINATOR). - append("Content-Type: application/octet-stream").append(LINE_TERMINATOR).append("Transfer-Encoding: chunked"). - append(LINE_TERMINATOR).append("Content-Transfer-Encoding: Binary").append(LINE_TERMINATOR).append("Connection: Keep-Alive"). - append(LINE_TERMINATOR); + builder.append("POST ").append(url.toExternalForm()).append(" HTTP/1.1").append(HttpTunnelClientSocketPipelineSink.LINE_TERMINATOR). + append("HOST: ").append(url.getHost()).append(":").append(url.getPort()).append(HttpTunnelClientSocketPipelineSink.LINE_TERMINATOR). + append("Content-Type: application/octet-stream").append(HttpTunnelClientSocketPipelineSink.LINE_TERMINATOR).append("Transfer-Encoding: chunked"). + append(HttpTunnelClientSocketPipelineSink.LINE_TERMINATOR).append("Content-Transfer-Encoding: Binary").append(HttpTunnelClientSocketPipelineSink.LINE_TERMINATOR).append("Connection: Keep-Alive"). + append(HttpTunnelClientSocketPipelineSink.LINE_TERMINATOR); if (reconnect) { - builder.append("Cookie: JSESSIONID=").append(sessionId).append(LINE_TERMINATOR); + builder.append("Cookie: JSESSIONID=").append(sessionId).append(HttpTunnelClientSocketPipelineSink.LINE_TERMINATOR); } - builder.append(LINE_TERMINATOR); + builder.append(HttpTunnelClientSocketPipelineSink.LINE_TERMINATOR); String msg = builder.toString(); channel.write(ChannelBuffers.wrappedBuffer(msg.getBytes("ASCII7"))); } public void sendChunk(ChannelBuffer a) throws IOException { int size = a.readableBytes(); - String hex = Integer.toHexString(size) + LINE_TERMINATOR; + String hex = Integer.toHexString(size) + HttpTunnelClientSocketPipelineSink.LINE_TERMINATOR; // try { synchronized (writeLock) { - a.writeBytes(LINE_TERMINATOR.getBytes()); + a.writeBytes(HttpTunnelClientSocketPipelineSink.LINE_TERMINATOR.getBytes()); channel.write(ChannelBuffers.wrappedBuffer(hex.getBytes())); channel.write(a).awaitUninterruptibly(); //channel.write(ChannelBuffers.wrappedBuffer(LINE_TERMINATOR.getBytes())); diff --git a/src/main/java/org/jboss/netty/channel/socket/servlet/ServletClientSocketChannelFactory.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelClientSocketChannelFactory.java similarity index 85% rename from src/main/java/org/jboss/netty/channel/socket/servlet/ServletClientSocketChannelFactory.java rename to src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelClientSocketChannelFactory.java index cedcfb708f..780c9ed565 100644 --- a/src/main/java/org/jboss/netty/channel/socket/servlet/ServletClientSocketChannelFactory.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelClientSocketChannelFactory.java @@ -20,7 +20,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.jboss.netty.channel.socket.servlet; +package org.jboss.netty.channel.socket.http; import java.net.URL; import java.util.concurrent.Executor; @@ -36,7 +36,7 @@ import org.jboss.netty.util.ExecutorUtil; * @author Andy Taylor (andy.taylor@jboss.org) * @version $Rev$, $Date$ */ -public class ServletClientSocketChannelFactory implements ClientSocketChannelFactory { +public class HttpTunnelClientSocketChannelFactory implements ClientSocketChannelFactory { private final Executor workerExecutor; private final ChannelSink sink; @@ -47,7 +47,7 @@ public class ServletClientSocketChannelFactory implements ClientSocketChannelFac * * @param workerExecutor */ - public ServletClientSocketChannelFactory(ClientSocketChannelFactory clientSocketChannelFactory, Executor workerExecutor, URL url) { + public HttpTunnelClientSocketChannelFactory(ClientSocketChannelFactory clientSocketChannelFactory, Executor workerExecutor, URL url) { this(url, workerExecutor, Runtime.getRuntime().availableProcessors()); this.clientSocketChannelFactory = clientSocketChannelFactory; } @@ -61,7 +61,7 @@ public class ServletClientSocketChannelFactory implements ClientSocketChannelFac * the {@link java.util.concurrent.Executor} which will execute the I/O worker threads * @param workerCount */ - public ServletClientSocketChannelFactory( + public HttpTunnelClientSocketChannelFactory( URL url, Executor workerExecutor, int workerCount) { if (url == null) { @@ -78,11 +78,11 @@ public class ServletClientSocketChannelFactory implements ClientSocketChannelFac } this.workerExecutor = workerExecutor; - sink = new ServletClientSocketPipelineSink(workerExecutor); + sink = new HttpTunnelClientSocketPipelineSink(workerExecutor); } public SocketChannel newChannel(ChannelPipeline pipeline) { - return new ServletClientSocketChannel(this, pipeline, sink, url, clientSocketChannelFactory); + return new HttpTunnelClientSocketChannel(this, pipeline, sink, url, clientSocketChannelFactory); } public void releaseExternalResources() { diff --git a/src/main/java/org/jboss/netty/channel/socket/servlet/ServletClientSocketPipelineSink.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelClientSocketPipelineSink.java similarity index 84% rename from src/main/java/org/jboss/netty/channel/socket/servlet/ServletClientSocketPipelineSink.java rename to src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelClientSocketPipelineSink.java index a5ae0f73f3..03088a1b8d 100644 --- a/src/main/java/org/jboss/netty/channel/socket/servlet/ServletClientSocketPipelineSink.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelClientSocketPipelineSink.java @@ -20,7 +20,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.jboss.netty.channel.socket.servlet; +package org.jboss.netty.channel.socket.http; import static org.jboss.netty.channel.Channels.*; @@ -42,18 +42,18 @@ import org.jboss.netty.util.ThreadRenamingRunnable; * @author Andy Taylor (andy.taylor@jboss.org) * @version $Rev$, $Date$ */ -class ServletClientSocketPipelineSink extends AbstractChannelSink { +class HttpTunnelClientSocketPipelineSink extends AbstractChannelSink { static String LINE_TERMINATOR = "\r\n"; private final Executor workerExecutor; - ServletClientSocketPipelineSink(Executor workerExecutor) { + HttpTunnelClientSocketPipelineSink(Executor workerExecutor) { this.workerExecutor = workerExecutor; } public void eventSunk( ChannelPipeline pipeline, ChannelEvent e) throws Exception { - ServletClientSocketChannel channel = (ServletClientSocketChannel) e.getChannel(); + HttpTunnelClientSocketChannel channel = (HttpTunnelClientSocketChannel) e.getChannel(); ChannelFuture future = e.getFuture(); if (e instanceof ChannelStateEvent) { ChannelStateEvent stateEvent = (ChannelStateEvent) e; @@ -62,36 +62,36 @@ class ServletClientSocketPipelineSink extends AbstractChannelSink { switch (state) { case OPEN: if (Boolean.FALSE.equals(value)) { - ServletWorker.close(channel, future); + HttpTunnelWorker.close(channel, future); } break; case BOUND: if (value != null) { bind(channel, future, (SocketAddress) value); } else { - ServletWorker.close(channel, future); + HttpTunnelWorker.close(channel, future); } break; case CONNECTED: if (value != null) { connect(channel, future, (SocketAddress) value); } else { - ServletWorker.close(channel, future); + HttpTunnelWorker.close(channel, future); } break; case INTEREST_OPS: - ServletWorker.setInterestOps(channel, future, ((Integer) value).intValue()); + HttpTunnelWorker.setInterestOps(channel, future, ((Integer) value).intValue()); break; } } else if (e instanceof MessageEvent) { - ServletWorker.write( + HttpTunnelWorker.write( channel, future, ((MessageEvent) e).getMessage()); } } private void bind( - ServletClientSocketChannel channel, ChannelFuture future, + HttpTunnelClientSocketChannel channel, ChannelFuture future, SocketAddress localAddress) { try { channel.bindSocket(localAddress); @@ -104,7 +104,7 @@ class ServletClientSocketPipelineSink extends AbstractChannelSink { } private void connect( - ServletClientSocketChannel channel, ChannelFuture future, + HttpTunnelClientSocketChannel channel, ChannelFuture future, SocketAddress remoteAddress) { boolean bound = channel.isBound(); @@ -130,7 +130,7 @@ class ServletClientSocketPipelineSink extends AbstractChannelSink { // Start the business. workerExecutor.execute(new ThreadRenamingRunnable( - new ServletWorker(channel), + new HttpTunnelWorker(channel), "Old I/O client worker (channelId: " + channel.getId() + ", " + channel.getLocalAddress() + " => " + channel.getRemoteAddress() + ')')); @@ -141,7 +141,7 @@ class ServletClientSocketPipelineSink extends AbstractChannelSink { fireExceptionCaught(channel, t); } finally { if (connected && !workerStarted) { - ServletWorker.close(channel, future); + HttpTunnelWorker.close(channel, future); } } } diff --git a/src/main/java/org/jboss/netty/channel/socket/servlet/ServletSocketChannelConfig.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelSocketChannelConfig.java similarity index 96% rename from src/main/java/org/jboss/netty/channel/socket/servlet/ServletSocketChannelConfig.java rename to src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelSocketChannelConfig.java index 77eef733a5..d3c0f3a3d5 100644 --- a/src/main/java/org/jboss/netty/channel/socket/servlet/ServletSocketChannelConfig.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelSocketChannelConfig.java @@ -20,7 +20,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.jboss.netty.channel.socket.servlet; +package org.jboss.netty.channel.socket.http; import java.net.Socket; import java.net.SocketException; @@ -39,7 +39,7 @@ import org.jboss.netty.util.ConversionUtil; * @author Andy Taylor (andy.taylor@jboss.org) * @version $Rev$, $Date$ */ -public class ServletSocketChannelConfig implements SocketChannelConfig { +public class HttpTunnelSocketChannelConfig implements SocketChannelConfig { final Socket socket; @@ -70,7 +70,7 @@ public class ServletSocketChannelConfig implements SocketChannelConfig { /** * Creates a new instance. */ - public ServletSocketChannelConfig(Socket socket) { + public HttpTunnelSocketChannelConfig(Socket socket) { this.socket = socket; } @@ -315,8 +315,8 @@ public class ServletSocketChannelConfig implements SocketChannelConfig { // Unused } - ServletSocketChannelConfig copyConfig(Socket socket) { - ServletSocketChannelConfig config = new ServletSocketChannelConfig(socket); + HttpTunnelSocketChannelConfig copyConfig(Socket socket) { + HttpTunnelSocketChannelConfig config = new HttpTunnelSocketChannelConfig(socket); config.setConnectTimeoutMillis(connectTimeoutMillis); if (trafficClass != null) { config.setTrafficClass(trafficClass); diff --git a/src/main/java/org/jboss/netty/channel/socket/servlet/ServletWorker.java b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelWorker.java similarity index 92% rename from src/main/java/org/jboss/netty/channel/socket/servlet/ServletWorker.java rename to src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelWorker.java index b74f6ad872..58f8288316 100644 --- a/src/main/java/org/jboss/netty/channel/socket/servlet/ServletWorker.java +++ b/src/main/java/org/jboss/netty/channel/socket/http/HttpTunnelWorker.java @@ -20,7 +20,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.jboss.netty.channel.socket.servlet; +package org.jboss.netty.channel.socket.http; import static org.jboss.netty.channel.Channels.*; @@ -34,10 +34,10 @@ import org.jboss.netty.channel.ChannelFuture; * @author Andy Taylor (andy.taylor@jboss.org) * @version $Rev$, $Date$ */ -class ServletWorker implements Runnable { - private final ServletClientSocketChannel channel; +class HttpTunnelWorker implements Runnable { + private final HttpTunnelClientSocketChannel channel; - ServletWorker(ServletClientSocketChannel channel) { + HttpTunnelWorker(HttpTunnelClientSocketChannel channel) { this.channel = channel; } @@ -85,7 +85,7 @@ class ServletWorker implements Runnable { } static void write( - ServletClientSocketChannel channel, ChannelFuture future, + HttpTunnelClientSocketChannel channel, ChannelFuture future, Object message) { try { @@ -99,7 +99,7 @@ class ServletWorker implements Runnable { } static void setInterestOps( - ServletClientSocketChannel channel, ChannelFuture future, int interestOps) { + HttpTunnelClientSocketChannel channel, ChannelFuture future, int interestOps) { // Override OP_WRITE flag - a user cannot change this flag. interestOps &= ~Channel.OP_WRITE; @@ -136,7 +136,7 @@ class ServletWorker implements Runnable { } } - static void close(ServletClientSocketChannel channel, ChannelFuture future) { + static void close(HttpTunnelClientSocketChannel channel, ChannelFuture future) { boolean connected = channel.isConnected(); boolean bound = channel.isBound(); try { diff --git a/src/main/java/org/jboss/netty/example/servlet/ServletClientExample.java b/src/main/java/org/jboss/netty/example/http/HttpTunnelClientExample.java similarity index 93% rename from src/main/java/org/jboss/netty/example/servlet/ServletClientExample.java rename to src/main/java/org/jboss/netty/example/http/HttpTunnelClientExample.java index 68b6a1e574..bd3ca70036 100644 --- a/src/main/java/org/jboss/netty/example/servlet/ServletClientExample.java +++ b/src/main/java/org/jboss/netty/example/http/HttpTunnelClientExample.java @@ -19,7 +19,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.jboss.netty.example.servlet; +package org.jboss.netty.example.http; import java.io.BufferedReader; import java.io.InputStreamReader; @@ -32,7 +32,7 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelFuture; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelPipelineCoverage; -import org.jboss.netty.channel.socket.servlet.ServletClientSocketChannelFactory; +import org.jboss.netty.channel.socket.http.HttpTunnelClientSocketChannelFactory; import org.jboss.netty.channel.socket.oio.OioClientSocketChannelFactory; import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; import org.jboss.netty.handler.codec.string.StringDecoder; @@ -84,10 +84,10 @@ import org.jboss.netty.handler.codec.string.StringEncoder; * @author Andy Taylor */ -public class ServletClientExample { +public class HttpTunnelClientExample { public static void main(String[] args) throws Exception { URL url = new URL("http", "localhost", 8080, "/netty/nettyServlet"); - ServletClientSocketChannelFactory factory = new ServletClientSocketChannelFactory(new OioClientSocketChannelFactory(Executors.newCachedThreadPool()), Executors.newCachedThreadPool(), url); + HttpTunnelClientSocketChannelFactory factory = new HttpTunnelClientSocketChannelFactory(new OioClientSocketChannelFactory(Executors.newCachedThreadPool()), Executors.newCachedThreadPool(), url); ClientBootstrap bootstrap = new ClientBootstrap(factory); bootstrap.getPipeline().addLast("decoder", new StringDecoder()); bootstrap.getPipeline().addLast("encoder", new StringEncoder()); diff --git a/src/main/java/org/jboss/netty/example/servlet/LocalTransportRegister.java b/src/main/java/org/jboss/netty/example/http/LocalTransportRegister.java similarity index 98% rename from src/main/java/org/jboss/netty/example/servlet/LocalTransportRegister.java rename to src/main/java/org/jboss/netty/example/http/LocalTransportRegister.java index 41eb374afc..68d5456ea9 100644 --- a/src/main/java/org/jboss/netty/example/servlet/LocalTransportRegister.java +++ b/src/main/java/org/jboss/netty/example/http/LocalTransportRegister.java @@ -19,7 +19,7 @@ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. */ -package org.jboss.netty.example.servlet; +package org.jboss.netty.example.http; import org.jboss.netty.bootstrap.ServerBootstrap; import org.jboss.netty.channel.Channel;