Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couldn't start WebServer: IndexOutOfBoundsException from SwaggerReflector #107

Open
mubarak opened this issue Jan 24, 2015 · 0 comments
Open

Comments

@mubarak
Copy link

mubarak commented Jan 24, 2015

I am trying to start the WebServer using

case class GetTestRequest(context: RestRequestContext) extends RestRequest
case class GetTestResponse(context: RestResponseContext, pet: Option[TestResponse]) extends RestResponse
object GetTestRegistration extends RestRegistration {
    val method = Method.GET
    val path = "/test"
    val requestParams = Seq(PathParam("id", "ID"))
    def processorActor(actorSystem: ActorSystem, request: RestRequest): ActorRef =
        actorSystem.actorOf(Props[TestProcessor])
}

object RestApp extends Logger {
    val actorConfig = """
    ...
    }"""

    val actorSystem = ActorSystem("Api", ConfigFactory.parseString(actorConfig))
    val restRegistry = RestRegistry("com.rest",
        RestConfig("1.0", "http://localhost:8888/api", reportRuntimeException = ReportRuntimeException.BadRequestsOnly))
    val restRouter = actorSystem.actorOf(Props(new RestHandler(restRegistry)).withRouter(FromConfig()), "rest-router")

    val routes = Routes({
           case HttpRequest(httpRequest) => httpRequest match {
               case PathSegments("api" :: relativePath) => {
                   restRouter ! httpRequest
               }
           }
    })
    def main(args: Array[String]) {
        val config = WebServerConfig(webLog = Some(WebLogConfig()))
        val server = new Server(config, routes, actorSystem)
        Runtime.getRuntime.addShutdownHook(new Thread {
            override def run {
                server.stop()
            }
        })
        server.start
    }
}

and TestResponse would look like

case class TestResonse(id: TestUri, tId: UUID, e: Date, q: Option[Date], max: Long, min: Long, m: List[String], h: Option[Date], x: Map[String, String])

and TestUri would look like

import spray.http.Uri
import spray.http.Uri.Path.{Empty, Segment, Slash}
import spray.json.DefaultJsonProtocol._

sealed trait TopUri {
  def uuid: UUID
  def string: String
  override def toString: String = string
}

case class TestUri(uuid: UUID) extends TopUri {
  lazy val uri = Uri("testing", Uri.Authority.Empty, Uri.Path("/test/" + uuid), Uri.Query(), None)
  lazy val string: String = uri.toString()
}

I did debug it and error comes from spray.http.Uri. Any thoughts?

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.rest.RestApp.main(RestApp.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: java.lang.IndexOutOfBoundsException: 0
    at scala.collection.LinearSeqOptimized$class.apply(LinearSeqOptimized.scala:51)
    at scala.collection.immutable.List.apply(List.scala:83)
    at org.mashupbots.socko.rest.SwaggerReflector$.containerContentType(SwaggerReflector.scala:153)
    at org.mashupbots.socko.rest.SwaggerModelRegistry.org$mashupbots$socko$rest$SwaggerModelRegistry$$parsePropertyType(SwaggerApiDocs.scala:484)
    at org.mashupbots.socko.rest.SwaggerModelRegistry$$anonfun$13.apply(SwaggerApiDocs.scala:439)
    at org.mashupbots.socko.rest.SwaggerModelRegistry$$anonfun$13.apply(SwaggerApiDocs.scala:434)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.reflect.internal.Scopes$Scope.foreach(Scopes.scala:373)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
    at scala.reflect.internal.Scopes$Scope.map(Scopes.scala:51)
    at org.mashupbots.socko.rest.SwaggerModelRegistry.registerComplexType(SwaggerApiDocs.scala:434)
    at org.mashupbots.socko.rest.SwaggerModelRegistry.register(SwaggerApiDocs.scala:530)
    at org.mashupbots.socko.rest.SwaggerModelRegistry$$anonfun$registerComplexType$1.apply(SwaggerApiDocs.scala:458)
    at org.mashupbots.socko.rest.SwaggerModelRegistry$$anonfun$registerComplexType$1.apply(SwaggerApiDocs.scala:458)
    at scala.collection.mutable.HashSet.foreach(HashSet.scala:78)
    at org.mashupbots.socko.rest.SwaggerModelRegistry.registerComplexType(SwaggerApiDocs.scala:458)
    at org.mashupbots.socko.rest.SwaggerModelRegistry.register(SwaggerApiDocs.scala:530)
    at org.mashupbots.socko.rest.SwaggerModelRegistry$$anonfun$registerComplexType$1.apply(SwaggerApiDocs.scala:458)
    at org.mashupbots.socko.rest.SwaggerModelRegistry$$anonfun$registerComplexType$1.apply(SwaggerApiDocs.scala:458)
    at scala.collection.mutable.HashSet.foreach(HashSet.scala:78)
    at org.mashupbots.socko.rest.SwaggerModelRegistry.registerComplexType(SwaggerApiDocs.scala:458)
    at org.mashupbots.socko.rest.SwaggerModelRegistry.register(SwaggerApiDocs.scala:530)
    at org.mashupbots.socko.rest.SwaggerApiOperation$.apply(SwaggerApiDocs.scala:286)
    at org.mashupbots.socko.rest.SwaggerApiPath$$anonfun$9.apply(SwaggerApiDocs.scala:246)
    at org.mashupbots.socko.rest.SwaggerApiPath$$anonfun$9.apply(SwaggerApiDocs.scala:246)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
    at scala.collection.immutable.List.map(List.scala:284)
    at org.mashupbots.socko.rest.SwaggerApiPath$.apply(SwaggerApiDocs.scala:246)
    at org.mashupbots.socko.rest.SwaggerApiDeclaration$$anonfun$7.apply(SwaggerApiDocs.scala:200)
    at org.mashupbots.socko.rest.SwaggerApiDeclaration$$anonfun$7.apply(SwaggerApiDocs.scala:198)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.immutable.Map$Map1.foreach(Map.scala:116)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
    at scala.collection.AbstractTraversable.map(Traversable.scala:104)
    at org.mashupbots.socko.rest.SwaggerApiDeclaration$.apply(SwaggerApiDocs.scala:198)
    at org.mashupbots.socko.rest.SwaggerApiDocs$$anonfun$3.apply(SwaggerApiDocs.scala:85)
    at org.mashupbots.socko.rest.SwaggerApiDocs$$anonfun$3.apply(SwaggerApiDocs.scala:83)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.immutable.Map$Map1.foreach(Map.scala:116)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
    at scala.collection.AbstractTraversable.map(Traversable.scala:104)
    at org.mashupbots.socko.rest.SwaggerApiDocs$.apply(SwaggerApiDocs.scala:83)
    at org.mashupbots.socko.rest.RestRegistry$.apply(RestRegistry.scala:149)
    at org.mashupbots.socko.rest.RestRegistry$.apply(RestRegistry.scala:102)

Is there any way to disable SwaggerApiDoc generation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant