Comments (8)
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.
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.
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.
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.
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:
- 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.
- I recently left LinkedIn, so my info will be a bit out of date.
from ping-play.
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.
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.
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)
- Invalid chunked response (play 2.3) HOT 3
- Update to Play 2.4.x with InjectedRoutesGenerator HOT 1
- Java examples no longer work HOT 3
- Docker image fails to build HOT 1
- Extension with HTMLCompressorFilter and GzipFilter HOT 3
- Killing open, not yet retuned Promises at the end of Controller. HOT 2
- Publish artifacts automatically as part of the build instead of manually
- Finish the "Composable Pagelets" implementation and documentation HOT 5
- Add support for pagelet priorities
- Add support for only rendering content that is visible
- Add support for specifying pagelet dependencies
- Add monitoring hooks
- Turn the sample apps into Typesafe Activator templates HOT 2
- Escaping not working HOT 9
- Use html tag / content in a stream template HOT 9
- install ping-play HOT 5
- get /sample-app-common/src/main/scala/data in Java ? HOT 18
- upgrade to play 2.5 HOT 4
- Library is not compatible with Play 2.3-RC1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ping-play.