jdegoes/blueeyes — Issue #29: HTTP POST fails
Author: mslinn
Created: 2011-10-22 19:46:57+00:00
State: open

Given this CURL POST:

curl -sSv --header Content-Type:application/json --data-urlencode 'document=Of course you realize that this means war' http://localhost:8585/json/blah/78e68fde-3995-4a35-bdc7-8746c6a2e47b

I get the following error message:

````
ERR [20111022-12:40:39.053] blueeyes: Error handling request
ERR [20111022-12:40:39.053] blueeyes: blueeyes.json.JsonParser$ParseException: Data is too big, use big data handler. If "aggregate" combinator is used then probably Json is broken.
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.data.BijectionsChunkJson$$anon$1.unapply(BijectionsChunkJson.scala:23)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.data.BijectionsChunkJson$$anon$1.unapply(BijectionsChunkJson.scala:11)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.data.Bijection$$anon$1.apply(Bijection.scala:20)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpRequestHandlerCombinators$$anon$10$$anonfun$apply$10.apply(HttpRequestHandlerCombinators.scala:347)
ERR [20111022-12:40:39.053] blueeyes: at scala.Option.map(Option.scala:133)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpRequestHandlerCombinators$$anon$10.apply(HttpRequestHandlerCombinators.scala:347)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpRequestHandlerCombinators$$anon$10.apply(HttpRequestHandlerCombinators.scala:331)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpRequestHandlerCombinators$$anonfun$path$1$$anon$1.apply(HttpRequestHandlerCombinators.scala:36)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpRequestHandlerCombinators$$anonfun$path$1$$anon$1.apply(HttpRequestHandlerCombinators.scala:28)
ERR [20111022-12:40:39.053] blueeyes: at scala.PartialFunction$$anon$1.apply(PartialFunction.scala:46)
ERR [20111022-12:40:39.053] blueeyes: at scala.PartialFunction$$anon$1.apply(PartialFunction.scala:45)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpServer$class.apply(HttpServer.scala:68)
ERR [20111022-12:40:39.053] blueeyes: at net.interdoodle.hbe.AppServer$.apply(AppServer.scala:7)
ERR [20111022-12:40:39.053] blueeyes: at net.interdoodle.hbe.AppServer$.apply(AppServer.scala:7)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.engines.NettyRequestHandler.messageReceived(NettyRequestHandler.scala:43)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:545)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:754)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:302)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.engines.NettyChunkedRequestHandler$$anonfun$messageReceived$1.apply(NettyChunkedRequestHandler.scala:58)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.engines.NettyChunkedRequestHandler$$anonfun$messageReceived$1.apply(NettyChunkedRequestHandler.scala:43)
ERR [20111022-12:40:39.053] blueeyes: at scala.Option.foreach(Option.scala:197)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.engines.NettyChunkedRequestHandler.messageReceived(NettyChunkedRequestHandler.scala:43)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:545)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:754)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.handler.stream.ChunkedWriteHandler.handleUpstream(ChunkedWriteHandler.java:148)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:545)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:754)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:302)
ERR [20111022-12:40:39.053] blueeyes: (...more...)
ERR [20111022-12:40:39.053] blueeyes: Caused by blueeyes.json.JsonParser$ParseException: unknown token d
Near: document=Of%20course%
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.json.JsonParser$Parser.fail(JsonParser.scala:230)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.json.JsonParser$Parser.nextToken(JsonParser.scala:325)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.json.JsonParser$$anonfun$4.apply(JsonParser.scala:188)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.json.JsonParser$$anonfun$4.apply(JsonParser.scala:142)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.json.JsonParser$.parse(JsonParser.scala:75)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.json.JsonParser$.parse(JsonParser.scala:51)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.data.BijectionsChunkJson$$anon$1.unapply(BijectionsChunkJson.scala:21)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.data.BijectionsChunkJson$$anon$1.unapply(BijectionsChunkJson.scala:11)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.data.Bijection$$anon$1.apply(Bijection.scala:20)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpRequestHandlerCombinators$$anon$10$$anonfun$apply$10.apply(HttpRequestHandlerCombinators.scala:347)
ERR [20111022-12:40:39.053] blueeyes: at scala.Option.map(Option.scala:133)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpRequestHandlerCombinators$$anon$10.apply(HttpRequestHandlerCombinators.scala:347)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpRequestHandlerCombinators$$anon$10.apply(HttpRequestHandlerCombinators.scala:331)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpRequestHandlerCombinators$$anonfun$path$1$$anon$1.apply(HttpRequestHandlerCombinators.scala:36)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpRequestHandlerCombinators$$anonfun$path$1$$anon$1.apply(HttpRequestHandlerCombinators.scala:28)
ERR [20111022-12:40:39.053] blueeyes: at scala.PartialFunction$$anon$1.apply(PartialFunction.scala:46)
ERR [20111022-12:40:39.053] blueeyes: at scala.PartialFunction$$anon$1.apply(PartialFunction.scala:45)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.HttpServer$class.apply(HttpServer.scala:68)
ERR [20111022-12:40:39.053] blueeyes: at net.interdoodle.hbe.AppServer$.apply(AppServer.scala:7)
ERR [20111022-12:40:39.053] blueeyes: at net.interdoodle.hbe.AppServer$.apply(AppServer.scala:7)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.engines.NettyRequestHandler.messageReceived(NettyRequestHandler.scala:43)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:545)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:754)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:302)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.engines.NettyChunkedRequestHandler$$anonfun$messageReceived$1.apply(NettyChunkedRequestHandler.scala:58)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.engines.NettyChunkedRequestHandler$$anonfun$messageReceived$1.apply(NettyChunkedRequestHandler.scala:43)
ERR [20111022-12:40:39.053] blueeyes: at scala.Option.foreach(Option.scala:197)
ERR [20111022-12:40:39.053] blueeyes: at blueeyes.core.service.engines.NettyChunkedRequestHandler.messageReceived(NettyChunkedRequestHandler.scala:43)
ERR [20111022-12:40:39.053] blueeyes: at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80)
ERR [20111022-12:40:39.053] blueeyes: (...more...)
````

