Scalate templates in Scalatra with WAR deployed in Jetty throw ResourceNotFoundException - scala

When attempting to send email using scalate templates, resource not found exceptions are thrown (see below). Initially I thought it was a path issue, as in dev environment on sbt it works file, but deploying the WAR to jetty causes these exceptions.
com.mysite.api.util.mail.EmailActor#324f0f97: caught org.fusesource.scalate.util.ResourceNotFoundException: Could not load resource: [/WEB-INF/scalate/templates/email-forgotpassword.ssp]
org.fusesource.scalate.util.ResourceNotFoundException: Could not load resource: [/WEB-INF/scalate/templates/email-forgotpassword.ssp]
After numerous attempts to actually get jetty to look for the template in the right place, this worked:
val dir = this.getClass.getClassLoader().getResource("/").toExternalForm() + "../scalate/"
but still I get this exception:
org.fusesource.scalate.util.ResourceNotFoundException: Could not load resource: [file:/var/cache/jetty/data/Jetty__8080_mysite_api_2.9.1.0.1.war__api__.1q1r37/webapp/WEB-INF/classes/../scalate/templates/email-forgotpassword.ssp]
The files definitely resides in that exact path, as a directory listing will confirm, so it's not a path issue I don't believe.
Any insight would be greatly appreciated. Thanks!

Related

NeTBeans Web Application Project gives a error message HTTP Status 404

When I run the project directly right clicking the project name I get a error "HTTP status 404" but when i individually run a file (eg. home.html) it runs.The project is a servlet project, where my home.html is connected to a servlet file.There are no errors for sure. What's the real issue?
404 errors are generated by the web container when a resource is not found. Clearly there must be an issue with your paths or something, but based on the limited information you provide it is hard to spot the mistake...

Cannot resolve template loader path Freemarker

I use freemarker with Spring.
This is the way I configure my freemarker :
<bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean">
<property name="templateLoaderPath" value="classpath:/META-INF/templates"/>
</bean>
This configuration is actually working fine, I am able to generate my report using the templates, etc.
However in Weblogic, I always get this Exception :
15 Sep 2012 01:03:02,060 DEBUG DefaultListableBeanFactory.doCreateBean:504 - Eagerly caching bean 'freemarkerConfiguration' to allow for resolving potential circular references
15 Sep 2012 01:03:02,074 DEBUG DefaultListableBeanFactory.invokeInitMethods:1498 - Invoking afterPropertiesSet() on bean with name 'freemarkerConfiguration'
15 Sep 2012 01:03:02,228 DEBUG FreeMarkerConfigurationFactoryBean.getTemplateLoaderForPath:360 - Cannot resolve template loader path [classpath:/META-INF/templates] to [java.io.File]: using SpringTemplateLoader as fallback
java.io.FileNotFoundException: class path resource [META-INF/templates] cannot be resolved to absolute file path because it does not reside in the file system: zip:C:/Oracle/Middleware/user_projects/domains/gppuser/servers/GPPFilesBCSIS/tmp/_WL_user/GPPFilesBCSIS/phxni8/war/WEB-INF/lib/_wl_cls_gen.jar!/META-INF/templates
at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:204)
at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:52)
at org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.getTemplateLoaderForPath(FreeMarkerConfigurationFactory.java:351)
at org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.createConfiguration(FreeMarkerConfigurationFactory.java:304)
at org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean.afterPropertiesSet(FreeMarkerConfigurationFactoryBean.java:60)
This Error actually happens during the loading. Anyone know how to solve and remove this Exception? The file is actually still generated using the templates provided, so I'm not really sure what this error about.
For your info : I'm not using exploded deployment.
This is nothing to worry about. Note that the log level is DEBUG, not ERROR or WARNING.
When the template directory is accessible through java.io.File (because it's not inside a jar, war, etc.), Spring will configure FreeMarker to use java.io.File directly to load the templates, because that way FreeMarker can check the last modification times and automatically reload templates. To find out if the path can be mapped to a plain directory, Spring will call Resource.getFile() and see if it throws IOException. If it did, Spring logs with DEBUG level, then configures FreeMarker to load the templates through Spring's Resource abstraction (without using Resource.getFile of course). So it's the normal program flow in your case.

How to use matlabcontrol api and jboss

thanks in advance for attention.
It's the first time i am writing on this site (quite newbie :) )
I previously read question of a user asking for my same problem. Although i read a lot i could not find a solution.
Problem:
I am trying to use MatlabControl jar (http://code.google.com/p/matlabcontrol/) to "call" matlab within my java code.
When i try this api within a normal java application to try it (including matlabcontrol.jar in the buildpath) everything works perfectly.
My issue is to make it work on an ejb module with jboss 5 AS:
i can deploy the ejb module and i can see classes of the matlabcontrol.jar (which i put in server/default/lib folder), but it is not working and is returning me the following exception:
Caused by: java.lang.NullPointerException
at java.io.File.<init>(File.java:251)
at matlabcontrol.Configuration.getSupportCodeLocation(Configuration.java:227)
at matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:278)
at matlabcontrol.RemoteMatlabProxyFactory.requestProxy(RemoteMatlabProxyFactory.java:116)
at matlabcontrol.RemoteMatlabProxyFactory.getProxy(RemoteMatlabProxyFactory.java:134)
at matlabcontrol.MatlabProxyFactory.getProxy(MatlabProxyFactory.java:81)
that lead me to the following lines:
URL url = Configuration.class.getProtectionDomain().getCodeSource().getLocation();
File file = new File(url.toURI().getPath()).getCanonicalFile();
The very strange thing is that very very rarely, after restarting jboss and re-deploying the ejb module, the system works!.
I really don't know if i have to modify the source code of these last 2 lines (as if it is a problem of not properly getting the location of the jar code) or to set some configuration files of jBoss to set the classpath differently.
Thanks again in advance.
Any help would be very appreciate.
The mistake was in the code to find the location of the jar at runtime.
I printed the path, which ended with "!" and double slash, so I removed these chars and I was finally able to make this API work.

Combining Akka, Spray, and embedded Jetty

I'm trying to create a standalone JAR containing Akka, Spray, and Jetty. Ideally I distribute the entire application in that single file, without any external files whatsoever.
I understand how to create an embedded Jetty server instance
def main(args: Array[String]): Unit = {
val server = new Server(9012);
server.start();
server.join();
Thread.sleep(2000);
server.stop();
}
and I've followed the Spray example code in creating a HelloService and Boot class, but I have no earthly idea of how to connect the two, so that when a URL is requested on the Jetty server a Spray service responds to it. Any help would be much appreciated.
Update: I'm getting a lot closer to solving this problem, thanks to a thread of inquiry prompted by Alois Cochard (I'm coming from a web scripting background, and getting my head around Java web services has been ... challenging!). I've modified my main method to start the server and read the Jetty and akka configuration files that are in the getting started template. It's reading both of those files, but now I'm getting this when I navigate to / on the Jetty server:
HTTP ERROR: 500
Problem accessing /. Reason:
assertion failed: 0 actors for id 'spray-root-service' found, expected exactly one
I know I'm missing something silly (and probably that I should break down and use SBT, but being able to just compile and run in Eclipse, and then refresh in the browser, is so simple and appealing).
Update #2: Figured out the problem. I wasn't creating a WebAppContext object, which meant that the web.xml was never getting read, and thus Akka was never being loaded. This is the revised main method which is now working.
According to the spray-template, you should add the Spray servlet connector in the web.xml configuration file:
http://github.com/spray/spray-template/blob/master/src/main/webapp/WEB-INF/web.xml
You can find some informations about how to configure a standealone jetty to use this file here (there is surely better references in netty documentation directly):
http://exist.sourceforge.net/deployment.html#d47e594
BTW, using the spray template as a basis for your project looks like a good idea ;)

Enterprise lib 5.0 not detecting app.config

I have a Solution which contains a Web project and a Class Library project. The Class library project contains Enterprise library 5.0 and app.config. When I try to perform a Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write, I get the following exception:
Resolution of the dependency failed,
type =
"Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter",
name = "(none)". Exception occurred
while: while resolving. Exception is:
InvalidOperationException - The type
LogWriter cannot be constructed. You
must configure the container to supply
this value.
----------------------------------------------- At the time of the exception, the
container was: Resolving
Microsoft.Practices.EnterpriseLibrary.Logging.LogWriter,(none)
If I move all the class files to the web project and have the Enterprise library configuration in the Web.config, everything works fine. I guess the issue is that the Enterprise library is not detecting the app.config which contains all the configuration.
Kindly help me with this regard.
Thanks in advance.
.NET dlls don't have config files. AppDomains do. You cannot put any configuration in a dll's "app.config" file and expect it to get automatically picked up. This is the way .NET config files work; it's not that "entlib is not automatically detecting" it, it's doing what the .NET framework defines the behavior of config files to be.
The answer is to leave the code in the library, but put the configuration in the web app's web.config file. Then everything will just work.
There are more advanced things you can do like manually loading the config file, but they're fairly advanced and, particularly with logging, can cause admin headaches later.