[ https://issues.apache.org/jira/browse/PIO-31?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16642817#comment-16642817 ]
ASF GitHub Bot commented on PIO-31: ----------------------------------- shimamoto commented on a change in pull request #474: [PIO-31] Move from spray to akka-http URL: https://github.com/apache/predictionio/pull/474#discussion_r223553781 ########## File path: data/src/main/scala/org/apache/predictionio/data/api/Common.scala ########## @@ -15,68 +15,59 @@ * limitations under the License. */ - package org.apache.predictionio.data.api -import org.apache.predictionio.data.webhooks.ConnectorException +import akka.http.scaladsl.server._ import org.apache.predictionio.data.storage.StorageException - -import spray.routing._ -import spray.routing.Directives._ -import spray.routing.Rejection -import spray.http.StatusCodes -import spray.httpx.Json4sSupport - -import org.json4s.Formats -import org.json4s.DefaultFormats +import org.apache.predictionio.data.webhooks.ConnectorException +import org.json4s.{DefaultFormats, Formats} +import akka.http.scaladsl.model._ +import akka.http.scaladsl.server.Directives._ +import org.apache.predictionio.akkahttpjson4s.Json4sSupport._ object Common { - object Json4sProtocol extends Json4sSupport { + object Json4sProtocol { + implicit val serialization = org.json4s.native.Serialization implicit def json4sFormats: Formats = DefaultFormats } import Json4sProtocol._ - val rejectionHandler = RejectionHandler { - case MalformedRequestContentRejection(msg, _) :: _ => + val exceptionHandler = ExceptionHandler { + case e: ConnectorException => { + complete(StatusCodes.BadRequest, Map("message" -> s"${e.getMessage()}")) + } + case e: StorageException => { + complete(StatusCodes.InternalServerError, Map("message" -> s"${e.getMessage()}")) + } + case e: Exception => { + complete(StatusCodes.InternalServerError, Map("message" -> s"${e.getMessage()}")) + } + } + + val rejectionHandler = RejectionHandler.newBuilder().handle { + case MalformedRequestContentRejection(msg, _) => complete(StatusCodes.BadRequest, Map("message" -> msg)) - case MissingQueryParamRejection(msg) :: _ => + + case MissingQueryParamRejection(msg) => complete(StatusCodes.NotFound, Map("message" -> s"missing required query parameter ${msg}.")) - case AuthenticationFailedRejection(cause, challengeHeaders) :: _ => { + + case AuthenticationFailedRejection(cause, challengeHeaders) => { val msg = cause match { case AuthenticationFailedRejection.CredentialsRejected => "Invalid accessKey." case AuthenticationFailedRejection.CredentialsMissing => "Missing accessKey." } - complete(StatusCodes.Unauthorized, challengeHeaders, Map("message" -> msg)) - } - case ChannelRejection(msg) :: _ => + // TODO complete(StatusCodes.Unauthorized, challengeHeaders, Map("message" -> msg)) Review comment: unused? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Move from spray to akka-http in servers > --------------------------------------- > > Key: PIO-31 > URL: https://issues.apache.org/jira/browse/PIO-31 > Project: PredictionIO > Issue Type: Improvement > Components: Core > Reporter: Marcin ZiemiĆski > Assignee: Naoki Takezoe > Priority: Major > Labels: gsoc2017, newbie > > On account of the death of spray for http and it being reborn as akka-http we > should update EventServer and Dashbord. It should be fairly simple, as > described in the following guide: > http://doc.akka.io/docs/akka/2.4/scala/http/migration-from-spray.html -- This message was sent by Atlassian JIRA (v7.6.3#76005)