Play Framework Public Assets "WEB Handler Not Found" - java

The first route below works, but the second doesn't. I want to serve a onepage angular/sockets app from my /public directory, but when I try via 2 below, I get a "WEB Handler Not Found error.
1/
GET /assets/*file controllers.cm_admin.Assets.versioned(path="/public", file: Asset)
2/
GET /*file controllers.cm_admin.Assets.versioned(path="/public", file: Asset)

Just worked it out.
I had the following statement in my app/Global:
case 'admin' => admin.Routes.routes.lift(request)
and changed it to:
case _ => admin.Routes.routes.lift(request)

Related

How to set JsonTemplateLayout eventTemplateUri outside of classpath in Log4j2

In Log4j2's JsonTemplateLayout, I have no problem using eventTemplateUri: "classpath:LayoutTemplate.jsson" with json file located in rc/main/resources.
However, I would need to keep this file outside of class path. so I would like to use file location something like he way we add log fileName: c:\...
But it's throwing an error when I use eventTemplateUri: "C:\ ....\LayoutTemplate.json"
rror message is " Could not create plugin of type class org.apache.logging.log4j.layout.template.json.JsonTemplateLa
yout for element JsonTemplateLayout: java.lang.RuntimeException: failed reading URI: C:...
Did I miss anything here?
is it possible to place this json file outside of class path?
Thanks!
All *Uri configuration knobs in JsonTemplateLayout expect a URI string. In your case, the URI scheme is missing. The eventTemplateUri should look like file:///C:/path/to/LayoutTemplate.json in your case. For internals, see how o.a.l.l.l.template.json.util.Uris.readUri(String,Charset) is implemented.

Where does ClassLoader.getSystemResource() go to?

There is existing code that has a call
URL resource = ClassLoader.getSystemResource("hp.obo.gz");
From my understanding, this searches the classpath for the requested file. I printed out the classpath using the code from here: https://www.mkyong.com/java/how-to-print-out-the-current-project-classpath/
and got the following:
/C:/Program%20Files/JetBrains/IntelliJ%20IDEA%202017.1.3/lib/idea_rt.jar
/C:/Program%20Files/JetBrains/IntelliJ%20IDEA%202017.1.3/plugins/junit/lib/junit-rt.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/charsets.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/deploy.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/access-bridge-64.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/cldrdata.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/dnsns.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/jaccess.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/jfxrt.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/localedata.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/nashorn.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/sunec.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/sunjce_provider.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/sunmscapi.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/sunpkcs11.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/ext/zipfs.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/javaws.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/jce.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/jfr.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/jfxswt.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/jsse.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/management-agent.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/plugin.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/resources.jar
/C:/Program%20Files/Java/jdk1.8.0_66/jre/lib/rt.jar
/C:/Users/johnp/Desktop/git_stuff/boqa/target/test-classes/
/C:/Users/johnp/Desktop/git_stuff/boqa/target/classes/
/C:/Users/johnp/.m2/repository/commons-cli/commons-cli/1.2/commons-cli-1.2.jar
/C:/Users/johnp/.m2/repository/de/charite/compbio/ontologizer-core/2.1-SNAPSHOT/ontologizer-core-2.1-20160115.222100-6.jar
/C:/Users/johnp/.m2/repository/com/att/research/grappa/1.2.1/grappa-1.2.1.jar
/C:/Users/johnp/.m2/repository/de/charite/compbio/ontologizer-benchmark/2.1-SNAPSHOT/ontologizer-benchmark-2.1-20160115.222106-6.jar
/C:/Users/johnp/.m2/repository/com/beust/jcommander/1.35/jcommander-1.35.jar
/C:/Users/johnp/.m2/repository/org/slf4j/slf4j-api/1.7.7/slf4j-api-1.7.7.jar
/C:/Users/johnp/.m2/repository/org/apache/logging/log4j/log4j-1.2-api/2.8.2/log4j-1.2-api-2.8.2.jar
/C:/Users/johnp/.m2/repository/org/apache/logging/log4j/log4j-api/2.8.2/log4j-api-2.8.2.jar
/C:/Users/johnp/.m2/repository/org/apache/logging/log4j/log4j-core/2.8.2/log4j-core-2.8.2.jar
/C:/Users/johnp/.m2/repository/junit/junit/4.12/junit-4.12.jar
/C:/Users/johnp/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
/C:/Program%20Files/JetBrains/IntelliJ%20IDEA%202017.1.3/lib/idea_rt.jar
However, where it actually is found is here (deleting hp.obo.gz causes a null pointer exception):
C:\Users\johnp\Desktop\git_stuff\boqa\src\main\resources
I don't see how it got this location given the above output (it seems similar to /C:/Users/johnp/Desktop/git_stuff/boqa/target/test-classes/
and
/C:/Users/johnp/Desktop/git_stuff/boqa/target/classes/). Any help would be appreciated. Thanks!
Right click on a folder and "mark directory as" -> "Resources Root". This will configure everything behind the scenes in IntelliJ to work

Maven. Nested properties filtering doesn't work

I have two property files:
#environment.properties
env = production
and second file is:
#commons.properties
production.port = 123
test.port = 567
Also,I have resource file which need be filtered by environment.properties file and commons.properties file and copied.
The resource-file contains:
${${env}.port}
So,I want to filter my resource file with first file and get:
${production.port}
and then I want to filter it with second filter file and get:
123
I use maven 3.2.5 and the resource-file isn't filtered at all.
I know that there's issue related with this problem:
https://jira.codehaus.org/browse/MRESOURCES-70 But it still unresolved.
So,my question is - is there any solution to resolve this problem? (actually,I think that resource-plugin should be modified for work with nested property filtering).
And second question - does exist any way to avoid this problem by refactoring,I mean any other architecture solution. Or, what would you do if you had same problem?

Route to upload file in Play Framework 2.10

I upload files to /upload folder, then I want to directly access my files, like:
http://localhost/upload/xxx.jpg
when I add routes as below:
GET /upload/*file controllers.Assets.at(path="/upload", file)
It causes another error:
not enough arguments for method at: (path: String, file: String)play.api.mvc.Call. Unspecified value parameter file.
<link rel="stylesheet" media="screen" href="#routes.Assets.at("stylesheets/main.css")">
Then, after I change #routes.Assets.at("stylesheets/main.css") to #routes.Assets.at("stylesheets/", "main.css"), there is another error:
[MatchError: (stylesheets/,main.css) (of class scala.Tuple2)]
(path: #unchecked, file: #unchecked) match {
Can somebody help me with this route? Thanks.
finnal, I got answer from playframework website, it not very obvious to find..
http://www.playframework.com/documentation/2.0.4/Assets
from this page:
However, if you define two mappings for the Assets.at action, like this:
GET /javascripts/*file controllers.Assets.at(path="/public/javascripts", file)
GET /images/*file controllers.Assets.at(path="/public/images", file)
Then you will need to specify both parameters when using the reverse router:
<script src="#routes.Assets.at("/public/javascripts", "jquery.js")"></script>
<image src="#routes.Assets.at("/public/images", "logo.png")">
but this may not solve my problem yet, it turn out to appear the second error mention in the question.
Be Careful, check the path param, it must be the same as you described in routes file. as:
when I set:
GET /public/*file controllers.Assets.at(path="/public", file)
in the html file, I should write as below:
#routes.Assets.at("/public", "stylesheets/main.css")
besides, if you use another folders, like /upload, adding below code in project/Build.scala in play.Project is essential. thanks TizianoPiccardi
playAssetsDirectories <+= baseDirectory / "foo"
You should add this line in project/Build.scala:
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
playAssetsDirectories <+= baseDirectory / "upload"
)
More info:
https://github.com/playframework/Play20/wiki/Assets

Play! Framework 2.0.3, i18n error, `=' expected but `-' found

I'm new in "Play! Framework" and I'm trying to do a i18n for pt-BR.
My message file is called 'Message.pt-BR' and i put the pt-BR lang in application.conf.
In Java I'm using something like this:
flash("success", Messages.get("logout.success"));
And in scala.html files I'm using this:
#Messages("logout")
In my Message.pt-BR file I've this:
logout=Sair
logout.success=Logout realizado com sucesso. Volte sempre!
When I compile the project I have no errors, but when I request some page a have this error:
`=' expected but `-' found
Messages.pt-BR
Someone can help me?
I think you have to rename your message file from Messages.pt-BR to Messages.pt_BR (with a lower '_').

Categories

Resources