Skip to content

Http Server

Stefan Tirea edited this page Jan 2, 2021 · 3 revisions

Presentation

Pitfalls

  • Socket Server

    • Reading the whole response is not possible with readLine() or lines() (Stream)
      • Problem: The request stays open until the response is coming from the server
      • Solution: extract the Content-Length and read only char by char!
    • Postman sends 2 requests towards localhost. The first one acts like a ping and is cancelled shortly after
      • Problem: The server crashed because of the wrong handling of the client request
      • Solution: Proper Exception handling at every level
  • Reflections

    • First time using it so I had to read a bit into it
    • One important feature was automatically knowing which parameter in the method belongs to which path variable in the url
    • So I just use the parameter name and compare it to the path (ex. "/api/{username}"). Problem: Method Parameter names are generalized by the compiler by default (String username => String arg1).
    • Solution: Add Compiler Argument -parameters => does not change the parameter name (since Java 8).
Clone this wiki locally