why do I get "The requested resource could not be found." when accessing simple spray route?
Asked Answered
P

2

6

I tried a simple spray example app and i cannot access the route, I uploaded the example source code which does not work to github: spray-tomcat-example:

 git clone https://github.com/avidanyum/spray-tomcat-example
 mvn package
 cp cp target/spray-tomcat-example-0.1-SNAPSHOT.war ~/tmp/tomcat/apache-tomcat-7.0.61/webapps/spraytomcat.war
 cd ~/tmp/tomcat/apache-tomcat-7.0.61/bin
 ./catalina.sh jpda run
 http://localhost:8080/spraytomcat/

I get

"The requested resource could not be found."

I defined the route as following:

class ServiceActor extends Actor with Service {

  def actorRefFactory = context
  def receive = runRoute(myRoute)
}

trait Service extends HttpService {
  import com.example.domain.Person

  val myRoute =
    path("") {
      get {
        respondWithMediaType(`text/html`) {
          complete {
            <html>
              <body>
                <h1>Say hello to <i>spray-routing</i> on <i>tomcat</i>!</h1>
              </body>
            </html>
          }
        }
      }
    }


}

and ofcourse I have the boot class in place

in application.conf

spray.servlet {
  boot-class = "com.example.SprayBoot"
  request-timeout = 10s
}

and SprayBoot itself:

class SprayBoot extends WebBoot {

  val system = ActorSystem("actorsystem")
  val serviceActor = system.actorOf(Props[ServiceActor])

}

I'm pretty sure I followed all requirements am i missing something? how can I update it to actually serve the content instead of "The requested resource could not be found."

Poise answered 17/4, 2015 at 14:9 Comment(4)
Try pathSingleSlash instead of path("").Thomas
@Thomas I just tried pathSingleSlash I get the same error also if i replace path("") with path("/something") then /sprayexapmle/something also didn't work for me...Poise
The problem seems to be that spray isn't stripping of the context path. So ,you need to set spray.servlet.root-path = "/spraytomcat" setting to make it work. See at github.com/spray/spray/blob/master/spray-servlet/src/main/…Thomas
@Thomas I would be happy to mark it as answer if posted as answer....Poise
P
0

as @jrudolph said

The problem seems to be that spray isn't stripping of the context path. So ,you need to set spray.servlet.root-path = "/spraytomcat" setting to make it work. See here

Poise answered 20/4, 2015 at 7:14 Comment(0)
W
1

The example will work when you deploy app into ROOT context without any extra configuration.

I've changed your script a bit:

git clone https://github.com/avidanyum/spray-tomcat-example mvn package cp target/spray-tomcat-example-0.1-SNAPSHOT.war ~/tmp/tomcat/apache-tomcat-7.0.61/webapps/ROOT.war cd ~/tmp/tomcat/apache-tomcat-7.0.61/bin ./catalina.sh jpda run wget http://localhost:8080/

Warrin answered 19/4, 2015 at 19:30 Comment(0)
P
0

as @jrudolph said

The problem seems to be that spray isn't stripping of the context path. So ,you need to set spray.servlet.root-path = "/spraytomcat" setting to make it work. See here

Poise answered 20/4, 2015 at 7:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.