Reading properties file through java backend webscript

cancel
Showing results for 
Search instead for 
Did you mean: 
kranthi
Active Member II

Reading properties file through java backend webscript

Jump to solution

How we will read alfresco-global.properties file through java backend webscript??

 For example mail.username 

1 Solution

Accepted Solutions
douglascrp
Advanced II

Re: Reading properties file through java backend webscript

Jump to solution

I know there has been a long time since you asked, but I am going to answer anyway, as it can be a reference for someone searching for the same in future.

In the links below, you can find some samples:

How to define de bean to inject the alfresco-global.properties into the Java class: alfresco-audit-analysis-reporting/webscript-context.xml at master · fcorti/alfresco-audit-analysis-r... 

How to define a setter method to the property: alfresco-audit-analysis-reporting/GetCountersWebScript.java at master · fcorti/alfresco-audit-analys... 

View solution in original post

5 Replies
krutik_jayswal
Senior Member II

Re: Reading properties file through java backend webscript

Jump to solution

Below is one sample bean where I am reading properties from alfresco-global.properties file like server host port etc..You can use similarly in case of webscript.

<bean id="org.alfresco.tutorial.policy.documentEventHandler"
class="com.trantorinc.liferay.webservice.Sample"
init-method="registerEventHandlers">
   <property name="liferayServerHost" value="${server.host}"/>
<property name="liferayServerPort" value="${server.port}"/>
<property name="userName" value="${username}"/>
<property name="password" value="${lpassword}"/>
</bean>

douglascrp
Advanced II

Re: Reading properties file through java backend webscript

Jump to solution

It is also possible to get the access to all the properties by using the method described at Accessing values from Alfresco's alfresco-global.properties file - Stack Overflow 

anakin59490
Established Member II

Re: Reading properties file through java backend webscript

Jump to solution

Hi,

this what i have added in one of my xml config file  :

<bean id="global-properties" parent="baseJavaScriptExtension" class="java.util.Properties">
<property name="properties">
<ref bean="global-properties"/>
</property>
</bean>

But how can i use it in my java class ?

Thank you

douglascrp
Advanced II

Re: Reading properties file through java backend webscript

Jump to solution

I know there has been a long time since you asked, but I am going to answer anyway, as it can be a reference for someone searching for the same in future.

In the links below, you can find some samples:

How to define de bean to inject the alfresco-global.properties into the Java class: alfresco-audit-analysis-reporting/webscript-context.xml at master · fcorti/alfresco-audit-analysis-r... 

How to define a setter method to the property: alfresco-audit-analysis-reporting/GetCountersWebScript.java at master · fcorti/alfresco-audit-analys... 

gtarafder
Active Member

Re: Reading properties file through java backend webscript

Jump to solution

Thanks  .This worked for me perfectly.

<!--Inside Bean-->
<property name="properties">   <ref bean="global-properties"/> </property

//In Java Class

private Properties properties;

// And while accessing 

properties.getProperty("your key from alfresco-global.properties");


Reference : Accessing values from Alfresco's alfresco-global.properties file - Stack Overflow