diff --git a/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java b/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java index 1be364ccc1..13423f977b 100644 --- a/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java +++ b/example/src/main/java/io/netty/example/http/upload/HttpUploadClient.java @@ -27,43 +27,43 @@ import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFuture; import io.netty.channel.socket.nio.NioClientSocketChannelFactory; -import io.netty.handler.codec.http.QueryStringEncoder; import io.netty.handler.codec.http.CookieEncoder; import io.netty.handler.codec.http.DefaultHttpDataFactory; import io.netty.handler.codec.http.DefaultHttpRequest; import io.netty.handler.codec.http.DiskAttribute; import io.netty.handler.codec.http.DiskFileUpload; -import io.netty.handler.codec.http.InterfaceHttpData; -import io.netty.handler.codec.http.HttpPostRequestEncoder; import io.netty.handler.codec.http.HttpDataFactory; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpPostRequestEncoder; +import io.netty.handler.codec.http.HttpPostRequestEncoder.ErrorDataEncoderException; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpVersion; -import io.netty.handler.codec.http.HttpPostRequestEncoder.ErrorDataEncoderException; +import io.netty.handler.codec.http.InterfaceHttpData; +import io.netty.handler.codec.http.QueryStringEncoder; /** */ public class HttpUploadClient { + + private final String baseUri; + private final String filePath; + + public HttpUploadClient(String baseUri, String filePath) { + this.baseUri = baseUri; + this.filePath = filePath; + } - public static void main(String[] args) { - if (args.length != 2) { - System.err.println( - "Usage: " + HttpUploadClient.class.getSimpleName() + - " baseURI Filepath"); - return; - } - - String baseURI = args[0]; + public void run() { String postSimple, postFile, get; - if (baseURI.endsWith("/")) { - postSimple = baseURI + "formpost"; - postFile = baseURI + "formpostmultipart"; - get = baseURI + "formget"; + if (baseUri.endsWith("/")) { + postSimple = baseUri + "formpost"; + postFile = baseUri + "formpostmultipart"; + get = baseUri + "formget"; } else { - postSimple = baseURI + "/formpost"; - postFile = baseURI + "/formpostmultipart"; - get = baseURI + "/formget"; + postSimple = baseUri + "/formpost"; + postFile = baseUri + "/formpostmultipart"; + get = baseUri + "/formget"; } URI uriSimple; try { @@ -97,7 +97,7 @@ public class HttpUploadClient { System.err.println("Error: " + e.getMessage()); return; } - File file = new File(args[1]); + File file = new File(filePath); if (! file.canRead()) { System.err.println("A correct path is needed"); return; @@ -135,7 +135,7 @@ public class HttpUploadClient { return; } // Multipart Post form: factory used - formpostmultipart(bootstrap, host, port, uriFile, file, factory, headers, bodylist); + formpostmultipart(bootstrap, host, port, uriFile, factory, headers, bodylist); // Shut down executor threads to exit. bootstrap.releaseExternalResources(); @@ -216,13 +216,7 @@ public class HttpUploadClient { /** * Standard post without multipart but already support on Factory (memory management) - * @param bootstrap - * @param host - * @param port - * @param uriSimple - * @param file - * @param factory - * @param headers + * * @return the list of HttpData object (attribute and file) to be reused on next post */ private static List formpost(ClientBootstrap bootstrap, @@ -311,17 +305,9 @@ public class HttpUploadClient { /** * Multipart example - * @param bootstrap - * @param host - * @param port - * @param uriFile - * @param file - * @param factory - * @param headers - * @param bodylist */ private static void formpostmultipart(ClientBootstrap bootstrap, String host, int port, - URI uriFile, File file, HttpDataFactory factory, + URI uriFile, HttpDataFactory factory, List> headers, List bodylist) { // XXX /formpostmultipart // Start the connection attempt. @@ -390,12 +376,19 @@ public class HttpUploadClient { channel.getCloseFuture().awaitUninterruptibly(); } + public static void main(String[] args) { + if (args.length != 2) { + System.err.println( + "Usage: " + HttpUploadClient.class.getSimpleName() + + " baseURI filePath"); + return; + } + String baseUri = args[0]; + String filePath = args[1]; - - - - + new HttpUploadClient(baseUri, filePath).run(); + } // use to simulate a big TEXTAREA field in a form private static final String textArea = diff --git a/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java b/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java index b81896b514..d5bf1194e6 100644 --- a/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java +++ b/example/src/main/java/io/netty/example/http/upload/HttpUploadServer.java @@ -21,10 +21,15 @@ import java.util.concurrent.Executors; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.socket.nio.NioServerSocketChannelFactory; -/** - */ public class HttpUploadServer { - public static void main(String[] args) { + + private final int port; + + public HttpUploadServer(int port) { + this.port = port; + } + + public void run() { // Configure the server. ServerBootstrap bootstrap = new ServerBootstrap( new NioServerSocketChannelFactory( @@ -35,6 +40,16 @@ public class HttpUploadServer { bootstrap.setPipelineFactory(new HttpUploadServerPipelineFactory()); // Bind and start to accept incoming connections. - bootstrap.bind(new InetSocketAddress(8080)); + bootstrap.bind(new InetSocketAddress(port)); + } + + public static void main(String[] args) { + int port; + if (args.length > 0) { + port = Integer.parseInt(args[0]); + } else { + port = 8080; + } + new HttpUploadServer(port).run(); } } diff --git a/example/src/main/java/io/netty/example/sctp/SctpClient.java b/example/src/main/java/io/netty/example/sctp/SctpClient.java index 39d1f4e24b..3357060b13 100644 --- a/example/src/main/java/io/netty/example/sctp/SctpClient.java +++ b/example/src/main/java/io/netty/example/sctp/SctpClient.java @@ -32,8 +32,15 @@ import java.util.concurrent.Executors; */ public class SctpClient { - public static void main(String[] args) throws Exception { + private final String host; + private final int port; + + public SctpClient(String host, int port) { + this.host = host; + this.port = port; + } + public void run() { // Configure the client. ClientBootstrap bootstrap = new ClientBootstrap( new SctpClientSocketChannelFactory( @@ -57,14 +64,31 @@ public class SctpClient { bootstrap.setOption("sctpNoDelay", true); // Start the connection attempt. - ChannelFuture future = bootstrap.connect(new InetSocketAddress("localhost", 2955), new InetSocketAddress("localhost", 2956)); + ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port)); // Wait until the connection is closed or the connection attempt fails. future.getChannel().getCloseFuture().awaitUninterruptibly(); - // Please check SctpClientHandler to see, how echo message is sent & received + // Please check SctpClientHandler to see, how echo message is sent & received // Shut down thread pools to exit. bootstrap.releaseExternalResources(); } + + public static void main(String[] args) throws Exception { + // Print usage if no argument is specified. + if (args.length != 2) { + System.err.println( + "Usage: " + SctpClient.class.getSimpleName() + + " "); + return; + } + + // Parse options. + final String host = args[0]; + final int port = Integer.parseInt(args[1]); + final int firstMessageSize; + + new SctpClient(host, port).run(); + } } diff --git a/example/src/main/java/io/netty/example/sctp/SctpServer.java b/example/src/main/java/io/netty/example/sctp/SctpServer.java index 15a9749aac..a45a66e9ff 100644 --- a/example/src/main/java/io/netty/example/sctp/SctpServer.java +++ b/example/src/main/java/io/netty/example/sctp/SctpServer.java @@ -30,8 +30,14 @@ import java.util.concurrent.Executors; * Echoes back any received data from a client. */ public class SctpServer { + + private final int port; + + public SctpServer(int port) { + this.port = port; + } - public static void main(String[] args) throws Exception { + public void run() { // Configure the server. ServerBootstrap bootstrap = new ServerBootstrap( new SctpServerSocketChannelFactory( @@ -54,6 +60,16 @@ public class SctpServer { bootstrap.setOption("child.sctpNoDelay", true); // Bind and start to accept incoming connections. - bootstrap.bind(new InetSocketAddress("localhost", 2955)); + bootstrap.bind(new InetSocketAddress(port)); + } + + public static void main(String[] args) throws Exception { + int port; + if (args.length > 0) { + port = Integer.parseInt(args[0]); + } else { + port = 2955; + } + new SctpServer(port).run(); } } diff --git a/example/src/main/java/io/netty/example/stdio/StdioLogger.java b/example/src/main/java/io/netty/example/stdio/StdioLogger.java index c2010cc40d..684f4799e5 100755 --- a/example/src/main/java/io/netty/example/stdio/StdioLogger.java +++ b/example/src/main/java/io/netty/example/stdio/StdioLogger.java @@ -39,10 +39,9 @@ import io.netty.handler.codec.string.StringEncoder; */ public class StdioLogger { - private static volatile boolean running = true; - - public static void main(String[] args) { + private volatile boolean running = true; + public void run() { final ExecutorService executorService = Executors.newCachedThreadPool(); final ClientBootstrap bootstrap = new ClientBootstrap(new IoStreamChannelFactory(executorService)); @@ -64,7 +63,7 @@ public class StdioLogger { e.getChannel().write("Message received: " + message); } if ("exit".equals(message)) { - StdioLogger.running = false; + running = false; } super.messageReceived(ctx, e); } @@ -93,7 +92,9 @@ public class StdioLogger { // Shut down all thread pools to exit. bootstrap.releaseExternalResources(); - } + public static void main(String[] args) { + new StdioLogger().run(); + } } diff --git a/pom.xml b/pom.xml index 6a0b21caf5..b2a53a3957 100644 --- a/pom.xml +++ b/pom.xml @@ -291,7 +291,7 @@ ${project.groupId} netty-build - 2-SNAPSHOT + 3 diff --git a/testsuite/pom.xml b/testsuite/pom.xml index d7c69b175f..3bc918d5c6 100644 --- a/testsuite/pom.xml +++ b/testsuite/pom.xml @@ -36,19 +36,5 @@ ${project.version} - - - - maven-jar-plugin - 2.3.2 - - - default-jar - none - - - - -