Setting properties that are shared by multiple web scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2013 06:53 PM
http://forums.alfresco.com/forum/developer-discussions/web-scripts/how-add-more-properties-propertie...
However, with more and more webscripts sharing the same information, this becomes error prone. I like to place this file in a central location where all of my webscripts can get to. How do I accomplish this? Is there a place to put this file or an existing file to modify and what would be the java method to get to it and read it. Thanks a bunch!
- Labels:
-
Archive
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2013 02:19 AM
Global and scoped config is read by the Alfresco Configuration Service. By default the following files are read:
alfresco/webscript-framework-config.xml
alfresco/extension/webscript-framework-config-custom.xml
any webscript-framework-config-custom.xml found in the META-INF folder of any JAR on the classpath
please refer to http://wiki.alfresco.com/wiki/Web_Scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2013 06:36 PM
I was able to add properties to alfresco-global.properties file and retrieve it via injecting the Properties bean into my webscript bean. The reference in my been definition includes this line
property name="properties" ref="global-properties" /
In my Java code, via the setProperties method, I get a Properties object back that contains properties in the alfresco-global.properties file. However, this seems to contain properties for alfresco-global.properties only. If I have a separate properties file, can this be done and how?
Thanks a bunch!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2013 11:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2013 09:29 AM
Thanks a bunch!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2013 01:30 PM
Like this
1.define your class and place it into {SHARED_CLASS}\
org.springframework.extensions.config.ConfigServicepublic class YourClass{ private ConfigService configService;//setter method public void setConfigService(ConfigService configService) { this.configService = configService; }}
2.define your spring bean in *****-context.xml and place your file in {SHARED_CLASS}\alfresco\extension
<bean id="yourbeanid" class="YourClass" > <property name="configService" ref="webscripts.config" /> </bean>
3.add your configuration sections in web-scripts-config-custom.xml file and place it in {SHARED_CLASS}\alfresco\extension,for exampl in global config add following code
<config> <server> <url>jdbc.***</url> <driver>org.myql.***</driver <username>user</username> </server></config>
4.in your class(YourClass),get the configuration like this
<code>
Config config = configService.getGlobalConfig();
ConfigElement server = config.get("server");
String url = server.getChildValue("url");
<code>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2013 04:30 PM
Here are what I have done.
Place this exact content in a file webscript-framework-config-custom under \tomcat\shared\classes\alfresco\extension
<alfresco-config>
<config>
<dbentity>
<dbpassword>password123</dbpassword>
</dbentity>
</config>
</alfresco-config>
Register the reference to configService in my bean definition
<property name="configService" ref="webscripts.config" />
Java code to read the file
Add the setter method
public void setConfigService(ConfigService myConfigService) {
this.myConfigService = myConfigService;
Code in main process
Config myConfig = myConfigService.getGlobalConfig();
ConfigElement dbEntity = myConfig.getConfigElement("dbentity");
String dbPassword = "notfound";
if (dbEntity != null)
dbPassword = dbEntity.getChildValue("dbpassword");
/* even try to get a list of elements */
Map myMap = myConfig.getConfigElements();
Iterator it = myMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
dbPassword = " - " + dbPassword;
}
dbPassword = dbPassword + " - " + (new Integer (myMap.size()).toString());
dbPassword always return "notfound - 0" with 0 as the size of the map.
I think the code is correct but the server is not getting to the file. I even placed the properties in this file name and location alfresco/webscript-framework-config.xml and still get nothing (per instructions by this URL http://wiki.alfresco.com/wiki/Web_Scripts#Web_Script_Configuration). I also tried place it in the META-INF folder of jar file and put the jar file in this path tomcat\webapps\alfresco\WEB-INF\lib (per instruction from same URL) and still getting nothing back.
Perhaps there is something real simple I have omitted.
Any advice?
Thanks a bunch!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-22-2013 10:36 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2013 06:44 PM
Thanks a bunch!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2013 11:18 PM
