Repository: netty/netty
Issue: Make WebSocketClientHandshakerFactory a utility class
Labels: cleanup

WebSocketClientHandshakerFactory does not need instantiation actually.  Let's make the methods static and make it a utility class.


Issue comments:
@trustin @normanmaurer Want me to tackle this one?

Go ahead!

Sent from my iPhone. Excuse any typos....

Am 09.12.2012 um 05:00 schrieb "Vibul Imtarnasan @vibuli" notifications@github.com:

> @trustin @normanmaurer Want me to tackle this one?
> 
> —
> Reply to this email directly or view it on GitHub.


Pull request review comments:
`return` is unnecessary.


Patch that resolved the issue:
diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerFactory.java b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerFactory.java
index baef4c6f5e1..06d768e5e77 100644
--- a/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerFactory.java
+++ b/codec-http/src/main/java/io/netty/handler/codec/http/websocketx/WebSocketClientHandshakerFactory.java
@@ -23,7 +23,13 @@
 /**
  * Instances the appropriate handshake class to use for clients
  */
-public class WebSocketClientHandshakerFactory {
+public final class WebSocketClientHandshakerFactory {
+
+    /**
+     * Private constructor so this static class cannot be instanced.
+     */
+    private WebSocketClientHandshakerFactory() {
+    }
 
     /**
      * Creates a new handshaker.
@@ -40,7 +46,7 @@ public class WebSocketClientHandshakerFactory {
      * @param customHeaders
      *            Custom HTTP headers to send during the handshake
      */
-    public WebSocketClientHandshaker newHandshaker(
+    public static WebSocketClientHandshaker newHandshaker(
             URI webSocketURL, WebSocketVersion version, String subprotocol,
             boolean allowExtensions, Map<String, String> customHeaders) {
         return newHandshaker(webSocketURL, version, subprotocol, allowExtensions, customHeaders, 65536);
@@ -64,7 +70,7 @@ public WebSocketClientHandshaker newHandshaker(
      *            Maximum allowable frame payload length. Setting this value to your application's
      *            requirement may reduce denial of service attacks using long data frames.
      */
-    public WebSocketClientHandshaker newHandshaker(
+    public static WebSocketClientHandshaker newHandshaker(
             URI webSocketURL, WebSocketVersion version, String subprotocol,
             boolean allowExtensions, Map<String, String> customHeaders, int maxFramePayloadLength) {
         if (version == V13) {
diff --git a/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java b/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java
index 0454f2a1c24..c7c101f697c 100644
--- a/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java
+++ b/example/src/main/java/io/netty/example/http/websocketx/client/WebSocketClient.java
@@ -79,7 +79,7 @@ public void run() throws Exception {
             // HttpResponseDecoder to WebSocketHttpResponseDecoder in the pipeline.
             final WebSocketClientHandler handler =
                     new WebSocketClientHandler(
-                            new WebSocketClientHandshakerFactory().newHandshaker(
+                            WebSocketClientHandshakerFactory.newHandshaker(
                                     uri, WebSocketVersion.V13, null, false, customHeaders));
 
             b.group(new NioEventLoopGroup())


Test patch: