All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jp.co.cyberagent.aeromock.server.http.AeromockApiHttpRequestProcessor.scala Maven / Gradle / Ivy

There is a newer version: 0.2.5
Show newest version
package jp.co.cyberagent.aeromock.server.http

import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.http.{FullHttpRequest, HttpResponse, HttpResponseStatus}
import jp.co.cyberagent.aeromock.api.AeromockApi
import jp.co.cyberagent.aeromock.config.Project
import jp.co.cyberagent.aeromock.helper._
import scaldi.Injector

class AeromockApiHttpRequestProcessor(implicit inj: Injector) extends HttpRequestProcessor with HttpResponseWriter {

  val project = inject[Project]

  override def process(request: FullHttpRequest)(implicit context: ChannelHandlerContext): HttpResponse = {

    AeromockApi.fetchController(request.parsedRequest) match {
      case Some(controller) => controller.render(request.parsedRequest)
      case None => renderJson(createNotFound, HttpResponseStatus.NOT_FOUND)
    }
  }

  private def createNotFound: Map[String, Any] = {
    Map(
      "status" -> HttpResponseStatus.NOT_FOUND.code(),
      "message" -> "endpoint not found.")
  }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy