@@ -58,7 +58,7 @@ class Server(handler: RequestHandler) extends HttpApp
5858 network()
5959 } ~
6060 path(" deploy" ) {
61- deployContainer()
61+ entity(as[ JsValue ]) { json => deployContainer(json.asJsObject)}
6262 } ~
6363 path(" count" ) {
6464 numberOfInstances()
@@ -419,36 +419,42 @@ class Server(handler: RequestHandler) extends HttpApp
419419 *
420420 * @return Server route that either maps to 202 ACCEPTED and the generated id of the instance, or the resp. error codes.
421421 */
422- def deployContainer (): server.Route = parameters( ' ComponentType .as[ String ], ' InstanceName .as[ String ]. ? ) { (compTypeString, name) =>
422+ def deployContainer (json : JsObject ): server.Route = {
423423 authenticateOAuth2[AccessToken ](" Secure Site" , AuthProvider .authenticateOAuthRequire(_, userType = UserType .Admin )) { token =>
424424 post {
425- if (name.isEmpty) {
426- log.debug(s " POST /instances/deploy?ComponentType= $compTypeString has been called " )
427- } else {
428- log.debug(s " POST /instances/deploy?ComponentType= $compTypeString&name= ${name.get} has been called " )
429- }
430- val compType : ComponentType = ComponentType .values.find(v => v.toString == compTypeString).orNull
431425
432- if (compType != null ) {
433- log.info(s " Trying to deploy container of type $compType" + (if (name.isDefined) {
434- s " with name ${name.get}... "
435- } else {
436- " ..."
437- }))
438- handler.handleDeploy(compType, name) match {
439- case Success (id) =>
440- complete {
441- HttpResponse (StatusCodes .Accepted , entity = id.toString)
442- }
443- case Failure (x) =>
444- complete {
445- HttpResponse (StatusCodes .InternalServerError , entity = s " Internal server error. Message: ${x.getMessage}" )
426+ log.debug(s " POST /instances/deploy has been called with data: $json" )
427+
428+ val name = Try (json.fields(" InstanceName" ).toString.replace(" \" " , " " )).toOption
429+
430+ Try (json.fields(" ComponentType" ).toString.replace(" \" " , " " )) match {
431+ case Success (compTypeString) =>
432+ val compType : ComponentType = ComponentType .values.find(v => v.toString == compTypeString).orNull
433+
434+ if (compType != null ) {
435+ log.info(s " Trying to deploy container of type $compType" + (if (name.isDefined) {
436+ s " with name ${name.get}... "
437+ } else {
438+ " ..."
439+ }))
440+ handler.handleDeploy(compType, name) match {
441+ case Success (id) =>
442+ complete {
443+ HttpResponse (StatusCodes .Accepted , entity = id.toString)
444+ }
445+ case Failure (x) =>
446+ complete {
447+ HttpResponse (StatusCodes .InternalServerError , entity = s " Internal server error. Message: ${x.getMessage}" )
448+ }
446449 }
447- }
448450
449- } else {
450- log.error(s " Failed to deserialize parameter string $compTypeString to ComponentType. " )
451- complete(HttpResponse (StatusCodes .BadRequest , entity = s " Could not deserialize parameter string $compTypeString to ComponentType " ))
451+ } else {
452+ log.error(s " Failed to deserialize parameter string $compTypeString to ComponentType. " )
453+ complete(HttpResponse (StatusCodes .BadRequest , entity = s " Could not deserialize parameter string $compTypeString to ComponentType " ))
454+ }
455+ case Failure (ex) =>
456+ log.warning(s " Failed to unmarshal parameters with message ${ex.getMessage}. Data: $json" )
457+ complete{HttpResponse (StatusCodes .BadRequest , entity = " Wrong data format supplied." )}
452458 }
453459 }
454460 }
@@ -890,7 +896,7 @@ class Server(handler: RequestHandler) extends HttpApp
890896 post {
891897 log.debug(s " POST /instances/ $id/label has been called with data $json. " )
892898
893- Try [String ](json.fields(" Label" ).toString) match {
899+ Try [String ](json.fields(" Label" ).toString.replace( " \" " , " " ) ) match {
894900 case Success (label) =>
895901 handler.handleAddLabel(id, label) match {
896902 case handler.OperationResult .IdUnknown =>
@@ -932,12 +938,12 @@ class Server(handler: RequestHandler) extends HttpApp
932938 case Failure (_) => None
933939 }
934940
935- val user = Try (json.fields(" User" ).toString) match {
941+ val user = Try (json.fields(" User" ).toString.replace( " \" " , " " ) ) match {
936942 case Success (res) => Some (res)
937943 case Failure (_) => None
938944 }
939945
940- Try (json.fields(" Command" ).toString) match {
946+ Try (json.fields(" Command" ).toString.replace( " \" " , " " ) ) match {
941947 case Success (command) =>
942948 handler.handleCommand(id, command, None , None , None , None , privileged, None , user) match {
943949 case handler.OperationResult .IdUnknown =>
0 commit comments