[jboss-svn-commits] JBL Code SVN: r8949 - in labs/jbossesb/trunk/product: core/services/src/org/jboss/internal/soa/esb/persistence/format/db and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Jan 21 04:33:56 EST 2007
Author: mark.little at jboss.com
Date: 2007-01-21 04:33:55 -0500 (Sun, 21 Jan 2007)
New Revision: 8949
Added:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreException.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/CBRException.java
Modified:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStore.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManager.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManagerDBCP.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBMessageStoreImpl.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouter.java
labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java
labs/jbossesb/trunk/product/etc/schemas/validation/src/org/jboss/soa/esb/services/xml/XmlValidation.java
Log:
Method signature changes for finer granularity exceptions.
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStore.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStore.java 2007-01-20 23:50:44 UTC (rev 8948)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStore.java 2007-01-21 09:33:55 UTC (rev 8949)
@@ -27,9 +27,8 @@
public interface MessageStore
{
+ public URI addMessage (Message message) throws MessageStoreException;
- public URI addMessage (Message message);
+ public Message getMessage (URI uid) throws MessageStoreException;
- public Message getMessage (URI uid) throws Exception;
-
}
Added: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreException.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreException.java (rev 0)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/services/persistence/MessageStoreException.java 2007-01-21 09:33:55 UTC (rev 8949)
@@ -0,0 +1,53 @@
+package org.jboss.soa.esb.services.persistence;
+
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., 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.
+ *
+ * (C) 2005-2006,
+ * @author mark.little at jboss.com
+ */
+
+/**
+ * Thrown if marshalling a message fails. This could be because
+ * conversion to XML encounters problems.
+ */
+
+public class MessageStoreException extends Exception
+{
+ private static final long serialVersionUID = 0xE;
+
+ public MessageStoreException()
+ {
+ super();
+ }
+
+ public MessageStoreException(String s)
+ {
+ super(s);
+ }
+
+ public MessageStoreException (Exception ex)
+ {
+ super(ex);
+ }
+
+ public MessageStoreException (String message, Exception ex)
+ {
+ super(message, ex);
+ }
+
+}
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManager.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManager.java 2007-01-20 23:50:44 UTC (rev 8948)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManager.java 2007-01-21 09:33:55 UTC (rev 8949)
@@ -22,82 +22,115 @@
package org.jboss.internal.soa.esb.persistence.format.db;
import java.sql.Connection;
+import java.sql.SQLException;
import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.common.Configuration;
import com.mchange.v2.c3p0.ComboPooledDataSource;
+public class DBConnectionManager
+{
-public class DBConnectionManager {
-
- private static DBConnectionManager instance =null;
-
+ private static DBConnectionManager instance = null;
+
protected ComboPooledDataSource pooledDS = null;
-
+
private static final Object foo = new Integer(0);
-
+
private static Logger _logger = Logger.getLogger(DBConnectionManager.class);
-
-
- protected DBConnectionManager() {}
-
- public static DBConnectionManager getInstance() {
- if (null != instance) {
+
+ protected DBConnectionManager ()
+ {
+ }
+
+ public static DBConnectionManager getInstance ()
+ {
+ if (null != instance)
+ {
+ return instance;
+ }
+
+ synchronized (foo)
+ {
+ if (null != instance)
return instance;
- } synchronized(foo) {
- if (null != instance)
- return instance;
- try {
- instance = new DBConnectionManager();
- instance.init();
- }catch(Exception e) {
- e.printStackTrace();
- return null;
- }
+
+ try
+ {
+ instance = new DBConnectionManager();
+ instance.init();
+ }
+ catch (Exception e)
+ {
+ _logger.error("Could not initialise instance.", e);
- return instance;
- }
-
+ return null;
+ }
+
+ return instance;
+ }
}
-
- private void init() throws Exception{
- _logger.info("Initializing DBConnectionManager");
+
+ private void init () throws ConfigurationException
+ {
+ _logger.info("Initializing DBConnectionManager");
pooledDS = new ComboPooledDataSource();
-
-
- pooledDS.setDriverClass(Configuration.getStoreDriver());
- pooledDS.setJdbcUrl(Configuration.getStoreUrl());
- pooledDS.setUser(Configuration.getStoreUser());
- pooledDS.setPassword(Configuration.getStorePwd());
- pooledDS.setMinPoolSize(Integer.valueOf(Configuration.getStorePoolMinSize()));
- pooledDS.setInitialPoolSize(Integer.valueOf(Configuration.getStorePoolInitialSize()));
- pooledDS.setMaxPoolSize(Integer.valueOf(Configuration.getStorePoolMaxSize()));
- pooledDS.setAutomaticTestTable(Configuration.getStorePoolTestTable());
- pooledDS.setCheckoutTimeout(Integer.valueOf(Configuration.getStorePoolTimeoutMillis()));
+
+ try
+ {
+ pooledDS.setDriverClass(Configuration.getStoreDriver());
+ pooledDS.setJdbcUrl(Configuration.getStoreUrl());
+ pooledDS.setUser(Configuration.getStoreUser());
+ pooledDS.setPassword(Configuration.getStorePwd());
+ pooledDS.setMinPoolSize(Integer.valueOf(Configuration
+ .getStorePoolMinSize()));
+ pooledDS.setInitialPoolSize(Integer.valueOf(Configuration
+ .getStorePoolInitialSize()));
+ pooledDS.setMaxPoolSize(Integer.valueOf(Configuration
+ .getStorePoolMaxSize()));
+ pooledDS.setAutomaticTestTable(Configuration.getStorePoolTestTable());
+ pooledDS.setCheckoutTimeout(Integer.valueOf(Configuration
+ .getStorePoolTimeoutMillis()));
+ }
+ catch (Exception ex)
+ {
+ throw new ConfigurationException(ex);
+ }
}
-
-
-
- public Connection getConnection() throws Exception{
-
+
+ public Connection getConnection () throws SQLException
+ {
Connection conn = null;
+
+ // TODO: figure out why this is neccessary - pool should never return
+ // null if DB is up and can connect
+ // testing showed null was being returned from pool in QA test
+ // MessageStoreTest
- //TODO: figure out why this is neccessary - pool should never return null if DB is up and can connect
- //testing showed null was being returned from pool in QA test MessageStoreTest
while (true)
{
- if (null!=pooledDS)
- if (null != (conn=pooledDS.getConnection()))
- break;
- else
- System.out.println("Null pooledDS");
- try { Thread.sleep(1000); }
- catch(Exception e) {}
+ if (null != pooledDS)
+ {
+ if (null != (conn = pooledDS.getConnection()))
+ break;
+ else
+ _logger.error("Null pooledDS");
+ }
+
+ try
+ {
+ // TODO magic number
+
+ Thread.sleep(1000);
+ }
+ catch (Exception e)
+ {
+ }
}
-
+
return conn;
-
}
}
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManagerDBCP.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManagerDBCP.java 2007-01-20 23:50:44 UTC (rev 8948)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBConnectionManagerDBCP.java 2007-01-21 09:33:55 UTC (rev 8949)
@@ -23,8 +23,8 @@
package org.jboss.internal.soa.esb.persistence.format.db;
-
import java.sql.Connection;
+import java.sql.SQLException;
import org.apache.commons.dbcp.ConnectionFactory;
import org.apache.commons.dbcp.DriverManagerConnectionFactory;
@@ -32,72 +32,88 @@
import org.apache.commons.dbcp.PoolingDataSource;
import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.impl.GenericObjectPool;
+import org.jboss.soa.esb.ConfigurationException;
import org.jboss.soa.esb.common.Configuration;
/*
- * the DBConnectionManager class (singleton) is used by classes implenting the MessageStore interface
- * to obtain a connection to the persistence store database.
- * This class uses the Apache Commons DB Connection Pooling to handle all aspects of managing the connections
- * in a pool.
- * $author Daniel Brum
+ * the DBConnectionManager class (singleton) is used by classes implenting the
+ * MessageStore interface to obtain a connection to the persistence store
+ * database. This class uses the Apache Commons DB Connection Pooling to handle
+ * all aspects of managing the connections in a pool. $author Daniel Brum
*/
+public class DBConnectionManagerDBCP
+{
-public class DBConnectionManagerDBCP {
+ private static DBConnectionManagerDBCP instance = null;
+
+ private PoolingDataSource dataSource = null;
+
+ protected DBConnectionManagerDBCP ()
+ {
+ }
+
+ public static DBConnectionManagerDBCP getInstance ()
+ {
+ if (null == instance)
+ {
+ try
+ {
+ instance = new DBConnectionManagerDBCP();
+ instance.init();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ return instance;
+ }
+
+ private void init () throws ConfigurationException
+ {
+ try
+ {
+ String connectURL = Configuration.getStoreUrl();
+ Class.forName(Configuration.getStoreDriver());
+ ObjectPool connectionPool = new GenericObjectPool(null);
+ ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(
+ connectURL, Configuration.getStoreUser(), Configuration
+ .getStorePwd());
- private static DBConnectionManagerDBCP instance =null;
- private PoolingDataSource dataSource = null;
+ @SuppressWarnings("unused")
+ PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(
+ connectionFactory, connectionPool, null, null, false, false);
- protected DBConnectionManagerDBCP() {}
+ int poolSize = Integer.valueOf(Configuration.getStorePoolInitialSize());
- public static DBConnectionManagerDBCP getInstance() {
- if (null == instance) {
- try {
- instance = new DBConnectionManagerDBCP();
- instance.init();
- }catch(Exception e) {
+ // add the max # of connections into the pool
+ for (int i = 0; i < poolSize; i++)
+ {
+ try
+ {
+ connectionPool.addObject();
+ }
+ catch (Exception e)
+ {
e.printStackTrace();
- return null;
}
- }
- return instance;
- }
-
- private void init() throws Exception{
-
- String connectURL = Configuration.getStoreUrl();
- Class.forName(Configuration.getStoreDriver());
-
- ObjectPool connectionPool = new GenericObjectPool(null);
-
- ConnectionFactory connectionFactory = new DriverManagerConnectionFactory(connectURL,
- Configuration.getStoreUser(), Configuration.getStorePwd());
-
- @SuppressWarnings("unused")
-
- PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(connectionFactory,
- connectionPool,null,null,false,false);
-
- int poolSize = Integer.valueOf(Configuration.getStorePoolInitialSize());
-
- //add the max # of connections into the pool
- for (int i=0 ; i<poolSize ; i++) {
- try {
- connectionPool.addObject();
- } catch (Exception e) {
- e.printStackTrace();
}
+
+ dataSource = new PoolingDataSource(connectionPool);
}
- dataSource = new PoolingDataSource(connectionPool);
+ catch (ClassNotFoundException ex)
+ {
+ throw new ConfigurationException(ex);
+ }
}
-
- public Connection getConnection() throws Exception{
+
+ public Connection getConnection () throws SQLException
+ {
return dataSource.getConnection();
}
-
-
-
}
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBMessageStoreImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBMessageStoreImpl.java 2007-01-20 23:50:44 UTC (rev 8948)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBMessageStoreImpl.java 2007-01-21 09:33:55 UTC (rev 8949)
@@ -32,96 +32,131 @@
import org.jboss.internal.soa.esb.thirdparty.Base64;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.persistence.MessageStore;
+import org.jboss.soa.esb.services.persistence.MessageStoreException;
import org.jboss.soa.esb.util.Util;
+public class DBMessageStoreImpl implements MessageStore
+{
-public class DBMessageStoreImpl implements MessageStore {
-
-
protected DBConnectionManager mgr = null;
+
protected Connection conn = null;
+
protected ResultSet rs = null;
+
protected PreparedStatement ps = null;
-
- public DBMessageStoreImpl() {
+
+ public DBMessageStoreImpl ()
+ {
mgr = DBConnectionManager.getInstance();
}
-
- public synchronized URI addMessage(Message message){
-
-// String messageString = null;
- URI uid = null;
-
-
- try {
+
+ public synchronized URI addMessage (Message message) throws MessageStoreException
+ {
+
+ // String messageString = null;
+ URI uid = null;
+
+ try
+ {
conn = mgr.getConnection();
-
- uid = new URI("urn:jboss:esb:message:UID:" + UUID.randomUUID().toString());
-
- String messageString = Base64.encodeObject(Util.serialize(message));
-
- //insert into the database
+
+ uid = new URI("urn:jboss:esb:message:UID:" + UUID.randomUUID()
+ .toString());
+
+ String messageString = Base64.encodeObject(Util.serialize(message));
+
+ // insert into the database
String sql = "insert into message(uuid, type, message) values(?,?,?)";
ps = conn.prepareStatement(sql);
ps.setString(1, uid.toString());
ps.setString(2, message.getType().toString());
ps.setString(3, messageString);
- ps.execute();
-
- } catch (Exception e) { e.printStackTrace(); }
- finally { release(); }
-
+ ps.execute();
+
+ }
+ catch (Exception e)
+ {
+ throw new MessageStoreException(e);
+ }
+ finally
+ {
+ release();
+ }
+
return uid;
}
- public synchronized Message getMessage(URI uid) throws Exception{
-
+ public synchronized Message getMessage (URI uid)
+ throws MessageStoreException
+ {
+
String sql = "select uuid,type,message from message where uuid=?";
Message message = null;
-
- try {
+
+ try
+ {
conn = mgr.getConnection();
ps = conn.prepareStatement(sql);
ps.setString(1, uid.toString());
-
+
rs = ps.executeQuery();
- if (! rs.next()) throw new Exception("Non existing Message for UUID: " + uid);
-
- message = Util.deserialize((Serializable)Base64.decodeToObject(rs.getString(3)));
-
-
- } catch (SQLException e) {
- e.printStackTrace();
- return null;
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }finally { release(); }
-
+ if (!rs.next())
+ throw new MessageStoreException("Non existing Message for UUID: " + uid);
+
+ message = Util.deserialize((Serializable) Base64.decodeToObject(rs
+ .getString(3)));
+
+ }
+ catch (SQLException e)
+ {
+ throw new MessageStoreException(e);
+ }
+ catch (Exception e)
+ {
+ throw new MessageStoreException(e);
+ }
+ finally
+ {
+ release();
+ }
+
return message;
-
+
}
-
- private void release() {
-
- if (conn != null) {
- if (rs != null) {
- try{
+
+ private void release ()
+ {
+
+ if (conn != null)
+ {
+ if (rs != null)
+ {
+ try
+ {
rs.close();
- }catch (Exception e) {}
+ }
+ catch (Exception e)
+ {
+ }
}
- try{
+
+ try
+ {
ps.close();
- }catch (Exception e1){}
- try{
+ }
+ catch (Exception e1)
+ {
+ }
+
+ try
+ {
conn.close();
- }catch(Exception e2){}
+ }
+ catch (Exception e2)
+ {
+ }
}
}
-
-
-
-
-
}
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java 2007-01-20 23:50:44 UTC (rev 8948)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/services/routing/cbr/JBossRulesRouter.java 2007-01-21 09:33:55 UTC (rev 8949)
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.internal.soa.esb.services.routing.cbr;
import java.io.IOException;
@@ -35,172 +35,235 @@
import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
+import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilder;
import org.drools.rule.Package;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.services.routing.MessageRouter;
+import org.jboss.soa.esb.services.routing.cbr.CBRException;
import org.jboss.soa.esb.services.routing.cbr.ContentBasedRouter;
/**
- * The Implementation of a rule based Content Router. Here we use JBossRules.
- * We keep a HashMap of so called working memories for performance reasons.
+ * The Implementation of a rule based Content Router. Here we use JBossRules. We
+ * keep a HashMap of so called working memories for performance reasons.
*
* @author kstam at redhat.com
- *
+ *
*/
-public class JBossRulesRouter extends ContentBasedRouter
+public class JBossRulesRouter extends ContentBasedRouter
{
- private static Map<String,RuleBase> ruleBases=new ConcurrentHashMap<String,RuleBase>();
- private static Map<String,String> ruleSets=new ConcurrentHashMap<String,String>();
+ private static Map<String, RuleBase> ruleBases = new ConcurrentHashMap<String, RuleBase>();
+
+ private static Map<String, String> ruleSets = new ConcurrentHashMap<String, String>();
+
private static Logger logger = Logger.getLogger(JBossRulesRouter.class);
+
/**
- * Route the message, where the routing rules are supplied as part of
- * the message itself. We don't support this yet, as I don't see
- * the need right now. However when the need arises, this is were it
- * goes.
- * @param message - Message that needs routing.
+ * Route the message, where the routing rules are supplied as part of the
+ * message itself. We don't support this yet, as I don't see the need right
+ * now. However when the need arises, this is were it goes.
+ *
+ * @param message -
+ * Message that needs routing.
*/
- public List<String> route(Message message){
+ public List<String> route (Message message)
+ {
logger.log(Priority.ERROR, "Do not use, this is not implemented");
- //Route to /dev/null?
+ // Route to /dev/null?
return null;
}
+
/**
* Route the message, using the given ruleSet (drl).
*
- * @param ruleSet - Filename of the drl that will be used.
- * @param message - Message that needs routing.
+ * @param ruleSet -
+ * Filename of the drl that will be used.
+ * @param message -
+ * Message that needs routing.
*/
- public List<String> route(String ruleSet, boolean ruleReload, Message message) {
- return route(ruleSet, null, ruleReload, message);
- }
+ public List<String> route (String ruleSet, boolean ruleReload,
+ Message message)
+ {
+ return route(ruleSet, null, ruleReload, message);
+ }
+
/**
- * Route the message, where the routing rules are supplied as part of
- * the message itself. We don't support this yet, as I don't see
- * the need right now. However when the need arises, this is were it
- * goes.
+ * Route the message, where the routing rules are supplied as part of the
+ * message itself. We don't support this yet, as I don't see the need right
+ * now. However when the need arises, this is were it goes.
*
- * @param ruleSet - Filename of the drl that will be used.
- * @param ruleLanguage - Filename of the dsl that will be used.
- * @param message - Message that needs routing.
+ * @param ruleSet -
+ * Filename of the drl that will be used.
+ * @param ruleLanguage -
+ * Filename of the dsl that will be used.
+ * @param message -
+ * Message that needs routing.
*/
@SuppressWarnings("unchecked")
- public List<String> route(String ruleSet, String ruleLanguage, boolean ruleReload, Message message)
+ public List<String> route (String ruleSet, String ruleLanguage,
+ boolean ruleReload, Message message)
{
List<String> destinationServices = new ArrayList<String>();
- try {
- String newRuleSet=null;
- boolean isRulesChanged=false;
-
- if (ruleReload) {
+ try
+ {
+ String newRuleSet = null;
+ boolean isRulesChanged = false;
+
+ if (ruleReload)
+ {
String currentRuleSet = ruleSets.get(ruleSet);
newRuleSet = getRules(ruleSet, ruleLanguage);
- if (currentRuleSet==null || !currentRuleSet.equals(newRuleSet)) {
- isRulesChanged=true;
+ if (currentRuleSet == null || !currentRuleSet
+ .equals(newRuleSet))
+ {
+ isRulesChanged = true;
}
}
RuleBase ruleBase = ruleBases.get(ruleSet);
- if (ruleBase==null || isRulesChanged) {
- logger.log(Priority.INFO, "Reading ruleSet from file=" + ruleSet);
- ruleBase = readRuleBase(ruleSet, ruleLanguage);
- if (ruleBase!=null) ruleBases.put(ruleSet, ruleBase);
- if (newRuleSet==null) {
+ if (ruleBase == null || isRulesChanged)
+ {
+ logger.log(Priority.INFO,
+ "Reading ruleSet from file=" + ruleSet);
+ ruleBase = readRuleBase(ruleSet, ruleLanguage);
+ if (ruleBase != null) ruleBases.put(ruleSet, ruleBase);
+ if (newRuleSet == null)
+ {
newRuleSet = getRules(ruleSet, ruleLanguage);
}
- if (ruleSet!=null)ruleSets.put(ruleSet, newRuleSet);
+ if (ruleSet != null) ruleSets.put(ruleSet, newRuleSet);
}
WorkingMemory workingMemory = ruleBase.newWorkingMemory();
- logger.log(Priority.DEBUG, "Obtained message=" + message + " with ruleSet=" + ruleSet);
+ logger.log(Priority.DEBUG,
+ "Obtained message=" + message + " with ruleSet=" + ruleSet);
workingMemory.setGlobal("destinationServices", destinationServices);
workingMemory.assertObject(message);
logger.log(Priority.INFO, "Fire the JBossRules Engine");
workingMemory.fireAllRules();
- destinationServices = (List) workingMemory.getGlobal("destinationServices"); // is this needed?
- logger.log(Priority.DEBUG, "Destination Services List: " + destinationServices);
- Boolean isDeliverMessages = (Boolean) message.getProperties().getProperty(MessageRouter.DELIVER_MESSAGES);
- //Deliver the message to their desitinations unless told not to.
- if (!Boolean.FALSE.equals(isDeliverMessages)) {
+ destinationServices = (List) workingMemory
+ .getGlobal("destinationServices"); // is this needed?
+ logger.log(Priority.DEBUG,
+ "Destination Services List: " + destinationServices);
+ Boolean isDeliverMessages = (Boolean) message.getProperties()
+ .getProperty(MessageRouter.DELIVER_MESSAGES);
+ // Deliver the message to their desitinations unless told not to.
+ if (!Boolean.FALSE.equals(isDeliverMessages))
+ {
deliverMessages(destinationServices, message);
}
- } catch (Exception e) {
- logger.log(Priority.ERROR, e.toString() + ". Message is not routed.", e);
- //Route to /dev/null?
}
+ catch (Exception e)
+ {
+ logger.log(Priority.ERROR,
+ e.toString() + ". Message is not routed.", e);
+ // Route to /dev/null?
+ }
return destinationServices;
}
-
- /**
- * Reading the rules and dsl from files. Note that we may want to allow other ways to
- * set the rule, but for now it's just files.
- */
- private static RuleBase readRuleBase(String rulesFile, String ruleLanguage) throws Exception
+
+ /**
+ * Reading the rules and dsl from files. Note that we may want to allow
+ * other ways to set the rule, but for now it's just files.
+ */
+ private static RuleBase readRuleBase (String rulesFile, String ruleLanguage)
+ throws DroolsParserException, IOException, CBRException
{
- //read in the rules
+ // read in the rules
logger.debug("Going to read the rule: " + rulesFile);
- InputStream inputStreamDrl = JBossRulesRouter.class.getResourceAsStream( "/" + rulesFile );
- if (inputStreamDrl==null) {
+ InputStream inputStreamDrl = JBossRulesRouter.class
+ .getResourceAsStream("/" + rulesFile);
+ if (inputStreamDrl == null)
+ {
logger.error("Could not find rulesFile: " + rulesFile);
return null;
- } else {
+ }
+ else
+ {
Reader rules = new InputStreamReader(inputStreamDrl);
PackageBuilder builder = new PackageBuilder();
- //this wil parse and compile in one step
- if (ruleLanguage==null) {
+ // this wil parse and compile in one step
+ if (ruleLanguage == null)
+ {
builder.addPackageFromDrl(rules);
- } else {
+ }
+ else
+ {
logger.debug("Going to read the language: " + ruleLanguage);
- InputStream inputStreamDsl = JBossRulesRouter.class.getResourceAsStream( "/" + ruleLanguage );
- if (inputStreamDsl==null) {
+ InputStream inputStreamDsl = JBossRulesRouter.class
+ .getResourceAsStream("/" + ruleLanguage);
+ if (inputStreamDsl == null)
+ {
logger.error("Could not find ruleLanguage: " + rulesFile);
- } else {
+ }
+ else
+ {
Reader dsl = new InputStreamReader(inputStreamDsl);
builder.addPackageFromDrl(rules, dsl);
}
}
- //get the compiled package (which is serializable)
+ // get the compiled package (which is serializable)
Package pkg = builder.getPackage();
- //add the package to a rulebase (deploy the rule package).
- RuleBase ruleBase = RuleBaseFactory.newRuleBase();
- ruleBase.addPackage(pkg);
- return ruleBase;
+ // add the package to a rulebase (deploy the rule package).
+
+ try
+ {
+ RuleBase ruleBase = RuleBaseFactory.newRuleBase();
+ ruleBase.addPackage(pkg);
+
+ return ruleBase;
+ }
+ catch (Exception ex)
+ {
+ throw new CBRException(ex);
+ }
}
}
-
- /**
- * Reading the rules and dsl from files. Note that we may want to allow other ways to
- * set the rule, but for now it's just files.
- */
- private static String getRules(String rulesFile, String ruleLanguage) throws Exception
+
+ /**
+ * Reading the rules and dsl from files. Note that we may want to allow
+ * other ways to set the rule, but for now it's just files.
+ */
+ private static String getRules (String rulesFile, String ruleLanguage)
+ throws Exception
{
logger.debug("Going to hash the rule: " + rulesFile);
- InputStream inputStreamDrl = JBossRulesRouter.class.getResourceAsStream( "/" + rulesFile );
- if (inputStreamDrl==null) {
+ InputStream inputStreamDrl = JBossRulesRouter.class
+ .getResourceAsStream("/" + rulesFile);
+ if (inputStreamDrl == null)
+ {
logger.error("Could not find rulesFile: " + rulesFile);
return null;
- } else {
+ }
+ else
+ {
String rules = getString(inputStreamDrl);
String language = "";
- if (ruleLanguage!=null) {
+ if (ruleLanguage != null)
+ {
logger.debug("Going to hash the language: " + ruleLanguage);
- InputStream inputStreamDsl = JBossRulesRouter.class.getResourceAsStream( "/" + ruleLanguage );
- if (inputStreamDrl==null) {
+ InputStream inputStreamDsl = JBossRulesRouter.class
+ .getResourceAsStream("/" + ruleLanguage);
+ if (inputStreamDrl == null)
+ {
logger.error("Could not find language: " + ruleLanguage);
- } else {
+ }
+ else
+ {
language = getString(inputStreamDsl);
}
}
return rules + language;
}
-
+
}
-
- private static String getString(InputStream in) throws IOException
+
+ private static String getString (InputStream in) throws IOException
{
StringBuffer stringBuffer = new StringBuffer();
- byte[] b = new byte[4096];
- for (int i; (i = in.read(b)) != -1;) {
- stringBuffer.append(new String(b, 0, i));
- }
- return stringBuffer.toString();
+ byte[] b = new byte[4096];
+ for (int i; (i = in.read(b)) != -1;)
+ {
+ stringBuffer.append(new String(b, 0, i));
+ }
+ return stringBuffer.toString();
}
}
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java 2007-01-20 23:50:44 UTC (rev 8948)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/MessageRouter.java 2007-01-21 09:33:55 UTC (rev 8949)
@@ -69,6 +69,9 @@
* @param message -
* the message that needs routing and delivery
*/
+
+ // TODO handle failures?
+
public synchronized static void deliverMessages(
Collection<String> destinationServices, Message message)
{
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/CBRException.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/CBRException.java (rev 0)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/CBRException.java 2007-01-21 09:33:55 UTC (rev 8949)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.soa.esb.services.routing.cbr;
+
+/**
+ * Configuration Exception.
+ *
+ * @since Version 4.0
+ */
+public class CBRException extends Exception
+{
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Construct an exception instance.
+ *
+ * @param message
+ * Exception message.
+ */
+ public CBRException (String message)
+ {
+ super(message);
+ }
+
+ /**
+ * Construct an exception instance.
+ *
+ * @param message
+ * Exception message.
+ * @param cause
+ * Exception cause.
+ */
+ public CBRException (String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ /**
+ * Construct an exception instance.
+ *
+ * @param cause
+ * Exception cause.
+ */
+ public CBRException (Throwable cause)
+ {
+ super(cause);
+ }
+}
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouter.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouter.java 2007-01-20 23:50:44 UTC (rev 8948)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/routing/cbr/ContentBasedRouter.java 2007-01-21 09:33:55 UTC (rev 8949)
@@ -28,36 +28,43 @@
/**
* Content Based Router Interface.
- *
+ *
* @author kurt.stam at redhat.com
- *
+ *
*/
-public abstract class ContentBasedRouter extends MessageRouter {
- /**
- * Route a message using a certain ruleSet wich and reference a custom
- * Domain Specific Language (DSL).
- *
- * @param ruleSet - String reference to a file which contains
- * a ruleSet.
- * @param ruleLanguage - String reference to a file which contais
- * a custom rule language definition
- * @param ruleReload - if set to true, a ruleSet update should result
- * in reloading the ruleSet.
- * @param message - Message that needs routing.
- * @return List of routing destinations.
- */
- public abstract List < String > route(String ruleSet, String ruleLanguage,
- boolean ruleReload, Message message);
- /**
- * Route a message using a certain ruleSet.
- *
- * @param ruleSet - String reference to a file which
- * contains a ruleSet.
- * @param ruleReload - if set to true, a ruleSet update should result
- * in reloading the ruleSet.
- * @param message - Message that needs routing.
- * @return List of routing destinations.
- */
- public abstract List < String > route(String ruleSet,
- boolean ruleReload, Message message);
+public abstract class ContentBasedRouter extends MessageRouter
+{
+ /**
+ * Route a message using a certain ruleSet wich and reference a custom
+ * Domain Specific Language (DSL).
+ *
+ * @param ruleSet -
+ * String reference to a file which contains a ruleSet.
+ * @param ruleLanguage -
+ * String reference to a file which contais a custom rule
+ * language definition
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading
+ * the ruleSet.
+ * @param message -
+ * Message that needs routing.
+ * @return List of routing destinations.
+ */
+ public abstract List<String> route (String ruleSet, String ruleLanguage,
+ boolean ruleReload, Message message);
+
+ /**
+ * Route a message using a certain ruleSet.
+ *
+ * @param ruleSet -
+ * String reference to a file which contains a ruleSet.
+ * @param ruleReload -
+ * if set to true, a ruleSet update should result in reloading
+ * the ruleSet.
+ * @param message -
+ * Message that needs routing.
+ * @return List of routing destinations.
+ */
+ public abstract List<String> route (String ruleSet, boolean ruleReload,
+ Message message);
}
Modified: labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java 2007-01-20 23:50:44 UTC (rev 8948)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/esb/persistence/tests/MessageStoreUnitTest.java 2007-01-21 09:33:55 UTC (rev 8949)
@@ -23,8 +23,8 @@
/**
* @author dbrum
- *
- *
+ *
+ *
*/
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -53,152 +53,189 @@
import org.junit.BeforeClass;
import org.junit.Test;
+public class MessageStoreUnitTest
+{
-public class MessageStoreUnitTest {
-
-// private static Logger log = Logger.getLogger(MessageStoreUnitTest.class);
-
+ // private static Logger log = Logger.getLogger(MessageStoreUnitTest.class);
+
@Test
- public void testDefaultMessageStore() {
- MessageStore store = MessageStoreFactory.getInstance().getMessageStore();
+ public void testDefaultMessageStore ()
+ {
+ MessageStore store = MessageStoreFactory.getInstance()
+ .getMessageStore();
assertEquals((store != null), true);
}
-
+
@Test
- public void testURIMessageStore() {
- //only DB supported for now
- MessageStore store1 = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
+ public void testURIMessageStore ()
+ {
+ // only DB supported for now
+ MessageStore store1 = MessageStoreFactory.getInstance()
+ .getMessageStore(MessageStoreType.DATABASE);
assertEquals((store1 != null), true);
}
-
+
@Test
- public void testStoreAndRetrieve() {
- //add new messages
- Message msg1 = MessageFactory.getInstance().getMessage(MessageType.JBOSS_XML);
- Message msg2 = MessageFactory.getInstance().getMessage(MessageType.JAVA_SERIALIZED);
+ public void testStoreAndRetrieve () throws Exception
+ {
+ // add new messages
+ Message msg1 = MessageFactory.getInstance().getMessage(
+ MessageType.JBOSS_XML);
+ Message msg2 = MessageFactory.getInstance().getMessage(
+ MessageType.JAVA_SERIALIZED);
assertEquals((msg1 != null), true);
assertEquals((msg2 != null), true);
-
- MessageStore store = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
+
+ MessageStore store = MessageStoreFactory.getInstance().getMessageStore(
+ MessageStoreType.DATABASE);
assertEquals((store != null), true);
-
- //set some properties inside the Message
+
+ // set some properties inside the Message
msg1.getProperties().setProperty("prop1", "val1");
msg2.getProperties().setProperty("prop1", "val1");
msg1.getProperties().setProperty("prop2", "val2");
msg2.getProperties().setProperty("prop2", "val2");
-
- //set the body inside the Message
+
+ // set the body inside the Message
msg1.getBody().setContents(("TEST BODY").getBytes());
msg2.getBody().setContents(("TEST BODY").getBytes());
-
- //set some object attachments inside the Message
+
+ // set some object attachments inside the Message
msg1.getAttachment().addItem(new String("TEST ATTACHMENT1"));
- msg1.getAttachment().addItem(new String("TEST ATTACHMENT2"));
+ msg1.getAttachment().addItem(new String("TEST ATTACHMENT2"));
msg2.getAttachment().addItem(new String("TEST ATTACHMENT1"));
msg2.getAttachment().addItem(new String("TEST ATTACHMENT2"));
-
- //keep track of the UID to use in retrieving the Message
- URI uid1=null;
+
+ // keep track of the UID to use in retrieving the Message
+ URI uid1 = null;
uid1 = store.addMessage(msg1);
System.out.println(uid1);
assertEquals((uid1 != null), true);
-
+
URI uid2 = null;
uid2 = store.addMessage(msg2);
System.out.println(uid2);
assertEquals((uid2 != null), true);
-
- //now retrieve the messages
- try {
- Message msgIn1 = store.getMessage(uid1);
+
+ // now retrieve the messages
+ try
+ {
+ Message msgIn1 = store.getMessage(uid1);
assertEquals((msgIn1 != null), true);
-
+
Message msgIn2 = store.getMessage(uid2);
assertEquals((msgIn2 != null), true);
- } catch (Exception e) {
+ }
+ catch (Exception e)
+ {
e.printStackTrace();
}
}
-
+
@Test
- public void testDBConnectionManager() {
- MessageStore store = MessageStoreFactory.getInstance().getMessageStore(MessageStoreType.DATABASE);
- assertEquals((store != null), true);
+ public void testDBConnectionManager ()
+ {
+ MessageStore store = MessageStoreFactory.getInstance().getMessageStore(
+ MessageStoreType.DATABASE);
+ assertEquals((store != null), true);
DBConnectionManager mgr = DBConnectionManager.getInstance();
assertEquals((mgr != null), true);
- }
-
+ }
+
@BeforeClass
- public static void runBeforeAllTests() {
+ public static void runBeforeAllTests ()
+ {
TestEnvironmentUtil.setESBPropertiesFileToUse();
System.out.println(Configuration.dump());
- try {
- if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver")) {
- HsqldbUtil.startHsqldb(TestEnvironmentUtil.getUserDir() + "build/hsqltestdb", "jbossesb");
- //Get the registry-schema create scripts
+ try
+ {
+ if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver"))
+ {
+ HsqldbUtil.startHsqldb(
+ TestEnvironmentUtil.getUserDir() + "build/hsqltestdb",
+ "jbossesb");
+ // Get the registry-schema create scripts
String database = "hsqldb";
String sqlDir = TestEnvironmentUtil.getUserDir() + "install/message-store/sql/" + database + "/";
- //Drop what is there now, if exists. We want to start fresh.
- String sqlCreateCmd = MessageStoreUnitTest.readTextFile(new File(sqlDir + "create_database.sql"));
- String sqlDropCmd = MessageStoreUnitTest.readTextFile(new File(sqlDir + "drop_database.sql"));
-
- try {
+ // Drop what is there now, if exists. We want to start fresh.
+ String sqlCreateCmd = MessageStoreUnitTest
+ .readTextFile(new File(sqlDir + "create_database.sql"));
+ String sqlDropCmd = MessageStoreUnitTest.readTextFile(new File(
+ sqlDir + "drop_database.sql"));
+
+ try
+ {
Class.forName(Configuration.getStoreDriver());
- } catch (Exception e) {
- System.out.println("ERROR: failed to load " + database + " JDBC driver.");
+ }
+ catch (Exception e)
+ {
+ System.out
+ .println("ERROR: failed to load " + database + " JDBC driver.");
e.printStackTrace();
return;
}
-
+
DBConnectionManager mgr = DBConnectionManager.getInstance();
Connection con = mgr.getConnection();
Statement stmnt = con.createStatement();
System.out.println("Dropping the schema if exist");
stmnt.execute(sqlDropCmd);
System.out.println("Creating the message store schema");
- stmnt.execute(sqlCreateCmd);
+ stmnt.execute(sqlCreateCmd);
}
- } catch (Exception e) { //
+ }
+ catch (Exception e)
+ { //
e.printStackTrace();
- System.out.println("We should stop testing, since we don't have a db.");
+ System.out
+ .println("We should stop testing, since we don't have a db.");
assertTrue(false);
}
}
-
+
@AfterClass
- public static void runAfterAllTests() {
- try {
+ public static void runAfterAllTests ()
+ {
+ try
+ {
if (Configuration.getStoreDriver().equals("org.hsqldb.jdbcDriver"))
HsqldbUtil.stopHsqldb(Configuration.getStoreUrl(),
- Configuration.getStoreUser(),Configuration.getStorePwd() );
- } catch (Exception e) { //
+ Configuration.getStoreUser(), Configuration
+ .getStorePwd());
+ }
+ catch (Exception e)
+ { //
e.printStackTrace();
}
}
-
+
/**
- * Read the file into a String.
- * @param file - the file to be read
- * @return String with the content of the file
- * @throws IOException - when we can't read the file
- */
- public static String readTextFile(File file) throws IOException
- {
- StringBuffer sb = new StringBuffer(1024);
- BufferedReader reader = new BufferedReader(new FileReader(file.getPath()));
- char[] chars = new char[1];
- while( (reader.read(chars)) > -1){
- sb.append(String.valueOf(chars));
- chars = new char[1];
- }
- reader.close();
- return sb.toString();
- }
-
- public static junit.framework.Test suite() {
+ * Read the file into a String.
+ *
+ * @param file -
+ * the file to be read
+ * @return String with the content of the file
+ * @throws IOException -
+ * when we can't read the file
+ */
+ public static String readTextFile (File file) throws IOException
+ {
+ StringBuffer sb = new StringBuffer(1024);
+ BufferedReader reader = new BufferedReader(new FileReader(file
+ .getPath()));
+ char[] chars = new char[1];
+ while ((reader.read(chars)) > -1)
+ {
+ sb.append(String.valueOf(chars));
+ chars = new char[1];
+ }
+ reader.close();
+ return sb.toString();
+ }
+
+ public static junit.framework.Test suite ()
+ {
return new JUnit4TestAdapter(MessageStoreUnitTest.class);
}
-
}
Modified: labs/jbossesb/trunk/product/etc/schemas/validation/src/org/jboss/soa/esb/services/xml/XmlValidation.java
===================================================================
--- labs/jbossesb/trunk/product/etc/schemas/validation/src/org/jboss/soa/esb/services/xml/XmlValidation.java 2007-01-20 23:50:44 UTC (rev 8948)
+++ labs/jbossesb/trunk/product/etc/schemas/validation/src/org/jboss/soa/esb/services/xml/XmlValidation.java 2007-01-21 09:33:55 UTC (rev 8949)
@@ -1,24 +1,24 @@
/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
package org.jboss.soa.esb.services.xml;
import org.xml.sax.SAXException;
@@ -38,90 +38,106 @@
/**
* A Helper classes used to validate xml files against supplied schemas.
- *
- * @author $Revision$
- * $Id$
+ *
+ * @author $Revision$ $Id$
*/
-public class XmlValidation {
+public class XmlValidation
+{
- /**
- * Our Logger
- */
- private Logger log = Logger.getLogger(XmlValidation.class);
- /**
- * The xml base directory.
- */
- private String xmlBaseDirectory = null;
- /**
- * The xml base directory key.
- */
- private String xmlBaseDirectoryKey = "xml.base.dir";
- /**
- * The xsd base directory.
- */
- private String xsdBaseDirectory = null;
- /**
- * The xsd base directory key.
- */
- private String xsdBaseDirectoryKey = "xsd.base.dir";
- /**
- * The path separator
- */
- private static String SEP = System.getProperty("file.separator");
+ /**
+ * Our Logger
+ */
+ private Logger log = Logger.getLogger(XmlValidation.class);
- /**
- * Default class constructor
- */
- public XmlValidation() {
- if(System.getProperty(xmlBaseDirectoryKey) != null) {
- xmlBaseDirectory = System.getProperty(xmlBaseDirectoryKey);
- log.info("Using xml base directory " + xmlBaseDirectory);
- }
- if(System.getProperty(xsdBaseDirectoryKey) != null) {
- xsdBaseDirectory = System.getProperty(xsdBaseDirectoryKey);
- log.info("Using xsd base directory " + xsdBaseDirectory);
- }
- }
+ /**
+ * The xml base directory.
+ */
+ private String xmlBaseDirectory = null;
- /**
- * Validation method used to validate an xml file against an xsd.
- * @param xml The xml file to be validated.
- * @param xsd The schema to validate against.
- * @return Boolean true/false indicating successful validation.
- * @throws Exception Failure during validation.
- */
- public boolean validate(String xml, String xsd) throws Exception {
- if(log.isInfoEnabled()) {
- log.info("Validating " + xml + " Against " + xsd);
- }
- boolean isValid = false;
- File xmlFile = new File(xmlBaseDirectory + SEP + xml);
- File xsdFile = new File(xsdBaseDirectory + SEP + xsd);
- log.info("Xml File=" + xmlFile.getAbsolutePath());
- log.info("Xsd File=" + xsdFile.getAbsolutePath());
- DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document document = parser.parse(xmlFile);
- //log.info("Xml=" + document.toString());
- SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
- Source schemaFile = new StreamSource(xsdFile);
- //log.info("Xsd=" + schemaFile.toString());
- Schema schema = factory.newSchema(schemaFile);
- Validator validator = schema.newValidator();
- try {
- validator.validate(new DOMSource(document));
- isValid = true;
- } catch (SAXException e) {
- log.error("Failed to validate xml",e);
- throw e;
- }
- if(log.isInfoEnabled()) {
- log.info("IsValid = " + isValid);
- }
- return isValid;
- }
+ /**
+ * The xml base directory key.
+ */
+ private String xmlBaseDirectoryKey = "xml.base.dir";
+ /**
+ * The xsd base directory.
+ */
+ private String xsdBaseDirectory = null;
+ /**
+ * The xsd base directory key.
+ */
+ private String xsdBaseDirectoryKey = "xsd.base.dir";
+ /**
+ * The path separator
+ */
+ private static String SEP = System.getProperty("file.separator");
+ /**
+ * Default class constructor
+ */
+ public XmlValidation ()
+ {
+ if (System.getProperty(xmlBaseDirectoryKey) != null)
+ {
+ xmlBaseDirectory = System.getProperty(xmlBaseDirectoryKey);
+ log.info("Using xml base directory " + xmlBaseDirectory);
+ }
+ if (System.getProperty(xsdBaseDirectoryKey) != null)
+ {
+ xsdBaseDirectory = System.getProperty(xsdBaseDirectoryKey);
+ log.info("Using xsd base directory " + xsdBaseDirectory);
+ }
+ }
+ /**
+ * Validation method used to validate an xml file against an xsd.
+ *
+ * @param xml
+ * The xml file to be validated.
+ * @param xsd
+ * The schema to validate against.
+ * @return Boolean true/false indicating successful validation.
+ * @throws SAXException
+ * Failure during validation.
+ */
+ public boolean validate (String xml, String xsd) throws SAXException
+ {
+ if (log.isInfoEnabled())
+ {
+ log.info("Validating " + xml + " Against " + xsd);
+ }
+ boolean isValid = false;
+ File xmlFile = new File(xmlBaseDirectory + SEP + xml);
+ File xsdFile = new File(xsdBaseDirectory + SEP + xsd);
+ log.info("Xml File=" + xmlFile.getAbsolutePath());
+ log.info("Xsd File=" + xsdFile.getAbsolutePath());
+ DocumentBuilder parser = DocumentBuilderFactory.newInstance()
+ .newDocumentBuilder();
+ Document document = parser.parse(xmlFile);
+ // log.info("Xml=" + document.toString());
+ SchemaFactory factory = SchemaFactory
+ .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ Source schemaFile = new StreamSource(xsdFile);
+ // log.info("Xsd=" + schemaFile.toString());
+ Schema schema = factory.newSchema(schemaFile);
+ Validator validator = schema.newValidator();
+ try
+ {
+ validator.validate(new DOMSource(document));
+ isValid = true;
+ }
+ catch (SAXException e)
+ {
+ log.error("Failed to validate xml", e);
+ throw e;
+ }
+ if (log.isInfoEnabled())
+ {
+ log.info("IsValid = " + isValid);
+ }
+ return isValid;
+ }
+
}
More information about the jboss-svn-commits
mailing list