from the following JsonService trait:

````
package net.interdoodle.hbe

import blueeyes._
import blueeyes.concurrent.Future
import blueeyes.core.data.{BijectionsChunkJson, BijectionsChunkString, ByteChunk}
import blueeyes.core.http.{HttpRequest, HttpResponse, HttpStatus}
import blueeyes.core.http.{HttpCookie, HttpDateTime}
import blueeyes.core.http.combinators.HttpRequestCombinators
import blueeyes.core.service.{HttpService, HttpServiceContext}
import blueeyes.json.JsonAST._
import net.interdoodle.hbe.domain.Hanuman
import scala.collection.mutable.HashMap
import java.util.UUID

trait HelloJsonServices extends BlueEyesServiceBuilder
with HttpRequestCombinators
with BijectionsChunkString
with BijectionsChunkJson {

val sessions = new HashMap[String, Some[Hanuman]]()

val helloJson: HttpService[ByteChunk] = service("helloJson", "0.1") {
requestLogging {
logging {
log =>
context: HttpServiceContext =>
request {
path("/json/") {
jvalue {
get {
requestParam:HttpRequest[JValue] =>
val json = JString("Hello World!")
val response = HttpResponse[JValue](content = Some(json))
log.info(response.toString())
Future.sync(response)
} ~
path('operation) {
get { request =>
val operation = request.parameters('operation)
if (operation=="newSession") {
val sessionID = UUID.randomUUID().toString
sessions += sessionID -> Some(null)
Future.sync(HttpResponse(
/*headers = HttpHeaders.Empty + sessionCookie(sessionID),*/
content = Some(sessionID)))
} else {
val msg = "The only operation that can be without a sessionID is newSession. You specified '" + operation + "'"
Future.sync(HttpResponse(status=HttpStatus(400, msg),
content = Some(msg)))
}
}
} ~
path('operation/'id) {
post { request =>
val operation = request.parameters('operation)
val sessionID = request.parameters('id)
val session = sessions.getOrElse(sessionID, None)
Future.sync(HttpResponse(
/*headers = HttpHeaders.Empty + sessionCookie(sessionID),*/
content = if (session==null)
Some("Session with ID " + sessionID + " does not exist")
else
Some("session ID=" + sessionID + "; operation: '" + operation + "'"))
)
}
} ~
path('operation/'id/'param) {
post { request =>
val operation = request.parameters('operation)
val sessionID = request.parameters('id)
val param = request.parameters('param)
val session = sessions.getOrElse(sessionID, None)
Future.sync(HttpResponse(
/*headers = HttpHeaders.Empty + sessionCookie(sessionID),*/
content = if (session==null)
Some("Session with ID " + sessionID + " does not exist")
else
Some("session ID=" + sessionID + "; operation: '" + operation + "'"))
)
}
}
}
}
}
}
}
}
}
````

The error does not manifest with an HTTP GET, when the service is modified for get instead of post.