Play will mysteriously will not compile. Anything in it is not recognized and causing a lot of grief. Akka isn't either and I downloaded 4.7.x I believe and put in in the lib directory

321 views
Skip to first unread message

Marc Lisevich

unread,
Apr 12, 2017, 4:58:09 PM4/12/17
to Play Framework
Put a lot of effort into it, tried to pay for a license from Lightbend, but was told there licence was for larger clientelle, and was told it was free software, so I cannot understand why?

Please help.

As mentioned before with them

I submitted my setup to them and they graciously investigated a l little but I did not hear back on this so I am assuming nothing is wrong 
Java 8 Play Framework 

Here is my setup build.sbt
// The Play pluginaddSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.5.14")// sbt-paradox, used for documentationaddSbtPlugin("com.lightbend.paradox" % "sbt-paradox" % "0.2.1")// Load testing tool:// http://gatling.io/docs/2.2.2/extensions/sbt_plugin.htmladdSbtPlugin("io.gatling" % "gatling-sbt" % "2.2.0")// Scala formatting: "sbt scalafmt"// https://olafurpg.github.io/scalafmtaddSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.3.1")
my project.sbt

import sbt.Keys._lazy val GatlingTest = config("gatling") extend TestscalaVersion := "2.11.8"libraryDependencies += "com.netaporter" %% "scala-uri" % "0.4.14"libraryDependencies += "net.codingwell" %% "scala-guice" % "4.1.0"libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "2.0.0" % TestlibraryDependencies += "io.gatling.highcharts" % "gatling-charts-highcharts" % "2.2.2" % TestlibraryDependencies += "io.gatling" % "gatling-test-framework" % "2.2.2" % TestlibraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.4.17"

Could someone kindly take time to ask me some questions as to why I am getting errors i.e. totally baffling me,




File Edit Options Buffers Tools Help package controllersimport Http.Requestimport play.api.libs.ws._import javax.inject._import play.api.libs.json.JsObjectimport play.api.libs.jsonimport java.util.UUIDimport akka.io._import play.api._import play.api.mvc._import util.OAuth2object SimpleAction extends ActionBuilder[Request] {def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = {block(request)}}



error] /home/cybronerd/TheRealStoreBuilder/storebuilder/ancient/scalatree/storebuilder/app/AuthFilter.scala:5: object Actor is not a member of package akka.io[error] import akka.io.Actor[error] ^[error] /home/cybronerd/TheRealStoreBuilder/storebuilder/ancient/scalatree/storebuilder/app/AuthFilter.scala:15: not found: type Request[error] case class Authenticate[A](request: Request[A])

Dominik Dorn

unread,
Apr 12, 2017, 5:05:40 PM4/12/17
to play-framework
Hi Marc,

unfortunately, your code got completely messed up in the email. 
If you could create a small github project with the setup you created, we can take a look. 



--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/99f1ffd4-3e46-49b5-b524-14433f1c546d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Dominik Dorn
http://dominikdorn.com
http://twitter.com/domdorn

Skripten, Mitschriften, Lernunterlagen, etc. findest Du auf http://www.studyguru.eu !

Greg Methvin

unread,
Apr 12, 2017, 5:54:37 PM4/12/17
to play-framework
Hi Marc,

Play and Akka are open source, released under the Apache 2 License. Lightbend offers support for those libraries, but we also provide help to other developers in the community when we can. A Lightbend subscription is typically only needed if you want support with guaranteed response times, for your production application. It seems you are an individual developer just getting started with Play, so a support subscription would not be worth it to you.

A few things about your questions:
 - You should only need to use the lib directory if you have dependencies not available through public maven or ivy repositories. In the case of Akka, Play already has a dependency on Akka so you don't even need to add the dependency manually.
 - I don't see the code for AuthFilter, which is where the compilation error seems to be occurring. I think the class you want is akka.actor.Actor.
 - The addSbtPlugin lines should be in project/plugins.sbt not in build.sbt. Your libraryDependencies and project settings should be in build.sbt. Are you using any of our starter projects or seed templates listed on the download page?

As Dominik said, it would help to have a sample project we could look at if you want more detailed help.

--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/99f1ffd4-3e46-49b5-b524-14433f1c546d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Greg Methvin
Tech Lead - Play Framework

Marc Lisevich

unread,
Apr 12, 2017, 9:48:35 PM4/12/17
to Play Framework
You are right. I need some help especially for Oauth2, And let me tell you, I have increased what I have done by a factor of 4 in terms of time using your framework. My problem is that I am always changing things so I can make it easier in the future (I kind of irony) but I have settled on Play and the more recent version, I am mixing what I found in your starter page with code I found elsewhere. You know Scala isn't even supposed to be on Google Cloud but I got it working except for the filter before using just Action { request => .... } I will post the code. and thanks for inviting me to your group I hope the other newbies to Play will learn to.
  Virtually nothing is being recognized in AuthFilter is where the errors are. I have an incredible amount to learn and learned tons so far, and I am basically trying to get Oauth2 working, the problem with that is in order to test it I have to have the code working! So much learning that I hired someone to do the html/ and UI part of the code. So maybe I have a conceptual problem too.  From what I have learned so far, a route sends the appropriate request depends on the particular GET request. When you first are trying to connect using the method that is best for me using Oauth2, you are initially sent a URI with an address with various parameters. So what I thought you would do, is modify the routes file, send it to a controller and then using something like andThen to handle the pattern of requests and callbacks and token exchanges etc. 
   So I am wondering...what is the purpose of the filter in Authorization. Is using a controller appropriate, or do I use a Filter or both? From what I have read, a Filter is called after every request, so it might be used to say refresh a token, but I am also wondering what is the purpose of a Filter in general, it is called after, so can it insert headers and footers and the like? If it could that would save time.
  So before I go ahead and post what I have for AuthFilter I will post Auth.scala the controller. I got this to compile or so I think, once you have many errors like that and you try again a new one could appear.
I am using just one instance on my servers right now, but after I get it working I will switch to akka so it is distributed.

Sorry for the formatting, I have to get the proper emacs .el file loaded, another thing I have to learn. I have Intellij too but can't use it to run or compile anything, but that is a completely another story involving CSIS. You wouldn't believe me if I told you.

package controllersimport scala.concurrent.Futureimport Http.Requestimport play.api.libs.ws._import javax.inject._import play.api.libs.json.JsObjectimport play.api.libs.jsonimport java.util.UUIDimport akka.io._import play.api._import play.api.mvc._import util.OAuth2object SimpleAction extends ActionBuilder[Request] {def invokeBlock[A](request: Request[A], block: (Request[A]) => Future[Result]) = {block(request)}}/*case class AuthenticationResult(valid: Boolean, user: Option[JsObject] = None)case class Oauth2AuthResult(valid: Boolean, user: Option[JsObJect] ) extends AuthenticationResultclass Authenticator extends Actor {def receive = {case Authenticate(request) =>if(request.headers.get("Authorization").isDefined)sender ! AuthenticationResult(valid = true, user = Json.obj())elsesender ! AuthenticationResult(valid = false)}}trait AuthenticatedRequest[+A] extends Request[A] {val user: Option[JsObject]}


object AuthenticatedRequest {def apply[A](u: Option[JsObject], r: Request[A]) = new AuthenticatedRequest[A] {<< def id = r.iddef tags = r.tagsdef uri = r.uridef path = r.pathdef method = r.methoddef version = r.versiondef queryString = r.queryStringdef headers = r.headerslazy val remoteAddress = r.remoteAddressdef username = Noneval body = r.bodyval user = u}}*//*class Authenticator extends Actor {def receive = {case Authenticate(request) => {if(request.headers.get("Authorization").isDefined)sender ! AuthenticationResult(valid = true, user = Json.obj())elsesender ! AuthenticationResult(valid = false)}}*/



