Giter VIP home page Giter VIP logo

Comments (8)

brikis98 avatar brikis98 commented on June 5, 2024

This Java adapter in this project is a quick example - it's not robust and does not do any error handling. It's very possible that it won't handle exceptions thrown while the enumerator is generating chunks. Do you have a simple example to repro?

It's worth noting that once you've started to stream a response and have sent out the headers, it's too late to send a 500 error. You'd have to catch the error, log it, and inject something into the body of the output stream to indicate an error. I don't have time to try it now, but the onComplete method has a parameter I'm ignoring which will contain either a Success or Error object; try to check that object and see if it has the info you need.

from ping-play.

matiwinnetou avatar matiwinnetou commented on June 5, 2024

Thanks Jim, your hint helped me a great deal, now I will test with some thing like:

def toChunks(): Chunks[Html] = {
val utf8 = Codec.javaSupported("utf-8")

new Chunks[Html](Writeable.writeableOf_Content(utf8, ContentTypeOf.contentTypeOf_Html(utf8))) {
  def onReady(out: Out[Html]) {
    val htmlF = enumerator.run(Iteratee.foreach { html =>
      if (!html.toString.isEmpty) {
        out.write(html)
      }
    })
    htmlF onComplete {
      case Success(html) => out.close()
      case Failure(t) => {
        Logger.error("Unable to handle request", t);
        out.close() }
    }
  }
}

}

That is most basic, at least it will log the problem (logback) but page is still going to be empty, next step I am going to try once this works is like you said to inject this into a stream but I guess it makes only sense in developer mode? Thanks for tips about 5xx vs 2xx, in fact that is the whole idea that we cannot change the response code in case of chunking but that was not my aim, my aim was to log this to a logback logger.

from ping-play.

matiwinnetou avatar matiwinnetou commented on June 5, 2024

By the way can you give me your email because I wanted to ask you about Play at LinkedIn, how many teams run Java version, how many Scala, and a maybe one or more question like this, if this is ok. I am trying to evangelize Play (where it makes sense) this for one of eBay spin offs in Germany so this may help me a great deal.

from ping-play.

brikis98 avatar brikis98 commented on June 5, 2024

next step I am going to try once this works is like you said to inject this into a stream but I guess it makes only sense in developer mode

Not necessarily. For example, if you're streaming HTML, you may inject some JavaScript into the stream to redirect the user to an error page:

<script>
  window.location = '/error?message=oops'
</script>

from ping-play.

brikis98 avatar brikis98 commented on June 5, 2024

By the way can you give me your email because I wanted to ask you about Play at LinkedIn, how many teams run Java version, how many Scala, and a maybe one or more question like this, if this is ok. I am trying to evangelize Play (where it makes sense) this for one of eBay spin offs in Germany so this may help me a great deal.

My email is my github username at gmail.com. That said, two important items:

  1. I've written quite a bit about LinkedIn's usage of Play: e.g. In which ways do you use the play framework in your company?, What are the pros and cons of the Play Framework 2, for a Java developer?, What are the pros and cons of Play Framework 2, for a Scala developer?, The Play Framework at LinkedIn.
  2. I recently left LinkedIn, so my info will be a bit out of date.

from ping-play.

matiwinnetou avatar matiwinnetou commented on June 5, 2024

Thanks Jim, I read most of them. I wanted to know if teams at LinkedIn really use Java version. I had a discussion here locally and the first site we did is Play Java but I am hearing voice of one guy that it doesn't mix well, in such case he is advising to go with Play Scala to be fully idiomatic in this world. What percentage out of your head teams are using java vs scala version of Play? What is the ratio I mean.

from ping-play.

brikis98 avatar brikis98 commented on June 5, 2024

It was roughly 50/50 when I left. LinkedIn was traditionally a Java shop, so much of the earlier usage was Java. However, the trend was gradually moving towards more and more scala usage.

If you have the option to use the Scala version, do it. It is the "idiomatic" version, has access to all of the Play APIs, and my personal opinion is that it's a better language overall. That said, the Java version is still very usable and a decent starting point for teams that don't have the time to invest in learning Scala.

from ping-play.

matiwinnetou avatar matiwinnetou commented on June 5, 2024

At the moment I don't have much choice, Java 8 and Play is crazy enough for our company here in Berlin. Gradually I would like to push Scala but it will take time if it even succeeds, step by step approach.

from ping-play.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.