Reputation: 179
I'm using playframework 2.2.0 with Java. How can I return Not Modified from my controller actions?
There are several methods in the Controller superClass: ok(), noContent() etc, but not notModified().
Looking at the source code for play I can see:
val NotModified = SimpleResult(header = ResponseHeader(NOT_MODIFIED), body = Enumerator.empty,
connection = HttpConnection.KeepAlive)
in play.api.mvc.Results. But how do I wrap a SimpleResult in something which can be returned by Java controller?
the method wants to return a Result:
public interface Result {
scala.concurrent.Future<play.api.mvc.SimpleResult> getWrappedResult();
}
but I don't know how to generate a Future from Java. (I tried with scala.concurrent.Future$.MODULE$... but it's not visible to my java code)
Upvotes: 1
Views: 542
Reputation: 4500
Instead of something like ok(), try this:
return status(304, "Content not modified, dude.");
Reference: http://www.playframework.com/documentation/2.2.0/JavaActions
It looks like play.api.mvc.Results, in the Scala API, actually has a NotModified generator, but the Java API does not. You can't use anything from the Scala API if you're going with the Java API. Seems like the Java API is the Play Framework's unloved child.
In summary, returning status 304 is much simpler than trying to drag in components from the Play Scala API and use them from Java. HTTP response code 304 = Content Not Modified.
See the list of codes here: http://www.w3.org/Protocols/HTTP/HTRESP.html
Upvotes: 1