Liferay: Get URL in portal.normal.vm from properties file - java

I have problems to read info from properties file "liferay-portal-6.1.0/tomcat-7.0.23/lib/myweb-application.properties" in portal_normal.vm
myweb-application.properties:
redirect.docs.url = http://stackoverflow.com/questions/ask
"liferay-portal-6.1.0/tomcat-7.0.23/webapps/web-theme/templates/portal_normal.vm":
#set ($docsURL = $propsUtil.get("redirect.docs.url")) #language("foot.docs")

Get value of portal-ext.properties
eg. test.name="sachin"
${propsUtil.get("test.name")}

PropsUtil (or $propsUtil) accesses portal.properties, typically configured through portal-ext.properties. So unless you add your myweb-application.properties as an "external properties" file, PropsUtil won't find it.
One way to do this is to add this line to your portal-ext.properties:
include-and-override=/path/to/myweb-application.properties
but make sure it's not using the same keys as portal.properties for different purposes.

Related

In focframework were can I get a list of all properties supported in config.properties file, and how to add my own properties to be used in my own

I am developing a web application using the full stack framework focframework, and I want to know what are the properties that I can control in my config.properties file. Is there a doc for this?
I tried searching the doc but dodn't find anything
Obviously we can figure out some of then from the sample on GitHub by looking at the config.properties file:
jdbc.drivers=org.h2.Driver
jdbc.url=jdbc:h2:./myfocapplication_data_h2
jdbc.username=sa
jdbc.password=
gui.rtl=0
allowAddInsideComboBox=0
focWebServerClassName=com.focframework.sample.myfocapplication.MyFocAppWebServer
dataSourceClass=b01.focDataSourceDB.FocDataSource_DB
cloudStorageClass=com.focCloudStorage.FocCloudStorageS3
cloudStorageClass=com.foc.cloudStorage.FocCloudStorage_LocalDisc
devMode=1
unitDevMode=0
unitAllowed=1
log.dir=c:/01barmaja/log
log.ConsoleActive=1
log.fileActive=1
log.popupExceptionDialog=1
log.dbRequest=1
log.dbSelect=1
debug.showStatusColumn=0
log.debug=1
perf.active=0
Is there any hint on how to get all of them? And what if I want to add my own to be used in my code?
The ConfigInfo.java file is the one responsible of reading all the properties and storing them in variables. It is straight forward to understand and check the variables names and usage. Yet I agree that someone should work on the documentation and add these parameters.
To add your own without modifying the ConfigInfo.java you can simply use this method in the middle of your code.
String myProperty = ConfigInfo.getProperty("my.property.with.a.meanignful.name");

How to obtain Felix Framework's properties in the config.properties file?

I have this line of code that returns me null and it should return 9193 which is the value that the property really has in my config.properties file...
System.getProperty("org.osgi.service.http.port") // returns null dunno why
My config.properties has the property correctly set up:
org.osgi.service.http.port=9193
Probably I am missing something here, because it is the first time I try to access those properties. I've googled a lot, so there is lack of examples online or I didn't search for the correct keywords.
What should I add/change to that line to make it return the correct value?
Thanks!
Try to use BundleContext.getProperty. The config.properties are set as OSGi framework properties. So this should be a way to retrieve them.

Scala Lift - Reading a file from "/resources/toserve"

I'm attempting to provide a StreamingResponse for files stored under Lifts resources/toserve directory, in order to authorize access for different users.
I can access an image for example with:
localhost:8080/classpath/images/test.jpg
But when I try and actually read the file using scala I keep getting file not found exceptions:
val file = new java.io.FileInputStream("/classpath/images/test.jpg")
Is there a specific method to reading files located on classpath?
Thanks in advance, much appreciated :)
To read resources from the toserve-directory you need to do a call like
LiftRules.getResource("/toserve/images/test.jpg")
If you try to use 'classpath' instead of 'toserve' you will receive an empty box.
By default, Lift uses two different path-prefixes to locate resources either programmatically within the server or through a link-element from HTML. For the former, you will use the 'toserve'-prefix, for the latter the 'classpath'-prefix.
This behavior is specified in the objects net.liftweb.http.LiftRules and net.liftweb.http.ResourceServer. In particular, you can there specify (i.e. replace) the path to the resources. The relevant code is:
/** (from net.liftweb.http.ResourceServer)
* The base package for serving resources. This way, resource names can't be spoofed
*/
var baseResourceLocation = "toserve"
You might also want to look at the following method in LiftRules, which allows you to redefine the name used to serve resources through the server:
/** (from net.liftweb.http.LiftRules)
* The path to handle served resources
*/
#volatile var resourceServerPath = "classpath"
If you wish to use the same prefix to refer both to resources you can use either (or both) of these settings to achieve your purpose.
Have you tried:
LiftRules.getResource("/classpath/images/test.jpg")
That should return a java.net.URL to the item you are looking for.
This may also have more information on what you are looking to do: http://exploring.liftweb.net/master/index-9.html#lst:streaming-download

log4j reset properties back to original as in log4j.properties file

In my application, I defined log4j.properites as follows
log4j.appender.email=org.apache.log4j.net.SMTPAppender
log4j.appender.email.Subject=email Notification
later in the program i am dynamically changing the subject to
Properties prop = new Properties();
prop.setProperty("log4j.appender.email.Subject", "Test Completed");
After I use this variable, I wan to reset this back to original on file. so I did this
LogManager.resetConfiguration();
PropertyConfigurator.configure(prop);
But, later in the code whenever I use this subject property it is giving its value as 'Test Completed'. Any suggestion to reset configuration is greatly appreciated. Thanks
As stated in my comments above both
LogManager.resetConfiguration();
PropertyConfigurator.configure(prop);
don't reconfigure already existing Logger instances, so that they still use your old EmailAppender. In order to make changes to take effect you should recreate loggers.
If it's not possible (your loggers are static final fields for example), you can create a simple Logger wrapper, which will register itself with some listener, that will notify on configuration change, so that wrapper can create fresh logger instance
This is a partial answer (I know); But you can do a reset without explicit LogManager.resetConfiguration();
Resetting Hierarchy
The hierarchy will be reset before configuration when log4j.reset=true is present in the properties file.
https://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/PropertyConfigurator.html

Setting jvmargs in log4j.properties file

This is a bit of a weird request but I am trying to set some jvmargs in the log4j.properties file. At present I use ant to for example set some args....
jvmarg value="-Dmail.smtp.socketFactory.port=465"
... but it would be great to group a few of these logging relevant arguments into the .properties file. Does anyone know how to do this?
Thanks in advance!
Log4j is only going to read the properties file after the JVM has already started - that means it can't affect the JVM arguments.
If the properties can be added after JVM startup, you could add a property to your properties file that lists all properties that you want to add to the SystemProperties collection, something like:
# property names of system properties
systemprops=mail.smtp.port mail.smtp.socketFactory.class
mail.smtp.port=465
mail.smtp.socketFactory.class=some.class
Your startup code can read the systemprops value, split on whitespace and add the resulting list of properties to the SystemProperties collection while reading the values from your properties collection.
This way your code does not need to know which properties to add to system props, only that the properties to add are defined by the systemprops property.
If your example is from your actual situation then you can set this value programatically for the java mail...
The SMTP protocol provider supports
the following properties, which may be
set in the JavaMail Session object.
The properties are always set as
strings; the Type column describes how
the string is interpreted. For
example, use
props.put("mail.smtp.port", "888");
http://java.sun.com/products/javamail/javadocs/com/sun/mail/smtp/package-summary.html
This example above should work for mail.smtp.socketFactory.port also.

Categories

Resources