Author: objectiser
Date: 2009-02-10 06:12:34 -0500 (Tue, 10 Feb 2009)
New Revision: 485
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/AbstractServiceValidator.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/DefaultValidatorConfig.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/Endpoint.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidator.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidatorFactory.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidatorManager.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfig.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfigFactory.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfigLoader.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorName.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/action/
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/action/ValidationAction.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAServiceRecorder.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAServiceValidator.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAValidatorConfigLoader.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/ValidatorConfigGenerator.java
Removed:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidationAction.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorGenerator.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorManager.java
Modified:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ESBUtil.java
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorFilter.java
Log:
Updated service validator to incorporate an update mechanism. Currently the
ValidationAction is not functional.
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/AbstractServiceValidator.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/AbstractServiceValidator.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/AbstractServiceValidator.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+/**
+ * Abstract base class representing the ServiceValidator.
+ */
+public abstract class AbstractServiceValidator implements ServiceValidator {
+
+ private static final String MODELS_PATH = "models/";
+
+ /**
+ * This is the constructor for the abstract
+ * service validator, initialised with the validator
+ * name.
+ *
+ * @param name The validator name
+ */
+ public AbstractServiceValidator(ValidatorName name) {
+ m_name = name;
+ }
+
+ /**
+ * This method returns the validator name.
+ *
+ * @return The validator name
+ */
+ public ValidatorName getValidatorName() {
+ return(m_name);
+ }
+
+ /**
+ * This method returns the input stream associated
+ * with the model.
+ *
+ * @return The model's input stream, or null if
+ * not found
+ */
+ protected java.io.InputStream getModel() {
+ String filePath=MODELS_PATH+getValidatorName().getModelName();
+
+ java.io.InputStream ret = AbstractServiceValidator.class.
+ getClassLoader().getResourceAsStream(filePath);
+
+ return(ret);
+ }
+
+ private ValidatorName m_name=null;
+}
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/DefaultValidatorConfig.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/DefaultValidatorConfig.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/DefaultValidatorConfig.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+import org.jboss.soa.esb.helpers.*;
+
+/**
+ * This class represents a default configuration that will be used for
+ * validation against a stream of ESB based messages.
+ */
+public class DefaultValidatorConfig implements ValidatorConfig {
+
+ /**
+ * This is the constructor for the default validator model.
+ *
+ * @param modeType The model type
+ * @param config The configuration
+ */
+ public DefaultValidatorConfig(String modelType, ConfigTree config) {
+ m_modelType = modelType;
+ m_configuration = config;
+ }
+
+ /**
+ * This method returns the type of the model associated
+ * with this validator configuration. This will
+ * general be based on the file extension of the model
+ * file.
+ *
+ * @return The model type
+ */
+ public String getModelType() {
+ return(m_modelType);
+ }
+
+ /**
+ * This method returns the validator configuration
+ * associated with the model.
+ *
+ * @return The validator model
+ */
+ public ConfigTree getConfiguration() {
+ return(m_configuration);
+ }
+
+ private String m_modelType=null;
+ private ConfigTree m_configuration=null;
+}
Modified:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ESBUtil.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ESBUtil.java 2009-02-09
20:27:42 UTC (rev 484)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ESBUtil.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -19,17 +19,18 @@
import java.util.logging.Logger;
-import org.pi4soa.common.util.NamesUtil;
-import org.pi4soa.common.xml.NameSpaceUtil;
-
+/**
+ * This class provides utility functions for processing
+ * ESB messages.
+ */
public class ESBUtil {
/**
- * This method returns the pi4soa message associated
+ * This method returns the message content associated
* with the supplied JBoss ESB message.
*
* @param message The esb message
- * @return The pi4soa message
+ * @return The message content
*/
public static java.io.Serializable getMessage(
org.jboss.soa.esb.message.Message message) {
@@ -58,7 +59,8 @@
} else if (message.getBody().getNames() != null &&
message.getBody().getNames().length > 1) {
- java.util.Hashtable multipart=new java.util.Hashtable();
+ java.util.Hashtable<String,Object> multipart=
+ new java.util.Hashtable<String,Object>();
for (int i=0; i < message.getBody().getNames().length; i++) {
multipart.put(message.getBody().getNames()[i],
@@ -76,74 +78,5 @@
return(ret);
}
- /**
- * This method returns the JBoss ESB message associated
- * with the supplied pi4soa message.
- *
- * @param message The pi4soa message
- * @return The esb message
- */
- public static org.jboss.soa.esb.message.Message getMessage(
- org.pi4soa.service.Message message) {
- org.jboss.soa.esb.message.Message ret=
- org.jboss.soa.esb.message.format.MessageFactory.getInstance().getMessage();
-
- // Check if multi-part message
- if (message.isMultiPart()) {
- if (message.getValue() instanceof java.util.Map) {
- java.util.Map parts=(java.util.Map)message.getValue();
-
- java.util.Iterator iter=parts.keySet().iterator();
- while (iter.hasNext()) {
- String key=(String)iter.next();
-
- ret.getBody().add(key, parts.get(key));
- }
- } else {
- logger.severe("JBossESB message " +
- "is not a valid multi-part message");
- }
- } else {
- ret.getBody().add(message.getValue());
- }
-
- // Determine if the message represents a fault
- if (NamesUtil.isSet(message.getFaultName())) {
- String namespace=NameSpaceUtil.getNamespace(message.getFaultName());
- String localpart=NameSpaceUtil.getLocalPart(message.getFaultName());
-
- try {
- ret.getFault().setCode(new java.net.URI(
- namespace+"/"+localpart));
- } catch(Exception e) {
- logger.severe("JBossESB message " +
- "failed to set fault code: "+e);
- }
- }
-
- return(ret);
- }
-
- public static String encodeServiceParameter(String param) {
- return(param.replaceAll(":", "/colon/"));
- }
-
- public static String decodeServiceParameter(String param) {
- return(param.replaceAll("/colon/", ":"));
- }
-
- public static String getCategory(String category) {
- String ret=category;
-
- if (ret.startsWith("http://")) {
- ret = ret.substring(7);
- }
-
- // Convert '/' into another separator
- ret = ret.replace('/', '_');
-
- return(ret);
- }
-
- private static Logger logger = Logger.getLogger("org.pi4soa.jbossesb.util");
+ private static Logger logger =
Logger.getLogger("org.jboss.soa.overlord.validator.jbossesb");
}
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/Endpoint.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/Endpoint.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/Endpoint.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+/**
+ * This class represents an endpoint being monitored by one
+ * or more service validator.
+ */
+public class Endpoint {
+
+ /**
+ * This is the constructor for the endpoint, supplying
+ * the destination associated with the endpoint.
+ *
+ * @param destination The destination
+ */
+ public Endpoint(String destination) {
+ m_destination = destination;
+ }
+
+ /**
+ * This method returns the destination for the endpoint.
+ *
+ * @return The destination
+ */
+ public String getDestination() {
+ return(m_destination);
+ }
+
+ /**
+ * This method returns the list of service validators
+ * associated with this endpoint.
+ *
+ * @return The list of service validators for this endpoint
+ */
+ public java.util.List<ServiceValidator> getServiceValidators() {
+ return(m_validators);
+ }
+
+ public boolean equals(Object obj) {
+ boolean ret=false;
+
+ if (obj instanceof Endpoint) {
+ Endpoint ep=(Endpoint)obj;
+
+ if (ep.getDestination() != null &&
+ ep.getDestination().equals(m_destination)) {
+ ret = true;
+ }
+ }
+
+ return(ret);
+ }
+
+ public int hashCode() {
+ int ret=0;
+
+ if (m_destination != null) {
+ ret = m_destination.hashCode();
+ }
+
+ return(ret);
+ }
+
+ private String m_destination=null;
+ private java.util.List<ServiceValidator> m_validators=
+ new java.util.Vector<ServiceValidator>();
+}
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidator.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidator.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidator.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * This interface represents a service validator responsible for
+ * validing a stream of ESB messages against a model.
+ */
+public interface ServiceValidator {
+
+ /**
+ * This method returns the validator name.
+ *
+ * @return The validator name
+ */
+ public ValidatorName getValidatorName();
+
+ /**
+ * This method processes a sent message against a service
+ * behavioural description.
+ *
+ * @param msg The message
+ * @throws Exception Failed to process sent message
+ */
+ public void messageSent(Message msg) throws Exception;
+
+ /**
+ * This method processes a received message against a service
+ * behavioural description.
+ *
+ * @param msg The message
+ * @throws Exception Failed to process received message
+ */
+ public void messageReceived(Message msg) throws Exception;
+
+ /**
+ * This method is called to update the model associated
+ * with the service validator.
+ */
+ public void update();
+
+ /**
+ * This method closes the service validator.
+ *
+ * @throws Exception Failed to close the service validator
+ */
+ public void close() throws Exception;
+
+}
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidatorFactory.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidatorFactory.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidatorFactory.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+import java.lang.reflect.Constructor;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class provides a factory for Service Validators.
+ */
+public class ServiceValidatorFactory {
+
+ /**
+ * This method returns the Service Validator appropriate
+ * for the supplied validator name.
+ *
+ * @param name The validator name
+ * @return The service validator
+ * @exception IOException Failed to create the service validator
+ */
+ public static ServiceValidator getServiceValidator(ValidatorName name)
+ throws Exception {
+ ServiceValidator ret=null;
+
+ String modelType=name.getModelType();
+
+ if (modelType != null &&
+ m_validatorClasses.containsKey(modelType)) {
+ Class<?> cls=m_validatorClasses.get(modelType);
+
+ Constructor<?> con=cls.getConstructor(
+ new Class[]{ValidatorName.class});
+
+ ret = (ServiceValidator)con.newInstance(new Object[]{name});
+ }
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Returning service validator for "+
+ name+": "+ret);
+ }
+
+ return(ret);
+ }
+
+ private static final Logger logger =
Logger.getLogger("org.jboss.soa.overlord.validator.jbossesb");
+
+ private static java.util.Map<String,Class<?>> m_validatorClasses=
+ new java.util.HashMap<String,Class<?>>();
+
+ static {
+ m_validatorClasses.put(org.jboss.soa.overlord.validator.jbossesb.pi4soa.Pi4SOAServiceRecorder.getModelType(),
+ org.jboss.soa.overlord.validator.jbossesb.pi4soa.Pi4SOAServiceRecorder.class);
+ m_validatorClasses.put(org.jboss.soa.overlord.validator.jbossesb.pi4soa.Pi4SOAServiceValidator.getModelType(),
+ org.jboss.soa.overlord.validator.jbossesb.pi4soa.Pi4SOAServiceValidator.class);
+ }
+}
Copied:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidatorManager.java
(from rev 479,
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorManager.java)
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidatorManager.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidatorManager.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,581 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+
+/**
+ * This class is responsible for managing the active
+ * service validators, the mapping of endpoints to the service
+ * validators and updating the configuration when changes
+ * are detected.
+ */
+public class ServiceValidatorManager {
+
+ /**
+ * Default constructor for the service validator manager.
+ */
+ private ServiceValidatorManager() {
+ initialize();
+ }
+
+ /**
+ * This method returns the singleton ValidatorConfigurationManager.
+ *
+ * @return The singleton
+ */
+ public synchronized static ServiceValidatorManager instance() {
+ if (m_instance == null) {
+ m_instance = new ServiceValidatorManager();
+ }
+
+ return(m_instance);
+ }
+
+ /**
+ * This method initializes the service validator manager on
+ * startup.
+ */
+ protected void initialize() {
+
+ java.net.URL url=
+ ValidatorFilter.class.getClassLoader().getResource(CONFIG_FILE);
+
+ if (url != null) {
+ m_validatorConfigFile = new java.io.File(url.getFile());
+
+ java.io.File[] files=m_validatorConfigFile.getParentFile().listFiles();
+
+ for (int i=0; m_modelsDir == null && i < files.length; i++) {
+ if (files[i].getName().equals("models") &&
+ files[i].isDirectory()) {
+ m_modelsDir = files[i];
+ }
+ }
+
+ if (m_modelsDir != null) {
+ ValidatorConfigChangeMonitor mon=
+ new ValidatorConfigChangeMonitor();
+
+ new Thread(mon).start();
+ }
+ }
+ }
+
+ /**
+ * This method returns the list of service validators associated
+ * with the supplied input endpoint.
+ *
+ * @param endpoint The input endpoint
+ * @return The list of service validators, or null if the endpoint
+ * is unknown
+ */
+ public java.util.List<ServiceValidator> getInputServiceValidators(Endpoint
endpoint) {
+ return(m_inputValidators.get(endpoint));
+ }
+
+ /**
+ * This method returns the list of service validators associated
+ * with the supplied output endpoint.
+ *
+ * @param endpoint The output endpoint
+ * @return The list of service validators, or null if the endpoint
+ * is unknown
+ */
+ public java.util.List<ServiceValidator> getOutputServiceValidators(Endpoint
endpoint) {
+ return(m_outputValidators.get(endpoint));
+ }
+
+ /**
+ * This method returns a ServiceValidator associated with the
+ * supplied validator name.
+ *
+ * @param name The validator name
+ * @return The service validator
+ * @throws Exception Failed to create service validator
+ */
+ public ServiceValidator createServiceValidator(ValidatorName name)
+ throws Exception {
+ ServiceValidator ret=null;
+
+ synchronized(m_serviceValidators) {
+ ret = m_serviceValidators.get(name);
+
+ // If does not exist, then create, else update
+ // the existing service validator
+ if (ret == null) {
+ ret = ServiceValidatorFactory.getServiceValidator(name);
+
+ m_serviceValidators.put(name, ret);
+ } else {
+
+ // Update the description
+ ret.update();
+ }
+ }
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Created Service Validator '"+name+"':
"+ret);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method removes the service validator associated with
+ * the supplied validator name.
+ *
+ * @param name The validator name
+ * @throws Exception Failed to remove the service validator
+ */
+ protected void removeServiceValidator(ValidatorName name)
+ throws Exception {
+ synchronized(m_serviceValidators) {
+ ServiceValidator validator=(ServiceValidator)
+ m_serviceValidators.remove(name);
+
+ // Check if validator should be removed from
+ // input/output endpoint mappings
+ java.util.Iterator<Endpoint> iter=m_inputValidators.keySet().iterator();
+
+ while (iter.hasNext()) {
+ Endpoint ep=iter.next();
+ java.util.List<ServiceValidator> list=
+ m_inputValidators.get(ep);
+
+ if (list.contains(validator)) {
+ list.remove(validator);
+
+ if (list.size() == 0) {
+ logger.severe("Input validator list, associated with endpoint '"+
+ ep+"' contains no entries after removal of validator '"+
+ name+"' - this Endpoint should have previously been removed");
+ }
+ }
+ }
+
+ iter=m_outputValidators.keySet().iterator();
+
+ while (iter.hasNext()) {
+ Endpoint ep=iter.next();
+ java.util.List<ServiceValidator> list=
+ m_outputValidators.get(ep);
+
+ if (list.contains(validator)) {
+ list.remove(validator);
+
+ if (list.size() == 0) {
+ logger.severe("Output validator list, associated with endpoint '"+
+ ep+"' contains no entries after removal of validator '"+
+ name+"' - this Endpoint should have previously been removed");
+ }
+ }
+ }
+
+ if (validator != null) {
+ validator.close();
+ }
+ }
+ }
+
+ /**
+ * This method returns the set of currently configured
+ * service validator names.
+ *
+ * @return The set of validator names
+ */
+ protected java.util.Set<ValidatorName> getServiceValidatorNames() {
+ java.util.Set<ValidatorName> ret=new java.util.HashSet<ValidatorName>();
+
+ ret.addAll(m_serviceValidators.keySet());
+
+ return(ret);
+ }
+
+ /**
+ * This method updates the configuration of the service
+ * validators and endpoint mappings.
+ */
+ protected void updateConfigurations() {
+ java.util.Set<ValidatorName> existingValidatorNames=
+ getServiceValidatorNames();
+
+ java.util.Set<Endpoint> existingInputEndpoints=
+ new java.util.HashSet<Endpoint>(m_inputValidators.keySet());
+
+ java.util.Set<Endpoint> existingOutputEndpoints=
+ new java.util.HashSet<Endpoint>(m_outputValidators.keySet());
+
+ java.io.InputStream is=ValidatorFilter.class.getClassLoader().
+ getResourceAsStream(CONFIG_FILE);
+
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("ValidationFilter: config="+CONFIG_FILE+" is="+is);
+ }
+
+ try {
+ updateConfiguration(ConfigTree.fromInputStream(is), existingValidatorNames,
+ existingInputEndpoints, existingOutputEndpoints);
+
+ // Work through choreography files in the models directory
+ java.io.File[] files=m_modelsDir.listFiles();
+
+ for (int i=0; i < files.length; i++) {
+
+ // Check if a ValidatorModel exists for the
+ // file
+ try {
+ ValidatorConfig vm=
+ ValidatorConfigFactory.getValidatorConfig(files[i]);
+
+ if (vm != null) {
+ ConfigTree config=vm.getConfiguration();
+
+ if (config != null) {
+ updateConfiguration(config,
+ existingValidatorNames,
+ existingInputEndpoints,
+ existingOutputEndpoints);
+ } else {
+ logger.severe("Failed to obtain configuration for model '"+
+ files[i].getName()+"'");
+ }
+ }
+ } catch(Exception e) {
+ logger.log(Level.SEVERE,
+ "Failed to update configuration for model '"+
+ files[i].getName()+"'", e);
+ }
+ }
+
+ // Any remaining input keys need to be removed
+ java.util.Iterator<Endpoint> iter=
+ existingInputEndpoints.iterator();
+
+ while (iter.hasNext()) {
+ Endpoint key=iter.next();
+ m_inputValidators.remove(key);
+ }
+
+ // Any remaining output keys need to be removed
+ iter = existingOutputEndpoints.iterator();
+
+ while (iter.hasNext()) {
+ Endpoint key=iter.next();
+ m_outputValidators.remove(key);
+ }
+
+ // Any remaining service description names need to
+ // have their associated monitors removed
+ java.util.Iterator<ValidatorName> sviter=
+ existingValidatorNames.iterator();
+
+ while (sviter.hasNext()) {
+ ValidatorName svkey=sviter.next();
+
+ try {
+ logger.info("Removing service validator: "+svkey);
+ removeServiceValidator(svkey);
+ } catch(Exception e) {
+ logger.log(Level.SEVERE,
+ "Failed to remove service validator: "+svkey, e);
+ }
+ }
+ } catch(Exception e) {
+ logger.log(Level.SEVERE,
+ "Failed to update configuration from input stream", e);
+ }
+ }
+
+ /**
+ * This method performs the update of the configuration of
+ * service monitors, based on the information in the validator
+ * configuration XML file, and the choreographies defined in the
+ * models folder.
+ *
+ * @param config The configuration
+ * @param existingValidatorNames The list of validator names
+ * @param existingInputEndpoints The list of input endpoints
+ * @param existingOutputEndpoints The list of output endpoints
+ */
+ protected void updateConfiguration(ConfigTree config,
+ java.util.Set<ValidatorName> existingValidatorNames,
+ java.util.Set<Endpoint> existingInputEndpoints,
+ java.util.Set<Endpoint> existingOutputEndpoints) {
+ logger.info("Update Service Validator Configuration");
+
+ if (config != null) {
+ try {
+ if (config.getName().equals(VALIDATOR_NODE)) {
+ String active=config.getAttribute(ACTIVE_ATTR);
+
+ if (active != null && active.equalsIgnoreCase("true")) {
+
+ logger.info("Setting validator into active mode");
+ m_active = true;
+ }
+ }
+
+ ConfigTree[] services=config.getChildren(SERVICE_NODE);
+
+ if (logger.isLoggable(Level.FINEST)) {
+ if (services != null) {
+ logger.finest("ValidationFilter: services="+services.length);
+ } else {
+ logger.finest("ValidationFilter: services null");
+ }
+ }
+
+ for (int i=0; i < services.length; i++) {
+ ServiceValidator sm=null;
+
+ // Create service monitor for service
+ String modelName=
+ services[i].getAttribute(MODEL_NAME);
+ String role=
+ services[i].getAttribute(ROLE_NAME);
+ boolean validate=
+ services[i].getBooleanAttribute(VALIDATE, true);
+
+ // Check for old attribute names, for
+ // backward compatibility - only support
+ // for a limited time
+ if (role == null) {
+ role = services[i].getAttribute("participantType");
+ }
+
+ if (modelName == null) {
+ modelName = services[i].getAttribute("cdmFilePath");
+
+ if (modelName != null) {
+ // Remove path
+ int pos=modelName.lastIndexOf('/');
+ if (pos != -1) {
+ modelName = modelName.substring(pos+1);
+ }
+ }
+ }
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Initialize service validator for: model="+
+ modelName+" role="+role+" validate="+validate);
+ }
+
+ if (role != null) {
+
+ if (modelName != null ||
+ validate == false) {
+ ValidatorName name=null;
+
+ if (validate) {
+ name = new ValidatorName(modelName, role);
+ } else {
+ name = new ValidatorName(role);
+
+ }
+ // Obtain the service container
+ sm = createServiceValidator(name);
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Service validator for '"+modelName+
+ "' and role '"+role+"' = "+sm);
+ }
+
+ // Remove validator name from list
+ existingValidatorNames.remove(sm.getValidatorName());
+ } else {
+ logger.severe("Model name must be specified in validation mode");
+ }
+ } else {
+ logger.severe("Role must be specified");
+ }
+
+ if (sm != null) {
+ // Map inputs to service
+ ConfigTree[] inputs=services[i].getChildren(INPUT_NODE);
+
+ for (int j=0; j < inputs.length; j++) {
+ String epr=inputs[j].getAttribute(EPR_ATTR);
+
+ if (epr != null) {
+ Endpoint endpoint=new Endpoint(epr);
+
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("Storing input endpoint '"+
+ endpoint+"' against validator: "+sm);
+ }
+
+ // Check if existing list
+ java.util.List<ServiceValidator> svs=
+ m_inputValidators.get(endpoint);
+
+ if (svs == null) {
+ svs = new java.util.Vector<ServiceValidator>();
+ m_inputValidators.put(endpoint, svs);
+ }
+
+ svs.add(sm);
+
+ existingInputEndpoints.remove(endpoint);
+ }
+ }
+
+ // Map outputs to service
+ ConfigTree[] outputs=services[i].getChildren(OUTPUT_NODE);
+
+ for (int j=0; j < outputs.length; j++) {
+ String epr=outputs[j].getAttribute(EPR_ATTR);
+
+ if (epr != null) {
+ Endpoint endpoint=new Endpoint(epr);
+
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("Storing output endpoint '"+
+ endpoint+"' against validator: "+sm);
+ }
+
+ // Check if existing list
+ java.util.List<ServiceValidator> svs=
+ m_outputValidators.get(endpoint);
+
+ if (svs == null) {
+ svs = new java.util.Vector<ServiceValidator>();
+ m_outputValidators.put(endpoint, svs);
+ }
+
+ svs.add(sm);
+
+ existingOutputEndpoints.remove(endpoint);
+ }
+ }
+ }
+ }
+ } catch(Exception e) {
+ logger.log(java.util.logging.Level.SEVERE,
+ "Failed to load validator config", e);
+ }
+ }
+ }
+
+ /**
+ * This method returns whether the service validator configuration
+ * is in 'active' mode. If yes, then invalid messages will
+ * be blocked from being delivered to their destination.
+ *
+ * @return Whether the service validator is in 'active' mode
+ */
+ public boolean isActive() {
+ return(m_active);
+ }
+
+ private static final Logger logger =
Logger.getLogger("org.jboss.soa.overlord.validator.jbossesb");
+
+ private static final String EPR_ATTR = "epr";
+ private static final String OUTPUT_NODE = "output";
+ private static final String INPUT_NODE = "input";
+ private static final String SERVICE_NODE = "service";
+ private static final String ACTIVE_ATTR = "active";
+ private static final String VALIDATOR_NODE = "validator";
+
+ private static final String CONFIG_FILE = "validator-config.xml";
+ public static final String MODEL_NAME="model";
+ public static final String ROLE_NAME="role";
+ public static final String VALIDATE="validate";
+
+ private static ServiceValidatorManager m_instance=null;
+ private java.io.File m_validatorConfigFile=null;
+ private java.io.File m_modelsDir=null;
+ private java.util.Map<ValidatorName,ServiceValidator> m_serviceValidators=
+ new java.util.HashMap<ValidatorName,ServiceValidator>();
+ private java.util.Map<Endpoint,java.util.List<ServiceValidator>>
m_inputValidators=new
java.util.Hashtable<Endpoint,java.util.List<ServiceValidator>>();
+ private java.util.Map<Endpoint,java.util.List<ServiceValidator>>
m_outputValidators=new
java.util.Hashtable<Endpoint,java.util.List<ServiceValidator>>();
+ private boolean m_active=false;
+
+ /**
+ * This class is responsible for monitoring the models folder,
+ * within the overlord validator ESB bundle, to determine when
+ * the configuration has changed.
+ */
+ public class ValidatorConfigChangeMonitor implements java.lang.Runnable {
+
+ public ValidatorConfigChangeMonitor() {
+ // Do initial check for updates, so monitors
+ // initialized before returning from construct,
+ // as remainder of checks will be in a separate
+ // thread - so we need to ensure that the monitors
+ // are configured before the first message is
+ // passed through the filter.
+ checkForUpdates();
+ }
+
+ public void run() {
+
+ while (true) {
+ checkForUpdates();
+
+ try {
+ synchronized(ValidatorConfigChangeMonitor.this) {
+ wait(30000);
+ }
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ protected void checkForUpdates() {
+ logger.info("Checking for config updates");
+
+ // Get last update time
+ long lastUpdate=getLastUpdate();
+
+ if (lastUpdate > m_lastUpdate) {
+
+ updateConfigurations();
+
+ m_lastUpdate = lastUpdate;
+ }
+ }
+
+ protected long getLastUpdate() {
+ long ret=0;
+
+ if (m_validatorConfigFile != null) {
+ ret = m_validatorConfigFile.lastModified();
+ }
+
+ if (m_modelsDir != null) {
+ java.io.File[] files=m_modelsDir.listFiles();
+
+ for (int i=0; i < files.length; i++) {
+ if (files[i].getName().endsWith(".cdm") &&
+ ret < files[i].lastModified()) {
+ ret = files[i].lastModified();
+ }
+ }
+ }
+
+ return(ret);
+ }
+
+ private long m_lastUpdate=0;
+ }
+}
Property changes on:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ServiceValidatorManager.java
___________________________________________________________________
Name: svn:mergeinfo
+
Deleted:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidationAction.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidationAction.java 2009-02-09
20:27:42 UTC (rev 484)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidationAction.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -1,247 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-package org.jboss.soa.overlord.validator.jbossesb;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.jboss.soa.esb.actions.*;
-import org.jboss.soa.esb.helpers.ConfigTree;
-import org.jboss.soa.esb.message.Message;
-
-import org.pi4soa.common.util.MessageUtil;
-import org.pi4soa.service.*;
-import org.pi4soa.service.behavior.*;
-import org.pi4soa.service.monitor.*;
-import org.pi4soa.common.util.NamesUtil;
-
-/**
- * This class provides the action implementation for validation
- * against the pi4soa state machine.
- */
-public class ValidationAction extends AbstractActionLifecycle {
-
- private static final String ACTIVE_ATTR = "active";
- private static final String INBOUND_ATTR = "inbound";
- public static final String CDM_FILE_PATH="cdmFilePath";
- public static final String PARTICIPANT_TYPE="participantType";
-
- /**
- * This constructor initializes the actions with the
- * service configuration details.
- *
- * @param config The service configuration
- */
- public ValidationAction(ConfigTree config) {
- m_config = config;
- }
-
- /**
- * This method initializes the service action.
- */
- public void initialise() throws ActionLifecycleException {
-
- if (logger.isLoggable(Level.FINE)) {
- logger.fine("ValidationAction initialise: "+this);
- }
-
- super.initialise();
-
- String direction=
- m_config.getAttribute(INBOUND_ATTR);
-
- if (direction != null && direction.equalsIgnoreCase("false")) {
- m_inbound = false;
- }
-
- String active=
- m_config.getAttribute(ACTIVE_ATTR);
-
- if (active != null && active.equalsIgnoreCase("false")) {
- m_active = false;
- }
-
- getServiceMonitor();
- }
-
- /**
- * This method returns the service monitor associated with
- * the ESB service.
- *
- * @return The service monitor
- */
- protected synchronized ServiceMonitor getServiceMonitor() {
-
- if (m_serviceMonitor == null) {
-
- try {
- ServiceDescription sdesc=null;
- String cdmFilePath=
- m_config.getAttribute(CDM_FILE_PATH);
- String participantType=
- m_config.getAttribute(PARTICIPANT_TYPE);
-
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest("ValidationAction config: cdm="+
- cdmFilePath+" participant="+participantType);
- }
-
- if (NamesUtil.isSet(cdmFilePath) &&
- NamesUtil.isSet(participantType)) {
-
- java.io.InputStream is=ValidationAction.class.
- getClassLoader().getResourceAsStream(cdmFilePath);
-
- if (is == null) {
-
- is = ClassLoader.getSystemResourceAsStream(cdmFilePath);
-
- if (is == null) {
- throw new ServiceException("Failed to locate path '"+
- cdmFilePath+"'");
- }
- }
-
- if (is != null) {
- sdesc =
org.pi4soa.service.util.DescriptionRetrievalUtil.instance().getServiceDescription(is,
participantType);
- }
- } else {
- logger.severe("Choreography file and Participant Type not specified:
"+this);
- }
-
- if (sdesc != null) {
- m_serviceDescriptionName = sdesc.getFullyQualifiedName();
-
- // Obtain the service container
- m_serviceMonitor = ValidatorManager.createServiceContainer(
- sdesc);
- } else {
- logger.severe("Service description could not be loaded: "+
- cdmFilePath+" participant="+participantType);
- }
-
- } catch(Exception e) {
- logger.log(Level.SEVERE,
- "Failed to initialize ValidationAction", e);
- }
- }
-
- return(m_serviceMonitor);
- }
-
- /**
- * This method processes a message for the service associated
- * with this ESB action.
- *
- * @param message The message
- * @return The message
- */
- public Message processMessage(Message message) throws ActionProcessingException {
-
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest("ValidationAction: "+this+" message="+message);
- }
-
- try {
- java.io.Serializable value=ESBUtil.getMessage(message);
-
- if (value == null) {
- throw new ServiceException("Failed to obtain value from message:
"+message);
- }
-
- String mesgType=MessageUtil.getMessageType(value);
-
- org.pi4soa.service.Message mesg=
- getServiceMonitor().createMessage(mesgType, null,
- null, value, null, null);
-
- try {
- if (m_inbound) {
- getServiceMonitor().messageReceived(mesg);
- } else {
- getServiceMonitor().messageSent(mesg);
- }
- } catch(OutOfSequenceMessageException osme) {
-
- if (m_active) {
- throw osme;
- } else {
- logger.severe("Out of sequence message detected");
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest(message.toString());
- }
- }
- } catch(UnexpectedMessageException ume) {
-
- if (m_active) {
- throw ume;
- } else {
- logger.severe("Unexpected message detected");
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest(message.toString());
- }
- }
- }
-
- } catch(Throwable t) {
- logger.log(java.util.logging.Level.SEVERE,
- "Failed to handle message", t);
-
- throw new ActionProcessingException("Failed to handle message", t);
- }
-
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest("ValidationAction: "+this+
- "serviceDescriptionName="+
- m_serviceDescriptionName+
- " finished processing message="+message);
- }
-
- return(message);
- }
-
- /**
- * This method is called to tidy up after the action is
- * no longer required.
- */
- public void destroy() throws ActionLifecycleException {
- if (logger.isLoggable(Level.FINE)) {
- logger.fine("ValidationAction destroy: "+this);
- }
-
- super.destroy();
-
- if (m_serviceMonitor != null &&
- m_serviceDescriptionName != null) {
- try {
- ValidatorManager.releaseServiceMonitor(m_serviceDescriptionName);
- } catch(org.pi4soa.service.ServiceException se) {
- throw new ActionLifecycleException("Failed to destroy service monitor",
- se);
- }
- }
- }
-
- private static final Logger logger =
Logger.getLogger("org.pi4soa.jbossesb.validator");
-
- private ConfigTree m_config=null;
- private String m_serviceDescriptionName=null;
- private ServiceMonitor m_serviceMonitor=null;
- private boolean m_inbound=true;
- private boolean m_active=true;
-}
\ No newline at end of file
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfig.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfig.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfig.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+import org.jboss.soa.esb.helpers.*;
+
+/**
+ * This interface represents a configuration that will be used for
+ * validation against a stream of ESB based messages.
+ */
+public interface ValidatorConfig {
+
+ /**
+ * This method returns the type of the model associated
+ * with this validator configuration. This will
+ * general be based on the file extension of the model
+ * file.
+ *
+ * @return The model type
+ */
+ public String getModelType();
+
+ /**
+ * This method returns the validator configuration
+ * associated with the model.
+ *
+ * @return The validator model
+ */
+ public ConfigTree getConfiguration();
+
+}
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfigFactory.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfigFactory.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfigFactory.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * This class provides a factory for ValidatorConfig objects
+ * based on supplied model file details.
+ */
+public class ValidatorConfigFactory {
+
+ /**
+ * This method retrieves a validator config associated with
+ * the supplied file. If the model associated with the
+ * file is not supported, then a null will be returned.
+ *
+ * @param file The file containing the model
+ * @return The validator config, or null if an unsupported type
+ * @exception IOException Failed to load supported model type
+ */
+ public static ValidatorConfig getValidatorConfig(java.io.File file)
+ throws java.io.IOException {
+ ValidatorConfig ret=null;
+
+ String modelType=null;
+
+ if (file != null && (modelType=getModelType(file.getName())) != null) {
+ ValidatorConfigLoader loader=null;
+
+ for (int i=0; loader == null &&
+ i < m_loaders.size(); i++) {
+
+ if (m_loaders.get(i).isSupported(modelType)) {
+ loader = m_loaders.get(i);
+ }
+ }
+
+ if (loader != null) {
+ java.io.FileInputStream fis=new java.io.FileInputStream(file);
+
+ ret = loader.loadValidatorConfig(fis, file.getName());
+
+ fis.close();
+ }
+ }
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Returning validator config for "+
+ file.getName()+": "+ret);
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method determines the model type associated with the
+ * supplied model filename.
+ *
+ * @param name The model filename
+ * @return The model type, or null if not known
+ */
+ protected static String getModelType(String name) {
+ String ret=null;
+ int pos=name.lastIndexOf('.');
+
+ if (pos != -1) {
+ ret = name.substring(pos+1);
+ }
+
+ return(ret);
+ }
+
+ private static final Logger logger =
Logger.getLogger("org.jboss.soa.overlord.validator.jbossesb");
+
+ private static java.util.List<ValidatorConfigLoader> m_loaders=
+ new java.util.Vector<ValidatorConfigLoader>();
+
+ static {
+ m_loaders.add(new
org.jboss.soa.overlord.validator.jbossesb.pi4soa.Pi4SOAValidatorConfigLoader());
+ }
+}
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfigLoader.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfigLoader.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorConfigLoader.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+/**
+ * This interface is implemented by model specific loaders, to
+ * load a ValidatorConfig for the particular model type.
+ */
+public interface ValidatorConfigLoader {
+
+ /**
+ * This method determines if the validator config loader
+ * implementation supports the supplied model type.
+ *
+ * @param modelType The model type
+ * @return Whether the loader supports the model type
+ */
+ public boolean isSupported(String modelType);
+
+ /**
+ * This method loads the validator config, contained within
+ * the supplied input stream representing a model of the
+ * supported type.
+ *
+ * @param is The input stream
+ * @param modelPath The path to the model file
+ * @return The validator config
+ * @throws java.io.IOException Failed to load validator config
+ */
+ public ValidatorConfig loadValidatorConfig(java.io.InputStream is,
+ String modelPath) throws java.io.IOException;
+
+}
Modified:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorFilter.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorFilter.java 2009-02-09
20:27:42 UTC (rev 484)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorFilter.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -22,84 +22,53 @@
import org.jboss.soa.esb.message.*;
import org.jboss.soa.esb.couriers.*;
-import org.jboss.soa.esb.helpers.*;
-import org.pi4soa.common.util.MessageUtil;
-import org.pi4soa.common.util.NamesUtil;
-import org.pi4soa.common.xml.XMLUtils;
-import org.pi4soa.service.OutOfSequenceMessageException;
-import org.pi4soa.service.ServiceException;
-import org.pi4soa.service.UnexpectedMessageException;
-import org.pi4soa.service.monitor.*;
-import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager;
-
+/**
+ * This class represents the filter used to intercept ESB
+ * messages an apply them to relevant Service Validators.
+ */
public class ValidatorFilter extends org.jboss.soa.esb.filter.InputOutputFilter {
- private static final String CONFIG_FILE = "validator-config.xml";
- public static final String CDM_FILE_PATH="cdmFilePath";
- public static final String PARTICIPANT_TYPE="participantType";
- public static final String VALIDATE="validate";
+ private static final String TOPIC_PREFIX = "topic/";
+ private static final String QUEUE_PREFIX = "queue/";
+ private static final String JMS_PROTOCOL_PREFIX = "jms:";
+ /**
+ * The default constructor.
+ */
public ValidatorFilter() {
- initialize();
}
+ /**
+ * This method is invoked when a message is sent by an
+ * ESB service.
+ *
+ * @param msg The ESB message
+ * @param params The parameters
+ * @throws CourierException Failed to validate message
+ */
public Message onOutput(Message msg, java.util.Map params)
throws CourierException {
- String key=getKey(msg);
-
- if (key != null) {
- ServiceMonitor sm=(ServiceMonitor)m_outputServices.get(key);
+ Endpoint endpoint=getEndpoint(msg);
+
+ if (endpoint != null) {
+ java.util.List<ServiceValidator> validators=
+ ServiceValidatorManager.instance().getOutputServiceValidators(endpoint);
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest("ValidationFilter: "+this+" message="+
- msg+" monitor="+sm);
- }
-
- if (sm != null) {
+ for (int i=0; validators != null &&
+ i < validators.size(); i++) {
+
try {
- java.io.Serializable value=ESBUtil.getMessage(msg);
+ validators.get(i).messageSent(msg);
- if (value == null) {
- throw new ServiceException("Failed to obtain value from message:
"+msg);
- }
-
- String mesgType=MessageUtil.getMessageType(value);
-
- org.pi4soa.service.Message mesg=
- sm.createMessage(mesgType,
- null, null, value, null, null);
-
- try {
- sm.messageSent(mesg);
- } catch(OutOfSequenceMessageException osme) {
-
- if (m_active) {
- throw osme;
- } else {
- logger.severe("Out of sequence message detected");
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest(msg.toString());
- }
- }
- } catch(UnexpectedMessageException ume) {
-
- if (m_active) {
- throw ume;
- } else {
- logger.severe("Unexpected message detected");
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest(msg.toString());
- }
- }
- }
-
} catch(Throwable t) {
logger.log(java.util.logging.Level.SEVERE,
- "Failed to handle message", t);
+ "Failed to handle sent message", t);
- throw new CourierException("Failed to handle message", t);
+ if (ServiceValidatorManager.instance().isActive()) {
+ throw new CourierException("Failed to handle sent message", t);
+ }
}
}
}
@@ -107,61 +76,36 @@
return(msg);
}
+ /**
+ * This method is invoked when a message is received by an
+ * ESB service.
+ *
+ * @param msg The ESB message
+ * @param params The parameters
+ * @throws CourierException Failed to validate message
+ */
public Message onInput(Message msg, java.util.Map params)
throws CourierException {
- String key=getKey(msg);
-
- if (key != null) {
- ServiceMonitor sm=(ServiceMonitor)m_inputServices.get(key);
+ Endpoint endpoint=getEndpoint(msg);
+
+ if (endpoint != null) {
+ java.util.List<ServiceValidator> validators=
+ ServiceValidatorManager.instance().getInputServiceValidators(endpoint);
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest("ValidationFilter: "+this+" message="+msg+"
monitor="+sm);
- }
-
- if (sm != null) {
+ for (int i=0; validators != null &&
+ i < validators.size(); i++) {
+
try {
- java.io.Serializable value=ESBUtil.getMessage(msg);
+ validators.get(i).messageReceived(msg);
- if (value == null) {
- throw new ServiceException("Failed to obtain value from message:
"+msg);
- }
-
- String mesgType=MessageUtil.getMessageType(value);
-
- org.pi4soa.service.Message mesg=
- sm.createMessage(mesgType,
- null, null, value, null, null);
-
- try {
- sm.messageReceived(mesg);
- } catch(OutOfSequenceMessageException osme) {
-
- if (m_active) {
- throw osme;
- } else {
- logger.severe("Out of sequence message detected");
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest(msg.toString());
- }
- }
- } catch(UnexpectedMessageException ume) {
-
- if (m_active) {
- throw ume;
- } else {
- logger.severe("Unexpected message detected");
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest(msg.toString());
- }
- }
- }
-
} catch(Throwable t) {
logger.log(java.util.logging.Level.SEVERE,
- "Failed to handle message", t);
+ "Failed to handle received message", t);
- throw new CourierException("Failed to handle message", t);
+ if (ServiceValidatorManager.instance().isActive()) {
+ throw new CourierException("Failed to handle received message",
t);
+ }
}
}
}
@@ -169,251 +113,15 @@
return(msg);
}
- protected void initialize() {
-
- java.net.URL url=
- ValidatorFilter.class.getClassLoader().getResource(CONFIG_FILE);
-
- System.out.println("CONFIG FILE URL="+url);
- System.out.println("CONFIG FILE URL TYPE="+url.getClass());
-
- if (url != null) {
- java.io.File file=new java.io.File(url.getFile());
-
- java.io.File[] files=file.getParentFile().listFiles();
- java.io.File models=null;
-
- for (int i=0; models == null && i < files.length; i++) {
- if (files[i].getName().equals("models") &&
- files[i].isDirectory()) {
- models = files[i];
- }
- }
-
- if (models != null) {
- ValidatorConfigChangeMonitor mon=new ValidatorConfigChangeMonitor(file, models);
-
- new Thread(mon).start();
- }
- }
- }
-
/**
- * This method performs the update of the configuration of
- * service monitors, based on the information in the validator
- * configuration XML file, and the choreographies defined in the
- * models folder.
- */
- protected void updateConfiguration(java.io.InputStream is,
- java.util.Set<String> existingServiceDescriptions,
- java.util.Set<String> existingInputKeys,
- java.util.Set<String> existingOutputKeys) {
-
- try {
- updateConfiguration(ConfigTree.fromInputStream(is),
- existingServiceDescriptions, existingInputKeys,
- existingOutputKeys);
- } catch(Exception e) {
-
- logger.log(Level.SEVERE,
- "Failed to update configuration from input stream", e);
- }
- }
-
- /**
- * This method performs the update of the configuration of
- * service monitors, based on the information in the validator
- * configuration XML file, and the choreographies defined in the
- * models folder.
- */
- protected void updateConfiguration(org.w3c.dom.Element elem,
- java.util.Set<String> existingServiceDescriptions,
- java.util.Set<String> existingInputKeys,
- java.util.Set<String> existingOutputKeys) {
-
- try {
- updateConfiguration(ConfigTree.fromElement(elem),
- existingServiceDescriptions, existingInputKeys,
- existingOutputKeys);
- } catch(Exception e) {
-
- logger.log(Level.SEVERE,
- "Failed to update configuration from DOM element", e);
- }
- }
-
- /**
- * This method performs the update of the configuration of
- * service monitors, based on the information in the validator
- * configuration XML file, and the choreographies defined in the
- * models folder.
- */
- protected void updateConfiguration(ConfigTree config,
- java.util.Set<String> existingServiceDescriptions,
- java.util.Set<String> existingInputKeys,
- java.util.Set<String> existingOutputKeys) {
- logger.info("Update Service Validator Configuration");
-
- if (config != null) {
- try {
- if (config.getName().equals(VALIDATOR_NODE)) {
- String active=config.getAttribute(ACTIVE_ATTR);
-
- if (active != null && active.equalsIgnoreCase("true")) {
-
- logger.info("Setting validator into active mode");
- m_active = true;
- }
- }
-
- ConfigTree[] services=config.getChildren(SERVICE_NODE);
-
- if (logger.isLoggable(Level.FINEST)) {
- if (services != null) {
- logger.finest("ValidationFilter: services="+services.length);
- } else {
- logger.finest("ValidationFilter: services null");
- }
- }
-
- for (int i=0; i < services.length; i++) {
- org.pi4soa.service.monitor.ServiceMonitor sm=null;
-
- // Create service monitor for service
- String cdmFilePath=
- services[i].getAttribute(CDM_FILE_PATH);
- String participantType=
- services[i].getAttribute(PARTICIPANT_TYPE);
- boolean validate=
- services[i].getBooleanAttribute(VALIDATE, true);
-
- if (NamesUtil.isSet(participantType)) {
-
- if (NamesUtil.isSet(cdmFilePath)) {
- java.io.InputStream is = ValidatorFilter.class.
- getClassLoader().getResourceAsStream(
- cdmFilePath);
-
- if (is != null) {
- org.pi4soa.service.behavior.ServiceDescription sdesc=
- org.pi4soa.service.util.DescriptionRetrievalUtil.instance().getServiceDescription(is,
participantType);
-
- if (sdesc != null) {
-
- // Obtain the service container
- sm = ValidatorManager.createServiceContainer(sdesc, validate);
-
- if (logger.isLoggable(Level.FINE)) {
- logger.fine("Service monitor for '"+cdmFilePath+
- "' and participantType '"+participantType+"'
= "+sm);
- }
-
- // Remove service description from list
- existingServiceDescriptions.remove(sdesc.getFullyQualifiedName());
-
- } else {
- logger.severe("Service description could not be loaded");
- }
-
- } else {
- logger.severe("Choreography file path not found: "+this);
- }
- } else if (validate == false) {
-
- logger.fine("Create non-validating service monitor for: "+
- participantType);
-
- // Just record information for participant
- // using the service tracker
- org.pi4soa.service.behavior.ServiceDescription sdesc=
- org.pi4soa.service.behavior.BehaviorFactory.eINSTANCE.createServiceDescription();
- sdesc.setName(participantType);
-
- sm = ValidatorManager.createServiceContainer(sdesc, validate);
-
- // Remove service description from list
- existingServiceDescriptions.remove(sdesc.getFullyQualifiedName());
-
- } else {
- logger.severe("Choreography file path not specified: "+this);
- }
- } else {
- logger.severe("Participant type not specified: "+this);
- }
-
- if (sm != null) {
- // Map inputs to service
- ConfigTree[] inputs=services[i].getChildren(INPUT_NODE);
-
- for (int j=0; j < inputs.length; j++) {
- String epr=inputs[j].getAttribute(EPR_ATTR);
-
- if (epr != null) {
-
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest("Storing input epr '"+
- epr+"' against monitor: "+sm);
- }
-
- // Check if EPR associated with different
- // input service
- ServiceMonitor tmp=m_inputServices.get(epr);
-
- if (tmp != null && tmp != sm) {
- logger.severe("Input EPR '"+epr+
- "' already associated with another Service Monitor");
- }
-
- m_inputServices.put(epr, sm);
-
- existingInputKeys.remove(epr);
- }
- }
-
- // Map outputs to service
- ConfigTree[] outputs=services[i].getChildren(OUTPUT_NODE);
-
- for (int j=0; j < outputs.length; j++) {
- String epr=outputs[j].getAttribute(EPR_ATTR);
-
- if (epr != null) {
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest("Storing output epr '"+
- epr+"' against monitor: "+sm);
- }
-
- // Check if EPR associated with different
- // output service
- ServiceMonitor tmp=m_outputServices.get(epr);
-
- if (tmp != null && tmp != sm) {
- logger.severe("Output EPR '"+epr+
- "' already associated with another Service Monitor");
- }
-
- m_outputServices.put(epr, sm);
-
- existingOutputKeys.remove(epr);
- }
- }
- }
- }
- } catch(Exception e) {
- logger.log(java.util.logging.Level.SEVERE,
- "Failed to load validator config", e);
- }
- }
- }
-
- /**
- * This method returns a key associated with the 'to'
+ * This method returns an endpoint associated with the 'to'
* destination of the supplied message.
*
* @param msg The message
- * @return The key, or null if not relevant
+ * @return The endpoint, or null if not relevant
*/
- protected String getKey(Message msg) {
- String ret=null;
+ protected Endpoint getEndpoint(Message msg) {
+ Endpoint ret=null;
if (msg != null && msg.getHeader() != null &&
msg.getHeader().getCall() != null &&
@@ -426,191 +134,16 @@
if (key.startsWith(JMS_PROTOCOL_PREFIX) &&
((ind=key.indexOf(QUEUE_PREFIX)) != -1 ||
(ind=key.indexOf(TOPIC_PREFIX)) != -1)) {
- ret = JMS_PROTOCOL_PREFIX+key.substring(ind);
+ ret = new Endpoint(JMS_PROTOCOL_PREFIX+key.substring(ind));
}
}
if (logger.isLoggable(Level.FINEST)) {
- logger.finest("Key for message '"+msg+"' is: "+ret);
+ logger.finest("Destination for message '"+msg+"' is:
"+ret);
}
return(ret);
}
- private static final Logger logger =
Logger.getLogger("org.pi4soa.jbossesb.validator");
-
- private static final String TOPIC_PREFIX = "topic/";
- private static final String QUEUE_PREFIX = "queue/";
- private static final String JMS_PROTOCOL_PREFIX = "jms:";
- private static final String EPR_ATTR = "epr";
- private static final String OUTPUT_NODE = "output";
- private static final String INPUT_NODE = "input";
- private static final String SERVICE_NODE = "service";
- private static final String ACTIVE_ATTR = "active";
- private static final String VALIDATOR_NODE = "validator";
-
- private java.util.Map<String,ServiceMonitor> m_inputServices=new
java.util.Hashtable<String,ServiceMonitor>();
- private java.util.Map<String,ServiceMonitor> m_outputServices=new
java.util.Hashtable<String,ServiceMonitor>();
- private boolean m_active=false;
-
- public class ValidatorConfigChangeMonitor implements java.lang.Runnable {
-
- public ValidatorConfigChangeMonitor(java.io.File validatorConfigFile,
- java.io.File modelsDir) {
- m_validatorConfigFile = validatorConfigFile;
- m_modelsDir = modelsDir;
-
- // Do initial check for updates, so monitors
- // initialized before returning from construct,
- // as remainder of checks will be in a separate
- // thread - so we need to ensure that the monitors
- // are configured before the first message is
- // passed through the filter.
- checkForUpdates();
- }
-
- public void run() {
-
- while (true) {
- checkForUpdates();
-
- try {
- synchronized(ValidatorConfigChangeMonitor.this) {
- wait(30000);
- }
- } catch(Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- protected void checkForUpdates() {
- logger.info("Checking for config updates");
-
- // Get last update time
- long lastUpdate=getLastUpdate();
-
- if (lastUpdate > m_lastUpdate) {
-
- updateConfigurations();
-
- m_lastUpdate = lastUpdate;
- }
- }
-
- protected void updateConfigurations() {
- java.util.Set<String> existingServiceDescriptions=
- ValidatorManager.getServiceDescriptionNames();
-
- java.util.Set<String> existingInputKeys=
- new java.util.HashSet<String>(m_inputServices.keySet());
-
- java.util.Set<String> existingOutputKeys=
- new java.util.HashSet<String>(m_outputServices.keySet());
-
- java.io.InputStream is=ValidatorFilter.class.getClassLoader().
- getResourceAsStream(CONFIG_FILE);
-
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest("ValidationFilter: config="+CONFIG_FILE+"
is="+is);
- }
-
- updateConfiguration(is, existingServiceDescriptions,
- existingInputKeys, existingOutputKeys);
-
- // Work through choreography files in the models directory
- java.io.File[] files=m_modelsDir.listFiles();
-
- for (int i=0; i < files.length; i++) {
- if (files[i].getName().endsWith(".cdm")) {
-
- try {
- java.io.FileInputStream fis=new java.io.FileInputStream(files[i]);
-
- org.pi4soa.cdl.Package cdlpack=
- org.pi4soa.service.util.DescriptionRetrievalUtil.instance().getCDLPackage(fis);
-
- ValidatorGenerator generator=new ValidatorGenerator();
-
- org.w3c.dom.Element validator=
- generator.generate(cdlpack, files[i].getName());
-
- if (logger.isLoggable(Level.FINEST)) {
- logger.finest("ValidationFilter: model="+files[i].getName()+
- " cdlpack="+cdlpack+" config=\r\n"+
- XMLUtils.getText(validator, true));
- }
-
- updateConfiguration(validator,
- existingServiceDescriptions,
- existingInputKeys, existingOutputKeys);
-
- fis.close();
- } catch(Exception e) {
- logger.log(Level.SEVERE,
- "Failed to update configuration for model '"+
- files[i].getName()+"'", e);
- }
- }
- }
-
- // Any remaining service description names need to
- // have their associated monitors removed
- java.util.Iterator<String> iter=
- existingServiceDescriptions.iterator();
-
- while (iter.hasNext()) {
- String sdescName=iter.next();
-
- try {
- logger.info("Removing service monitor for
'"+sdescName+"'");
- ValidatorManager.removeServiceMonitor(sdescName);
- } catch(Exception e) {
- logger.log(Level.SEVERE,
- "Failed to remove service monitor '"+sdescName+"'",
e);
- }
- }
-
- // Any remaining input keys need to be removed
- iter = existingInputKeys.iterator();
-
- while (iter.hasNext()) {
- String key=iter.next();
- m_inputServices.remove(key);
- }
-
- // Any remaining output keys need to be removed
- iter = existingOutputKeys.iterator();
-
- while (iter.hasNext()) {
- String key=iter.next();
- m_outputServices.remove(key);
- }
- }
-
- protected long getLastUpdate() {
- long ret=0;
-
- if (m_validatorConfigFile != null) {
- ret = m_validatorConfigFile.lastModified();
- }
-
- if (m_modelsDir != null) {
- java.io.File[] files=m_modelsDir.listFiles();
-
- for (int i=0; i < files.length; i++) {
- if (files[i].getName().endsWith(".cdm") &&
- ret < files[i].lastModified()) {
- ret = files[i].lastModified();
- }
- }
- }
-
- return(ret);
- }
-
- private java.io.File m_validatorConfigFile=null;
- private java.io.File m_modelsDir=null;
- private long m_lastUpdate=0;
- }
+ private static final Logger logger =
Logger.getLogger("org.jboss.soa.overlord.validator.jbossesb");
}
Deleted:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorGenerator.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorGenerator.java 2009-02-09
20:27:42 UTC (rev 484)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorGenerator.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -1,229 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-package org.jboss.soa.overlord.validator.jbossesb;
-
-import java.util.Collections;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.pi4soa.cdl.*;
-import org.pi4soa.common.annotations.*;
-import org.pi4soa.common.xml.XMLUtils;
-
-/**
- * This class provides a generator for the JBossESB Validator
- * configuration.
- */
-public class ValidatorGenerator {
-
- private static final String CDM_FILE_PATH_ATTR = "cdmFilePath";
- private static final String FILE_PATH_PREFIX = "models/";
- private static final String SERVICE_ELEMENT = "service";
- private static final String VALIDATOR_ELEMENT = "validator";
-
- public ValidatorGenerator() {
- }
-
- public org.w3c.dom.Element generate(org.pi4soa.cdl.Package cdlpack,
- String cdmFileName) {
- org.w3c.dom.Element ret=null;
-
- try {
- ret = createValidatorConfig();
-
- String cdmFilePath=getFilePath(cdmFileName);
-
- // Create the new entries for the supplied choreography
- createEntries(ret, cdmFilePath, cdlpack);
-
- } catch(Exception e) {
- e.printStackTrace();
- }
-
- return(ret);
- }
-
- protected org.w3c.dom.Element createValidatorConfig()
- throws Exception {
- org.w3c.dom.Element ret=null;
-
- org.w3c.dom.Document doc=
- javax.xml.parsers.DocumentBuilderFactory.
- newInstance().newDocumentBuilder().newDocument();
-
- ret = doc.createElement(VALIDATOR_ELEMENT);
-
- doc.appendChild(ret);
-
- return(ret);
- }
-
- protected void createEntries(org.w3c.dom.Element validator,
- String cdmFilePath, org.pi4soa.cdl.Package cdlpack) {
-
- for (int i=0; i < cdlpack.getTypeDefinitions().getParticipantTypes().size(); i++) {
- org.pi4soa.cdl.ParticipantType ptype=
- cdlpack.getTypeDefinitions().getParticipantTypes().get(i);
-
- org.w3c.dom.Element service=
- validator.getOwnerDocument().createElement(SERVICE_ELEMENT);
-
- service.setAttribute(CDM_FILE_PATH_ATTR, cdmFilePath);
- service.setAttribute("participantType", ptype.getName());
-
- cdlpack.visit(new InputOutputAnalyser(ptype, service));
-
- if (service.getFirstChild() != null) {
- validator.appendChild(service);
- }
- }
- }
-
- protected String getFilePath(String cdmFileName) {
- return(FILE_PATH_PREFIX+cdmFileName);
- }
-
- private static Logger logger =
Logger.getLogger("org.jboss.tools.overlord.cdl.validator.jbossesb.actions");
-
- public class InputOutputAnalyser extends DefaultCDLVisitor {
-
- private static final String JBOSSESB_ANNOTATION = "jbossesb";
- private static final String JBOSSESB_ELEMENT = "jbossesb";
- private static final String DESTINATION_ELEMENT = "destination";
- private static final String NAME_ATTR = "name";
- private static final String EPR_ATTR = "epr";
- private static final String INPUT_ELEMENT = "input";
- private static final String OUTPUT_ELEMENT = "output";
-
- public InputOutputAnalyser(org.pi4soa.cdl.ParticipantType ptype,
- org.w3c.dom.Element service) {
- m_participantType = ptype;
- m_service = service;
-
- m_templateProcessor =
- org.pi4soa.common.annotations.AnnotationsManagerFactory.getAnnotationsManager().getTemplateProcessor(JBOSSESB_ANNOTATION);
- }
-
- public void interaction(Interaction interaction) {
- if (m_participantType.getRoleTypes().contains(interaction.getFromRoleType()) ||
- (interaction.getFromParticipant() != null &&
- Collections.disjoint(m_participantType.getRoleTypes(),
- interaction.getFromParticipant().getRoleTypes()) == false)) {
-
- for (int i=0; i < interaction.getExchangeDetails().size(); i++) {
- processExchangeDetails(interaction.getExchangeDetails().get(i), true);
- }
- } else if (m_participantType.getRoleTypes().contains(interaction.getToRoleType()) ||
- (interaction.getToParticipant() != null &&
- Collections.disjoint(m_participantType.getRoleTypes(),
- interaction.getToParticipant().getRoleTypes()) == false)) {
- for (int i=0; i < interaction.getExchangeDetails().size(); i++) {
- processExchangeDetails(interaction.getExchangeDetails().get(i), false);
- }
- }
- }
-
- protected void processExchangeDetails(ExchangeDetails details, boolean from) {
-
- for (int i=0; i < details.getSemanticAnnotations().size(); i++) {
- SemanticAnnotation sa=details.getSemanticAnnotations().get(i);
- org.w3c.dom.Element dest=null;
-
- if (sa.getAnnotation() != null && sa.getName() != null &&
- sa.getName().equals(JBOSSESB_ANNOTATION)) {
- try {
- // Transform the text representation to DOM
- DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance();
- fact.setNamespaceAware(true);
-
- DocumentBuilder builder=fact.newDocumentBuilder();
- org.w3c.dom.Document doc=
- builder.parse(new java.io.ByteArrayInputStream(
- sa.getAnnotation().getBytes()));
-
- if (doc.getDocumentElement() != null &&
- doc.getDocumentElement().getNodeName().equals(
- JBOSSESB_ELEMENT)) {
- org.w3c.dom.NodeList nl=
- doc.getDocumentElement().getElementsByTagName(DESTINATION_ELEMENT);
-
- if (nl.getLength() == 1) {
- dest = (org.w3c.dom.Element)nl.item(0);
- } else if (nl.getLength() > 1) {
- logger.severe("Too many destination elements ("+
- nl.getLength()+") found");
- } else {
- logger.severe("No destinations found");
- }
- }
-
- } catch(Exception e) {
- logger.log(Level.SEVERE,
- "Failed to load jbossesb annotation", e);
- }
- }
-
- if (dest != null) {
- processDestination(details, dest, from);
- }
- }
- }
-
- protected void processDestination(ExchangeDetails details,
- org.w3c.dom.Element dest, boolean from) {
- String elemName=null;
-
- if (dest != null &&
- dest.getAttribute("temporary").equalsIgnoreCase("true") ==
false) {
- if (from) {
- if (details.getAction() == ExchangeActionType.REQUEST) {
- elemName = OUTPUT_ELEMENT;
- } else {
- elemName = INPUT_ELEMENT;
- }
- } else {
- if (details.getAction() == ExchangeActionType.REQUEST) {
- elemName = INPUT_ELEMENT;
- } else {
- elemName = OUTPUT_ELEMENT;
- }
- }
-
- // Parameter has been stored in a structured manner
- // to support use of templates and presentations,
- // so need to extract the value
- java.util.List<TemplateParameter> params=
- m_templateProcessor.getTemplateParameters(dest.getAttribute(NAME_ATTR));
-
- if (params != null && params.size() > 0) {
- org.w3c.dom.Element elem=m_service.getOwnerDocument().createElement(elemName);
- elem.setAttribute(EPR_ATTR, params.get(0).getValue());
-
- m_service.appendChild(elem);
- }
- }
- }
-
- private ParticipantType m_participantType=null;
- private org.w3c.dom.Element m_service=null;
- private org.pi4soa.common.annotations.TemplateProcessor m_templateProcessor=null;
- }
-}
Deleted:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorManager.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorManager.java 2009-02-09
20:27:42 UTC (rev 484)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorManager.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -1,234 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * 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,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-package org.jboss.soa.overlord.validator.jbossesb;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.pi4soa.service.ServiceException;
-import org.pi4soa.service.behavior.ServiceDescription;
-import org.pi4soa.service.monitor.*;
-
-public class ValidatorManager {
-
- /**
- * This method returns a reference to the service monitor
- * associated with the supplied service description name,
- * or null if one does not exist.
- *
- * @param sdesc The service description name
- * @return The service monitor, or null if does not exist
- */
- public static ServiceMonitor getServiceMonitor(String sdesc) {
- ServiceMonitor ret=null;
-
- synchronized(m_serviceMonitors) {
- ret = (ServiceMonitor)m_serviceMonitors.get(sdesc);
- }
-
- return(ret);
- }
-
- /**
- * This method returns a reference counted Service Monitor
- * associated with the supplied service description.
- *
- * @param sdesc The service description
- * @return The service monitor
- */
- public static ServiceMonitor createServiceContainer(ServiceDescription sdesc) {
- return(createServiceContainer(sdesc, true));
- }
-
- /**
- * This method returns a reference counted Service Monitor
- * associated with the supplied service description.
- *
- * @param sdesc The service description
- * @param validate Whether the behavior should be validated
- * @return The service monitor
- */
- public static ServiceMonitor createServiceContainer(ServiceDescription sdesc,
- boolean validate) {
- ServiceMonitor ret=null;
-
- synchronized(m_serviceMonitors) {
-
- if ((ret = (ServiceMonitor)m_serviceMonitors.get(
- sdesc.getFullyQualifiedName())) == null) {
-
- if (logger.isLoggable(Level.FINE)) {
- logger.fine("Service monitor for '"+
- sdesc.getFullyQualifiedName()+
- "' being created");
- }
-
- try {
- // Use XML configuration, to enable alternative
- // runtime configuration to be specified by
- // including a pi4soa.xml file in the environment
- DefaultMonitorConfiguration conf=
- new XMLMonitorConfiguration();
-
- conf.setValidateBehaviour(validate);
-
- ret = ServiceMonitorFactory.getServiceMonitor(conf);
-
- // Register service description
- ret.getConfiguration().getServiceRepository().
- addServiceDescription(sdesc);
-
- logger.info("Created monitor for service description
"+sdesc.getFullyQualifiedName());
-
- m_serviceMonitors.put(sdesc.getFullyQualifiedName(), ret);
-
- //m_serviceMonitorCounters.put(sdesc.getFullyQualifiedName(), new Integer(1));
-
- } catch(Exception e) {
- logger.severe("Failed to initialize service monitor: "+e);
- }
- } else {
-
- // Service monitor already in use for the service
- // description, so update description
- try {
- // Clear previous version of the service description
- ServiceDescription[] sdescs=
- ret.getConfiguration().getServiceRepository().getServiceDescriptions();
-
- for (int i=0; sdescs != null && i < sdescs.length; i++) {
- ret.getConfiguration().getServiceRepository().
- removeServiceDescription(sdescs[i]);
- }
-
- logger.info("Updating service description for
"+sdesc.getFullyQualifiedName());
-
- ret.getConfiguration().getServiceRepository().addServiceDescription(sdesc);
- } catch(Exception e) {
- logger.log(Level.SEVERE, "Failed to update service description '"+
- sdesc.getFullyQualifiedName()+"'", e);
- }
-
- /* MAY REMOVE
- *
- // Increment the counter
- Integer
counter=(Integer)m_serviceMonitorCounters.get(sdesc.getFullyQualifiedName());
- if (counter != null) {
- counter = new Integer(counter.intValue()+1);
- m_serviceMonitorCounters.put(sdesc.getFullyQualifiedName(), counter);
-
- if (logger.isLoggable(Level.FINE)) {
- logger.fine("Service monitor for '"+
- sdesc.getFullyQualifiedName()+"' reference count now: "+counter);
- }
- } else {
- logger.severe("Failed to find counter for
"+sdesc.getFullyQualifiedName());
- }
- */
- }
- }
-
- return(ret);
- }
-
- /**
- * This method removes the service monitor associated with
- * the supplied service description name.
- *
- * @param sdesc The service description name
- * @throws ServiceException Failed to remove the service monitor
- */
- public static void removeServiceMonitor(String sdesc)
- throws ServiceException {
- synchronized(m_serviceMonitors) {
- ServiceMonitor monitor=(ServiceMonitor)
- m_serviceMonitors.remove(sdesc);
-
- if (monitor != null) {
- monitor.close();
- }
- }
- }
-
- /**
- * This method decrements the service monitor reference count
- * associated with the service description, and if reaches zero,
- * then it will close the service monitor.
- *
- * @param sdesc The service description name
- * @throws ServiceException Failed to release the service monitor
- */
- public static void releaseServiceMonitor(String sdesc)
- throws ServiceException {
-
- /* MAY REMOVE
- *
- synchronized(m_serviceMonitors) {
-
- Integer counter=(Integer)m_serviceMonitorCounters.get(sdesc);
- if (counter != null) {
-
- if (counter.intValue() > 1) {
- counter = new Integer(counter.intValue()-1);
- m_serviceMonitorCounters.put(sdesc, counter);
-
- if (logger.isLoggable(Level.FINE)) {
- logger.fine("Service monitor for '"+
- sdesc+"' reference count now: "+counter);
- }
- } else {
- if (logger.isLoggable(Level.FINE)) {
- logger.fine("Service monitor for '"+
- sdesc+"' being closed");
- }
-
- m_serviceMonitorCounters.remove(sdesc);
-
- ServiceMonitor monitor=(ServiceMonitor)
- m_serviceMonitors.remove(sdesc);
-
- monitor.close();
- }
- } else {
- logger.severe("Failed to find counter for "+sdesc);
- }
- }
- */
- }
-
- /**
- * This method returns the set of service description names
- * that are associated with service monitors.
- *
- * @return The set of service monitors
- */
- public static java.util.Set<String> getServiceDescriptionNames() {
- java.util.Set<String> ret=new java.util.HashSet<String>();
-
- // Return copy to ensure changes in the map, do not
- // affect the returned set of names
- ret.addAll(m_serviceMonitors.keySet());
-
- return(ret);
- }
-
- private static Logger logger =
Logger.getLogger("org.pi4soa.jbossesb.validator");
-
- private static java.util.Map<String,ServiceMonitor> m_serviceMonitors=new
java.util.Hashtable<String,ServiceMonitor>();
- //private static java.util.Map<String,Integer> m_serviceMonitorCounters=new
java.util.Hashtable<String,Integer>();
-}
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorName.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorName.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorName.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,133 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb;
+
+/**
+ * This class represents a key for looking up a service validator.
+ */
+public class ValidatorName {
+
+ /**
+ * This constructor is initialized with the details used to
+ * identify the validator.
+ *
+ * @param role The role
+ */
+ public ValidatorName(String role) {
+ m_role = role;
+ m_validate = false;
+ }
+
+ /**
+ * This constructor is initialized with the details used to
+ * identify the validator.
+ *
+ * @param modelName The model name
+ * @param role The role
+ * @param validate Whether to validate, or simply record
+ */
+ public ValidatorName(String modelName, String role) {
+ m_modelName = modelName;
+ m_role = role;
+ m_validate = true;
+ }
+
+ /**
+ * This method returns the model name associated with the
+ * service validator.
+ *
+ * @return The model name
+ */
+ public String getModelName() {
+ return(m_modelName);
+ }
+
+ /**
+ * This method returns the type associated with the model.
+ * If no model has been defined for the validator name,
+ * as in the case of a validator in record mode, then
+ * this method will return ValidatorName.NO_MODEL_TYPE.
+ *
+ * @return The model type
+ */
+ public String getModelType() {
+ String ret=null;
+ int pos=0;
+
+ if (m_modelName != null &&
+ (pos=m_modelName.lastIndexOf('.')) != -1) {
+ ret = m_modelName.substring(pos+1);
+ } else {
+ ret = NO_MODEL_TYPE;
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method returns the role associated with the Service
+ * Validator.
+ *
+ * @return The role
+ */
+ public String getRole() {
+ return(m_role);
+ }
+
+ /**
+ * This method determines whether the associated service
+ * validator is in validation or record mode.
+ *
+ * @return Whether in validation or record mode
+ */
+ public boolean isValidate() {
+ return(m_validate);
+ }
+
+ public boolean equals(Object obj) {
+ boolean ret=false;
+
+ if (obj instanceof ValidatorName) {
+ ret = obj.toString().equals(toString());
+ }
+
+ return(ret);
+ }
+
+ public int hashCode() {
+ return(toString().hashCode());
+ }
+
+ public String toString() {
+ String ret=null;
+
+ if (isValidate()) {
+ ret = m_modelName+":"+m_role;
+ } else {
+ ret = m_role;
+ }
+
+ return(ret);
+ }
+
+ public static final String NO_MODEL_TYPE="NoModelType";
+
+ private String m_modelName=null;
+ private String m_role=null;
+ private boolean m_validate=false;
+}
\ No newline at end of file
Copied:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/action/ValidationAction.java
(from rev 479,
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidationAction.java)
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/action/ValidationAction.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/action/ValidationAction.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,249 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb.action;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.soa.esb.actions.*;
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.overlord.validator.jbossesb.ESBUtil;
+
+import org.pi4soa.common.util.MessageUtil;
+import org.pi4soa.service.*;
+import org.pi4soa.service.behavior.*;
+import org.pi4soa.service.monitor.*;
+import org.pi4soa.common.util.NamesUtil;
+
+/**
+ * This class provides the action implementation for validation
+ * against the pi4soa state machine.
+ */
+public class ValidationAction extends AbstractActionLifecycle {
+
+ private static final String ACTIVE_ATTR = "active";
+ private static final String INBOUND_ATTR = "inbound";
+ public static final String CDM_FILE_PATH="cdmFilePath";
+ public static final String PARTICIPANT_TYPE="participantType";
+
+ /**
+ * This constructor initializes the actions with the
+ * service configuration details.
+ *
+ * @param config The service configuration
+ */
+ public ValidationAction(ConfigTree config) {
+ m_config = config;
+ }
+
+ /**
+ * This method initializes the service action.
+ */
+ public void initialise() throws ActionLifecycleException {
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("ValidationAction initialise: "+this);
+ }
+
+ super.initialise();
+
+ String direction=
+ m_config.getAttribute(INBOUND_ATTR);
+
+ if (direction != null && direction.equalsIgnoreCase("false")) {
+ m_inbound = false;
+ }
+
+ String active=
+ m_config.getAttribute(ACTIVE_ATTR);
+
+ if (active != null && active.equalsIgnoreCase("false")) {
+ m_active = false;
+ }
+
+ getServiceMonitor();
+ }
+
+ /**
+ * This method returns the service monitor associated with
+ * the ESB service.
+ *
+ * @return The service monitor
+ */
+ protected synchronized ServiceMonitor getServiceMonitor() {
+
+ if (m_serviceMonitor == null) {
+
+ try {
+ ServiceDescription sdesc=null;
+ String cdmFilePath=
+ m_config.getAttribute(CDM_FILE_PATH);
+ String participantType=
+ m_config.getAttribute(PARTICIPANT_TYPE);
+
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("ValidationAction config: cdm="+
+ cdmFilePath+" participant="+participantType);
+ }
+
+ if (NamesUtil.isSet(cdmFilePath) &&
+ NamesUtil.isSet(participantType)) {
+
+ java.io.InputStream is=ValidationAction.class.
+ getClassLoader().getResourceAsStream(cdmFilePath);
+
+ if (is == null) {
+
+ is = ClassLoader.getSystemResourceAsStream(cdmFilePath);
+
+ if (is == null) {
+ throw new ServiceException("Failed to locate path '"+
+ cdmFilePath+"'");
+ }
+ }
+
+ if (is != null) {
+ sdesc =
org.pi4soa.service.util.DescriptionRetrievalUtil.instance().getServiceDescription(is,
participantType);
+ }
+ } else {
+ logger.severe("Choreography file and Participant Type not specified:
"+this);
+ }
+
+ if (sdesc != null) {
+ m_serviceDescriptionName = sdesc.getFullyQualifiedName();
+
+ // Obtain the service container
+ //m_serviceMonitor = createServiceContainer(sdesc);
+ } else {
+ logger.severe("Service description could not be loaded: "+
+ cdmFilePath+" participant="+participantType);
+ }
+
+ } catch(Exception e) {
+ logger.log(Level.SEVERE,
+ "Failed to initialize ValidationAction", e);
+ }
+ }
+
+ return(m_serviceMonitor);
+ }
+
+ /**
+ * This method processes a message for the service associated
+ * with this ESB action.
+ *
+ * @param message The message
+ * @return The message
+ */
+ public Message processMessage(Message message) throws ActionProcessingException {
+
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("ValidationAction: "+this+" message="+message);
+ }
+
+ try {
+ java.io.Serializable value=ESBUtil.getMessage(message);
+
+ if (value == null) {
+ throw new ServiceException("Failed to obtain value from message:
"+message);
+ }
+
+ String mesgType=MessageUtil.getMessageType(value);
+
+ org.pi4soa.service.Message mesg=
+ getServiceMonitor().createMessage(mesgType, null,
+ null, value, null, null);
+
+ try {
+ if (m_inbound) {
+ getServiceMonitor().messageReceived(mesg);
+ } else {
+ getServiceMonitor().messageSent(mesg);
+ }
+ } catch(OutOfSequenceMessageException osme) {
+
+ if (m_active) {
+ throw osme;
+ } else {
+ logger.severe("Out of sequence message detected");
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest(message.toString());
+ }
+ }
+ } catch(UnexpectedMessageException ume) {
+
+ if (m_active) {
+ throw ume;
+ } else {
+ logger.severe("Unexpected message detected");
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest(message.toString());
+ }
+ }
+ }
+
+ } catch(Throwable t) {
+ logger.log(java.util.logging.Level.SEVERE,
+ "Failed to handle message", t);
+
+ throw new ActionProcessingException("Failed to handle message", t);
+ }
+
+ if (logger.isLoggable(Level.FINEST)) {
+ logger.finest("ValidationAction: "+this+
+ "serviceDescriptionName="+
+ m_serviceDescriptionName+
+ " finished processing message="+message);
+ }
+
+ return(message);
+ }
+
+ /**
+ * This method is called to tidy up after the action is
+ * no longer required.
+ */
+ public void destroy() throws ActionLifecycleException {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("ValidationAction destroy: "+this);
+ }
+
+ super.destroy();
+
+ if (m_serviceMonitor != null &&
+ m_serviceDescriptionName != null) {
+ /*
+ try {
+ ServiceValidatorManager.releaseServiceMonitor(m_serviceDescriptionName);
+ } catch(org.pi4soa.service.ServiceException se) {
+ throw new ActionLifecycleException("Failed to destroy service monitor",
+ se);
+ }
+ */
+ }
+ }
+
+ private static final Logger logger =
Logger.getLogger("org.jboss.soa.overlord.validator.jbossesb.action");
+
+ private ConfigTree m_config=null;
+ private String m_serviceDescriptionName=null;
+ private ServiceMonitor m_serviceMonitor=null;
+ private boolean m_inbound=true;
+ private boolean m_active=true;
+}
\ No newline at end of file
Property changes on:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/action/ValidationAction.java
___________________________________________________________________
Name: svn:mergeinfo
+
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAServiceRecorder.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAServiceRecorder.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAServiceRecorder.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,155 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb.pi4soa;
+
+import java.util.logging.*;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.overlord.validator.jbossesb.*;
+import org.pi4soa.common.util.MessageUtil;
+import org.pi4soa.service.ServiceException;
+import org.pi4soa.service.behavior.*;
+import org.pi4soa.service.monitor.*;
+
+/**
+ * This class implements the pi4soa service validator responsible for
+ * recording a stream of ESB messages.
+ */
+public class Pi4SOAServiceRecorder extends AbstractServiceValidator {
+
+ /**
+ * This is the constructor for the pi4soa service
+ * recorder implementation.
+ *
+ * @param name The validator name
+ */
+ public Pi4SOAServiceRecorder(ValidatorName name) {
+ super(name);
+
+ initialize();
+ }
+
+ /**
+ * This method initializes the service recorder.
+ */
+ protected void initialize() {
+ try {
+ // Use XML configuration, to enable alternative
+ // runtime configuration to be specified by
+ // including a pi4soa.xml file in the environment
+ DefaultMonitorConfiguration conf=
+ new XMLMonitorConfiguration();
+
+ conf.setValidateBehaviour(getValidatorName().isValidate());
+
+ m_monitor = ServiceMonitorFactory.getServiceMonitor(conf);
+
+ ServiceDescription sdesc=BehaviorFactory.eINSTANCE.createServiceDescription();
+ sdesc.setName(getValidatorName().getRole());
+
+ // Register service description
+ m_monitor.getConfiguration().getServiceRepository().
+ addServiceDescription(sdesc);
+
+ logger.info("Created monitor for service description
"+sdesc.getFullyQualifiedName());
+
+ } catch(Exception e) {
+ logger.severe("Failed to initialize service monitor: "+e);
+ }
+ }
+
+ /**
+ * This method returns the model type associated with this
+ * service recorder.
+ *
+ * @return The model type
+ */
+ public static String getModelType() {
+ return(ValidatorName.NO_MODEL_TYPE);
+ }
+
+ /**
+ * This method is called to update the model associated
+ * with the service validator.
+ */
+ public void update() {
+ }
+
+ /**
+ * This method processes a sent message against a service
+ * behavioural description.
+ *
+ * @param msg The message
+ * @throws Exception Failed to process sent message
+ */
+ public void messageSent(Message msg) throws Exception {
+ java.io.Serializable value=ESBUtil.getMessage(msg);
+
+ if (value == null) {
+ throw new ServiceException("Failed to obtain value from message: "+msg);
+ }
+
+ String mesgType=MessageUtil.getMessageType(value);
+
+ org.pi4soa.service.Message mesg=
+ m_monitor.createMessage(mesgType,
+ null, null, value, null, null);
+
+ synchronized(m_monitor) {
+ m_monitor.messageSent(mesg);
+ }
+ }
+
+ /**
+ * This method processes a received message against a service
+ * behavioural description.
+ *
+ * @param msg The message
+ * @throws Exception Failed to process received message
+ */
+ public void messageReceived(Message msg) throws Exception {
+ java.io.Serializable value=ESBUtil.getMessage(msg);
+
+ if (value == null) {
+ throw new ServiceException("Failed to obtain value from message: "+msg);
+ }
+
+ String mesgType=MessageUtil.getMessageType(value);
+
+ org.pi4soa.service.Message mesg=
+ m_monitor.createMessage(mesgType,
+ null, null, value, null, null);
+
+ synchronized(m_monitor) {
+ m_monitor.messageReceived(mesg);
+ }
+ }
+
+ /**
+ * This method closes the service validator.
+ *
+ * @throws Exception Failed to close the service validator
+ */
+ public void close() throws Exception {
+ m_monitor.close();
+ }
+
+ private static final Logger logger =
Logger.getLogger("org.jboss.soa.overlord.validator.jbossesb.pi4soa");
+
+ private org.pi4soa.service.monitor.ServiceMonitor m_monitor=null;
+}
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAServiceValidator.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAServiceValidator.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAServiceValidator.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,202 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb.pi4soa;
+
+import java.util.logging.*;
+
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.overlord.validator.jbossesb.*;
+import org.pi4soa.common.util.MessageUtil;
+import org.pi4soa.service.ServiceException;
+import org.pi4soa.service.behavior.*;
+import org.pi4soa.service.monitor.*;
+
+/**
+ * This class implements the pi4soa service validator responsible for
+ * validating a stream of ESB messages against a choreography model.
+ */
+public class Pi4SOAServiceValidator extends AbstractServiceValidator {
+
+ private static final String CDM_MODEL_TYPE = "cdm";
+
+ /**
+ * This is the constructor for the pi4soa service
+ * validator implementation.
+ *
+ * @param name The validator name
+ */
+ public Pi4SOAServiceValidator(ValidatorName name) {
+ super(name);
+
+ update();
+ }
+
+ /**
+ * This method returns the model type associated with this
+ * service validator.
+ *
+ * @return The model type
+ */
+ public static String getModelType() {
+ return CDM_MODEL_TYPE;
+ }
+
+ /**
+ * This method is called to update the model associated
+ * with the service validator.
+ */
+ public void update() {
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Update: "+getValidatorName());
+ }
+
+ java.io.InputStream is=getModel();
+
+ if (is != null) {
+ org.pi4soa.service.behavior.ServiceDescription sdesc=
+ org.pi4soa.service.util.DescriptionRetrievalUtil.instance().getServiceDescription(is,
+ getValidatorName().getRole());
+
+ if (sdesc != null) {
+
+ if (m_monitor == null) {
+
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Service monitor for '"+
+ sdesc.getFullyQualifiedName()+
+ "' being created");
+ }
+
+ try {
+ // Use XML configuration, to enable alternative
+ // runtime configuration to be specified by
+ // including a pi4soa.xml file in the environment
+ DefaultMonitorConfiguration conf=
+ new XMLMonitorConfiguration();
+
+ conf.setValidateBehaviour(getValidatorName().isValidate());
+
+ m_monitor = ServiceMonitorFactory.getServiceMonitor(conf);
+
+ // Register service description
+ m_monitor.getConfiguration().getServiceRepository().
+ addServiceDescription(sdesc);
+
+ logger.info("Created monitor for service description
"+sdesc.getFullyQualifiedName());
+
+ } catch(Exception e) {
+ logger.severe("Failed to initialize service monitor: "+e);
+ }
+ } else {
+
+ synchronized(m_monitor) {
+ // Service monitor already in use for the service
+ // description, so update description
+ try {
+ // Clear previous version of the service description
+ ServiceDescription[] sdescs=
+ m_monitor.getConfiguration().getServiceRepository().getServiceDescriptions();
+
+ for (int i=0; sdescs != null && i < sdescs.length; i++) {
+ m_monitor.getConfiguration().getServiceRepository().
+ removeServiceDescription(sdescs[i]);
+ }
+
+ logger.info("Updating service description for
"+sdesc.getFullyQualifiedName());
+
+ m_monitor.getConfiguration().getServiceRepository().addServiceDescription(sdesc);
+ } catch(Exception e) {
+ logger.log(Level.SEVERE, "Failed to update service description '"+
+ sdesc.getFullyQualifiedName()+"'", e);
+ }
+ }
+ }
+ } else {
+ logger.severe("Unable to obtain service description for validator '"+
+ getValidatorName()+"'");
+ }
+ } else {
+ logger.severe("Unable to obtain model for validator '"+
+ getValidatorName()+"'");
+ }
+ }
+
+ /**
+ * This method processes a sent message against a service
+ * behavioural description.
+ *
+ * @param msg The message
+ * @throws Exception Failed to process sent message
+ */
+ public void messageSent(Message msg) throws Exception {
+ java.io.Serializable value=ESBUtil.getMessage(msg);
+
+ if (value == null) {
+ throw new ServiceException("Failed to obtain value from message: "+msg);
+ }
+
+ String mesgType=MessageUtil.getMessageType(value);
+
+ org.pi4soa.service.Message mesg=
+ m_monitor.createMessage(mesgType,
+ null, null, value, null, null);
+
+ synchronized(m_monitor) {
+ m_monitor.messageSent(mesg);
+ }
+ }
+
+ /**
+ * This method processes a received message against a service
+ * behavioural description.
+ *
+ * @param msg The message
+ * @throws Exception Failed to process received message
+ */
+ public void messageReceived(Message msg) throws Exception {
+ java.io.Serializable value=ESBUtil.getMessage(msg);
+
+ if (value == null) {
+ throw new ServiceException("Failed to obtain value from message: "+msg);
+ }
+
+ String mesgType=MessageUtil.getMessageType(value);
+
+ org.pi4soa.service.Message mesg=
+ m_monitor.createMessage(mesgType,
+ null, null, value, null, null);
+
+ synchronized(m_monitor) {
+ m_monitor.messageReceived(mesg);
+ }
+ }
+
+ /**
+ * This method closes the service validator.
+ *
+ * @throws Exception Failed to close the service validator
+ */
+ public void close() throws Exception {
+ m_monitor.close();
+ }
+
+ private static final Logger logger =
Logger.getLogger("org.jboss.soa.overlord.validator.jbossesb.pi4soa");
+
+ private org.pi4soa.service.monitor.ServiceMonitor m_monitor=null;
+}
Added:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAValidatorConfigLoader.java
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAValidatorConfigLoader.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/Pi4SOAValidatorConfigLoader.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb.pi4soa;
+
+import org.jboss.soa.esb.helpers.ConfigTree;
+import org.jboss.soa.overlord.validator.jbossesb.*;
+
+/**
+ * This class provides the pi4soa implementation of the
+ * validator config loader.
+ */
+public class Pi4SOAValidatorConfigLoader implements ValidatorConfigLoader {
+
+ public static final String PI4SOA_MODEL_TYPE="cdm";
+
+ /**
+ * This method determines if the validator config loader
+ * implementation supports the supplied model type.
+ *
+ * @param modelType The model type
+ * @return Whether the loader supports the model type
+ */
+ public boolean isSupported(String modelType) {
+ return(PI4SOA_MODEL_TYPE.equals(modelType));
+ }
+
+ /**
+ * This method loads the validator config, contained within
+ * the supplied input stream representing a model of the
+ * supported type.
+ *
+ * @param is The input stream
+ * @param modelPath The path to the model file
+ * @return The validator config
+ * @throws java.io.IOException Failed to load validator config
+ */
+ public ValidatorConfig loadValidatorConfig(java.io.InputStream is,
+ String modelPath) throws java.io.IOException {
+ ValidatorConfig ret=null;
+
+ org.pi4soa.cdl.Package cdlpack=
+ org.pi4soa.service.util.DescriptionRetrievalUtil.instance().getCDLPackage(is);
+
+ ValidatorConfigGenerator generator=new ValidatorConfigGenerator();
+
+ org.w3c.dom.Element validator=
+ generator.generate(cdlpack, modelPath);
+
+ ret = new DefaultValidatorConfig(PI4SOA_MODEL_TYPE,
+ ConfigTree.fromElement(validator));
+
+ return(ret);
+ }
+}
Copied:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/ValidatorConfigGenerator.java
(from rev 479,
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/ValidatorGenerator.java)
===================================================================
---
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/ValidatorConfigGenerator.java
(rev 0)
+++
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/ValidatorConfigGenerator.java 2009-02-10
11:12:34 UTC (rev 485)
@@ -0,0 +1,269 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+package org.jboss.soa.overlord.validator.jbossesb.pi4soa;
+
+import java.util.Collections;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.pi4soa.cdl.*;
+import org.pi4soa.common.annotations.*;
+
+/**
+ * This class provides a generator for the JBossESB Validator
+ * configuration.
+ */
+public class ValidatorConfigGenerator {
+
+ private static final String ROLE_ATTR = "role";
+ private static final String MODEL_ATTR = "model";
+ private static final String SERVICE_ELEMENT = "service";
+ private static final String VALIDATOR_ELEMENT = "validator";
+
+ /**
+ * The default constructor.
+ */
+ public ValidatorConfigGenerator() {
+ }
+
+ /**
+ * This method generates the validator configuration associated
+ * with the supplied choreography.
+ *
+ * @param cdlpack The CDL package
+ * @param model The model (choreography file name)
+ * @return The validator config
+ */
+ public org.w3c.dom.Element generate(org.pi4soa.cdl.Package cdlpack,
+ String model) {
+ org.w3c.dom.Element ret=null;
+
+ try {
+ ret = createValidatorConfig();
+
+ // Create the new entries for the supplied choreography
+ createEntries(ret, model, cdlpack);
+
+ } catch(Exception e) {
+ e.printStackTrace();
+ }
+
+ return(ret);
+ }
+
+ /**
+ * This method creates the initial template for the
+ * validator config.
+ *
+ * @return The initial validator config
+ * @throws Exception Failed to generate validator config
+ */
+ protected org.w3c.dom.Element createValidatorConfig()
+ throws Exception {
+ org.w3c.dom.Element ret=null;
+
+ org.w3c.dom.Document doc=
+ javax.xml.parsers.DocumentBuilderFactory.
+ newInstance().newDocumentBuilder().newDocument();
+
+ ret = doc.createElement(VALIDATOR_ELEMENT);
+
+ doc.appendChild(ret);
+
+ return(ret);
+ }
+
+ /**
+ * This method creates the entries in the validator config.
+ *
+ * @param validator The validator config
+ * @param model The model
+ * @param cdlpack The choreography description
+ */
+ protected void createEntries(org.w3c.dom.Element validator,
+ String model, org.pi4soa.cdl.Package cdlpack) {
+
+ for (int i=0; i < cdlpack.getTypeDefinitions().getParticipantTypes().size(); i++) {
+ org.pi4soa.cdl.ParticipantType ptype=
+ cdlpack.getTypeDefinitions().getParticipantTypes().get(i);
+
+ org.w3c.dom.Element service=
+ validator.getOwnerDocument().createElement(SERVICE_ELEMENT);
+
+ service.setAttribute(MODEL_ATTR, model);
+ service.setAttribute(ROLE_ATTR, ptype.getName());
+
+ cdlpack.visit(new InputOutputAnalyser(ptype, service));
+
+ if (service.getFirstChild() != null) {
+ validator.appendChild(service);
+ }
+ }
+ }
+
+ private static Logger logger =
Logger.getLogger("org.jboss.soa.overlord.validator.jbossesb.pi4soa");
+
+ public class InputOutputAnalyser extends DefaultCDLVisitor {
+
+ private static final String JBOSSESB_ANNOTATION = "jbossesb";
+ private static final String JBOSSESB_ELEMENT = "jbossesb";
+ private static final String DESTINATION_ELEMENT = "destination";
+ private static final String NAME_ATTR = "name";
+ private static final String EPR_ATTR = "epr";
+ private static final String INPUT_ELEMENT = "input";
+ private static final String OUTPUT_ELEMENT = "output";
+
+ public InputOutputAnalyser(org.pi4soa.cdl.ParticipantType ptype,
+ org.w3c.dom.Element service) {
+ m_participantType = ptype;
+ m_service = service;
+
+ m_templateProcessor =
+ org.pi4soa.common.annotations.AnnotationsManagerFactory.getAnnotationsManager().getTemplateProcessor(JBOSSESB_ANNOTATION);
+ }
+
+ /**
+ * This method inspects the supplied interaction.
+ *
+ */
+ public void interaction(Interaction interaction) {
+ if (m_participantType.getRoleTypes().contains(interaction.getFromRoleType()) ||
+ (interaction.getFromParticipant() != null &&
+ Collections.disjoint(m_participantType.getRoleTypes(),
+ interaction.getFromParticipant().getRoleTypes()) == false)) {
+
+ for (int i=0; i < interaction.getExchangeDetails().size(); i++) {
+ processExchangeDetails(interaction.getExchangeDetails().get(i), true);
+ }
+ } else if (m_participantType.getRoleTypes().contains(interaction.getToRoleType()) ||
+ (interaction.getToParticipant() != null &&
+ Collections.disjoint(m_participantType.getRoleTypes(),
+ interaction.getToParticipant().getRoleTypes()) == false)) {
+ for (int i=0; i < interaction.getExchangeDetails().size(); i++) {
+ processExchangeDetails(interaction.getExchangeDetails().get(i), false);
+ }
+ }
+ }
+
+ /**
+ * This method checks the supplied exchange details to determine
+ * if there is a 'jbossesb' annotation containing information
+ * about a destination to be validated.
+ *
+ * @param details The exchange details
+ * @param from Whether the 'from' details should be checked,
+ * otherwise the 'to' details will be checked
+ */
+ protected void processExchangeDetails(ExchangeDetails details, boolean from) {
+
+ for (int i=0; i < details.getSemanticAnnotations().size(); i++) {
+ SemanticAnnotation sa=details.getSemanticAnnotations().get(i);
+ org.w3c.dom.Element dest=null;
+
+ if (sa.getAnnotation() != null && sa.getName() != null &&
+ sa.getName().equals(JBOSSESB_ANNOTATION)) {
+ try {
+ // Transform the text representation to DOM
+ DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance();
+ fact.setNamespaceAware(true);
+
+ DocumentBuilder builder=fact.newDocumentBuilder();
+ org.w3c.dom.Document doc=
+ builder.parse(new java.io.ByteArrayInputStream(
+ sa.getAnnotation().getBytes()));
+
+ if (doc.getDocumentElement() != null &&
+ doc.getDocumentElement().getNodeName().equals(
+ JBOSSESB_ELEMENT)) {
+ org.w3c.dom.NodeList nl=
+ doc.getDocumentElement().getElementsByTagName(DESTINATION_ELEMENT);
+
+ if (nl.getLength() == 1) {
+ dest = (org.w3c.dom.Element)nl.item(0);
+ } else if (nl.getLength() > 1) {
+ logger.severe("Too many destination elements ("+
+ nl.getLength()+") found");
+ } else {
+ logger.severe("No destinations found");
+ }
+ }
+
+ } catch(Exception e) {
+ logger.log(Level.SEVERE,
+ "Failed to load jbossesb annotation", e);
+ }
+ }
+
+ if (dest != null) {
+ processDestination(details, dest, from);
+ }
+ }
+ }
+
+ /**
+ * This method processes the destination information
+ * associated with the exchange details.
+ *
+ * @param details The exchange details
+ * @param dest The destination DOM element
+ * @param from Whether the 'from' or 'to' role should
+ * be considered
+ */
+ protected void processDestination(ExchangeDetails details,
+ org.w3c.dom.Element dest, boolean from) {
+ String elemName=null;
+
+ if (dest != null &&
+ dest.getAttribute("temporary").equalsIgnoreCase("true") ==
false) {
+ if (from) {
+ if (details.getAction() == ExchangeActionType.REQUEST) {
+ elemName = OUTPUT_ELEMENT;
+ } else {
+ elemName = INPUT_ELEMENT;
+ }
+ } else {
+ if (details.getAction() == ExchangeActionType.REQUEST) {
+ elemName = INPUT_ELEMENT;
+ } else {
+ elemName = OUTPUT_ELEMENT;
+ }
+ }
+
+ // Parameter has been stored in a structured manner
+ // to support use of templates and presentations,
+ // so need to extract the value
+ java.util.List<TemplateParameter> params=
+ m_templateProcessor.getTemplateParameters(dest.getAttribute(NAME_ATTR));
+
+ if (params != null && params.size() > 0) {
+ org.w3c.dom.Element elem=m_service.getOwnerDocument().createElement(elemName);
+ elem.setAttribute(EPR_ATTR, params.get(0).getValue());
+
+ m_service.appendChild(elem);
+ }
+ }
+ }
+
+ private ParticipantType m_participantType=null;
+ private org.w3c.dom.Element m_service=null;
+ private org.pi4soa.common.annotations.TemplateProcessor m_templateProcessor=null;
+ }
+}
Property changes on:
cdl/trunk/validator/jbossesb/src/main/java/org/jboss/soa/overlord/validator/jbossesb/pi4soa/ValidatorConfigGenerator.java
___________________________________________________________________
Name: svn:mergeinfo
+