Loading ...
Sorry, an error occurred while loading the content.

Re: [blueeyes-web] Problems with contentType combinator

Expand Messages
  • Noel Welsh
    I ve sent the fix as a pull request. Basically type inference was failing for the implicit bijections taken by the contentType combinator (buzzword bingo!) I
    Message 1 of 6 , Apr 22, 2013
    • 0 Attachment
      I've sent the fix as a pull request. Basically type inference was failing for the implicit bijections taken by the contentType combinator (buzzword bingo!) I don't particularly like bijections because of this reason -- they lead to very opaque error messages when they go wrong. They are removed in the 1.0 branch, which is currently in development.

      I also updated to Scala 2.9.3 and BE 0.6.1-SNAPSHOT.

      HTH,
      N.



      On Mon, Apr 22, 2013 at 2:21 PM, Daniel Yule <daniel.yule@...> wrote:
       

      HI Noel,

      I thought that I was making some obvious mistake that would be visible just from the code.  I made a github with the relevant code in it.  You can clone it at https://github.com/danielyule/newserver

      Thanks,
      -Daniel


      On Mon, Apr 22, 2013 at 8:55 AM, Noel Welsh <noelwelsh@...> wrote:
       

      Hi Daniel,

      It's not clear to me exactly what the problem is. Could you create a small Github repo showing the issue? This will make it much easier to diagnose and fix.

      Thanks,
      N.


      On Sun, Apr 21, 2013 at 1:50 PM, samwormie <daniel.yule@...> wrote:
       

      Hi,

      I have two problems currently with my very simple service, but I'll start with the more pressing. As of now, my service is only supposed to respond to requests of type application/json, and should only respond with data of type application/json, so I am using the contentType combinator to accomplish this. Here is the relevant part of my code:

      request { config: Unit =>

      path("/(.*)") {
      contentType(application/json) {
      get {
      (req: HttpRequest[Future[JValue]]) => {
      val jstring = JString("Hello World!")
      val jfield = JField("result", jstring)
      val jobject = JObject(jfield :: Nil)

      Future{HttpResponse[JValue](content = Some(jobject))}
      }
      }
      }

      }
      }

      I have been able to get this to work using the produces combinator, but I had to manually convert the JValue to a ByteChunk, and set the types of both the Request and response to be of type ByteChunk as well. I've tried it with various Bijections mixed in, and they don't seem to help (in fact, when following the suggestion in the book to include both the JSON and FutureJSON bijection, it causes an ambiguity error). I am sure there is something I don't understand here, as I am new to not only blue eyes, but to Scala.

      Can anyone point out where I am making my mistake?

      -Daniel




    • Daniel Yule
      Thanks Noel, It didn t occur to me that you could (or would want to) explicitly state the type of the contentType combinators. I very much appreciate your
      Message 2 of 6 , Apr 22, 2013
      • 0 Attachment
        Thanks Noel,

        It didn't occur to me that you could (or would want to) explicitly state the type of the contentType combinators.  I very much appreciate your assistance.  This gave me the information I needed to fix my other problems as well.

        Looking forward to 1.0!

        -Daniel


        On Mon, Apr 22, 2013 at 11:26 AM, Noel Welsh <noelwelsh@...> wrote:
         

        I've sent the fix as a pull request. Basically type inference was failing for the implicit bijections taken by the contentType combinator (buzzword bingo!) I don't particularly like bijections because of this reason -- they lead to very opaque error messages when they go wrong. They are removed in the 1.0 branch, which is currently in development.

        I also updated to Scala 2.9.3 and BE 0.6.1-SNAPSHOT.

        HTH,
        N.



        On Mon, Apr 22, 2013 at 2:21 PM, Daniel Yule <daniel.yule@...> wrote:
         

        HI Noel,

        I thought that I was making some obvious mistake that would be visible just from the code.  I made a github with the relevant code in it.  You can clone it at https://github.com/danielyule/newserver

        Thanks,
        -Daniel


        On Mon, Apr 22, 2013 at 8:55 AM, Noel Welsh <noelwelsh@...> wrote:
         

        Hi Daniel,

        It's not clear to me exactly what the problem is. Could you create a small Github repo showing the issue? This will make it much easier to diagnose and fix.

        Thanks,
        N.


        On Sun, Apr 21, 2013 at 1:50 PM, samwormie <daniel.yule@...> wrote:
         

        Hi,

        I have two problems currently with my very simple service, but I'll start with the more pressing. As of now, my service is only supposed to respond to requests of type application/json, and should only respond with data of type application/json, so I am using the contentType combinator to accomplish this. Here is the relevant part of my code:

        request { config: Unit =>

        path("/(.*)") {
        contentType(application/json) {
        get {
        (req: HttpRequest[Future[JValue]]) => {
        val jstring = JString("Hello World!")
        val jfield = JField("result", jstring)
        val jobject = JObject(jfield :: Nil)

        Future{HttpResponse[JValue](content = Some(jobject))}
        }
        }
        }

        }
        }

        I have been able to get this to work using the produces combinator, but I had to manually convert the JValue to a ByteChunk, and set the types of both the Request and response to be of type ByteChunk as well. I've tried it with various Bijections mixed in, and they don't seem to help (in fact, when following the suggestion in the book to include both the JSON and FutureJSON bijection, it causes an ambiguity error). I am sure there is something I don't understand here, as I am new to not only blue eyes, but to Scala.

        Can anyone point out where I am making my mistake?

        -Daniel





      • Kris Nuttycombe
        Actually, something that John and I have been discussing is that transcoding and header manipulation probably need to be separate, so these two functions have
        Message 3 of 6 , Apr 22, 2013
        • 0 Attachment
          Actually, something that John and I have been discussing is that transcoding and header manipulation probably need to be separate, so these two functions have been pulled apart on a WIP branch that I'm currently working on. Just a heads-up. I want to actually eliminate the bijections entirely; they were a bad idea originally, and remain problematic today.

          Kris
        Your message has been successfully submitted and would be delivered to recipients shortly.