I'm trying to create a log filter, base on Play documentation but i can't figure out what is going on.
I got thios error message :
Unexpected exception ProvisionException: Unable to provision, see the following errors:
1) Error injecting constructor, java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lplay.mvc.EssentialFilter; at Filters.(Filters.scala:11) while locating Filters while locating play.http.HttpFilters for parameter 0 at play.api.http.JavaHttpFiltersAdapter.(HttpFilters.scala:63)
while locating play.api.http.JavaHttpFiltersAdapter while locating play.api.http.HttpFilters for parameter 3 at play.api.http.JavaCompatibleHttpRequestHandler.(HttpRequestHandler.scala:200) while locating play.api.http.JavaCompatibleHttpRequestHandler while locating play.api.http.HttpRequestHandler for parameter 4 at play.api.DefaultApplication.(Application.scala:221) at play.api.DefaultApplication.class(Application.scala:221) while locating play.api.DefaultApplication while locating play.api.Application1 error
But my LoggingFilter extends EssentialFilter (I copied the documentation code). Do I need to bind something for Guice ?
Here my built.sbt:
name := """abc"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.8"
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
filters,
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test,
"org.webjars" %% "webjars-play" % "2.5.0",
"org.webjars" % "react" % "0.13.1"
)
resolvers += "scalaz-bintray" at "http://dl.bintray.com/scalaz/releases"
routesGenerator := InjectedRoutesGenerator
Here my plugins.sbt :
// The Typesafe repository
resolvers += "Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/"
// Eclpise Plugin
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.4")
// web plugins
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")
addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")
addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")
addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.2")
// transform JSX assets to js
addSbtPlugin("com.github.ddispaltro" % "sbt-reactjs" % "0.5.0")
It looks like this is a bug in the DefaultHttpFilters class's constructor. The error is present in 2.5.4 and will be fixed in the 2.5.5 milestone which is not yet available and does not have a due date. I would like a workaround for this as well.
Url to the issue: https://github.com/playframework/playframework/pull/6238
I don't know if this will help any of you with this problem. But I did get my CORSFilter to work. (Play 2.5.4)
import com.google.inject.Inject;
import play.http.HttpFilters;
import play.mvc.EssentialAction;
import play.mvc.EssentialFilter;
import play.filters.cors.CORSFilter;
public class MyFilters extends EssentialFilter implements HttpFilters {
@Inject
private CORSFilter corsFilter;
@Override
public EssentialAction apply(EssentialAction next) {
return corsFilter.asJava().apply(next);
}
@Override
public EssentialFilter[] filters() {
EssentialFilter[] result = new EssentialFilter[1];
result[0] = this;
return result;
}
}
Also added this into the application.conf
play.filters.cors{
# allow all paths
pathPrefixes = ["/"]
# allow all origins
allowedOrigins = null
allowedHttpMethods = ["GET", "POST", "PUT", "DELETE"]
# allow all headers
allowedHttpHeaders = null
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With