Jetty error: HTTP method GET is not supported by this URL

212 Views Asked by At

I am using HTTP4S and the webapp is running on jetty. The web app file is configured as:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">


   <servlet>
      <servlet-name>user-svc</servlet-name>
      <servlet-class>io.databaker.UserSvcServlet</servlet-class>
      <async-supported>true</async-supported>
   </servlet>

   <servlet-mapping>
      <servlet-name>user-svc</servlet-name>
      <url-pattern>/*</url-pattern>
   </servlet-mapping>

</web-app>

The available URI's are:

object UserSvcRoutes {

  def helloWorldRoutes[F[_]: Sync](H: HelloWorld[F]): HttpRoutes[F] = {
    val dsl = new Http4sDsl[F]{}
    import dsl._
    HttpRoutes.of[F] {
      case GET -> Root =>
        Ok("Example")
      case GET -> Root / "hello" / name =>
        for {
          greeting <- H.hello(HelloWorld.Name(name))
          resp <- Ok(greeting)
        } yield resp
    }
  }

}

When I call http://localhost:8080/ I've got:

enter image description here What I am doing wrong?

1

There are 1 best solutions below

0
earldouglas On BEST ANSWER

Http4sServlet was recently made abstract, with two concrete implementations provided by BlockingHttp4sServlet and AsyncHttp4sServlet.

You can get your example working by changing UserSvcServlet to extend either of these:

package io.databaker

import AppContextShift._
import cats.effect._
import java.util.concurrent.Executors
import org.http4s.server.DefaultServiceErrorHandler
import org.http4s.servlet.BlockingHttp4sServlet
import org.http4s.servlet.BlockingServletIo

class UserSvcServlet
  extends BlockingHttp4sServlet[IO](
    service = UserSvcServer.start,
    servletIo = BlockingServletIo(4096, Blocker.liftExecutorService(Executors.newCachedThreadPool())),
    serviceErrorHandler = DefaultServiceErrorHandler
  )