cancel
Showing results for 
Search instead for 
Did you mean: 

Reading properties file through java backend webscript

kranthi
Star Contributor
Star Contributor

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

 For example mail.username 

1 ACCEPTED ANSWER

douglascrp
World-Class Innovator
World-Class Innovator

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 answer in original post

5 REPLIES 5

krutik_jayswal
Elite Collaborator
Elite Collaborator

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>

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 

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
World-Class Innovator
World-Class Innovator

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
Champ on-the-rise
Champ on-the-rise

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