TooTallNate/Java-WebSocket · error · InvalidHandshakeException

Invalid request method received

Error message

Invalid request method received: %s Status line: %s

What it means

This guard fires in Draft.translateHandshakeHttpServer while parsing the server side of a WebSocket opening handshake: the first token of the HTTP request/status line must be the GET method. Receiving any other HTTP method means the request cannot be a valid WebSocket upgrade, so the library rejects the handshake with InvalidHandshakeException. The faulty input is a handshake whose status/request line starts with a method other than GET (e.g. POST, PUT) sent to the server endpoint.

Solutions

  1. Ensure clients connect with an HTTP GET request carrying the WebSocket Upgrade headers, not other HTTP methods
  2. Fix client code (or misconfigured HTTP clients/curl calls) that POSTs or PUTs to the WebSocket endpoint
  3. Check for reverse proxies or gateways rewriting the request method before it reaches the WebSocket server
  4. Log the offending method and status line to identify the non-WebSocket client and reject or redirect it at the HTTP layer
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/main/java/org/java_websocket/drafts/Draft.java:145 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of TooTallNate/Java-WebSocket@afeacbf8c0 (2026-09-09). Data as JSON: /api/errors/a50707c405349806. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/org/java_websocket/drafts/Draft.java:145

    }
    if (line == null) {
      throw new IncompleteHandshakeException();
    }
    return handshake;
  }

  /**
   * Checking the handshake for the role as server
   *
   * @param firstLineTokens the token of the first line split as as an string array
   * @param line            the whole line
   * @return a handshake
   */
  private static HandshakeBuilder translateHandshakeHttpServer(String[] firstLineTokens,
      String line) throws InvalidHandshakeException {
    // translating/parsing the request from the CLIENT
    if (!"GET".equalsIgnoreCase(firstLineTokens[0])) {
      throw new InvalidHandshakeException(String
          .format("Invalid request method received: %s Status line: %s", firstLineTokens[0], line));
    }
    if (!"HTTP/1.1".equalsIgnoreCase(firstLineTokens[2])) {
      throw new InvalidHandshakeException(String
          .format("Invalid status line received: %s Status line: %s", firstLineTokens[2], line));
    }
    ClientHandshakeBuilder clienthandshake = new HandshakeImpl1Client();
    clienthandshake.setResourceDescriptor(firstLineTokens[1]);
    return clienthandshake;
  }

  /**
   * Checking the handshake for the role as client
   *
   * @param firstLineTokens the token of the first line split as as an string array
   * @param line            the whole line
   * @return a handshake
   */

View on GitHub (pinned to afeacbf8c0)