Created
September 21, 2012 19:30
-
-
Save pendor/3763412 to your computer and use it in GitHub Desktop.
SystemPropertiesService forward-ported for JBoss 7.x
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<server xmlns="urn:jboss:service:7.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="urn:jboss:service:7.0 http://our.private.schema.server/dtds/jb7/jboss-service_7_0.xsd"> | |
<mbean code="ucs.jb4compat.SystemPropertiesService" name="jboss.util:type=Service,name=SystemProperties-YourEarName"> | |
<!-- Load properties from each of the given comma seperated URLs. Path is relative to root of JBoss/standalone. --> | |
<attribute name="URLList">configuration/YourEarName.properties</attribute> | |
</mbean> | |
</server> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Layout of the module: | |
modules/ucs/jb4compat/main/jb4compat.jar | |
modules/ucs/jb4compat/main/module.xml | |
Contents of the JAR: | |
$ unzip -l modules/ucs/jb4compat/main/jb4compat.jar | |
Archive: modules/ucs/jb4compat/main/jb4compat.jar | |
Length Date Time Name | |
-------- ---- ---- ---- | |
0 09-21-12 14:44 META-INF/ | |
106 09-21-12 14:44 META-INF/MANIFEST.MF | |
0 09-21-12 14:44 ucs/ | |
0 09-21-12 14:44 ucs/jb4compat/ | |
6497 09-21-12 14:44 ucs/jb4compat/DynamicLoginConfig.class | |
674 09-21-12 14:44 ucs/jb4compat/DynamicLoginConfigMBean.class | |
3284 09-21-12 14:44 ucs/jb4compat/SystemPropertiesService.class | |
603 09-21-12 14:44 ucs/jb4compat/SystemPropertiesServiceMBean.class | |
5301 09-21-12 14:44 ucs/jb4compat/XMLLoginConfig.class | |
1419 09-21-12 14:44 ucs/jb4compat/XMLLoginConfigMBean.class | |
-------- ------- | |
17884 10 files | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- | |
JBoss module which adds back functionality removed between JBoss 4.2.3 and 7.1.1 | |
--> | |
<module xmlns="urn:jboss:module:1.1" name="ucs.jb4compat"> | |
<resources> | |
<resource-root path="jb4compat.jar"/> | |
</resources> | |
<dependencies> | |
<!-- Note: There are more modules listed here than necessary for this: We're working on a few other mbeans from 4.2.x to get login-config.xml parsed, etc. --> | |
<module name="javax.api"/> | |
<module name="org.jboss.common-core"/> | |
<module name="org.jboss.as.security"/> | |
<module name="org.jboss.as.server"/> | |
<module name="org.jboss.ironjacamar.api"/> | |
<module name="org.jboss.logging"/> | |
<module name="org.picketbox"/> | |
<module name="org.slf4j"/> | |
</dependencies> | |
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ucs.jb4compat; | |
/*************************************** | |
* * | |
* JBoss: The OpenSource J2EE WebOS * | |
* * | |
* Distributable under LGPL license. * | |
* See terms of license at gnu.org. * | |
* * | |
***************************************/ | |
import java.io.File; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
import java.util.Properties; | |
import java.util.StringTokenizer; | |
import org.slf4j.LoggerFactory; | |
/** | |
* A service to access system properties. | |
* | |
* @jmx:mbean name="jboss.varia:type=Service,name=SystemProperties" extends="org.jboss.system.ServiceMBean" | |
* | |
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a> | |
* @author Scott.Stark@jboss.org | |
* @author zbedell - hacked to import minimal property file loading capability for JBoss 7.x | |
*/ | |
public class SystemPropertiesService implements SystemPropertiesServiceMBean { | |
// ///////////////////////////////////////////////////////////////////////// | |
// Property/PropertyManager Access // | |
// ///////////////////////////////////////////////////////////////////////// | |
/** | |
* Set a system property. | |
* | |
* @jmx:managed-operation | |
* | |
* @param name | |
* The name of the property to set. | |
* @param value | |
* The value of the property. | |
* @return Previous property value or null | |
*/ | |
@Override | |
public String set(final String name, final String value) { | |
return (String) System.getProperties().put(name, value); | |
} | |
/** | |
* Get a system property. | |
* | |
* @jmx:managed-operation | |
* | |
* @param name | |
* Property name | |
* @param defaultValue | |
* Default property value | |
* @return Property value or default | |
*/ | |
@Override | |
public String get(final String name, final String defaultValue) { | |
return System.getProperties().getProperty(name, defaultValue); | |
} | |
/** | |
* Get a system property. | |
* | |
* @jmx:managed-operation | |
* | |
* @param name | |
* Property name | |
* @return Property value or null | |
*/ | |
@Override | |
public String get(final String name) { | |
return System.getProperties().getProperty(name); | |
} | |
/** | |
* Remove a system property. | |
* | |
* @jmx:managed-operation | |
* | |
* @param name | |
* The name of the property to remove. | |
* @return Removed property value or null | |
*/ | |
@Override | |
public String remove(final String name) { | |
return (String)System.getProperties().remove(name); | |
} | |
/** | |
* Check if a system property of the given name exists. | |
* | |
* @jmx:managed-operation | |
* | |
* @param name | |
* Property name | |
* @return True if property exists | |
*/ | |
@Override | |
public boolean exists(final String name) { | |
return System.getProperties().containsKey(name); | |
} | |
// ///////////////////////////////////////////////////////////////////////// | |
// Property Loading // | |
// ///////////////////////////////////////////////////////////////////////// | |
/** | |
* Load some system properties from the given URL. | |
* | |
* @jmx:managed-operation | |
* | |
* @param url | |
* The url to load properties from. | |
*/ | |
@Override | |
public void load(final URL url) throws IOException { | |
LoggerFactory.getLogger(SystemPropertiesService.class).info("Loading system properties from: " + url); | |
final Properties props = System.getProperties(); | |
final InputStream is = url.openConnection().getInputStream(); | |
props.load(is); | |
is.close(); | |
} | |
/** | |
* Load some system properties from the given URL. | |
* | |
* @jmx:managed-operation | |
* | |
* @param url | |
* The url to load properties from. | |
*/ | |
@Override | |
public void load(final String url) throws IOException, MalformedURLException { | |
load(new File(new File(System.getProperty("jboss.server.base.dir")), url).toURI().toURL()); | |
} | |
// ///////////////////////////////////////////////////////////////////////// | |
// JMX & Configuration Helpers // | |
// ///////////////////////////////////////////////////////////////////////// | |
/** | |
* Load system properties for each of the given comma separated urls. | |
* | |
* @jmx:managed-attribute | |
* | |
* @param list | |
* A list of comma separated urls. | |
*/ | |
@Override | |
public void setURLList(final String list) throws MalformedURLException, IOException { | |
if(list == null) { | |
// We'll get null if JBoss is rolling back the deployment. Ignore it... No way to put the Genie back in the bottle | |
// once we've dumped our properties System.getProperties(). | |
return; | |
} | |
final StringTokenizer stok = new StringTokenizer(list, ","); | |
while(stok.hasMoreTokens()) { | |
final String url = stok.nextToken(); | |
load(url); | |
} | |
} | |
/** | |
* Set system properties by merging the given properties object. This will replace valid references to properties of the form ${x} | |
* in 'props' or a System property with the value of x. | |
* | |
* @jmx:managed-attribute | |
* | |
* @param props | |
* Properties object to merge. | |
*/ | |
@Override | |
public void setProperties(final Properties props) throws IOException { | |
LoggerFactory.getLogger(SystemPropertiesService.class).debug("Merging with system properties: " + props); | |
System.getProperties().putAll(props); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ucs.jb4compat; | |
/* | |
* JBoss, Home of Professional Open Source. | |
* Copyright 2008, Red Hat Middleware LLC, and individual contributors | |
* as indicated by the @author tags. See the copyright.txt file in the | |
* distribution for a full listing of individual contributors. | |
* | |
* This is free software; you can redistribute it and/or modify it | |
* under the terms of the GNU Lesser General Public License as | |
* published by the Free Software Foundation; either version 2.1 of | |
* the License, or (at your option) any later version. | |
* | |
* This software is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
* Lesser General Public License for more details. | |
* | |
* You should have received a copy of the GNU Lesser General Public | |
* License along with this software; if not, write to the Free | |
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
* 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
*/ | |
/** | |
* MBean interface. | |
*/ | |
public interface SystemPropertiesServiceMBean { | |
/** | |
* Set a system property. | |
* @param name The name of the property to set. | |
* @param value The value of the property. | |
* @return Previous property value or null */ | |
java.lang.String set(java.lang.String name,java.lang.String value) ; | |
/** | |
* Get a system property. | |
* @param name Property name | |
* @param defaultValue Default property value | |
* @return Property value or default */ | |
java.lang.String get(java.lang.String name,java.lang.String defaultValue) ; | |
/** | |
* Get a system property. | |
* @param name Property name | |
* @return Property value or null */ | |
java.lang.String get(java.lang.String name) ; | |
/** | |
* Remove a system property. | |
* @param name The name of the property to remove. | |
* @return Removed property value or null */ | |
java.lang.String remove(java.lang.String name) ; | |
/** | |
* Check if a system property of the given name exists. | |
* @param name Property name | |
* @return True if property exists */ | |
boolean exists(java.lang.String name) ; | |
/** | |
* Load some system properties from the given URL. | |
* @param url The url to load properties from. */ | |
void load(java.net.URL url) throws java.io.IOException; | |
/** | |
* Load some system properties from the given URL. | |
* @param url The url to load properties from. */ | |
void load(java.lang.String url) throws java.io.IOException, java.net.MalformedURLException; | |
/** | |
* Load system properties for each of the given comma separated urls. | |
* @param list A list of comma separated urls. */ | |
void setURLList(java.lang.String list) throws java.net.MalformedURLException, java.io.IOException; | |
/** | |
* Set system properties by merging the given properties object. This will replace valid references to properties of the form ${x} in 'props' or a System property with the value of x. | |
* @param props Properties object to merge. */ | |
void setProperties(java.util.Properties props) throws java.io.IOException; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks a lot for this properties service port, it works great!!
We will wondering if you have some code for loginXMLConfigService?
Thanks in advance