|
From: <bsc...@us...> - 2011-01-13 13:13:14
|
Revision: 8553
http://unicore.svn.sourceforge.net/unicore/?rev=8553&view=rev
Author: bschuller
Date: 2011-01-13 13:13:03 +0000 (Thu, 13 Jan 2011)
Log Message:
-----------
some more refactoring; add access control; let Kernel load and configure services; gateway support; move uas security handlers
Modified Paths:
--------------
wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/Kernel.java
wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/ServiceFactory.java
wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/impl/ResourceImpl.java
wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/security/SecurityManager.java
wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/server/AccessControlInterceptor.java
wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/server/JettyServer.java
wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/FileWatcher.java
wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/Utilities.java
wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/deployment/ServiceConfigReader.java
wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/TestKernel.java
wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/testservice/MockServiceFactory.java
wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/utils/deployment/TestServiceConfigReader.java
wsrflite/trunk/core/src/test/resources/conf/wsrflite.xml
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/admin/service/AdminServiceImpl.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/WSRFInvoker.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/WSRFServletController.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/XFireClientFactory.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/XFireKernel.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/XFireServiceFactory.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/client/BaseWSRFClient.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/impl/WSResourceHomeImpl.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/impl/WSResourceImpl.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/sg/impl/ServiceGroupRegistrationImpl.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/NotificationProducerHomeImpl.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/NotificationProducerImpl.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/NotificationProducerSupport.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/impl/SubscriptionImpl.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xmlbeans/wsn/util/Filters.java
wsrflite/trunk/wsrfcore/src/test/java/de/fzj/unicore/wsrflite/functional/client/TestClient.java
wsrflite/trunk/wsrfcore/src/test/java/de/fzj/unicore/wsrflite/impl/TestSG.java
wsrflite/trunk/wsrfcore/src/test/java/de/fzj/unicore/wsrflite/performancetests/SimpleLoadTest.java
wsrflite/trunk/wsrfcore/src/test/java/de/fzj/unicore/wsrflite/utils/TestUtilities.java
wsrflite/trunk/wsrfcore/src/test/java/de/fzj/unicore/wsrflite/xfire/TestHeaderConstants.java
wsrflite/trunk/wsrfcore/src/test/java/de/fzj/unicore/wsrflite/xfire/TestServiceFactory.java
wsrflite/trunk/wsrfcore/src/test/java/de/fzj/unicore/wsrflite/xmlbeans/impl/TestWsResourceImpl.java
Added Paths:
-----------
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/utils/WSConstants.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/utils/WSUtilities.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/utils/
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/utils/AbstractLoadTester.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/utils/CachingWSDLWriter.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/utils/CheckUnderstoodHeadersHandler.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/utils/CustomWSDLBuilder.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/utils/FinishTimeHandler.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/utils/StartTimeHandler.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/utils/WSRFAddressingOutHandler.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/utils/WSRFHtmlServiceWriter.java
Removed Paths:
-------------
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/utils/Constants.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/utils/Log.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/utils/Utilities.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/AbstractLoadTester.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/AccessControlInterceptor.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/AddressingConstants.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/CachingWSDLWriter.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/CheckUnderstoodHeadersHandler.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/CustomWSDLBuilder.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/FinishTimeHandler.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/StartTimeHandler.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/WSRFAddressingOutHandler.java
wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/xfire/WSRFHtmlServiceWriter.java
Modified: wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/Kernel.java
===================================================================
--- wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/Kernel.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/Kernel.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -29,11 +29,14 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
********************************************************************************/
-
package de.fzj.unicore.wsrflite;
+import java.io.File;
+import java.io.FileNotFoundException;
import java.lang.management.ManagementFactory;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -41,11 +44,13 @@
import java.util.List;
import java.util.Map;
import java.util.Properties;
+import java.util.concurrent.TimeUnit;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
import de.fzj.unicore.metrix.IMetric;
import de.fzj.unicore.metrix.MetricRegistry;
@@ -53,319 +58,409 @@
import de.fzj.unicore.wsrflite.messaging.MessagingException;
import de.fzj.unicore.wsrflite.messaging.MessagingImpl;
import de.fzj.unicore.wsrflite.security.ISecurityProperties;
+import de.fzj.unicore.wsrflite.security.SecurityManager;
import de.fzj.unicore.wsrflite.security.UASSecurityProperties;
import de.fzj.unicore.wsrflite.server.JettyServer;
+import de.fzj.unicore.wsrflite.utils.FileWatcher;
import de.fzj.unicore.wsrflite.utils.Log;
+import de.fzj.unicore.wsrflite.utils.deployment.ServiceConfigReader;
/**
- * Central class of WSRFlite, serves for lookup
- * of components, services, and properties<br/>
+ * Central class of WSRFlite, serves for lookup of components, services, and
+ * properties<br/>
*
* Main class for WSRFlite standalone use<br/>
*
- * @author schuller
+ * @author schuller
*/
public class Kernel {
-
- public static final String VERSION = Kernel.class.getPackage().getImplementationVersion()!=null?
- Kernel.class.getPackage().getImplementationVersion():"DEVELOPMENT";
-
+
+ public static final String VERSION = Kernel.class.getPackage()
+ .getImplementationVersion() != null ? Kernel.class.getPackage()
+ .getImplementationVersion() : "DEVELOPMENT";
+
/**
- * property defining the base URL where services can be contacted
- * (for example "http://localhost:7777/services").<br/>
- * This should NOT end with a slash "/"
+ * property defining the base URL where services can be contacted (for
+ * example "http://localhost:7777/services").<br/> This should NOT end with
+ * a slash "/"
*
* This is the address that is published in registries, etc
*/
- public static final String WSRF_BASEURL="unicore.wsrflite.baseurl";
-
+ public static final String WSRF_BASEURL = "unicore.wsrflite.baseurl";
+
/** property defining the host (e.g. "localhost") */
- public static final String WSRF_HOST="unicore.wsrflite.host";
-
+ public static final String WSRF_HOST = "unicore.wsrflite.host";
+
/** property defining the port (e.g. 7777) */
- public static final String WSRF_PORT="unicore.wsrflite.port";
-
+ public static final String WSRF_PORT = "unicore.wsrflite.port";
+
/** property defining the Servlet context path (usually "/services") */
- public static final String WSRF_SERVLETPATH="unicore.wsrflite.servletpath";
+ public static final String WSRF_SERVLETPATH = "unicore.wsrflite.servletpath";
+
+ /**
+ * Enable registration with a gateway
+ */
+ public static final String AUTOREGISTER_WITH_GATEWAY_KEY = "uas.gatewayregistration";
+
+ /**
+ * update interval for the registration with a gateway in seconds (default =
+ * 30 second)
+ */
+ public static final String AUTOREGISTER_WITH_GATEWAY_UPDATE_KEY = "uas.gatewayregistration.updateinterval";
+
+ /**
+ * Enable multicast discovery of a gateway
+ */
+ public static final String DISCOVER_GATEWAY_KEY = "uas.gatewaydiscovery";
+
+ /**
+ * To override the default UAS startup code, set this to a list of names
+ * (space-separated) of classes implementing java.lang.Runnable
+ */
+ public static final String ON_STARTUP_KEY = "uas.onstartup";
+
+ /**
+ * whether to run a connections check after startup (defaults to "true")
+ */
+ public static final String ON_STARTUP_SELFTEST = "uas.onstartup.selftest";
+
+ /**
+ * property defining the vsite name
+ */
+ public static final String VSITE_NAME_PROPERTY = "uas.targetsystem.sitename";
+
private static Kernel kernel;
-
- private final Properties properties=new Properties();
-
+
+ private final Properties properties = new Properties();
+
private final List<String> monitorMetrics = new ArrayList<String>();;
- private static final Logger logger=Log.getLogger(Log.WSRFLITE,Kernel.class);
-
- private final Map<String, Service> services = Collections.synchronizedMap(new HashMap<String, Service>());
-
- private final Map<String, ServiceFactory> serviceFactories = Collections.synchronizedMap(new HashMap<String, ServiceFactory>());
-
+ private static final Logger logger = Log.getLogger(Log.WSRFLITE,
+ Kernel.class);
+
+ private final Map<String, Service> services = Collections
+ .synchronizedMap(new HashMap<String, Service>());
+
+ private final Map<String, ServiceFactory> serviceFactories = Collections
+ .synchronizedMap(new HashMap<String, ServiceFactory>());
+
private JettyServer jetty;
+ private final GatewayHandler gwHandler;
+
private ISecurityProperties securityProperties;
+
+ private ServiceConfigReader serviceConfigurator;
- private Kernel(){
- printHeader();
- securityProperties=new UASSecurityProperties();
+ private Kernel() {
+ securityProperties = new UASSecurityProperties();
+ gwHandler=new GatewayHandler(this);
registerDefaultFactories();
}
-
- private void printHeader(){
- logger.info("UNICORE Services Environment "+VERSION+" (c) 2006-2010 Forschungszentrum Juelich GmbH");
+
+ /**
+ * get the singleton kernel instance
+ *
+ * @return
+ */
+ public static synchronized Kernel getKernel() {
+ if (kernel == null)
+ kernel = new Kernel();
+ return kernel;
}
-
- //register "standard" service factories
- private void registerDefaultFactories(){
- String[]factoryClasses={"de.fzj.unicore.wsrflite.xfire.XFireServiceFactory",};
-
- for(String clazz: factoryClasses){
- try{
- Class<?>c=Class.forName(clazz);
- ServiceFactory f=(ServiceFactory)c.newInstance();
- registerServiceFactory(f);
- }catch(ClassNotFoundException cnfe){
- //OK, maybe the module is not present
- }
- catch(Exception e){
- logger.error("Can't register service factory "+clazz,e);
- }
- }
+
+ public static final String getVersion() {
+ String ver = VERSION != null ? VERSION : "DEVELOPMENT";
+ return ver;
}
-
+
+ public final String getHeader() {
+ String lineSep = System.getProperty("line.separator");
+ String s = lineSep
+ + " _ _ _ _ _____ _____ ____ _____ ______"
+ + lineSep
+ + "| | | | \\ | |_ _/ ____/ __ \\| __ \\| ____|"
+ + lineSep
+ + "| | | | \\| | | || | | | | | |__) | |__"
+ + lineSep
+ + "| | | | . ` | | || | | | | | _ /| __|"
+ + lineSep
+ + "| |__| | |\\ |_| |_ |____ |__| | | \\ \\| |____"
+ + lineSep
+ + " \\____/|_| \\_|_____\\_____\\____/|_| \\_\\______|"
+ + lineSep + "UNICORE Services Environment" + lineSep
+ + "Version " + getVersion() + ", http://www.unicore.eu";
+ return s;
+ }
+
/**
* shutdown all services in a clean manner
*/
- public void shutdown(){
- for(Service s:services.values()){
- try{
+ public void shutdown() {
+ try {
+ if (jetty != null) {
+ jetty.stop();
+ }
+ } catch (Exception e) {
+ Log.logException("Problem shutting down the Jetty server", e,
+ logger);
+ }
+ for (Service s : services.values()) {
+ try {
s.stop();
- }catch(Throwable t){
- logger.error("Error during shutdown of service <"+s.getName()+">",t);
+ } catch (Throwable t) {
+ logger.error("Error during shutdown of service <" + s.getName()
+ + ">", t);
}
}
}
- public JettyServer getServer(){
+ public JettyServer getServer() {
return jetty;
}
-
- public void setServer(JettyServer server){
- jetty=server;
+
+ public void setServer(JettyServer server) {
+ jetty = server;
}
-
+
/**
- * add a JMX MBean under the given name
+ * add a JMX MBean to the VM-wide MBean server under the given name
*
* @param mbean
+ * - the mbean to add
* @param name
+ * - the name
*/
- public static void addMBean(Object mbean, String name){
- try{
+ public static void addMBean(Object mbean, String name) {
+ try {
MBeanServer mbs = null;
// Get the platform MBeanServer
mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName adminName = null;
- // Uniquely identify the MBeans and register them with the platform MBeanServer
- adminName = new ObjectName("UAS:name="+name);
+ // Uniquely identify the MBeans and register them with the platform
+ // MBeanServer
+ adminName = new ObjectName("UAS:name=" + name);
mbs.registerMBean(mbean, adminName);
- }catch(Exception ex){
- Log.logException("Error registering mbean.",ex,logger);
+ } catch (Exception ex) {
+ Log.logException("Error registering mbean.", ex, logger);
}
}
-
+
/**
* register a service
- * @param service - the service to register
- * @return the service of the same name that was previously registered, or null
+ *
+ * @param service
+ * - the service to register
+ * @return the service of the same name that was previously registered, or
+ * null
*/
- public synchronized Service addService(Service service){
+ public synchronized Service addService(Service service) {
return services.put(service.getName(), service);
}
-
+
/**
* get the service of the given name
+ *
* @param name
* @return
*/
- public Service getService(String name){
+ public Service getService(String name) {
return services.get(name);
}
- public ServiceFactory getServiceFactory(String type){
+ public ServiceFactory getServiceFactory(String type) {
return serviceFactories.get(type);
}
-
- public void registerServiceFactory(ServiceFactory factory){
+
+ public void registerServiceFactory(ServiceFactory factory) {
serviceFactories.put(factory.getType(), factory);
- logger.info("Registered '"+factory.getClass().getName()+"'"+
- " for service type '"+factory.getType()+"'");
+ logger.info("Registered '" + factory.getClass().getName() + "'"
+ + " for service type '" + factory.getType() + "'");
}
-
+
/**
- * get a read only list of all service factories
+ * get a read-only list of all service factories
*/
- public Collection<ServiceFactory>getServiceFactories(){
+ public Collection<ServiceFactory> getServiceFactories() {
return Collections.unmodifiableCollection(serviceFactories.values());
}
-
+
/**
* convenience method to retrieve the service home
- * @param serviceName - the name of the service
+ *
+ * @param serviceName
+ * - the name of the service
*/
- public Home getHome(String serviceName){
- Service s=services.get(serviceName);
- return s!=null?s.getHome():null;
+ public Home getHome(String serviceName) {
+ Service s = services.get(serviceName);
+ return s != null ? s.getHome() : null;
}
-
+
/**
* set the security properties on this kernel
+ *
* @param securityProperties
*/
- public void setSecurityProperties(ISecurityProperties securityProperties){
- this.securityProperties=securityProperties;
+ public void setSecurityProperties(ISecurityProperties securityProperties) {
+ this.securityProperties = securityProperties;
}
-
+
/**
* retrieve the security properties
+ *
* @return securityProperties
*/
- public ISecurityProperties getSecurityProperties(){
+ public ISecurityProperties getSecurityProperties() {
return securityProperties;
}
/**
* get a property. If not found, try System.getProperty
- * @param key - the property key
+ *
+ * @param key
+ * - the property key
* @return
*/
- public String getProperty(String key){
- String v=(String) properties.get(key);
- if(v==null){
- v=System.getProperty(key);
+ public String getProperty(String key) {
+ String v = (String) properties.get(key);
+ if (v == null) {
+ v = System.getProperty(key);
}
return v;
}
-
- public String getProperty(String key,String defaultValue){
- String v=getProperty(key);
- return v!=null ? v : defaultValue;
+
+ public String getProperty(String key, String defaultValue) {
+ String v = getProperty(key);
+ return v != null ? v : defaultValue;
}
-
-
+
/**
* Retrieve a boolean property
- * @param key - the property key
+ *
+ * @param key
+ * - the property key
* @return true if the property is set and equal to 'true' (ignoring case)
*/
- public boolean getBooleanProperty(String key){
+ public boolean getBooleanProperty(String key) {
return Boolean.parseBoolean(getProperty(key));
- }
-
+ }
/**
* Retrieve a boolean property
- * @param key - the property key
- * @param defaultValue - the response in case the property is not set
- * @return true if the property is set and equal to 'true' (ignoring case), else the supplied default
+ *
+ * @param key
+ * - the property key
+ * @param defaultValue
+ * - the response in case the property is not set
+ * @return true if the property is set and equal to 'true' (ignoring case),
+ * else the supplied default
*/
- public boolean getBooleanProperty(String key, boolean defaultValue){
- String val=getProperty(key);
- if(val==null)return defaultValue;
+ public boolean getBooleanProperty(String key, boolean defaultValue) {
+ String val = getProperty(key);
+ if (val == null)
+ return defaultValue;
return Boolean.parseBoolean(getProperty(key));
}
-
- public void setProperty(String key,String value){
- //workaround: java.util.Properties won't accept null values
- if(value==null){
+
+ public void setProperty(String key, String value) {
+ // workaround: java.util.Properties won't accept null values
+ if (value == null) {
properties.remove(key);
+ } else {
+ properties.put(key, value);
}
- else{
- properties.put(key,value);
- }
}
+ public void removeProperty(String key){
+ properties.remove(key);
+ }
+
/**
- * get a property that is defined per service.<br/>
- * As primary fallback, get the "general" property, and
- * as secondary fallback, the provided default value<br/>
- * Thus, the lookup sequence to find the property is:
- * <ul>
- * <li>PROPKEY.SERVICENAME</li>
- * <li>PROPKEY</li>
- * <li>default value</li>
- * </ul>
- *
- * @param key - the property key
- * @param serviceName - the service name
- * @param defaultValue - the value to return if no matching property can be found
+ * get a property that is defined per service.<br/> As primary fallback, get
+ * the "general" property, and as secondary fallback, the provided default
+ * value<br/> Thus, the lookup sequence to find the property is:
+ * <ul>
+ * <li>PROPKEY.SERVICENAME</li>
+ * <li>PROPKEY</li>
+ * <li>default value</li>
+ * </ul>
+ *
+ * @param key
+ * - the property key
+ * @param serviceName
+ * - the service name
+ * @param defaultValue
+ * - the value to return if no matching property can be found
* @return
*/
- public String getPerServiceProperty(String key, String serviceName, String defaultValue) {
- String res=properties.getProperty(key+"."+serviceName);
- if(res==null)res=properties.getProperty(key, defaultValue);
+ public String getPerServiceProperty(String key, String serviceName,
+ String defaultValue) {
+ String res = properties.getProperty(key + "." + serviceName);
+ if (res == null)
+ res = properties.getProperty(key, defaultValue);
return res;
}
-
- public Properties getProperties(){
+
+ public Properties getProperties() {
return properties;
}
-
+
/**
- * get access to the message system
+ * get access to the message system
*/
- public static IMessaging getMessaging()throws MessagingException{
+ public IMessaging getMessaging() throws MessagingException {
return MessagingImpl.get();
}
-
/**
* get the list of metrics to be published by the admin service
+ *
* @return
*/
public List<IMetric<?>> getMonitorMetrics() {
- List<IMetric<?>>res=new ArrayList<IMetric<?>>();
- for(String name: monitorMetrics){
- IMetric<?>m=MetricRegistry.getInstance().getMetric(name);
- if(m!=null)res.add(m);
+ List<IMetric<?>> res = new ArrayList<IMetric<?>>();
+ for (String name : monitorMetrics) {
+ IMetric<?> m = MetricRegistry.getInstance().getMetric(name);
+ if (m != null)
+ res.add(m);
}
return res;
}
-
-
+
/**
- * add a metric to the list of metrics that are published by the admin service
+ * add a metric to the list of metrics that are published by the admin
+ * service
+ *
* @see MonitorEntriesRP
- * @param name - the name of the metric to be published
+ * @param name
+ * - the name of the metric to be published
*/
public void registerMonitorMetric(String name) {
monitorMetrics.add(name);
}
- public static synchronized Kernel getKernel(){
- if(kernel==null) kernel=new Kernel();
- return kernel;
+ public long getLastConfigFileChangeTime(){
+ return serviceConfigurator!=null ? serviceConfigurator.getLastConfigFileUpdateTime() : -1;
}
-
-
+
/**
- * starts the UNICORE/X server asynchronously, i.e. this method returns immediately
+ * starts the UNICORE/X server asynchronously, i.e. this method returns
+ * immediately
*/
- public void start(final String conf)throws Exception{
- Thread t=new Thread(
- new Runnable(){
- public void run(){
- try{
- startSynchronous(conf);
- }catch(Throwable e){
- Log.logException("Error during server start.", e, logger);
- //make sure this ends up on the console
- System.err.println("ERROR DURING SERVER STARTUP!");
- e.printStackTrace();
- System.exit(1);
- }
- }
+ public void start(final String conf) throws Exception {
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ try {
+ startSynchronous(conf);
+ } catch (Throwable e) {
+ Log.logException("Error during server start.", e, logger);
+ System.err.println("ERROR DURING SERVER STARTUP!");
+ e.printStackTrace();
+ System.exit(1);
}
- );
+ }
+ });
t.setName("UNICORE/X-Startup");
t.start();
}
@@ -375,46 +470,144 @@
*
* @throws Exception
*/
- public void startSynchronous(String conf) throws Exception{
- //TODO
+ public void startSynchronous(String conf) throws Exception {
+ long start = System.currentTimeMillis();
+ printHeader();
+ List<Runnable> tasks = deployServices(conf);
+ initGateway();
+ SecurityManager.createAttributeSource();
+
+ jetty = new JettyServer();
+ jetty.start();
+
+ // runStartupCode();
+
+ //run init tasks after basic setup is complete
+ if(tasks!=null){
+ for (Runnable r : tasks) {
+ r.run();
+ }
+ }
+ // initJMX();
+ startLogConfigWatcher();
+ addShutDownHook();
+ logger.info("Startup time: " + (System.currentTimeMillis() - start)
+ + " ms.");
+ logger.info("***** Server started. *****");
+ System.out.println("***** Server started. *****");
+ System.out.println("Send TERM signal to shutdown gracefully.");
}
-
/**
- * Use this when running WSRFlite as a standalone server.
- * Services can be configured using an XML file
- * (by default found in conf/wsrflite.xml)
+ * Use this when running WSRFlite as a standalone server. Services can be
+ * configured using an XML file (by default found in conf/wsrflite.xml)
*
- * @param args First arg is the name of the config file
+ * @param args
+ * First arg is the name of the config file
* @throws Exception
*/
- public static void main(String[] args)throws Exception{
- String conf="conf/wsrflite.xml";
- try{
- conf=args[0];
- }catch(Exception e){}
- System.out.println("Reading configuration from file "+conf);
+ public static void main(String[] args) throws Exception {
+ String conf = new File("conf","wsrflite.xml").getAbsolutePath();
+ try {
+ conf = args[0];
+ } catch (Exception e) {
+ }
+ System.out.println("Reading configuration from file " + conf);
Kernel.getKernel().startSynchronous(conf);
}
-
- public static final String getVersion(){
- String ver=VERSION!=null?VERSION:"DEVELOPMENT";
- return ver;
+ public void printHeader() {
+ String header = getHeader();
+ System.out.println(header);
+ logger.info(header);
}
+
+ // register "standard" service factories
+ private void registerDefaultFactories() {
+ String[] factoryClasses = { "de.fzj.unicore.wsrflite.xfire.XFireServiceFactory", };
+
+ for (String clazz : factoryClasses) {
+ try {
+ Class<?> c = Class.forName(clazz);
+ ServiceFactory f = (ServiceFactory) c.newInstance();
+ registerServiceFactory(f);
+ } catch (ClassNotFoundException cnfe) {
+ // OK, maybe the module is not present
+ logger.debug("Service factory '" + clazz
+ + "' is not available (class not found).");
+ } catch (Exception e) {
+ logger.error("Can't register service factory " + clazz, e);
+ }
+ }
+ }
+
+ private void addShutDownHook() {
+ Runtime.getRuntime().addShutdownHook(new Thread("UNICORE/X-Shutdown") {
+ public void run() {
+ try {
+ shutdown();
+ } catch (Exception e) {
+ Log.logException("Error during shutdown", e, logger);
+ }
+ }
+ });
+ }
+
+ /**
+ * deploy and configure services
+ *
+ * @throws Exception
+ */
+ private List<Runnable> deployServices(String configFile) throws Exception {
+ List<Runnable> tasks = null;
+ if (configFile == null) {
+ logger.info("No services to deploy.");
+ return tasks;
+ }
+ File file = new File(configFile);
+ serviceConfigurator=new ServiceConfigReader(file, 5000);
+ serviceConfigurator.configureServices();
+ tasks=serviceConfigurator.getInitTasks();
+ return tasks;
+ }
- public static final String getHeader(){
- String lineSep=System.getProperty("line.separator");
- String s=lineSep+" _ _ _ _ _____ _____ ____ _____ ______ ___ __"+lineSep+
- "| | | | \\ | |_ _/ ____/ __ \\| __ \\| ____| / \\ \\ / /"+lineSep+
- "| | | | \\| | | || | | | | | |__) | |__ / / \\ V / "+lineSep+
- "| | | | . ` | | || | | | | | _ /| __| / / > < "+lineSep+
- "| |__| | |\\ |_| |_ |____ |__| | | \\ \\| |____ / / / . \\ "+lineSep+
- " \\____/|_| \\_|_____\\_____\\____/|_| \\_\\______/_/ /_/ \\_\\"+lineSep+
- "UNICORE Services Environment"+lineSep+
- "Version "+getVersion()+", http://www.unicore.eu";
- return s;
+ private void initGateway()throws Exception{
+ // wait for the gateway
+ if (!gwHandler.waitForGateway()) {
+ throw new Exception(
+ "The Gateway is not available (and the property '"
+ + GatewayHandler.ON_STARTUP_WAIT_KEY + "' is set to 'true')");
+ }
+ // if appropriate, dynamically register with gateway
+ gwHandler.enableGatewayRegistration();
}
-
-
+
+ /**
+ * sets up a watchdog that checks for changes to the log4j configuration file,
+ * and re-configures log4j if that file has changed
+ */
+ private void startLogConfigWatcher(){
+ final String logConfig=System.getProperty("log4j.configuration");
+ if(logConfig==null){
+ logger.debug("No logger configuration found.");
+ return;
+ }
+ try{
+ Runnable r=new Runnable(){
+ public void run(){
+ logger.info("LOG CONFIG MODIFIED, re-configuring.");
+ PropertyConfigurator.configure(logConfig);
+ }
+ };
+ File logProperties=logConfig.startsWith("file:")?new File(new URI(logConfig)):new File(logConfig);
+ FileWatcher fw=new FileWatcher(logProperties,r);
+ ResourcePool.getScheduledExecutorService().scheduleWithFixedDelay(fw, 5, 5, TimeUnit.SECONDS);
+ }catch(FileNotFoundException fex){
+ logger.warn("Log configuration file <"+logConfig+"> not found.");
+ }
+ catch(URISyntaxException use){
+ logger.warn("Location of log configuration is not an URI: <"+logConfig+">");
+ }
+
+ }
}
Modified: wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/ServiceFactory.java
===================================================================
--- wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/ServiceFactory.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/ServiceFactory.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -7,12 +7,36 @@
*/
public interface ServiceFactory {
+ /**
+ * the type of service handled by this factory
+ */
public String getType();
+ /**
+ * initialise this factory. This is called on container start before any services are
+ * deployed
+ *
+ * @throws Exception
+ */
+ public void start()throws Exception;
+
+ /**
+ * build a {@link Service} from the given configuration
+ * @param configuration
+ * @return {@link Service}
+ */
public Service build(ServiceConfiguration configuration);
+ /**
+ * servlet class name
+ * @return
+ */
public String getServletClass();
+ /**
+ * servlet path. Will be used to construct the address, e.g.
+ * https://host:port/servlet_path/service_name
+ */
public String getServletPath();
}
Modified: wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/impl/ResourceImpl.java
===================================================================
--- wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/impl/ResourceImpl.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/impl/ResourceImpl.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -35,12 +35,18 @@
import java.io.Serializable;
import java.lang.reflect.Field;
+import java.security.cert.CertPath;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import javax.security.auth.x500.X500Principal;
+
import org.apache.log4j.Logger;
import de.fzj.unicore.wsrflite.Home;
@@ -51,15 +57,25 @@
import de.fzj.unicore.wsrflite.persistence.Persist;
import de.fzj.unicore.wsrflite.persistence.PersistenceManager;
import de.fzj.unicore.wsrflite.persistence.PersistenceSettings;
+import de.fzj.unicore.wsrflite.security.SecurityManager;
import de.fzj.unicore.wsrflite.utils.Log;
import de.fzj.unicore.wsrflite.utils.Utilities;
+import eu.unicore.security.Client;
+import eu.unicore.security.SecurityTokens;
+import eu.unicore.security.etd.TrustDelegation;
/**
* Base implementation of the WSRFInstance lifecycle interface<br/>
*
* Persistence is handled using annotations: persistent fields are
- * marked with the {@link Persist} annotation.
+ * marked with the {@link Persist} annotation.<br/>
*
+ * Security features: this class holds
+ * <ul>
+ * <li>the {@link SecurityTokens} pertaining to the current request</li>
+ * <li>the DN of the service's owner</li>
+ * <li>a reference to the current {@link Client}</li>
+ * </ul>
* @author schuller
*/
public abstract class ResourceImpl implements Resource {
@@ -88,7 +104,17 @@
@Persist
private Calendar terminationTime;
+
+ /**
+ * the owner of this resource.
+ */
+ @Persist
+ private X500Principal owner;
+
+ @Persist
+ protected String initialXlogin=null;
+
/**
* an initialisation parameter that may be used to set the
* unique id on a resource,
@@ -119,7 +145,15 @@
*/
public static final String INITPARAM_CLIENT=ResourceImpl.class.getName()+".init.clientReference";
+
/**
+ * default constructor<br/>
+ * further initialisation is done through initialise() or activate()
+ */
+ public ResourceImpl() {
+ }
+
+ /**
* set the "dirty" flag, so the state of this instance will be written to
* permanent storage
*/
@@ -131,29 +165,11 @@
isDirty=false;
}
- /**
- * default constructor<br/>
- * further initialisation is done through initialise() or activate()
- */
- public ResourceImpl() {
-
+ public void postActivate() {
+ //make sure client will be initialised once per request
+ getClient();
}
- public void postActivate(){
- }
-
- public Map<String, Object> getSecurityContext() {
- return securityContexts.get();
- }
-
- public void setSecurityContext(Map<String, Object> ctx) {
- securityContexts.set(ctx);
- }
-
- public void clearSecurityContext() {
- securityContexts.remove();
- }
-
public String getUniqueID(){return uniqueID;}
public String getServiceName(){return serviceName;}
@@ -322,7 +338,152 @@
}
public void processMessages(PullPoint messageIterator){
+ }
+
+ // --- security functions --- //
+
+
+ public Map<String, Object> getSecurityContext() {
+ return securityContexts.get();
}
+ public void setSecurityContext(Map<String, Object> ctx) {
+ securityContexts.set(ctx);
+ }
+
+ public void clearSecurityContext() {
+ securityContexts.remove();
+ }
+
+
+ /**
+ * get the Client object <br/>
+ * if null, create it from the message context, ssl things, etc.
+ *
+ * @return Cient
+ */
+ public synchronized Client getClient() {
+ if(getSecurityContext()==null)return null;
+ Client client=(Client)getSecurityContext().get("unicore.authz.client");
+ if(client==null){
+ try{
+ SecurityTokens tokens=getSecurityTokens();
+ client=SecurityManager.createAndAuthoriseClient(tokens);
+ getSecurityContext().put("unicore.authz.client", client);
+ }catch(Exception e){
+ Log.logException("Error creating client info.",e,logger);
+ }
+ if(initialXlogin!=null){
+ try{
+ if(client.getXlogin().isValid(initialXlogin)){
+ client.setUserName(initialXlogin);
+ if(logger.isDebugEnabled()){
+ logger.debug("Using user name <"+initialXlogin+">");
+ }
+ }
+ }catch(Exception e){
+ Log.logException("Error setting user name.",e,logger);
+ }
+ }
+ }
+ return client;
+ }
+
+
+ /**
+ * Get the DN of the owner of this resource.
+ * If not set in the security context, this is set to be the server.
+ *
+ * @return {@link X500Principal}
+ */
+ public X500Principal getOwner(){
+ if(owner!=null)return owner;
+ try{
+ owner=SecurityManager.getServerIdentity();
+ logger.debug("Setting server as owner of "+getServiceName()+"<"+getUniqueID()+">");
+ return owner;
+ }catch(Exception e){
+ Log.logException("Error setting owner attribute.",e,logger);
+ }
+ return null;
+ }
+
+ /**
+ * set the default owner of this resource, which is
+ * <ul>
+ * <li>the original user if trust delegation info is present, or we have the user cert</li>
+ * <li>the consignor, if available</li>
+ * </ul>
+ */
+ protected void setDefaultOwner(){
+ SecurityTokens tokens=getSecurityTokens();
+ if(tokens!=null){
+ X500Principal p=tokens.getEffectiveUserName();
+ //in proxy mode
+ if(SecurityManager.isProxyModeEnabled()){
+ try{
+ p=SecurityManager.getProxiedUserCert(tokens).getSubjectX500Principal();
+ }catch(CertificateException ce){
+ Log.logException("Invalid certs for request?", ce,logger);
+ }
+ }
+ if(p!=null)setOwner(p);
+ }
+ if(logger.isDebugEnabled()){
+ if(owner!=null)logger.debug("Owner: "+getOwner().getName());
+ else{
+ logger.debug("Owner could not be assigned.");
+ }
+ }
+ }
+
+ /**
+ * get the security tokens that were extracted from the request
+ */
+ public SecurityTokens getSecurityTokens(){
+ try{
+ return(SecurityTokens)getSecurityContext().get(SecurityTokens.KEY);
+ }catch(NullPointerException npe){return null;}
+ }
+
+ /**
+ * get the trust delegation chain that was extracted from the request
+ */
+ public List<TrustDelegation> getTrustDelegationTokens(){
+ return getSecurityTokens().getTrustDelegationTokens();
+ }
+
+
+ public void setOwner(CertPath owner){
+ this.owner=((X509Certificate)owner.getCertificates().get(0)).getSubjectX500Principal();
+ }
+
+ /**
+ * set the owner using a {@link X509Certificate}
+ *
+ * @param owner - an {@link X509Certificate}
+ */
+ public void setOwner(X509Certificate owner){
+ this.owner=owner.getSubjectX500Principal();
+ }
+
+ /**
+ * set the owner using an {@link X500Principal}
+ *
+ * @param owner - an {@link X500Principal}
+ */
+ public void setOwner(X500Principal owner){
+ this.owner=owner;
+ }
+
+ /**
+ * set the owner using the String form of an {@link X500Principal}
+ *
+ * @param owner
+ */
+ public void setOwner(String owner){
+ this.owner=new X500Principal(owner);
+ }
+
}
Modified: wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/security/SecurityManager.java
===================================================================
--- wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/security/SecurityManager.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/security/SecurityManager.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -167,7 +167,7 @@
*
* <ul>
* <li>it can be configured statically, by adding the certificate to the truststore and
- * setting the property {@link IUASSecurityProperties#UAS_GATEWAY_ALIAS} to the
+ * setting the property {@link ISecurityProperties#UAS_GATEWAY_ALIAS} to the
* alias of the certificate</li>
* <li>it is retrieved dynamically by opening an SSL connection to the server at the configured
* base url</li>
@@ -626,16 +626,40 @@
return true;
}
+ private static final ThreadLocal<Boolean>localCalls=new ThreadLocal<Boolean>();
- //TODO better implementation of this without XFire stuff in it
+
+ /**
+ * for the current thread, set the "local call" flag. This should be used always in
+ * using a try-finally construct, i.e.
+ *
+ * <pre>
+ * SecurityManager.setLocalCall();
+ * try{
+ * //... perform call
+ * }
+ * finally{
+ * SecurityManager.clearLocalCall();
+ * }
+ * </pre>
+ */
+ public static void setLocalCall(){
+ localCalls.set(Boolean.TRUE);
+ }
+
+ /**
+ * for the current thread, clear the "local call" flag
+ * @return
+ */
+ public static void clearLocalCall(){
+ localCalls.set(null);
+ }
+
+ /**
+ * check whether the current request is local (i.e. made from within the same VM)
+ */
public static boolean isLocalCall(){
- throw new eu.unicore.security.SecurityException("SecurityManager.isLocalCall() is NOT IMPLEMENTED YET!!");
-// try{
-// return XFireServletController.getRequest()==null;
-// }catch(Exception ex){
-// logger.error(ex);
-// }
-// return false;
+ return Boolean.TRUE.equals(localCalls.get());
}
/**
Modified: wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/server/AccessControlInterceptor.java
===================================================================
--- wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/server/AccessControlInterceptor.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/server/AccessControlInterceptor.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -5,8 +5,6 @@
* Perform access control immediately before invoking
* a method on a service object
*
- * @see WSRFInvoker
- *
* @author schuller
*/
public interface AccessControlInterceptor {
Modified: wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/server/JettyServer.java
===================================================================
--- wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/server/JettyServer.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/server/JettyServer.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -307,12 +307,13 @@
if (p == null) {
p = String.valueOf(defaults.get(pName));
}
- logger.info("Jetty server property <" + pName + "> is <" + p + ">");
+ if(logger.isDebugEnabled()){
+ logger.debug("Jetty server property <" + pName + "> is <" + p + ">");
+ }
return Integer.parseInt(p);
}
protected void addServlets() throws Exception {
- logger.info("Adding servlets.");
boolean enableGzip = Boolean.parseBoolean(Kernel.getKernel().getProperty(ConfigurableGzipFilter.ENABLE_GZIP));
for(ServiceFactory f: Kernel.getKernel().getServiceFactories()){
Modified: wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/FileWatcher.java
===================================================================
--- wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/FileWatcher.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/FileWatcher.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -40,5 +40,5 @@
action.run();
}
}
-
+
}
Modified: wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/Utilities.java
===================================================================
--- wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/Utilities.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/Utilities.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -33,7 +33,9 @@
package de.fzj.unicore.wsrflite.utils;
+import java.io.IOException;
import java.net.URI;
+import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -49,6 +51,7 @@
import org.w3c.dom.NodeList;
import de.fzj.unicore.wsrflite.Kernel;
+import de.fzj.unicore.wsrflite.security.ISecurityProperties;
/**
* tools and utilities, mainly for working with XMLBeans
@@ -326,4 +329,41 @@
return true;
}
+
+ /**
+ * return the physical server address
+ * @return a URL of the form scheme://host:port where 'scheme' is http or https
+ */
+ public static String getPhysicalServerAddress(){
+ String host=Kernel.getKernel().getProperty(Kernel.WSRF_HOST);
+ String port=Kernel.getKernel().getProperty(Kernel.WSRF_PORT);
+ String proto="http";
+ if("true".equals(Kernel.getKernel().getProperty(ISecurityProperties.WSRF_SSL))){
+ proto="https";
+ };
+ return proto+"://"+host+":"+port;
+ }
+
+
+ /**
+ * return the Gateway address, i.e.e the base part of this server's URL
+ * @return
+ * @throws Exception
+ */
+ public static String getGatewayAddress()throws Exception{
+ URL u=new URL(Kernel.getKernel().getProperty(Kernel.WSRF_BASEURL));
+ return u.toString().split(u.getPath())[0];
+ }
+
+ public static List<XmlObject>extractElements(XmlObject source, QName name)throws IOException,XmlException{
+ List<XmlObject>res=new ArrayList<XmlObject>();
+ XmlCursor cursor=source.newCursor();
+ while(skipToElement(cursor, name)){
+ XmlObject o=XmlObject.Factory.parse(cursor.newReader());
+ res.add(o);
+ }
+ cursor.dispose();
+ return res;
+ }
+
}
Modified: wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/deployment/ServiceConfigReader.java
===================================================================
--- wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/deployment/ServiceConfigReader.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/main/java/de/fzj/unicore/wsrflite/utils/deployment/ServiceConfigReader.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -115,10 +115,6 @@
private String wsdlLocation=null;
- public static final String WATCH_CONFIG="wsrflite.config.watch";
-
- public static final String WATCH_CONFIG_INTERVAL="wsrflite.config.watch.interval";
-
private final File configFile;
public ServiceConfigReader() {
@@ -127,14 +123,14 @@
/**
* Configure from the given file. This file will be watched for changes using
- * the given period (use -1 to disable the watch)
+ * the given period (use a negative number to disable the watch)
*
- * @param configFile - the config file
- * @param period - the file checking period in milliseconds
+ * @param config - the config file
+ * @param period - the file checking period in milliseconds (use a negative number to disable)
* @throws FileNotFoundException
*/
- public ServiceConfigReader(final File configFile, long period) throws FileNotFoundException{
- this.configFile=configFile;
+ public ServiceConfigReader(File config, long period) throws FileNotFoundException{
+ this.configFile=config;
Runnable r=new Runnable() {
public void run() {
try{
@@ -179,7 +175,7 @@
* @throws ParserConfigurationException - if no SAX parser can be set up
* @throws
*/
- public void configureServices(InputStream is) throws SAXException, ParserConfigurationException, IOException{
+ private void configureServices(InputStream is) throws SAXException, ParserConfigurationException, IOException{
InputSource source=new InputSource(is);
SAXParserFactory factory=SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
@@ -244,6 +240,11 @@
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
+ if("serviceFactory".equals(localName)){
+ String sfClass=attributes.getValue("class");
+ doRegisterServiceFactory(sfClass);
+ }
+
if("globalHandler".equals(localName)){
String globalHandlerType=attributes.getValue("type");
String globalHandlerClass=attributes.getValue("class");
@@ -256,8 +257,7 @@
}
}
}
-
- if("service".equals(qName)){
+ else if("service".equals(qName)){
type=attributes.getValue("type");
current=attributes.getValue("name");
isPersistent=Boolean.parseBoolean(attributes.getValue("persistent"));
@@ -366,6 +366,15 @@
}
}
+ private void doRegisterServiceFactory(String clazz)throws ServiceDeploymentException{
+ try{
+ ServiceFactory sf=(ServiceFactory)Class.forName(clazz).newInstance();
+ Kernel.getKernel().registerServiceFactory(sf);
+ }catch(Exception ex){
+ throw new ServiceDeploymentException("Can't register '"+clazz+"' as a service factory.",ex);
+ }
+ }
+
//reset state
protected void reInit(){
inhandlers.clear();
@@ -401,5 +410,12 @@
return initTasks;
}
+ /**
+ * return the time the config file was last modified
+ * @return the config file's {@link File#lastModified()} or -1 if no config file was defined
+ */
+ public long getLastConfigFileUpdateTime(){
+ return configFile!=null? configFile.lastModified() : -1;
+ }
}
Modified: wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/TestKernel.java
===================================================================
--- wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/TestKernel.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/TestKernel.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -1,12 +1,21 @@
package de.fzj.unicore.wsrflite;
+import de.fzj.unicore.wsrflite.security.ISecurityProperties;
import junit.framework.TestCase;
public class TestKernel extends TestCase {
- public void testKernel(){
+ public void testHeader(){
+ System.out.println(Kernel.getKernel().getHeader());
+ }
+
+ public void testKernelStartup()throws Exception{
Kernel k=Kernel.getKernel();
assertNotNull(k);
+ k.startSynchronous("src/test/resources/conf/wsrflite.xml");
+ ISecurityProperties sp=k.getSecurityProperties();
+ assertNotNull(sp);
+ assertEquals("src/test/resources/conf/keystore.jks",sp.getKeystore());
}
-
+
}
Modified: wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/testservice/MockServiceFactory.java
===================================================================
--- wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/testservice/MockServiceFactory.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/testservice/MockServiceFactory.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -22,5 +22,8 @@
return "/mock/*";
}
-
+ public void start(){
+
+ }
+
}
Modified: wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/utils/deployment/TestServiceConfigReader.java
===================================================================
--- wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/utils/deployment/TestServiceConfigReader.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/test/java/de/fzj/unicore/wsrflite/utils/deployment/TestServiceConfigReader.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -1,24 +1,20 @@
package de.fzj.unicore.wsrflite.utils.deployment;
import java.io.File;
-import java.io.FileInputStream;
+import junit.framework.TestCase;
import de.fzj.unicore.wsrflite.Kernel;
import de.fzj.unicore.wsrflite.Service;
import de.fzj.unicore.wsrflite.testservice.MockService;
import de.fzj.unicore.wsrflite.testservice.MockServiceFactory;
-import junit.framework.TestCase;
-
public class TestServiceConfigReader extends TestCase {
public void testDeployService()throws Exception{
Kernel.getKernel().registerServiceFactory(new MockServiceFactory());
File conf=new File("src/test/resources/conf/wsrflite.xml");
- FileInputStream is=new FileInputStream(conf);
- ServiceConfigReader r=new ServiceConfigReader();
- r.configureServices(is);
- is.close();
+ ServiceConfigReader r=new ServiceConfigReader(conf,-1);
+ r.configureServices();
Service s=Kernel.getKernel().getService("test");
assertNotNull(s);
assertEquals(MockService.TYPE,s.getType());
Modified: wsrflite/trunk/core/src/test/resources/conf/wsrflite.xml
===================================================================
--- wsrflite/trunk/core/src/test/resources/conf/wsrflite.xml 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/core/src/test/resources/conf/wsrflite.xml 2011-01-13 13:13:03 UTC (rev 8553)
@@ -1,11 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<services xmlns="http://www.fz-juelich.de/unicore/wsrflite">
- <!-- hosting configuration: persistence, security etc. -->
+ <!-- interface to bind to -->
<property name="unicore.wsrflite.host" value="localhost"/>
+ <!-- persistence -->
<property name="unicore.wsrflite.persistence.persist" value="de.fzj.unicore.wsrflite.persistence.Persistence"/>
<property name="persistence.directory" value="target/test/resources/data"/>
+
+ <!-- security config -->
<property name="unicore.wsrflite.ssl" value="true"/>
<property name="unicore.wsrflite.ssl.clientauth" value="true"/>
<property name="unicore.wsrflite.ssl.truststore" value="src/test/resources/conf/keystore.jks"/>
@@ -15,7 +18,10 @@
<property name="unicore.wsrflite.ssl.keypass" value="the!njs"/>
<property name="unicore.wsrflite.ssl.keytype" value="jks"/>
<property name="unicore.wsrflite.ssl.keyalias" value="njs test certificate"/>
-
+
+ <!-- additional service factories -->
+ <serviceFactory class="de.fzj.unicore.wsrflite.testservice.MockServiceFactory"/>
+
<!--the services to deploy-->
<service name="test" type="mock">
<interface class=""/>
Modified: wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/admin/service/AdminServiceImpl.java
===================================================================
--- wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/admin/service/AdminServiceImpl.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/admin/service/AdminServiceImpl.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -52,7 +52,7 @@
import de.fzj.unicore.wsrflite.Kernel;
import de.fzj.unicore.wsrflite.persistence.PersistenceManager;
import de.fzj.unicore.wsrflite.utils.Log;
-import de.fzj.unicore.wsrflite.utils.Utilities;
+import de.fzj.unicore.wsrflite.utils.WSUtilities;
import de.fzj.unicore.wsrflite.xmlbeans.ClearMetricDataRequestDocument;
import de.fzj.unicore.wsrflite.xmlbeans.ClearMetricDataResponseDocument;
import de.fzj.unicore.wsrflite.xmlbeans.DeleteServiceInstanceRequestDocument;
@@ -107,7 +107,7 @@
String uid = req.getGetServiceInstanceRequest().getUid();
try {
- String instanceURL = Utilities.makeAddress(serviceName, uid);
+ String instanceURL = WSUtilities.makeAddress(serviceName, uid);
EndpointReferenceType epr=EndpointReferenceType.Factory.newInstance();
epr.addNewAddress().setStringValue(instanceURL);
Deleted: wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/utils/Constants.java
===================================================================
--- wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/utils/Constants.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/utils/Constants.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -1,74 +0,0 @@
-/*********************************************************************************
- * Copyright (c) 2006 Forschungszentrum Juelich GmbH
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * (1) Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the disclaimer at the end. Redistributions in
- * binary form must reproduce the above copyright notice, this list of
- * conditions and the following disclaimer in the documentation and/or other
- * materials provided with the distribution.
- *
- * (2) Neither the name of Forschungszentrum Juelich GmbH nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * DISCLAIMER
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- ********************************************************************************/
-
-
-package de.fzj.unicore.wsrflite.utils;
-
-import javax.xml.namespace.QName;
-
-/**
- * constants related to WS(RF) support
- *
- * @author schuller
- */
-public class Constants {
-
- @Deprecated
- public final static QName FLE_RESOURCE_DISAMBIGUATOR=
- new QName("http://com.fujitsu.arcon.addressing",
- "ResourceDisambiguator");
-
- public final static QName U6_RESOURCE_ID=
- new QName("http://www.unicore.eu/unicore6",
- "ResourceId");
-
- public static QName[] supported=new QName[]{
- U6_RESOURCE_ID,
- new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
- "Security"),
- //the next one is for backwards compatibility with older clients
- FLE_RESOURCE_DISAMBIGUATOR,
- };
-
- public final static QName EPR_METADATA=
- new QName("http://www.w3.org/2005/08/addressing",
- "Metadata");
-
- public final static QName INTERFACE_NAME=
- new QName("http://www.w3.org/2005/08/addressing/metadata",
- "InterfaceName");
-
- public final static QName SERVER_NAME=
- new QName("http://www.unicore.eu/unicore6",
- "ServerIdentity");
-
-}
Deleted: wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/utils/Log.java
===================================================================
--- wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/utils/Log.java 2011-01-13 12:46:33 UTC (rev 8552)
+++ wsrflite/trunk/wsrfcore/src/main/java/de/fzj/unicore/wsrflite/utils/Log.java 2011-01-13 13:13:03 UTC (rev 8553)
@@ -1,131 +0,0 @@
-package de.fzj.unicore.wsrflite.utils;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.MDC;
-
-public class Log {
-
- protected Log(){}
-
- /**
- * logger prefix for admin stuff
- */
- public static final String ADMIN="unicore.admin";
-
- /**
- * logger prefix for general WSRFlite code
- */
- public static final String WSRFLITE="unicore.wsrflite";
-
- /**
- * logger prefix for persistence related code
- */
- public static final String PERSISTENCE="unicore.wsrflite.persistence";
-
- /**
- * logger prefix for services
- */
- public static final String SERVICES="unicore.services";
-
- /**
- * logger prefix for security
- */
- public static final String SECURITY="unicore.security";
-
-
- /**
- * returns a logger name, using the given prefix and the simple name
- * of the given class
- *
- * @param prefix - the prefix to use
- * @param clazz - the class
- * @return logger name
- */
- public static String getLoggerName(String prefix, Class<?>clazz){
- return prefix+"."+clazz.getSimpleName();
- }
-
- /**
- * returns a logger, using the given prefix and the simple name
- * of the given class
- *
- * @param prefix - the prefix to use
- * @param clazz - the class
- * @return logger
- */
- public static Logger getLogger(String prefix, Class<?>clazz){
- return Logger.getLogger(prefix+"."+clazz.getSimpleName());
- }
-
- /**
- * log an error message to the default logger ("unicore.wsrflite")
- * A human-friendly message is constructed and logged at "INFO" level.
- * The stack trace is logged at "DEBUG" level.
- *
- * @param message - the error message
- * @param cause - the cause of the error
- *
- */
- public static void logException(String message, Throwable cause){
- logException(message,cause,Logger.getLogger(WSRFLITE));
- }
-
- /**
- * log an error message to the specified logger.
- * A human-friendly message is constructed and logged at "ERROR" level.
- * The stack trace is logged at "DEBUG" level.
- *
- * @param message - the error message
- * @param cause - the cause of the error
- * @param logger - the logger to use
- */
- public static void logException(String message, Throwable cause, Logger logger){
- logger.error(message);
- if(cause!=null){
- logger.error("Th...
[truncated message content] |