class Auth @Inject() {// later akka extends Actor {def authorize = SimpleAction { implicit request =>val oauth2 = new OAuth2(Play.current)val callbackUrl = util.routes.OAuth2.callback(Some("store-builder"), Some("Authorized").absoluteURL())val scope = "build-store" // request store builder accessval state = UUID.randomUUID().toString // random confirmation stringval redirectUrl = oauth2.getAuthorizationUrl(callbackUrl, scope, state)Ok(views.html.index(redirectUrl)) // Just want to see what it iswithSession("oauth-state" -> state)}/*def receive = {case Authenticate(request) =>if(request.headers.get("Authorization").isDefined)sender ! AuthenticationResult(valid = true, user = Json.obj())elsesender ! AuthenticationResult(valid = false)}*/}

So that is the reason and you caught it... I was using import akka.io.Actor
 and now my errors are down to six  don't really know wher they are coming from..


[error] /home/cybronerd/TheRealStoreBuilder/storebuilder/ancient/scalatree/storebuilder/app/AuthFilter.scala:15: Authenticate is already defined as case class Authenticate[error] case class Authenticate[A](request: Request[A])[error] ^[error] /home/cybronerd/TheRealStoreBuilder/storebuilder/ancient/scalatree/storebuilder/app/AuthFilter.scala:16: AuthenticationResult is already defined as case class AuthenticationResult[error] case class AuthenticationResult(valid: Boolean, user: Option[JsObject] = None)[error] ^[error] /home/cybronerd/TheRealStoreBuilder/storebuilder/ancient/scalatree/storebuilder/app/AuthFilter.scala:19: Authenticator is already defined as class Authenticator[error] class Authenticator extends Actor {[error] ^[error] /home/cybronerd/TheRealStoreBuilder/storebuilder/ancient/scalatree/storebuilder/app/AuthFilter.scala:29: AuthenticatedRequest is already defined as trait AuthenticatedRequest[error] trait AuthenticatedRequest[+A] extends Request[A] {[error] ^[error] /home/cybronerd/TheRealStoreBuilder/storebuilder/ancient/scalatree/storebuilder/app/AuthFilter.scala:34: AuthenticatedRequest is already defined as object AuthenticatedRequest[error] object AuthenticatedRequest {[error] ^[error] /home/cybronerd/TheRealStoreBuilder/storebuilder/ancient/scalatree/storebuilder/app/AuthFilter.scala:51: Authfilter is already defined as class Authfilter[error] class Authfilter @Inject() { // extends Actor {[error] ^[error] 6 errors found[error] (root/compile:compileIncremental) Compilation failed[error] Total time: 4 s, completed Apr 13, 2017 1:43:43 AM

import javax.inject.Injectimport play.api.mvc.{Result, RequestHeader, Filter}import scala.concurrent.Futureimport play.api.http.DefaultHttpFiltersimport akka.akka.Actorimport play.api.libs.json.JsObject/*** Add the following filters by default to all projects** https://www.playframework.com/documentation/latest/ScalaCsrf* https://www.playframework.com/documentation/latest/AllowedHostsFilter* https://www.playframework.com/documentation/latest/SecurityHeaders*/case class Authenticate[A](request: Request[A])case class AuthenticationResult(valid: Boolean, user: Option[JsObject] = None)class Authenticator extends Actor {def receive = {case Authenticate(request) =>if(request.headers.get("Authorization").isDefined)sender ! AuthenticationResult(valid = true, user = Json.obj())elsesender ! AuthenticationResult(valid = false)}}trait AuthenticatedRequest[+A] extends Request[A] {val user: Option[JsObject]}


object AuthenticatedRequest {def apply[A](u: Option[JsObject], r: Request[A]) = new AuthenticatedRequest[A] {def id = r.iddef tags = r.tagsdef uri = r.uridef path = r.pathdef method = r.methoddef version = r.versiondef queryString = r.queryStringdef headers = r.headerslazy val remoteAddress = r.remoteAddressdef username = Noneval body = r.bodyval user = u}}


class Authfilter @Inject() { // extends Actor {object Authenticated extends ActionBuilder[Request] {def invokeBlock[A](request: Request[A], block: (AuthenticatedRequest[A]) => Future[SimpleResult]) = {(authenticationActor ask Authenticate(request)).mapTo[AuthenticationResult] flatMap { result =>if(result.valid)block(AuthenticatedRequest[A](Some(result.user.get), request))elseblock(AuthenticatedRequest[A](None, request))} recover {case e => Results.Status(Status.INTERNAL_SERVER_ERROR)}}}def receive = {case Authenticate(request) =>if(request.headers.get("Authorization").isDefined)sender ! AuthenticationResult(valid = true, user = Json.obj())elsesender ! AuthenticationResult(valid = false)}}
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.

Marc Lisevich

unread,
Apr 12, 2017, 9:53:07 PM4/12/17
to Play Framework
And sorry, every time I post code, it undoes the formatting I will try another method like copying it into a local editor where the scala emacs formatting is setup properly and then post it here.

Marc Lisevich

unread,
Apr 12, 2017, 9:55:29 PM4/12/17
to Play Framework
Ok I have a GitHub account will post the link shortly since it is just starting up and revealing the code won't hurt.


On Wednesday, April 12, 2017 at 2:58:09 PM UTC-6, Marc Lisevich wrote:

Marc Lisevich

unread,
Apr 12, 2017, 11:33:27 PM4/12/17
to Play Framework
Ok you will see what I mean by changing my setup, and probably chuckle, when you see the number of changes in my google repo that I am posting here on github



On Wednesday, April 12, 2017 at 2:58:09 PM UTC-6, Marc Lisevich wrote:

Marc Lisevich

unread,
Apr 14, 2017, 3:20:25 AM4/14/17
to Play Framework
Bump. Ok, I removed AuthFilter.scala and just to see if the errors popped up in the project and guess what like I said even Http.Request is not recognized and from this simple file I have 24 errors all relating to imports not being found and I think my questions would be good for newbies starting out here.  I I am still kind of baffled as to what the problem is, I simple reply about what filters are for and maybe  a quick look would be appreciated.

From your site.

The filter API is intended for cross cutting concerns that are applied indiscriminately to all routes. For example, here are some common use cases for filters:

  • Logging/metrics collection
I don't  really need these right now, but when I successfully did compile and run and loaded a page and then telnet'd into it to test, the GET Request was satisfied, but I got an error message saying that I didn't have a filter and the server gave an error and on my console I got that error, but that was back in the good old days when I could get it to compile.


BTW what is the average response time here, I guess I will know when there is one or else I will simply repost.

Marc Lisevich

unread,
Apr 14, 2017, 3:23:24 AM4/14/17
to Play Framework
I just need a kick to get going then I can take it from there.


On Wednesday, April 12, 2017 at 2:58:09 PM UTC-6, Marc Lisevich wrote:

Marc Lisevich

unread,
Apr 14, 2017, 3:47:22 AM4/14/17
to Play Framework
Should I somehow put the play dependencies in the build.sbt file then the p


On Wednesday, April 12, 2017 at 3:54:37 PM UTC-6, Greg Methvin wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.

Marc Lisevich

unread,
Apr 14, 2017, 3:49:38 AM4/14/17
to Play Framework
I am going to go back to using simple Action { request= > } instead of Action builder because I download the simple sample app and it compiles and runs. Will quickly modify code and see if iI can get it  to work again


On Wednesday, April 12, 2017 at 3:54:37 PM UTC-6, Greg Methvin wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.

Marc Lisevich

unread,
Apr 14, 2017, 5:13:07 AM4/14/17
to Play Framework
Update. Something was messed up. Basically deleted project in one server  committed and pushed,  downloaded the sample outh2 app from Play Framework page, copied old repo code from servers using text editor and then compiled 4 errors and a believe I can get it working soon, but have to got to bed, thanks for the pointer. I have not updated the GitHub account code posted, but I have it on my google repos. Should be fine thanks for inviting me to this group.


On Wednesday, April 12, 2017 at 2:58:09 PM UTC-6, Marc Lisevich wrote:

Dominik Dorn

unread,
Apr 14, 2017, 6:12:41 AM4/14/17
to play-framework
Hi Marc,

I took a look at the uploaded code.. it is a little confusing/messy to me.. its not really clear what is your current code and what are old artefacts, local IDE configuration files, etc.. 

I suggest you start from one of the starter examples
 - https://github.com/playframework/play-java-starter-example   or
 - https://github.com/playframework/play-scala-starter-example

clone/download the repo, start the application, make sure that it runs and works (open http://localhost:9000 ) and then incrementally make changes to it, 
always verifying that it still works after your change. I also suggest to adjust the .gitignore file to prevent stuff like .DS_Store, .idea, .gradle, target/ or .g8 to be added to source-control. 

Choose either Java or Scala and stick to it, at least while learning. 

For editing/coding: My personal preference is to use IntelliJ Idea (I have Ultimate, you may get a free license from a local JUG or use a evaluation one or a early access preview) - 
it has great support for scala, sbt and even play-specific stuff and will show you a lot of potential errors right while you code and makes sure you have the right imports. 

From the logs you posted, it looks like some of your imports are wrong.. e.g. "Actor" is in package "akka.actor" not "akka.io" or "akka.akka". You also need to take care to don't specify classes multiple times -
e.g. just because you can put multiple classes into one file in scala, does not mean that they are isolated from classes in another file. If you have two scala-files in app/controllers/ and both have a class X in them, 
you will run into problems. A good practice is to put classes into their own files, like its done in Java.. that way you'll spot problems right from the beginning.
Also try to put classes in at least one package (so not directly under /app/ which would be the root package). 


Also, when starting, maybe start with the easy stuff.. create controllers + actions, but leave Filters, ActionBuilders, RequestHandler and ErrorHandlers out until up to the point where your application
is working like it should and you can use those things to make it more fancy.

I hope this helps you get on the right track! Would be great to see a updated version of your app soon!

Cheers,
Dominik


--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/b274d273-d8a9-40b0-9cc8-e28302d4bcdc%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages