Cannot resolve template loader path Freemarker - classpath

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.

Related

Ecore EMF PackageNotFoundException

I have to work with a project I didn't wrote myself. It uses Ecore EMF (I have no experience with this) and I can't figure out how to solve this error:
At some point the program loads a .xmi file with this function: org.eclipse.emf.ecore.xmi.impl.XMLHandler.getPackageForURI()
And this results in this error:
org.eclipse.emf.ecore.xmi.PackageNotFoundException: Package with uri 'platform:/plugin/Animals/model/Animals.ecore' not found. (file:/C:/Users/model917.xmi, 2, 193)
It seems like the file model917.xmi exists and is not the origin of this error. I think the problem is caused because the Animals.ecore file is not found. In the model917.xmi file I found this statement:
xmlns: Animals ="platform:/plugin/Animals/model/Animals.ecore
So I think the model in file model917.xmi uses another model defined in Animals.ecore which can't be found and causes the error.
I have access to the Animals.ecore file and found out that EMF/ecore uses something like a registry to find such files. So it seems like I have to add the Animals.ecore file to this registry and I found some answers online which didn't work and I run out of ideas what to try next. Can someone give me an easy way to register this file so it will be found? I am using Eclipse if this is relevant/maybe there is an easy way to do it with Eclipse.
Usually, EMF-based softwares should rely on the so-called "namespace URI" (nsURI) of EPackages, which are usually of the form "http://foo/bar/Animals".
"http://foo/bar/Animals" should be registered in the EMF Registry and dispatch depending on your actual runtime situation to a URI that looks like "platform:/plugin/bar.foo/Animals.ecore" (when file Animals.ecore is deployed in an Eclipse plugin for an Eclipse-based application), or "platform:/resource/bar.foo/Animals.ecore" (when file Animals.ecore is deployed in the workspace of the running Eclipse-based application) or even "file:///path/to/Animals.ecore" (anywhere on the filesystem).
Technically you can use any of those URI forms as long as they are correctly resolved at runtime, but you must understand that not all URIs make sense in all contexts, for instance "platform:/" URIs only make sense in Eclipse-based context. nsURIs are supposed to be resolveable in all contexts (thanks to the registry!)
Is your code meant to be running in the context of an Eclipse-based application ? Then the project containing Animals.ecore should be deployed as a plugin, and I am guessing it is currently not.
Is your code meant to be standalone? Then the reference in your xmi file, to the ecore file, should not be of the form "platform:/..." but rather of the form "http://foo/bar/Animals" (the nsURI of the EPackage that is the root element of Animals.ecore)

How to read external config file when starting a bundle jboss fuse karaf

The problem is simple: i want to print all topics from apache kafka after installing kafka module on karaf. I need to get properties from cfg file which is located in jbossfuse/etc and create a KafkaConsumer object. I want to implement BundleActivator to be able to start method in the moment of installation module.
The question is: how can i get properties from the config file?
I found some solution here: some solution, they said " you can use ConfigAdimn service from OSGi spec. ". How can i use it? All examples with the code are welcome
Karaf uses Felix-FileInstall to read config files: http://felix.apache.org/documentation/subprojects/apache-felix-file-install.html
So if there is a file named kafka.cfg, it will pick it up and register a config with the ConfigAdmin-Service under the pid 'kafka'.
You can fetch the ConfigAdmin-Service and fetch the config using an Activator and read that config from there, but I strongly recommend to use DeclarativeServices or Blueprint instead to interact with the OSGi-Framework, both support injection of configuration if it is available.
Because otherwise you have to deal yourself with the following topics:
there is no ConfigAdmin (yet), maybe because your bundle starts earlier)
the ConfigAdmin changes (for example due to a package refresh or update)
the configuration is not yet registered (because felix has not read it yet)
the configuration gets updated (for example somone changes the file)

Debugging Drools inside an EJB in eclipse

I am currently debugging a web application which uses a drools ruleset inside an EJB to process business rules. It's deployed inside a JBoss server. I've configured eclipse to run the server so I could use Debug on Server functionality of eclipse.
When I reach the class that fires the drools ruleset, the server loses focus and returns after all the rules are fired. Is there a way where I could trace what rules are being fired? Right now, what I do is put logs inside the *.drl files so I know where the application is inside the rules engine.
you can get the generated java source code of any rule when you add a file with name drools.packagebuilder.conf to your %USERHOME% directory.
The file must contain the following instruction:
drools.dump.dir = d:/myDroolsJavaSourceCode
The directory d:/myDroolsJavaSourceCode - Directory (or any other given name) must exist otherwise the Drools Packagebuild will stop execution.
Then you can add this directory to your Eclipse Environment as new project (probably you have to remove the flag 'Default Location' to choose the 'myDroolJavaSourceCode').
Then you can open the file in Eclipse and set break points in the editor.
May be you must attach the directory also during debugging execution twice.
Best regards!
Christof
As far as I know you can't debug drl file. What we did was to encapsulate the logic of when and then in a method, so that you can at least debug that.
Maddy
What I did is I downloaded the sources for drools-engine and compiled the drl files to their java sources. When you run the app, you'll have an option to attach sources when the break point reaches the engine. It's still hard to trace the rules that are fired (multiple rules from different drls can be fired) but it's better than just sysout logging.

Scalate templates in Scalatra with WAR deployed in Jetty throw ResourceNotFoundException

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!

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.